Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/excelbench/harness/adapters/wolfxl_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ def _color_to_hex(color: Any) -> str | None:
if color is None:
return None

rgb = getattr(color, "rgb", None)
if isinstance(color, str):
# WolfXL exposes fill colors as plain ARGB strings where openpyxl
# returns Color objects; both spellings normalize the same way.
rgb: Any = color
else:
rgb = getattr(color, "rgb", None)
if isinstance(rgb, str) and len(rgb) >= 6:
return f"#{rgb[2:]}" if len(rgb) == 8 else f"#{rgb}"

Expand Down
37 changes: 37 additions & 0 deletions tests/test_wolfxl_adapter_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,40 @@ def test_hyperlink_round_trip(adapter: Any, tmp_path: Path) -> None:
assert any(link.get("target") == "https://example.com" for link in links)
finally:
adapter.close_workbook(reopened)


def test_conditional_format_read_includes_rule_format(
adapter: Any, tmp_path: Path
) -> None:
from openpyxl import Workbook
from openpyxl.formatting.rule import CellIsRule
from openpyxl.styles import PatternFill

src = Workbook()
ws = src.active
ws.title = "CF"
for row in range(1, 6):
ws.cell(row=row, column=2, value=row * 10)
ws.conditional_formatting.add(
"B2:B6",
CellIsRule(
operator="greaterThan",
formula=["25"],
fill=PatternFill(
start_color="00FFFF00", end_color="00FFFF00", fill_type="solid"
),
),
)
path = tmp_path / "cf.xlsx"
src.save(path)

workbook = adapter.open_workbook(path)
try:
rules = adapter.read_conditional_formats(workbook, "CF")
finally:
adapter.close_workbook(workbook)
assert len(rules) == 1
rule = rules[0]
assert rule["rule_type"] == "cellIs"
assert rule["operator"] == "greaterThan"
assert rule["format"] == {"bg_color": "#FFFF00"}
Loading