Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

condif2css

PyPI Version License Buy Me a Coffee

condif2css helps translate Excel conditional formatting into reusable CSS classes.

The library is designed to work with openpyxl workbooks and is currently focused on:

  • Evaluating conditional-format formulas per cell (processor.process)
  • Resolving workbook/theme/indexed colors to aRGB (create_themed_css_color_resolver)
  • Building deduplicated CSS rules from Cell / DifferentialStyle objects (css.py)

What It Does

  1. Reads conditional-format rules from an openpyxl worksheet.
  2. Evaluates each rule formula against each target cell (with relative/absolute ref offsets).
  3. Returns matching (sheet, cell, priority, dxf_id, stop_if_true) metadata.
  4. Converts style objects into CSS declarations and stable class names.

Installation

Install from PyPI:

pip install condif2css

If the latest published version is a pre-release, use:

pip install --pre condif2css

Local development install:

pip install -e .

Or with pdm (including dev dependencies):

pdm sync --group dev

Or with uv (including dev dependencies):

uv sync --group dev

Quick Example

from openpyxl import load_workbook

from condif2css import (
    CssBuilder,
    CssRulesRegistry,
    argb_to_css,
    create_get_css_from_cell,
    create_themed_css_color_resolver,
    get_differential_style,
    get_theme_colors,
    process_conditional_formatting,
)

wb = load_workbook("input.xlsx", data_only=True)
ws = wb["Sheet1"]

theme_colors = get_theme_colors(wb)
get_argb = create_themed_css_color_resolver(theme_colors)

def get_css_color(color):
    argb = get_argb(color)
    return argb_to_css(argb) if isinstance(argb, str) else None

css_builder = CssBuilder(get_css_color)
css_registry = CssRulesRegistry(prefix="cf")
get_css_from_cell = create_get_css_from_cell(css_registry, css_builder)

# { "Sheet1\\!A1": ("Sheet1", "A1", priority, dxf_id, stop_if_true), ... }
matched_rules = process_conditional_formatting(ws)

# Apply each matched differential style and collect class names per cell
cell_classes = {}
for code, (_, _, _, dxf_id, _) in matched_rules.items():
    dxf = get_differential_style(wb, dxf_id)
    if dxf is None:
        continue
    cell_classes[code] = sorted(get_css_from_cell(dxf, is_important=True))

# Final CSS text
css_text = "\n".join(css_registry.get_rules())

Public API (Current)

  • condif2css.create_themed_css_color_resolver(theme_colors)
  • condif2css.get_theme_colors(workbook, strict=False)
  • condif2css.process_conditional_formatting(sheet, fail_ok=True)
  • condif2css.get_differential_style(workbook, dxf_id)
  • condif2css.ThemeColorsError
  • condif2css.CssBuilder
  • condif2css.CssRulesRegistry
  • condif2css.create_get_css_from_cell(...)
  • condif2css.color.argb_to_css(...) and color/tint utility helpers

Current Scope and Limitations

  • Conditional-format evaluation supports:
    • expression rules with exactly one formula
    • cellIs rules (equal, notEqual, greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual, between, notBetween)
    • containsText, notContainsText, beginsWith, and endsWith
  • Formula evaluation expects references that resolve to single cells.
  • Non-boolean formula results are ignored.
  • Other conditional formatting rule types are currently skipped with a warning.
  • Style extraction supports:
    • Borders: top/right/bottom/left
    • Alignment: horizontal/vertical
    • Fill: solid fills and approximated pattern fills
    • Font: size, color, bold, italic, underline
  • The package provides building blocks; no CLI is included.

Development

Run tests:

pdm run pytest

Build and check distributions:

pdm build
python -m pip install --upgrade twine
python -m twine check dist/*

Releases

  • Versioning is SCM-driven from Git tags.
  • Stable releases must use SemVer tags in the format vMAJOR.MINOR.PATCH (example: v1.4.0).
  • GitHub Actions is configured to publish on matching v* tags and validates the strict stable SemVer format before publishing.

Acknowledgements

License

Licensed under either of:

at your option.

Metadata

Release files for condif2css 0.15.0rc2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for condif2css 0.15.0rc2
File Size Uploaded
condif2css-0.15.0rc2.tar.gz 26.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for condif2css 0.15.0rc2
File Interpreter ABI Platform
condif2css-0.15.0rc2-py3-none-any.whl Python 3 none any Details

Total release size: 49.2 kB

Release files / condif2css-0.15.0rc2.tar.gz

Download URL condif2css-0.15.0rc2.tar.gz
Size 26.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fc79f45035349638c2470a497fb47d3e839d24ae4da2fbe4d8b6d051e896fc77
BLAKE2b-256 checksum
How to use checksums
bfdf4b2a43f96339a0d87c4147867ae199987eab18096d8ddfd6f364a322c3ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 19, 2026.

Transparency log

Release files / condif2css-0.15.0rc2-py3-none-any.whl

Download URL condif2css-0.15.0rc2-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
449bea9a25467665db78fdbc4e7bee80ea0c7369cdf7c49be0e443f726a6aad9
BLAKE2b-256 checksum
How to use checksums
5c883a45cd1e9ea054e61605150268aa20a975648db3cc544c611d7b85d86b5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 19, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page