How to create a new Excel XLSX spreadsheet from column and row data in Python

Cloudmersive
2 min readMay 6, 2020

Creating new Excel files from within an app should be a breeze right? Well, not exactly. There are a number of considerations that need to be accounted for, and well, frankly it’s a hassle on an epic scale. So why don’t we just skip all that and create our Excel sheets a different way? With an easy to use API call, we will be able to generate new XLSX files from existing column and row data in a matter of seconds. If you would like to create blank files, you can use the function edit_document_xlsx_create_blank_spreadsheet instead.

Now let’s begin by first installing the Cloudmersive conversion API.

pip install cloudmersive-convert-api-client

Next we will be instantiating the API, which will then allow us to call edit_document_xlsx_create_spreadsheet_from_data, like so:

from __future__ import print_functionimport timeimport cloudmersive_convert_api_clientfrom cloudmersive_convert_api_client.rest import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_convert_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_convert_api_client.EditDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))input = cloudmersive_convert_api_client.CreateSpreadsheetFromDataRequest() # CreateSpreadsheetFromDataRequest | Document input requesttry:# Create a new Excel XLSX spreadsheet from column and row dataapi_response = api_instance.edit_document_xlsx_create_spreadsheet_from_data(input)pprint(api_response)except ApiException as e:print("Exception when calling EditDocumentApi->edit_document_xlsx_create_spreadsheet_from_data: %s\n" % e)

Done! Wasn’t that easy?

--

--

Cloudmersive

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