A workbook defines a bold font in its styles part and carries a shared string for the bold cell.
Library verdicts: python-xlsx: — xlsxjs: pass
| Feature id | xlsx/cell-bold |
|---|---|
| Format | xlsx |
| Category | cell-formatting |
| Spec | ecma-376-5-part-1 § 18.8.22 font |
| ID / part | Predicate | XPath | python-xlsx | xlsxjs |
|---|---|---|---|---|
bold-font-definedxl/styles.xml | existAt least one <font> entry in the styles part must declare bold via a <b> child. | //x:fonts/x:font[x:b] | — | — |
shared-string-presentxl/sharedStrings.xml | existThe shared-strings table must contain 'Hello bold cell'. | //x:sst/x:si/x:t[normalize-space()='Hello bold cell'] | — | — |
| ID | Predicate | Selector | python-xlsx | xlsxjs |
|---|---|---|---|---|
cell-bold-text-present | css_selector/ match-text = Hello bold cellThe rendered sheet must contain a cell with the fixture text. | section.xlsx td, section.xlsx th | — | pass |
cell-bold-is-bold | computed_style = ^(bold|700)$ style=font-weightThe computed font-weight on the cell must be bold or 700. (Assumes the renderer applies styles directly — adjust selector if nested in a span.) | section.xlsx td, section.xlsx th | — | pass |
cell-bold-visual-ssim | visual_ssimA Playwright screenshot of the rendered sheet must score >= 0.85 SSIM against the LibreOffice-rendered reference PNG (refs/xlsx/cell-bold-page1.png, resolved by the runner from the machine-fixture name). Threshold matches the docx default because xlsx tables are regular grids with little geometric variance. | — | — | |
sheet-count | css_selector/ equal-countExactly one rendered sheet section. Catches renderers that emit zero sheets (hard failure) or duplicate a sheet. | section.xlsx | — | — |
scripts/gen_cell_bold.py
#!/usr/bin/env python3
"""Generate ``fixtures/xlsx/cell-bold.xlsx``.
A minimal one-sheet workbook with cell A1 containing ``Hello bold cell``
formatted with a bold font. Designed to satisfy the assertions in
``features/xlsx/cell-bold.json``.
"""
from __future__ import annotations
from pathlib import Path
from xlsx import Workbook
from xlsx.styles import Font
import datetime as _dt
_REPRODUCIBLE_DT = _dt.datetime(2000, 1, 1, 0, 0, 0)
_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "xlsx" / "cell-bold.xlsx"
def main() -> int:
wb = Workbook()
ws = wb.active
ws["A1"] = "Hello bold cell"
ws["A1"].font = Font(bold=True)
_OUT.parent.mkdir(parents=True, exist_ok=True)
wb.save(_OUT, zip_date_time=_REPRODUCIBLE_DT)
print(_OUT)
return 0
if __name__ == "__main__":
raise SystemExit(main())
{
"$schema": "../manifest.schema.json",
"id": "xlsx/cell-bold",
"title": "Bold cell font",
"format": "xlsx",
"category": "cell-formatting",
"summary": "A workbook defines a bold font in its styles part and carries a shared string for the bold cell.",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "18.8.22",
"element": "font",
"rnc_reference": "spec/ecma-376-5/part-1/rnc/SpreadsheetML.rnc",
"xsd_reference": "spec/ecma-376-5/part-1/xsd/sml.xsd",
"notes": "Bold in SpreadsheetML lives on a <font> entry in xl/styles.xml's <fonts> table as a <b/> child (Word emits <b val=\"1\"/> but the presence of the <b> element is the canonical signal). A <xf> record in <cellXfs> then points at that fontId. The assertion here checks the simpler shape: at least one <font> in xl/styles.xml contains a <b> child. SpreadsheetML parts use a default namespace with no prefix; XPath therefore needs an explicit binding (here 'x'). Content of cell A1 appears in xl/sharedStrings.xml as an <si><t>Hello bold cell</t></si> entry."
},
"fixtures": {
"machine": "xlsx/cell-bold",
"office": "xlsx/cell-bold"
},
"generator": {
"python": "scripts/gen_cell_bold.py"
},
"assertions": [
{
"id": "bold-font-defined",
"part": "xl/styles.xml",
"namespaces": {
"x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
},
"xpath": "//x:fonts/x:font[x:b]",
"must": "exist",
"description": "At least one <font> entry in the styles part must declare bold via a <b> child."
},
{
"id": "shared-string-present",
"part": "xl/sharedStrings.xml",
"namespaces": {
"x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
},
"xpath": "//x:sst/x:si/x:t[normalize-space()='Hello bold cell']",
"must": "exist",
"description": "The shared-strings table must contain 'Hello bold cell'."
}
],
"render_assertions": [
{
"id": "cell-bold-text-present",
"kind": "css_selector",
"selector": "section.xlsx td, section.xlsx th",
"must": "match-text",
"value": "Hello bold cell",
"description": "The rendered sheet must contain a cell with the fixture text."
},
{
"id": "cell-bold-is-bold",
"kind": "computed_style",
"selector": "section.xlsx td, section.xlsx th",
"style_property": "font-weight",
"value": "^(bold|700)$",
"description": "The computed font-weight on the cell must be bold or 700. (Assumes the renderer applies styles directly — adjust selector if nested in a span.)"
},
{
"id": "cell-bold-visual-ssim",
"kind": "visual_ssim",
"min_ssim": 0.85,
"description": "A Playwright screenshot of the rendered sheet must score >= 0.85 SSIM against the LibreOffice-rendered reference PNG (refs/xlsx/cell-bold-page1.png, resolved by the runner from the machine-fixture name). Threshold matches the docx default because xlsx tables are regular grids with little geometric variance."
},
{
"id": "sheet-count",
"kind": "css_selector",
"selector": "section.xlsx",
"must": "equal-count",
"count": 1,
"description": "Exactly one rendered sheet section. Catches renderers that emit zero sheets (hard failure) or duplicate a sheet."
}
]
}
