How to Convert Excel to PNG in Python

Cloudmersive
1 min readMar 12, 2024

--

We can make Excel to PNG conversions a breeze by calling a free API with complementary Python code.

Let’s start with installing the client SDK. Let’s run this command to install via pip install:

pip install cloudmersive-convert-api-client

Before we call the function, let’s get a free Cloudmersive API key to authorize our calls. This will allow us to make a limit of 800 API calls per month with zero commitments.

Now we can finish up by adding the imports and calling the function. We can provide our Excel document file path to make our conversion:

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 PNG image array
api_response = api_instance.convert_document_xlsx_to_png(input_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling ConvertDocumentApi->convert_document_xlsx_to_png: %s\n" % e)

We’ll receive one PNG file per page of our Excel document.

Nice and easy — that’s all the code we’ll need.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet