How to create a blank Excel XLSX spreadsheet in Python

Having the ability to create new Excel spreadsheets from within your app is important, but implementation of this can really be a challenge if you don’t approach it in the right way. In my mind, that right way is to not approach the problem at all. It’s not necessary when an API has already done it for me.

So we start things off with installation for our client using this command for pip install.

pip install cloudmersive-convert-api-client

The next step is having the client create an instance of our Edit Document API, and then using that instance to call the CreateBlankSpreadsheetRequest() method.

from __future__ import print_functionimport timeimport cloudmersive_convert_api_clientfrom 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.CreateBlankSpreadsheetRequest() # CreateBlankSpreadsheetRequest | Document input requesttry:# Create a blank Excel XLSX spreadsheetapi_response = api_instance.edit_document_xlsx_create_blank_spreadsheet(input)pprint(api_response)except ApiException as e:print("Exception when calling EditDocumentApi->edit_document_xlsx_create_blank_spreadsheet: %s\n" % e)

Alright, we’re done! Upon sending in the request, our new XLSX will be created on the server, ready to be filled out using our other spreadsheet editing functions. When you’re done, call edit_document_finish_editing and you will receive your file, simple as that.

No need to deal with this kind of mess when you’ve got an API!

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