C#/VB.NET: Convert Excel to Open XML or Open XML to Excel

2023-05-04 06:38:00 Written by  support iceblue
Rate this item
(1 Vote)

Open XML is an XML-based file format developed by Microsoft that allows users to store and exchange various types of files such as word processing documents, spreadsheets, presentations, charts, and diagrams. It is widely recognized and supported by various applications, making it a reliable choice for long-term data preservation.

In some cases, it may be necessary to convert Excel files to Open XML format to ensure that these files can be opened and read by other software. On the other hand, there may be situations where users need to convert Open XML files to Excel format to take advantage of the data analysis tools available in Excel, such as pivot tables and charts. In this article, we will introduce how to convert Excel to Open XML or Open XML to Excel 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 Excel to Open XML in C# and VB.NET

To convert an Excel file to Open XML, you need to load the Excel file using the Workbook.LoadFromFile(string fileName) method, then call the Workbook.SaveAsXml(string fileName) method to save it in Open XML format.

The following steps demonstrate how to convert an Excel file to Open XML:

  • Initialize an instance of the Workbook class.
  • Load an Excel file using the Workbook.LoadFromFile(string fileName) method.
  • Call the Workbook.SaveAsXml(string fileName) method to save the Excel file in Open XML format.
  • C#
  • VB.NET
using Spire.Xls;

namespace ConvertExcelToOpenXML
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Workbook class
            Workbook workbook = new Workbook();
            //Load an Excel file
            workbook.LoadFromFile("Sample.xlsx");

            //Save the Excel file in Open XML file format
            workbook.SaveAsXml("ExcelToXML.xml");
        }
    }
}

C#/VB.NET: Convert Excel to Open XML or Open XML to Excel

Convert Open XML to Excel in C# and VB.NET

To convert an Open XML file to Excel, you need to load the Open XML file using the Workbook.LoadFromXml(string fileName) method, then call the Workbook.SaveToFile(string fileName, ExcelVersion version) method to save it in Excel format.

The following are the steps to convert an Open XML file to Excel:

  • Initialize an instance of the Workbook class.
  • Load an Open XML file using the Workbook.LoadFromXml(string fileName) method.
  • Call the Workbook.SaveToFile(string fileName, ExcelVersion version) method to save the Open XML file in Excel format.
  • C#
  • VB.NET
using Spire.Xls;

namespace ConvertOpenXMLToExcel
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Workbook class
            Workbook workbook = new Workbook();
            //Load an Open XML file
            workbook.LoadFromXml("ExcelToXML.xml");

            //Save the Open XML file in Excel XLSX file format
            workbook.SaveToFile("XMLToExcel.xlsx", ExcelVersion.Version2016);
        }
    }
}

C#/VB.NET: Convert Excel to Open XML or Open XML to Excel

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, 04 May 2023 01:28