How to Easily Convert Excel XLSX to PDF in Python

Cloudmersive
2 min readMay 28, 2024

--

Converting our Excel spreadsheets to PDF is an important and highly repetitive task. Thankfully, it’s one we can easily simplify with a free API.

Using the below code, we can easily call a free document conversion API that performs high-fidelity Excel to PDF conversions. We can use this solution to quickly automate our Excel to PDF conversion process, leaving us with more time to focus on other pressing needs in our Python projects.

We can structure our API call in two quick steps.

First, we need to run the following pip install command to install the client SDK:

pip install cloudmersive-convert-api-client

Next, we can use the below code to add our imports and call the function:

from __future__ import print_function
import time
import cloudmersive_convert_api_client
from cloudmersive_convert_api_client.rest import ApiException
from pprint import pprint

# Configure API key authorization: Apikey
configuration = cloudmersive_convert_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'



# create an instance of the API class
api_instance = cloudmersive_convert_api_client.ConvertDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))
input_file = '/path/to/inputfile' # file | Input file to perform the operation on.

try:
# Convert Excel XLSX Spreadsheet to PDF
api_response = api_instance.convert_document_xlsx_to_pdf(input_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling ConvertDocumentApi->convert_document_xlsx_to_pdf: %s\n" % e)

Before we start converting our Excel files to PDF, we’ll need to authorize our API calls with a free Cloudmersive API key. This will allow us to make up to 800 conversions per month with zero additional commitments, and we can simply replace ‘YOUR_API_KEY’ placeholder text with our API key string once we have it.

That’s all there is to it! Now we can quickly and easily convert our Excel documents to PDF with just a few lines of Python code.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet