May 5, 2020

2 min read

How to get styles from an Excel XLSX spreadsheet or worksheet in Python

By the end of this article, all of your prayers about retrieving style information from Excel spreadsheets will have been answered.

To grease the wheels, we will be employing an API function that’s going to help immensely. To use it, we will need to install its client, like so:

pip install cloudmersive-convert-api-client

Now we can instance our API, which we will follow with a call for edit_document_xlsx_get_styles:

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.GetXlsxStylesRequest() # GetXlsxStylesRequest | Document input requesttry:# Get styles from a Excel XLSX spreadsheet, worksheetapi_response = api_instance.edit_document_xlsx_get_styles(input)pprint(api_response)except ApiException as e:print("Exception when calling EditDocumentApi->edit_document_xlsx_get_styles: %s\n" % e)

And that wraps things up nicely. Soon after making the request, we will be given back our response, which includes this set of information:

{"Successful": true,"Styles": [{"StyleID": "string","Path": "string","Bold": true,"Italic": true,"Underline": true,"FontSize": "string","FontFamily": "string"}]}