Convert Excel XLSX Files to XML Files in C#

Cloudmersive
1 min readFeb 24, 2022

Transition your Excel files to a more storage & transport-friendly format using the /convert/xlsx/to/xml iteration of the Cloudmersive Convert API. With code from the Cloudmersive API Console, you can connect in a few easy steps. If you’ve never used a Cloudmersive API before, head to the Cloudmersive website before you get started to create a free account (zero commitments) and receive your API key. Below, we’ll walk through how to use this API in C#.

If you’re working in a .NET environment, first install the SDK:

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 3.4.2using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;

If you’re using .NET Core, use the following instead:

Install-Package Cloudmersive.APIClient.NETCore.DocumentAndDataConvert -Version 2.2.1using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Api;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Client;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Model;

Now you can simply copy the below code to complete the function — and you’re all set.

namespace Example
{
public class ConvertDataXlsxToXmlExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
var apiInstance = new ConvertDataApi();
var inputFile = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Input file to perform the operation on.
try
{
// Convert Excel XLSX to XML conversion
byte[] result = apiInstance.ConvertDataXlsxToXml(inputFile);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ConvertDataApi.ConvertDataXlsxToXml: " + e.Message );
}
}
}
}

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.