xlsx/column-width

A workbook widens column A of the first worksheet to 30 character-widths via a <col> entry with customWidth='1'.

Library verdicts: python-xlsx: — xlsxjs: pass

Metadata

Feature idxlsx/column-width
Formatxlsx
Categorysheet-layout
Spececma-376-5-part-1 § 18.3.1.13 col

XPath assertions

ID / partPredicateXPathpython-xlsxxlsxjs
col-a-width-30
xl/worksheets/sheet1.xml
match = ^30(\.0+)?$
Column A (<col min='1' max='1'>) must declare @width='30' (optionally with trailing decimal zeros).
string(//x:cols/x:col[@min='1' and @max='1']/@width)

Render assertions

IDPredicateSelectorpython-xlsxxlsxjs
column-width-text-presentcss_selector/ match-text = Wide col
The rendered sheet must contain a cell with the fixture text.
section.xlsx td, section.xlsx thpass
column-width-widecomputed_style = ^(1[8-9][0-9]|2[0-4][0-9])(\.[0-9]+)?px$ style=width
The cell or col element's computed width must be roughly 180-249px (30 chars at a default-font monospace-ish width sits around 200-230px at 96dpi).
section.xlsx td, section.xlsx th, section.xlsx colpass
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_column_width.py

#!/usr/bin/env python3
"""Generate ``fixtures/xlsx/column-width.xlsx``.

A minimal one-sheet workbook with cell A1 containing ``Wide col`` and
column A widened to 30 character-widths. Designed to satisfy the
assertions in ``features/xlsx/column-width.json``.
"""

from __future__ import annotations

from pathlib import Path

from xlsx import Workbook

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" / "column-width.xlsx"


def main() -> int:
    wb = Workbook()
    ws = wb.active
    ws["A1"] = "Wide col"
    ws.column_dimensions["A"].width = 30
    _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/column-width",
  "title": "Column width (30 character-widths)",
  "format": "xlsx",
  "category": "sheet-layout",
  "summary": "A workbook widens column A of the first worksheet to 30 character-widths via a <col> entry with customWidth='1'.",
  "spec": {
    "source": "ecma-376-5-part-1",
    "clause": "18.3.1.13",
    "element": "col",
    "rnc_reference": "spec/ecma-376-5/part-1/rnc/SpreadsheetML.rnc",
    "xsd_reference": "spec/ecma-376-5/part-1/xsd/sml.xsd",
    "notes": "Column width in SpreadsheetML lives on a <col> element inside <cols>, with @min and @max bracketing the affected 1-indexed column range and @width carrying the width in character-widths of the default font's '0' glyph. python-xlsx emits @customWidth='1' alongside @width. SpreadsheetML parts use a default namespace with no prefix; XPath therefore needs an explicit binding (here 'x')."
  },
  "fixtures": {
    "machine": "xlsx/column-width",
    "office": "xlsx/column-width"
  },
  "generator": {
    "python": "scripts/gen_column_width.py"
  },
  "assertions": [
    {
      "id": "col-a-width-30",
      "part": "xl/worksheets/sheet1.xml",
      "namespaces": {
        "x": "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
      },
      "xpath": "string(//x:cols/x:col[@min='1' and @max='1']/@width)",
      "must": "match",
      "value": "^30(\\.0+)?$",
      "description": "Column A (<col min='1' max='1'>) must declare @width='30' (optionally with trailing decimal zeros)."
    }
  ],
  "render_assertions": [
    {
      "id": "column-width-text-present",
      "kind": "css_selector",
      "selector": "section.xlsx td, section.xlsx th",
      "must": "match-text",
      "value": "Wide col",
      "description": "The rendered sheet must contain a cell with the fixture text."
    },
    {
      "id": "column-width-wide",
      "kind": "computed_style",
      "selector": "section.xlsx td, section.xlsx th, section.xlsx col",
      "style_property": "width",
      "value": "^(1[8-9][0-9]|2[0-4][0-9])(\\.[0-9]+)?px$",
      "description": "The cell or col element's computed width must be roughly 180-249px (30 chars at a default-font monospace-ish width sits around 200-230px at 96dpi)."
    },
    {
      "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 column-width.xlsx (4.8 KB)

Reference preview

Reference (machine, page 1 PNG)

xlsx/column-width page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec notes

Column width in SpreadsheetML lives on a <col> element inside <cols>, with @min and @max bracketing the affected 1-indexed column range and @width carrying the width in character-widths of the default font's '0' glyph. python-xlsx emits @customWidth='1' alongside @width. SpreadsheetML parts use a default namespace with no prefix; XPath therefore needs an explicit binding (here 'x').