How to split an Excel XLSX into Separate Worksheets in Python

If you are anything like me, you are probably bored stiff at the idea of writing this one out from scratch. So what do you say we skip the torturous part and just have it all done in a couple minutes? While that may sound too good to be true, you are about to learn otherwise.

We begin with setting up our API client via pip install.

pip install cloudmersive-convert-api-client

Next comes split_document_xlsx, seen below:

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.SplitDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))input_file = '/path/to/file' # file | Input file to perform the operation on.return_document_contents = true # bool | Set to true to return the contents of each Worksheet directly, set to false to only return URLs to each resulting worksheet.  Default is true. (optional)try:# Split a single Excel XLSX into Separate Worksheetsapi_response = api_instance.split_document_xlsx(input_file, return_document_contents=return_document_contents)pprint(api_response)except ApiException as e:print("Exception when calling SplitDocumentApi->split_document_xlsx: %s\n" % e)

And now you can get right back to more important things, because that’s all there is to it. You’re welcome.

Image for post
Image for post

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