Saving Excel file as text or comma delimited from C#

D

dd

I am kind of puzzled with this problem.
I am trying to open an xls file from C# and then save it as text or comma
delimited. Here is the code:
Excel.ApplicationClass oExcelApp = new Excel.ApplicationClass();
Object oMissing = System.Reflection.Missing.Value;
Excel.Workbook oWB = oExcelApp.Workbooks.Open(sFileName, oMissing,
oMissing,oMissing, oMissing,oMissing, oMissing, oMissing,
oMissing,oMissing,oMissing, oMissing, oMissing);
object oSaveFileName = REPOSITORY_PATH + System.Guid.NewGuid().ToString() +
".txt";
oExcelApp.ActiveWorkbook.SaveAs(oSaveFileName,
Excel.XlFileFormat.xlCSVWindows, oMissing, oMissing, oMissing,oMissing,
Excel.XlSaveAsAccessMode.xlShared, oMissing, oMissing, oMissing, oMissing);

I am getting an exception: "An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in Test1.exe
Additional information: Exception from HRESULT: 0x800A03EC."

When I change Excel.XlFileFormat.xlCSVWindows to
Excel.XlFileFormat.xlWorkbookNormal it works fine saving as an Excel file.

Can please anybody help?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top