How to open an existing XLSX workbook and save it as XLS?
3 Nov 20252 minutes to read
You can open and save an existing .xlsx file to the .xls file by using XlsIO. The following code snippet illustrates this.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
//Open an existing Excel 2013 file
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx", ExcelOpenType.Automatic);
//Save it as "Excel 97 to 2003" format
workbook.SaveAs("Output.xls");
workbook.Close();
excelEngine.Dispose();
}using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
//Open an existing Excel 2013 file
IWorkbook workbook = excelEngine.Excel.Workbooks.Open("Sample.xlsx", ExcelOpenType.Automatic);
//Save it as "Excel 97 to 2003" format
workbook.Version = ExcelVersion.Excel97to2003;
workbook.SaveAs("Output.xls");
}Using excelEngine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Excel2013
'Open an existing Excel 2013 file
Dim workbook As IWorkbook = excelEngine.Excel.Workbooks.Open("Sample.xlsx", ExcelOpenType.Automatic)
'Save it as "Excel 97 to 2003" format
workbook.Version = ExcelVersion.Excel97to2003
workbook.SaveAs("Output.xls")
End UsingNOTE
Workbook must be saved in appropriate version, failing in this leads to file corruption.
See Also
- How to open an Excel file from stream?
- How to open an Excel 2013 Macro Enabled Template?
- How to create and open Excel Template files by using XlsIO?
- How to save a file to stream?
- How to merge excel files from more than one workbook to a single file?
- How to opening an existing workbook?
- How to save an Excel workbook to file system?