How to Convert Excel Workbooks to a PDF in Python
Microsoft Excel is the go-to program for organizing large amounts of data using pivot tables, formulas, graphing tools and more. However, the information contained in the documents can be easily damaged by the simplest mis-key. Converting the spreadsheet to a PDF file will ensure the quality and message of your data remains stable when shared with customers or partners.
The following API will assist in transforming all worksheets in your XLSX or XLSB workbook to an easily shareable PDF file.
Our first step is to run this command to install the SDK:
pip install cloudmersive-convert-api-client
Next, we can call the conversion function with the following code:
from __future__ import print_function
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)
except ApiException as e:
print("Exception when calling ConvertDocumentApi->convert_document_xlsx_to_pdf: %s\n" % e)
The returned result will provide you with a new PDF file with all your data intact. To retrieve your free API key and receive 800 calls/month, simply visit the Cloudmersive website and register for the base account.