C # Convert Excel 2007 (xlsx) to Excel 2003 file (xls)

I am working on a console application that converts an xlsx file to an xls file. I do not want to rename it from xlsx to xls, because it will open in excel 2007, but it will be shown as a damaged file in excel 2003. You are looking for a way to download the document, and then it will be saved as xls format.

My current code is just renaming 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(); 
+6
source share
4 answers

Try saving with XlFileFormat.xlExcel9795 . You can also use XlFileFormat.xlWorkbookNormal

+1
source

Your listing is wrong, instead of XlFileFormat.xlOpenXMLTemplate you want XlFileFormat.xlExcel8 , so your code will be like this:

 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 details here .

+4
source

I found the following snippet from here :

 // Create new XLSX file. var xlsxFile = new ExcelFile(); // Load data from XLSX file. xlsxFile.LoadXlsx(fileName + ".xls", XlsxOptions.PreserveMakeCopy); // Save XLSX file to XLS file. xlsxFile.SaveXls(fileName + ".xls"); 

He uses this component .

0
source

I think this has the answer you are looking for:

What is the correct enumeration of `XlFileFormat` for Excel 97-2003

The file format is xlOpenXMLTemplate . Try using xlExcel8 ? This should be a file format for books 97-2003.

0
source

All Articles