How to convert xls file to xlsx file using C#?

Hamzatovic picture Hamzatovic · Oct 25, 2017 · Viewed 17.6k times · Source

I was developing an application which read data from an excel file, but when I try to open it, an exception  was thrown if the source file is saved with the xls format (File contains corrupted data error when opening Excel sheet with OpenXML). indeed when I save this file with the xlsx format it works fine. please help me to solve this problem.

Answer

j1rjacob picture j1rjacob · Apr 10, 2018

Use Free Spire.XLS dll available via NuGet.

Sample:

Workbook workbook = new Workbook();
workbook.LoadFromFile("Input.xls");
workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2013);