How to Convert XLSX to PDF in C#

Cloudmersive
2 min readFeb 22, 2021

No matter what industry you’re in, Excel spreadsheets are an excellent way to display detailed and/or confidential data with clients. Unfortunately, Excel also has a history of being hyper-sensitive due to the potential complexity of the structure; formulas, statistics, and programming can be skewed by a careless stroke of the keyboard. This is where our Excel to PDF conversion API can be particularly useful, since PDFs are known for their ability to keep the quality and form of the original source material.

To start the process, we will first install the .NET Core SDK (.NET Framework available as well):

Install-Package Cloudmersive.APIClient.NETCore.DocumentAndDataConvert -Version 2.0.7

The next step is to configure our API key, instance the API, and call the conversion function with the following code:

using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Api;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Client;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Model;
namespace Example
{
public class ConvertDocumentXlsxToPdfExample
{
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 PDF
byte[] result = apiInstance.ConvertDocumentXlsxToPdf(inputFile);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentXlsxToPdf: " + e.Message );
}
}
}
}

This will complete the process and deliver you a fresh PDF file to the specified output folder. Visit the Cloudmersive website to retrieve your free API key and gain access to 800 monthly calls across our library of APIs.

--

--

Cloudmersive

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