How to Convert Excel to XML in Python

Cloudmersive
2 min readMar 18, 2024

--

Converting Excel documents to XML files in Python can be done more quickly, more easily, and more scalably than we might think.

We can call a free, low-code Excel to XML conversion API using complementary, ready-to-run Python code examples.

Let’s start by installing the client SDK. We can run the below command to install via pip install:

pip install cloudmersive-convert-api-client

Next, let’s copy the below code to call the function. Our function call will use our Excel file path in the input_file request variable:

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

# 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.ConvertDataApi(cloudmersive_convert_api_client.ApiClient(configuration))
input_file = '/path/to/inputfile' # file | Input file to perform the operation on.

try:
# Convert Excel XLSX to XML conversion
api_response = api_instance.convert_data_xlsx_to_xml(input_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling ConvertDataApi->convert_data_xlsx_to_xml: %s\n" % e)

Finally, let’s get a free Cloudmersive API key to authenticate our API call. This will allow us to make up to 800 API calls per month with no commitments, and we can copy it into the configure.api_key snippet.

That’s all there is to it — now we can easily convert Excel documents to XML files with minimal Python code.

--

--

Cloudmersive

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