xlsx2html is a Python library designed for converting Excel (XLSX) files into HTML tables while striving to preserve cell formatting. It is actively maintained, with ongoing updates to support newer Python versions, address bugs, and introduce new features for more flexible conversions. The current stable version is 0.6.4.
pip install xlsx2htmlVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to convert an XLSX file to HTML. It shows both direct file-to-file conversion and in-memory conversion using file-like objects. Remember to replace 'example.xlsx' with your actual file.
Upgrade your Python environment to 3.7 or higher.
For v0.6.0 and later, use `xlsx2html(sheet=-1)` to render all sheets, or pass a list of sheet indices/names (e.g., `sheet=[0, 'Sheet2']`) to select specific sheets. For older versions, manually iterate through sheets using an underlying library like `openpyxl`.
Ensure you are using the latest version of `xlsx2html` as improvements are continuously made. For persistent issues, simplify Excel formatting or consider custom post-processing of the generated HTML. Check the GitHub issues for known limitations or workarounds.
Open your XLSX file-like objects with `'rb'` mode: `xlsx_file = open('path/to/example.xlsx', 'rb')`.Upgrade `xlsx2html` to version 0.5.0 or newer: `pip install --upgrade xlsx2html`.
Upgrade `xlsx2html` to version 0.6.1 or newer: `pip install --upgrade xlsx2html`. This version includes a fix for `UnicodeEncodeError`.
If using `xlsx2html` 0.6.0 or newer, specify `sheet=-1` to convert all sheets (e.g., `xlsx2html(..., sheet=-1)`), or provide a list of sheet indices/names (e.g., `sheet=[0, 1]`). If using an older version, consider upgrading or implementing custom multi-sheet iteration.