Hi Sir,
Could anyone help me to revise or update this code in converting text file to excel in proper format (with header and proper column)? the code below converts text file to excel file but I need the clear output in excel file in a standard format by column. Here's the sample text file data input and my code.
Here's my sample text file:
tag ord_no ref_no acv_no prog_no prog_date acv_type_id
--- ----------- -------- ------- ---------- -------------------------- -------------
DL 6636500 1 9 11 Feb 3 2011 11:11AM DLINSTLN
DL 6649978 1 10 8 Feb 4 2011 12:29PM DLINSTLN
DL 6722809 1 6 3 Feb 2 2011 5:35PM DLINSTLN
Here's my C# code in converting text file to excel:
private void Convert_TextFile_To_ExcelFile()
{
// Open the text file in Excel.
m_objExcel = new Microsoft.Office.Interop.Excel.Application();
m_objBooks = (Microsoft.Office.Interop.Excel.Workbooks)m_objExcel.Workbooks;
m_objBooks.OpenText(m_strSampleFolder + "sampledoc.txt",
Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, 1,
Microsoft.Office.Interop.Excel.XlTextParsingType.xlDelimited,
Microsoft.Office.Interop.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;
// Save the text file in the typical workbook format and quit Excel.
m_objBook.SaveAs(m_strSampleFolder + "sampledoc.xls",
Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal,
m_objOpt, m_objOpt, m_objOpt, m_objOpt,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt);
m_objBook.Close(false, m_objOpt, m_objOpt);
m_objExcel.Quit();
}
Loading

Amit ChoudharyRank #145 · 15.8K reputationPosted Feb 10, 2011, 9:19 PM EST
Seems like you have generated the txt file from some tool itself.. it'll be easy to generate the excel if the txt file is in some comma separated or some other separation way..
Thanks
jess romero14 reputationPosted Feb 10, 2011, 9:27 PM EST
Amit ChoudharyRank #145 · 15.8K reputationPosted Feb 11, 2011, 1:33 AM EST
jess romero14 reputationPosted Feb 14, 2011, 2:15 PM EST