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
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)
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.