Hi,
I want to save an excel file with specific wroksheet to a csv file.
How to write this?
thans.
Save an excel file to a csv file
Re: Save an excel file to a csv file
Hey
You can use the below code
This works for Office 2013 Excel Interop lib.
BR
Manish
You can use the below code
Code: Select all
string inputFilepath = @"C:\temp\testtable.xlsx";
string outputFilepath = @"C:\Temp\output.csv";
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.ApplicationClass();
Microsoft.Office.Interop.Excel.Workbook wb = app.Workbooks.Open(inputFilepath);
wb.SaveAs(outputFilepath, Microsoft.Office.Interop.Excel.XlFileFormat.xlCSVWindows);
wb.Close(false);
app.Quit();
BR
Manish
Re: Save an excel file to a csv file
Hi manish,
Thanks you so much for your reply.
I also use Office 2013 Excel Interop .
I found an error [HRESULT 0x800A03EC] When I run your code.
Thanks you so much for your reply.
I also use Office 2013 Excel Interop .
I found an error [HRESULT 0x800A03EC] When I run your code.
Re: Save an excel file to a csv file
Hi,
Do you use .xls or .xlsx file extension for the excel sheet you are using?
Once you save the file as .xlsx, it should work fine.
Do you use .xls or .xlsx file extension for the excel sheet you are using?
Once you save the file as .xlsx, it should work fine.
Re: Save an excel file to a csv file
Hi,
I save with .xlsx. I repair a little.
I save with .xlsx. I repair a little.
Code: Select all
string inputFile = @"C:\Users\Administrator\Desktop\TestingCopy123.xlsx";
string outputFile = @"C:\Users\Administrator\Desktop\TestingCopy123__Csv.csv";
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.ApplicationClass();
Microsoft.Office.Interop.Excel.Workbook wb = app.Workbooks.Open(inputFile);
Microsoft.Office.Interop.Excel.Worksheet xlSheet = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets["Sheet1"];
wb.SaveAs(outputFile,Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV);
wb.Close(false);
app.Quit();