Hi,
I have follwing C# code which opens that tab delimited .txt file and does the saveas to Excel file. Problem what I am running into is some of the text field has value such as "91010105212974 61515213" is getting converted to "9.10101E+2 1". How do I prevent getting converted to scientific notation and leave as text instead using below function ?
I have follwing C# code which opens that tab delimited .txt file and does the saveas to Excel file. Problem what I am running into is some of the text field has value such as "91010105212974 61515213" is getting converted to "9.10101E+2 1". How do I prevent getting converted to scientific notation and leave as text instead using below function ?
Code:
public void SaveTextFileAsExcel(string filefrompath, string filetopath, string newtabname)
{
// Excel object references.
Excel.Application m_objExcel = new Excel.Application();
Excel.Workbooks m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
Excel._Workbook m_objBook = null;
Excel.Sheets m_objSheets = null;
Excel._Worksheet m_objSheet = null;
// Frequenty-used variable for optional arguments.
object m_objOpt = System.Reflection.Missing.Value;
if (filefrompath != "")
{
m_objBooks.OpenText(filefrompath, Excel.XlPlatform.xlWindows,1,
Excel.XlTextParsingType.xlDelimited, Excel.XlTextQualifier.xlTextQualifierDoubleQuote,
false, true, false, false, false, false,m_objOpt, m_objOpt,
m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt);
m_objBook = m_objExcel.ActiveWorkbook;
m_objSheets = m_objBook.Worksheets;
m_objSheet = (Excel.Worksheet)m_objSheets.get_Item(1);//Get the reference of second worksheet
string strWorksheetName = m_objSheet.Name;//Get the name of worksheet.
if (newtabname != "") { m_objSheet.Name = newtabname; }
if (filetopath !="")
{
// Save the text file in the typical workbook format and quit Excel.
m_objBook.SaveAs(filetopath, Excel.XlFileFormat.xlWorkbookNormal,
m_objOpt, m_objOpt, m_objOpt, m_objOpt, Excel.XlSaveAsAccessMode.xlNoChange, m_objOpt, m_objOpt,
m_objOpt, m_objOpt, m_objOpt);
} //if (filetopath !="")
} //if (filefrompath != "")
m_objBook.Close(false, m_objOpt, m_objOpt);
m_objExcel.Quit();
} //SaveAsExcel