How to Convert XLS to XLSX in C#

This quick tutorial describes how to convert XLS to XLSX in C# without using any third-party tool. It assists to customize the XLS loading operation to reduce the memory requirement and creation of XLSX files with the desired data only from the source XLS. To convert XLS to XLSX C# code is also provided that demonstrates not only the required conversion but also guides to customize the XLS loading process for avoiding unnecessary data to be copied to the converted XLSX.

Steps to Convert XLS to XLSX using C#

  1. Setup your application to add a reference to Aspose.Cells for .NET from the NuGet package manager
  2. Instantiate the LoadOptions class object to control the loading of the XLS file
  3. Configure the LoadOptions class object before loading the XLS file
  4. Load the XLS file into the Workbook object using the LoadOptions settings
  5. Save the loaded XLS file as XLSX on the disk

The above steps provide a step-by-step process to assist how using C# convert XLS to XLSX. This process is quite simple and a matter of a couple of lines of code if you want to just save the XLS to XLSX without any customization. However, for the learning purpose, steps and sample code are shared to control the XLS file loading operation like you filter data from the XLS and also set the flag to execute formulas automatically while opening the source XLS file.

Code to Convert XLS to XLSX in C#

This code uses the LoadOptions class object and demonstrates a few properties like memory settings, flag to parse formula once the file is opened, set password to open the file, and set filter to load data from sheets having pictures only. There are many other options also like checking Excel restrictions or not while entering data into cells, configuring the default fonts, setting paper size, and so on.

In this tutorial, we have learned in order to save XLS to XLSX C# based API can be effectively used. If you want to learn the process to convert Excel to an image, refer to the article on how to convert Excel to image in C#.

 English