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 Using

NOTE

Workbook must be saved in appropriate version, failing in this leads to file corruption.

See Also