How to Convert Excel XSLX Documents to HTML in C# .NET Framework
With our Excel spreadsheet content in HTML format, we can easily display important data in our web browsers and take advantage of advanced HTML formatting elements. To make that conversion using code, we’ll need a straightforward solution that gets the job done.
Using the ready-to-run code examples below, we can easily take advantage of a free API that converts Excel spreadsheets to HTML documents in C# .NET framework. Once we receive our HTML result in a plain text string, we can use that content wherever and however we want.
We can begin structuring our API call by installing the SDK. Let’s take care of that by running the below command in the Package Manager console (to install via NuGet):
Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 3.4.2
With installation out of the way, let’s turn our attention to request authorization. We’ll need a free-tier API key for that; these allow a limit of 800 API calls per month with no additional commitments (our call limit will simply reset the following month once reached).
Now let’s call the function using the below code examples. We can copy our API key into the appropriate snippet, and we can then make our request with multipart/form-data.
using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;
namespace Example
{
public class ConvertDocumentXlsxToHtmlExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
var apiInstance = new ConvertDocumentApi();
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 Spreadsheet to HTML Document
byte[] result = apiInstance.ConvertDocumentXlsxToHtml(inputFile);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentXlsxToHtml: " + e.Message );
}
}
}
}
Just like that, we can now easily convert Excel files to HTML strings & expand our data presentation capabilities.