Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 688
Hamzatovic Avatar asked Oct 25 '17 16:10

Hamzatovic


1 Answers

For reliably reading XLS files you could use ExcelDataReader which is a lightweight and fast library written in C# for reading Microsoft Excel files. It supports the import of Excel files all the way back to version 2.0 of Excel (released in 1987!)

Alternatively you could use a file conversion API like Zamzar. This service has been around for 10+ years, and provides a simple REST API for file conversion - it supports XLS to XLSX conversion. You can use it in C# and it has extra features like allowing you to import and export files to and from Amazon S3, FTP servers etc.

Full disclosure: I'm the lead developer for the Zamzar API.

like image 186
Chris Whyley Avatar answered Oct 05 '22 23:10

Chris Whyley