General Excel File From a Flat File

If you want to generate a Excel file from a Flat file typically a TSV (Tab Seperated Values) , you can make use of the methods in the Excel Interop.

Here is a routine that does that task

 

public static void GenerateExcelFromFlatFile(string flatFileName, string newFileName) 


       { 


           //Create a Excel App Class 


           Excel.ApplicationClass app = new Excel.ApplicationClass(); 


           //Open the Flat File 


           Excel.Workbook wb=app.Workbooks._Open(flatFileName,Missing.Value,Missing.Value,Missing.Value, 


               Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value, Missing.Value,Missing.Value,Missing.Value); 


           //Save the Flat File as new XLFileFormat 


           wb.SaveAs(newFileName, Excel.XlFileFormat.xlWorkbookNormal, Missing.Value, 


               Missing.Value, Missing.Value, Missing.Value, Excel.XlSaveAsAccessMode.xlExclusive, 


               Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); 


           //Indicate whether saved 


           wb.Saved = true; 


           //Quit 


           app.Quit(); 


 


       }






 



Hope this Helps



Happy Coding!!!!

0 Responses to "General Excel File From a Flat File"

Post a Comment