Converting XLS to XLSX Format in Just 3 Steps Using C#

Jollen Moyani - Jan 31 - - Dev Community

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!

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.

Create a .NET Core Console application in Visual StudioStep 2: Install and configure the Excel Library

Then, add the Syncfusion.XlsIO.Net.Core NuGet package to your application.

Install Syncfusion.XlsIO.Net.Core NuGet packageStep 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();
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Refer to the following image showing the input Excel document.

Input Excel document

Input Excel document

After executing the provided code example, the output document will resemble the following image.

Converting XLS to XLSX format using Syncfusion Excel Library in C#

Converting XLS to XLSX format using Syncfusion Excel Library in C#

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.

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

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .