Dear All,
Please need your support i need to convert xlsx file to xls. can anyone share with me best solution.
Dear All,
Please need your support i need to convert xlsx file to xls. can anyone share with me best solution.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jayraj ChhayaPosted Jan 17, 2024, 10:57 AM
To convert an XLSX file to XLS format in C#, you can make use of the Microsoft Office Interop libraries. These libraries provide functionality to work with Excel files programmatically.
Here's an example of how you can convert a single XLSX file to XLS format:
In the above code, we create an instance of the
Excel.Applicationclass and open the XLSX file using theWorkbooks.Openmethod. We then save the workbook in XLS format using theSaveAsmethod with thexlExcel8file format. Finally, we close the workbook and quit the Excel application.To convert multiple XLSX files to XLS format, you can iterate over the files and call the
ConvertXlsxToXlsmethod for each file. Here's an example:In the above code, we iterate over the array of XLSX file paths and generate the corresponding XLS file path using the
Path.CombineandPath.GetFileNameWithoutExtensionmethods. We then call theConvertXlsxToXlsmethod to convert each XLSX file to XLS format.Remember to add a reference to the
Microsoft.Office.Interop.Excelassembly in your project.Leon DPosted Jan 22, 2024, 2:37 AM
Hello,
You can use Spire.XLS package to easily convert xlsx to xls and vice versa.
Here is an example that converts an xlsx file to xls format:
More details can be found in this documentation:
https://www.e-iceblue.com/Tutorials/Spire.XLS/Spire.XLS-Program-Guide/Excel-Conversion/NET-Excel-Conversion-between-Excel-97-2003.xls-and-Excel-2007.xlsx.html
Jignesh KumarPosted Jan 18, 2024, 7:55 AM
Hello Feroz,
Please use this code, use EPPlus Nuget package
Uttam ChaturvediPosted Jan 17, 2024, 2:45 PM
I would also recommend NPOI as a quite useful package
Microsoft Office Interop does'nt work on azure appservices
Tahir AnsariPosted Jan 17, 2024, 8:29 AM
First, you'll need to install the required NuGet packages. In your Visual Studio project, open the Package Manager Console and run the following commands:
Once the packages are installed, you can use the following code to convert a .xlsx file to .xls:
This code uses the EPPlus library to read the .xlsx file and the NPOI library to create a new .xls file with the same data.