Skip to main content

Convert XLSX workbooks to single styled HTML file with support for conditional formatting and in-cell images.

Project description

xx2html

PyPI Version License Buy Me a Coffee

xx2html converts Excel workbooks (.xlsx) into a single HTML file while preserving:

  • Cell formatting and styles
  • Conditional formatting classes (via condif2css)
  • Worksheet link behavior
  • Embedded worksheet images and in-cell rich-value images

Installation

pip install xx2html

Usage

from xx2html import apply_openpyxl_patches, create_xlsx_transform

# Explicit entrypoint. Patches are also applied automatically on import.
apply_openpyxl_patches()

transform = create_xlsx_transform(
    sheet_html=(
        '<section id="{enc_sheet_name}" data-sheet-name="{sheet_name}">'
        "{table_generated_html}"
        "</section>"
    ),
    sheetname_html='<a class="sheet-nav" href="#{sheet_name}.A1">{sheet_name}</a>',
    index_html=(
        "<!doctype html><html><head>"
        "{fonts_html}{core_css_html}{user_css_html}{generated_css_html}"
        "{generated_incell_css_html}{conditional_css_html}"
        "</head><body>{sheets_names_generated_html}{sheets_generated_html}"
        "{safari_js}</body></html>"
    ),
    fonts_html="",
    core_css="",
    user_css="",
    safari_js="",
    apply_cf=True,
)

ok, err = transform("input.xlsx", "output.html", "en_US")
if not ok:
    raise RuntimeError(err)

API Map

Public API (xx2html):

  • apply_openpyxl_patches() -> None
    • Applies required openpyxl monkey patches (idempotent).
  • create_xlsx_transform(...) -> Callable[[str, str, str], tuple[bool, str | None]]
    • Returns a transformer callable with signature (source_xlsx, dest_html, locale).
    • Returns (True, None) on success, (False, "<error repr>") on failure.

Core helpers (xx2html.core, useful for advanced integrations):

  • get_worksheet_contents(...) -> WorksheetContents
  • cova_render_table(worksheet_contents) -> str
  • get_incell_images_refs(archive) -> tuple[dict[str, str], Exception | None]
  • get_incell_css(...) -> str
  • apply_cf_styles(html, cf_style_relations) -> str
  • update_links(html, encoded_sheet_names, ...) -> str

Template Placeholders

sheet_html requires:

  • {enc_sheet_name}
  • {sheet_name}
  • {table_generated_html}

sheetname_html requires:

  • {enc_sheet_name}
  • {sheet_name}

index_html requires:

  • {sheets_generated_html}
  • {sheets_names_generated_html}
  • {source_filename}
  • {fonts_html}
  • {core_css_html}
  • {user_css_html}
  • {generated_css_html}
  • {generated_incell_css_html}
  • {safari_js}
  • {conditional_css_html}

Monkey Patching Behavior

xx2html relies on an openpyxl monkey patch to carry rich-value metadata used for in-cell images.

  • The patch is applied automatically when xx2html.core is imported.
  • The explicit API entrypoint is apply_openpyxl_patches().

Development

uv sync --group dev
python3 tests/scripts/generate_fixtures.py
python3 -m compileall src tests
python3 -m pytest

License

xx2html is dual-licensed under MIT or Apache-2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xx2html-0.15.0b6021700.tar.gz (132.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xx2html-0.15.0b6021700-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file xx2html-0.15.0b6021700.tar.gz.

File metadata

  • Download URL: xx2html-0.15.0b6021700.tar.gz
  • Upload date:
  • Size: 132.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.6 CPython/3.14.3 Darwin/24.6.0

File hashes

Hashes for xx2html-0.15.0b6021700.tar.gz
Algorithm Hash digest
SHA256 0a04bd100d86ec1862332dd1d3d033d5f41a545952882cba642b6f340723cf56
MD5 048e8f07fd543a68216de0c708d4f035
BLAKE2b-256 31fcf825ad16705f83036c014fa73bb00d7c47c5c1917781126ab49f12dc428c

See more details on using hashes here.

File details

Details for the file xx2html-0.15.0b6021700-py3-none-any.whl.

File metadata

  • Download URL: xx2html-0.15.0b6021700-py3-none-any.whl
  • Upload date:
  • Size: 25.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.6 CPython/3.14.3 Darwin/24.6.0

File hashes

Hashes for xx2html-0.15.0b6021700-py3-none-any.whl
Algorithm Hash digest
SHA256 52f683a7910c69fc615ff5bd77b688bea1aa6243e12ff71b49e794ad817c1fd3
MD5 faf1226d0f73cd0a3615e18732d9a42b
BLAKE2b-256 7c6b8c37030db2b17bb18f1892b1430db560f0f1f4740abf3d86f2e880e03af8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page