Conversion between Excel 97-2003 and Excel 2007 in C#

To make backward and forward compatibility easier, Spire.XLS allows you to convert existing excel worksheets to another Excel version. In this article, we will show you how to convert .xls file to .xlsx file and convert .xlsx file to .xls in C# in only several lines of codes.

Firstly, Download Spire.XLS for .NET and install it on your system. The Spire.XLS installation is clean, professional and wrapped up in a MSI installer. Then, adds Spire.XLS.dll as reference in the downloaded Bin folder thought the below path: "..\Spire.XLS\Bin\NET4.0\ Spire.XLS.dll".

Spire.XLS has a powerful conversion function and it supports many elements, such as table, chart, shape, smart art, pivot table, header and footer etc.

Here comes to the steps of how to convert Excel 97-2003(.xls) workbook to Excel 2007, Excel 2010 (.xlsx) workbook.

// create a new excel document
Workbook book = new Workbook();

//load a document from file
book.LoadFromFile("test.xls");

//Save the file to the version you want
book.SaveToFile("test.xlsx", ExcelVersion.Version2007);

With the following code snippet, we convert a document from new excel version 2007 (.xlsx file) to older version excel 97-2003 (.xls file).

Workbook book = new Workbook();
book.LoadFromFile("XLS1.xlsx");
book.SaveToFile("result.xls", ExcelVersion.Version97to2003);

Please check the screenshot of the results. The added Evaluation warning worksheet will be removed once you apply the license file of Spire.XLS.

Convert .xls file to .xlsx file:

Convert .xls file to .xlsx file.

Convert .xlsx file to .xls file:

Convert .xlsx file to .xls file.