C#/VB.NET: Convert XLS to XLSX and Vice versa

XLS and XLSX are two different file formats for Microsoft Excel spreadsheets. XLS is the default file format for Microsoft Excel 2003 and earlier versions, while XLSX is the default file format for Microsoft Excel 2007 and later versions. In some cases, developers may need to convert between Excel XLS and XLSX file formats. In this article, we will explain how to convert XLS to XLSX or XLSX to XLS in C# and VB.NET using Spire.XLS for .NET.

Install Spire.XLS for .NET

To begin with, you need to add the DLL files included in the Spire.XLS for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.XLS

Convert XLS to XLSX in C# and VB.NET

The following are the steps to convert an XLS file to XLSX format using Spire.XLS for .NET:

  • Create a Workbook instance.
  • Load the XLS file using Workbook.LoadFromFile() method.
  • Save the XLS file to XLSX format using Workbook.SaveToFile(string, ExcelVersion) method.
  • C#
  • VB.NET
using Spire.Xls;

namespace ConvertXlsToXlsx
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Workbook instance
            Workbook workbook = new Workbook();
            //Load an XLS file
            workbook.LoadFromFile("Input.xls");

            //Convert the file to XLSX format
            workbook.SaveToFile("ToXlsx.xlsx", ExcelVersion.Version2016);
        }
    }
}

C#/VB.NET: Convert XLS to XLSX and Vice versa

Convert XLSX to XLS in C# and VB.NET

The following are the steps to convert an XLSX file to XLS format using Spire.XLS for .NET:

  • Create a Workbook instance.
  • Load the XLSX file using Workbook.LoadFromFile() method.
  • Save the XLSX file to XLS format using Workbook.SaveToFile(string, ExcelVersion) method.
  • C#
  • VB.NET
using Spire.Xls;

namespace ConvertXlsxToXls
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Workbook instance
            Workbook workbook = new Workbook();
            //Load an XLSX file
            workbook.LoadFromFile("Input.xlsx");

            //Convert the file to XLS format
            workbook.SaveToFile("ToXls.xls", ExcelVersion.Version97to2003);
        }
    }
}

C#/VB.NET: Convert XLS to XLSX and Vice versa

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Additional Info

  • tutorial_title:
Last modified on Thursday, 25 August 2022 02:07