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!
Enjoy a smooth experience with Syncfusion’s Excel Library! Get started with a few lines of code and without Microsoft or interop dependencies.
Steps to convert XLS to XLSX format using C#
Step 1: Create a new .NET Core console application
First, create a new .NET Core console application in Visual Studio.
Refer to the following image.
Handle Excel files like a pro with Syncfusion’s C# Excel Library, offering well-documented APIs for each functionality.
Step 2: Install and configure the Excel Library
Then, add the Syncfusion.XlsIO.Net.Core NuGet package to your application.
Step 3: Convert XLS to XLSX format
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.
References
You can download the example demonstrating the conversion of XLS files to XLSX documents in C# on our GitHub demos.
Don't settle for ordinary spreadsheet solutions. Switch to Syncfusion and upgrade the way you handle Excel files in your apps!
Conclusion
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!
Related blogs
- Merge Multiple Excel Files into One in Just 3 Steps Using C#
- 6 Easy Ways to Export Data to Excel in C#
- Seamlessly Import and Export CSV Data in Excel Using C#
- How to Export Data from SQL Server to an Excel Table in C#
- Export Data from a Collection to Excel and Group It in C#
- Export Data to a Predefined Excel Template in C#
- Easy Steps to Export HTML Tables to Excel in C#