XLSX to HTML Converter

0.6.4 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import io
from xlsx2html import xlsx2html

# Create a dummy XLSX file for demonstration
# (In a real scenario, you would have an actual .xlsx file)
# For this example, let's assume 'example.xlsx' exists.
# You can create one manually or with openpyxl.
# Example: workbook = openpyxl.Workbook(); workbook.active['A1'] = 'Hello'; workbook.save('example.xlsx')

# Option 1: Convert an XLSX file path to an HTML file path
# xlsx2html('path/to/example.xlsx', 'path/to/output.html')

# Option 2: Convert an XLSX file-like object to an HTML string (in-memory)
with open('example.xlsx', 'rb') as xlsx_file:
    output_stream = io.StringIO()
    xlsx2html(xlsx_file, output_stream, locale='en')
    output_stream.seek(0)
    html_content = output_stream.read()
    print(html_content[:500]) # Print first 500 chars of HTML for brevity

view raw JSON →