How to Split a Single Excel XLSX Document into Separate Worksheets using Python

Each worksheet in an excel file can contain a mountain of useful data in and of itself. Sometimes you only need one worksheet, and sometimes you need them all individually for different purposes. With our Excel Split API, you can easily convert a single Excel file with multiple worksheets into separate files with one worksheet each. You can also elect to receive URLs to each worksheet page rather than a physical document — the choice is up to you.

In the below demonstration, we’ll walk through how to structure your API call using Python code examples.

To begin, let’s install the Python SDK by running this command:

pip install cloudmersive-convert-api-client

After that, let’s include the imports:

from __future__ import print_function
import time
import cloudmersive_convert_api_client
from cloudmersive_convert_api_client.rest import ApiException
from pprint import pprint

Finally, we can call the function — starting with the API key authorization snippet. To get an API key, visit our website and register an account (free-tier accounts will provide a limit of 800 API calls per month).

# Configure API key authorization: Apikey
configuration = cloudmersive_convert_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_convert_api_client.SplitDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))
input_file = '/path/to/inputfile' # 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 Worksheets
api_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)

With that, you’re all set — no more code needed.

--

--

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
Cloudmersive

Cloudmersive

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