You can easily view Microsoft Excel data in HTML on the cloud. It may facilitate showing data to relevant stakeholders without sharing the actual Excel data files with them. As a Python developer, you can render spreadsheet data from XLS or XLSX files in HTML programmatically on the cloud. This article will be focusing on how to render Excel data to HTML using a REST API in Python.
Document Viewer REST API and Python SDK
For rendering XLS or XLSX spreadsheets, I will be using the Python SDK of GroupDocs.Viewer Cloud API. It allows you to programmatically render and view all sorts of popular documents and image file formats. It also provides .NET, Java, PHP, Ruby, Android, and Node.js SDKs as its document viewer family members for the Cloud API.
You can install GroupDocs.Viewer Cloud to your Python project using the following command in the console:
pip install groupdocs_viewer_cloud
Please get your Client ID and Client Secret from the dashboard before you start following the steps and available code examples. Once you have your ID and secret, add in the code as demonstrated below:
Render Excel Data to HTML using a REST API in Python
You can render Microsoft Excel spreadsheet data in HTML by following the simple steps mentioned below:
- Upload the XLSX file to the Cloud
- Render Excel to HTML
- Render Excel to HTML with Watermark
- Download the rendered PDF file
Upload the Document
Firstly, upload the XLSX file to the Cloud using the code example given below:
As a result, the sample.xlsx file will be uploaded to Cloud Storage and will be available in the files section of your dashboard.
Render Excel to HTML in Python
Please follow the steps mentioned below to render Excel data to HTML programmatically.
- Create an instance of View API
- Define ViewOptions
- Set file path and view_format as “HTML”
- Set RenderOptions as HtmlOptions
- Define spreadsheet rendering options if any applies
- Create a view request by calling the CreateViewRequest method
- Get a response by calling the create_view method
The following code snippet shows how to render Excel spreadsheet data to HTML using a REST API.
By default, one worksheet is rendered into one page. You may customize the rendering of Excel by applying the following options:
- Render an Excel Worksheets to Multiple Pages
view_options.render_options.spreadsheet_options.paginate_sheets = True
view_options.render_options.spreadsheet_options.count_rows_per_page = 45
- Show Gridlines in HTML
view_options.render_options.spreadsheet_options.render_grid_lines = True
- Render Empty Rows and Columns
view_options.render_options.spreadsheet_options.render_empty_rows = True
view_options.render_options.spreadsheet_options.render_empty_columns = True
- Show Hidden Rows and Columns
view_options.render_options.spreadsheet_options.render_hidden_columns = True
view_options.render_options.spreadsheet_options.render_hidden_rows = True
- Render Print Area Only
view_options.render_options.spreadsheet_options.render_print_area_only = True
- Set Text Overflow Mode
view_options.render_options.spreadsheet_options.text_overflow_mode = "HideText"
Render Excel to HTML with Watermark
Please follow the steps mentioned below to add a watermark text while rendering Excel data to HTML programmatically.
- Create an instance of View API
- Define ViewOptions
- Set file path and view_format as “HTML”
- Define Watermark view option
- Set watermark text and size
- Create a view request by calling the CreateViewRequest method
- Get a response by calling the create_view method
The following code snippet shows how to add a watermark text to rendered HTML using a REST API.
Download the Updated File
The above code sample will save the rendered HTML file on the cloud. You can download them using the following code sample:
Try Online
Please try the following free online spreadsheet rendering tool, which is developed using the above API. https://products.groupdocs.app/viewer/xlsx
Conclusion
In this article, you have learned how to render Excel spreadsheet data to HTML on the cloud with Document Viewer REST API using Python. You also learned how to programmatically upload the XLSX file on the cloud and then download the rendered HTML files from the cloud. You can learn even more about GroupDocs.Viewer Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser. In case of any ambiguity, please feel free to contact us on the forum.