How to set and update cell contents in an Excel XLSX by index in Python

Given that spreadsheets are one of the most common types of work product, having the ability to edit Excel files is crucial any productivity app. If you need a method for working this into your project, then look no further. I will be guiding you Python users through this step by step. The good news is that there are only two steps.

First we install our API client.

pip install cloudmersive-convert-api-client

We can proceed by setting up edit_document_xlsx_set_cell_by_identifier, which will require an API instance. Now we just need to specify our cell identifier and the desired info to be inserted.

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.SetXlsxCellByIdentifierRequest() # SetXlsxCellByIdentifierRequest | Document input requesttry:# Set, update cell contents in an Excel XLSX spreadsheet, worksheet by cell identifierapi_response = api_instance.edit_document_xlsx_set_cell_by_identifier(input)pprint(api_response)except ApiException as e:print("Exception when calling EditDocumentApi->edit_document_xlsx_set_cell_by_identifier: %s\n" % e)

And now we can go off and celebrate because we are officially done!

Image for post
Image for post

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store