I have a text file that is comma delimited. some numbers are representing Codes or Credit Card numbers and they should show in the Excel as TEXT and should not be treated as numbers (left Zero is important )
here is my code:
m_objBooks.OpenText(
Filename: _fileInfo.FullName,
Origin: Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,
StartRow: 1,
DataType: Microsoft.Office.Interop.Excel.XlTextParsingType.xlDelimited,
TextQualifier: Microsoft.Office.Interop.Excel.XlTextQualifier.xlTextQualifierDoubleQuote,
ConsecutiveDelimiter: false,
Tab: false,
Semicolon: false,
Comma: true,
Space: false,
Other: false,
OtherChar: m_objOpt,
FieldInfo: m_objOpt,
TextVisualLayout: m_objOpt,
DecimalSeparator: m_objOpt,
ThousandsSeparator: m_objOpt,
TrailingMinusNumbers: m_objOpt,
Local: m_objOpt
);
m_objBook = m_objExcel.ActiveWorkbook;
// Save the text file in the typical workbook format and quit Excel.
m_objBook.SaveAs(excelFile, Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook,
m_objOpt, m_objOpt, m_objOpt, m_objOpt,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, m_objOpt, m_objOpt,
m_objOpt, m_objOpt);
m_objBook.Close(false, m_objOpt, m_objOpt);
m_objExcel.Quit();
Although the Code and Credit Card fields has the Double Quotes around them, the generated excel file still treats them as numbers by removing the Left Zero and stuff like that. why?