C# Convert Excel 2007 (xlsx) file into Excel 2003 (xls) file
11,737
Solution 1
Try with to save with XlFileFormat.xlExcel9795
. You can also use XlFileFormat.xlWorkbookNormal
Solution 2
Your enum is wrong, instead of XlFileFormat.xlOpenXMLTemplate you want XlFileFormat.xlExcel8, so your code would be like so:
string fileName = @"C:\Users\L-3\Desktop\my.xlsx";
string svfileName = @"C:\Users\L-3\Desktop\ssc\my1.xls";
object oMissing = Type.Missing;
var app = new Microsoft.Office.Interop.Excel.Application();
var wb = app.Workbooks.Open(fileName, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
wb.SaveAs(svfileName, XlFileFormat.xlExcel8, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
app.Quit();
More info here.
Author by
Sangram Nandkhile
SOreadytohelp Full Stack .NET developer, Melbourne, Australia Linkedin: https://www.linkedin.com/in/sangram-nandkhile/
Updated on June 22, 2022Comments
-
Sangram Nandkhile almost 2 years
I am working on a console application which will convert xlsx file into xls file. I don't want to rename it from xlsx to xls because it will get opened in excel 2007 but it will be shown as corrupted file in excel 2003. Looking for a way which will load the document and then it will be saved as xls format.
My current code Just renames the xlsx to xls
string fileName = @"C:\Users\L-3\Desktop\my.xlsx"; string svfileName = @"C:\Users\L-3\Desktop\ssc\my1.xls"; object oMissing = Type.Missing; var app = new Microsoft.Office.Interop.Excel.Application(); var wb = app.Workbooks.Open(fileName, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing); wb.SaveAs(svfileName, XlFileFormat.xlOpenXMLTemplate, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); app.Quit();