How to Convert XLSX to PDF in C#

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):

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

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.

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store