In today’s fast-paced technological landscape, staying up to date is crucial for seamless data management. The XLS (Excel 97-2003) format has limited features compared to the latest XLSX format. Converting XLS documents to XLSX format will enable you to explore more features of Excel and avoid compatibility issues. This is where the Syncfusion Excel Library becomes invaluable, allowing you to perform conversion easily.
The Syncfusion Excel Library , also known as Essential XlsIO, is a robust tool that facilitates the smooth creation, reading, and editing of Excel documents using C#. It supports the creation of Excel documents from scratch, modification of existing Excel documents, import and export of data, Excel formulas, conditional formats, data validations, charts, sparklines, tables, pivot tables, pivot charts, template markers, and much more.
One of the key features of the Syncfusion Excel Library is its ability to open and convert XLS files to XLSX format with just a few lines of code.
Let’s see how to achieve this!
First, create a new .NET Core console application in Visual Studio.
Refer to the following image.
Then, add the Syncfusion.XlsIO.Net.Core NuGet package to your application.
Finally, implement the following code in the Program.cs file to convert an XLS file to an XLSX document from a designated folder path.
using Syncfusion.XlsIO; using System.IO; namespace ConvertXlsToXlsx { class Program { private static string inputPath = @"../../../Data/"; private static string outputPath = @"../../../Output/"; static void Main(string[] args) { string fileName = "Report.xls"; // Convert the Excel document ConvertXlsToXLSX(inputPath + fileName); } /// <summary> /// Convert the Excel document from the given path. /// </summary> /// <param name="filePath">Excel file path</param> private static void ConvertXlsToXLSX(string filePath) { FileStream inputData = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite); using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; IWorkbook workbook = application.Workbooks.Open(inputData); IWorksheets worksheets = workbook.Worksheets; workbook.Version = ExcelVersion.Xlsx; FileStream fileStream = new FileStream(outputPath + Path.GetFileNameWithoutExtension(filePath) + ".xlsx", FileMode.Create, FileAccess.ReadWrite); workbook.SaveAs(fileStream); fileStream.Close(); } } } }
Refer to the following image showing the input Excel document.
After executing the provided code example, the output document will resemble the following image.
Note: For more details, explore the XLS features by Syncfusion Excel Library.
You can download the example demonstrating the conversion of XLS files to XLSX documents in C# on our GitHub demos.
Thanks for reading! In this blog, we explored how to convert XLS files to XLSX documents in C# with the Syncfusion Excel Library (XlsIO). With the Excel Library, you can also export Excel data to PDF, images, data tables, CSV, TSV, HTML, collections of objects, ODS , JSON, and more file formats.
Take a moment to peruse the import data documentation, where you’ll discover additional importing options and features such as data tables, collection objects, grid view, data columns, and HTML, all accompanied by code samples.
Feel free to try out these methods and share your feedback in the comments section of this blog post!
For existing customers, the new version of Essential Studio® is available for download from the License and Downloads page. If you are not yet a Syncfusion customer, you can try our 30-day free trial to check out our available features.
For questions, you can contact us through our support forum, support portal, or feedback portal. We are happy to assist you!