Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Render Excel Spreadsheet data to HTML programmatically using a REST API in Python.
Render Excel to HTML using Python
1. Programmatically upload XLSX file on the cloud
2. Render Excel Worksheet data to HTML programmatically using Python.
3. Download the HTML files from the cloud.
client_id = "659fe7da-715b-4744-a0f7-cf469a392b73"
client_secret = "b377c36cfa28fa69960ebac6b6e36421"
my_storage = ""
configuration = groupdocs_viewer_cloud.Configuration(client_id, client_secret)
configuration.api_base_url = "https://api.groupdocs.cloud"
# Create instance of the API
api_instance = groupdocs_viewer_cloud.ViewApi.from_keys(client_id, client_secret)
# Define View Options
view_options = groupdocs_viewer_cloud.ViewOptions()
view_options.file_info = groupdocs_viewer_cloud.FileInfo()
view_options.file_info.file_path = "sample.xlsx"
view_options.view_format = "HTML"
# Add Watermark
view_options.watermark = groupdocs_viewer_cloud.Watermark()
view_options.watermark.size = 70
view_options.watermark.text = "This is a watermark"
# Prepare request
request = groupdocs_viewer_cloud.CreateViewRequest(view_options)
# Convert
response = api_instance.create_view(request)
# Create instance of the API
file_api = groupdocs_viewer_cloud.FileApi.from_config(configuration)
for page in response.pages:
# Download HTML Page
request = groupdocs_viewer_cloud.DownloadFileRequest(page.path, my_storage)
response = file_api.download_file(request)
# Move downloaded file to your working directory
shutil.move(response, "C:\\Files\\Html\\")
# Create instance of the API
api_instance = groupdocs_viewer_cloud.ViewApi.from_keys(client_id, client_secret)
# Define View Options
view_options = groupdocs_viewer_cloud.ViewOptions()
view_options.file_info = groupdocs_viewer_cloud.FileInfo()
view_options.file_info.file_path = "sample.xlsx"
view_options.view_format = "HTML"
view_options.render_options = groupdocs_viewer_cloud.HtmlOptions()
# Define Spreadsheet rendering options
view_options.render_options.spreadsheet_options = groupdocs_viewer_cloud.SpreadsheetOptions()
view_options.render_options.spreadsheet_options.paginate_sheets = False
# Prepare request
request = groupdocs_viewer_cloud.CreateViewRequest(view_options)
# Convert
response = api_instance.create_view(request)
# Create instance of the API
file_api = groupdocs_viewer_cloud.FileApi.from_config(configuration)
request = groupdocs_viewer_cloud.UploadFileRequest("sample.xlsx", "C:\\Files\\sample.xlsx", my_storage)
response = file_api.upload_file(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment