How to Convert Excel to HTML in Python
Using a few complementary Python code examples, we can easily convert our Excel documents to HTML files through a free API.
Making this conversion will optimize our Excel content for display on the web and allow us to customize further display elements by writing our own HTML code.
To structure our API call, we can start by installing the client SDK via pip install:
pip install cloudmersive-convert-api-client
Next, we should turn our attention to authorization. We’ll need a free API key to use this service (this will allow us to make up to 800 API calls per month with zero commitments).
We can now copy the below Python code examples into our file to structure our API call. We can supply our Excel file path as our sole request variable (and enter our API key in the configuration.api_key snippet):
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.ConvertDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))
input_file = '/path/to/inputfile' # file | Input file to perform the operation on.
try:
# Convert Excel XLSX Spreadsheet to HTML Document
api_response = api_instance.convert_document_xlsx_to_html(input_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling ConvertDocumentApi->convert_document_xlsx_to_html: %s\n" % e)
Now we can quickly and easily convert Excel files to HTML format.