xlsx/cell-italic

A workbook defines an italic font in its styles part and carries a shared string for the italic cell.

Library verdicts: python-xlsx: — xlsxjs: pass

Metadata

Feature idxlsx/cell-italic
Formatxlsx
Categorycell-formatting
Spececma-376-5-part-1 § 18.8.22 font

XPath assertions

ID / partPredicateXPathpython-xlsxxlsxjs
italic-font-defined
xl/styles.xml
exist
At least one <font> entry in the styles part must declare italic via an <i> child.
//x:fonts/x:font[x:i]
shared-string-present
xl/sharedStrings.xml
exist
The shared-strings table must contain 'Hello italic cell'.
//x:sst/x:si/x:t[normalize-space()='Hello italic cell']

Render assertions

IDPredicateSelectorpython-xlsxxlsxjs
cell-italic-text-presentcss_selector/ match-text = Hello italic cell
The rendered sheet must contain a cell with the fixture text.
section.xlsx td, section.xlsx thpass
cell-italic-is-italiccomputed_style = ^italic$ style=font-style
The computed font-style on the cell must be italic. (Assumes the renderer applies styles directly — adjust selector if nested in a span.)
section.xlsx td, section.xlsx thpass
sheet-countcss_selector/ equal-count
Exactly one rendered sheet section. Catches renderers that emit zero sheets (hard failure) or duplicate a sheet.
section.xlsx

Generator source

scripts/gen_cell_italic.py

#!/usr/bin/env python3
"""Generate ``fixtures/xlsx/cell-italic.xlsx``.

A minimal one-sheet workbook with cell A1 containing ``Hello italic cell``
formatted with an italic font. Designed to satisfy the assertions in
``features/xlsx/cell-italic.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-italic.xlsx"


def main() -> int:
    wb = Workbook()
    ws = wb.active
    ws["A1"] = "Hello italic cell"
    ws["A1"].font = Font(italic=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())

Manifest (expanded)

{
  "$schema": "../manifest.schema.json",
  "id": "xlsx/cell-italic",
  "title": "Italic cell font",
  "format": "xlsx",
  "category": "cell-formatting",
  "summary": "A workbook defines an italic font in its styles part and carries a shared string for the italic 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": "Italic in SpreadsheetML lives on a <font> entry in xl/styles.xml's <fonts> table as an <i/> child (python-xlsx emits <i val=\"1\"/> but the presence of the <i> 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 an <i> 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 italic cell</t></si> entry."
  },
  "fixtures": {
    "machine": "xlsx/cell-italic",
    "office": "xlsx/cell-italic"
  },
  "generator": {
    "python": "scripts/gen_cell_italic.py"
  },
  "assertions": [
    {
      "id": "italic-font-defined",
      "part": "xl/styles.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "//x:fonts/x:font[x:i]",
      "must": "exist",
      "description": "At least one <font> entry in the styles part must declare italic via an <i> 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 italic cell']",
      "must": "exist",
      "description": "The shared-strings table must contain 'Hello italic cell'."
    }
  ],
  "render_assertions": [
    {
      "id": "cell-italic-text-present",
      "kind": "css_selector",
      "selector": "section.xlsx td, section.xlsx th",
      "must": "match-text",
      "value": "Hello italic cell",
      "description": "The rendered sheet must contain a cell with the fixture text."
    },
    {
      "id": "cell-italic-is-italic",
      "kind": "computed_style",
      "selector": "section.xlsx td, section.xlsx th",
      "style_property": "font-style",
      "value": "^italic$",
      "description": "The computed font-style on the cell must be italic. (Assumes the renderer applies styles directly — adjust selector if nested in a span.)"
    },
    {
      "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."
    }
  ]
}

Fixture

Download cell-italic.xlsx (4.7 KB)

Reference preview

Reference (machine, page 1 PNG)

xlsx/cell-italic page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec notes

Italic in SpreadsheetML lives on a <font> entry in xl/styles.xml's <fonts> table as an <i/> child (python-xlsx emits <i val="1"/> but the presence of the <i> 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 an <i> 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 italic cell</t></si> entry.