Skip to content

docs(xlsx): note banner-merge and header/footer ampersand gotchas - #1454

Open
TemRevil wants to merge 1 commit into
anthropics:mainfrom
TemRevil:docs/xlsx-banner-header-gotchas
Open

TemRevil wants to merge 1 commit into
anthropics:mainfrom
TemRevil:docs/xlsx-banner-header-gotchas

Conversation

@TemRevil

Copy link
Copy Markdown

Refs #1440.

Two openpyxl presentation gotchas that silently produce visually broken output, both within the xlsx skill's existing scope. Added as two bullets to the "openpyxl gotchas" section.

1. A fill + long text does not overflow a cell reliably

A colored title/banner in A1 whose text is wider than column A relies on overflow into empty neighbors. But the fill covers only A1, and the overflow text clips at the cell edge in many renderers/exports (worst when the first column is narrow, e.g. a # column). Merging the row across the table makes both the fill and the text span:

from openpyxl.utils import get_column_letter
ws.merge_cells(f"A1:{get_column_letter(ws.max_column)}1")

2. A literal & in a header/footer must be doubled

openpyxl writes oddHeader/oddFooter text straight into Excel's field-code language, where & introduces a field (&C center, &P page number, ...). So "Revenue & Costs" loses everything after the &; write "Revenue && Costs".

Verified (openpyxl 3.1.5)

  • Banner: a PatternFill on A1 leaves B1 unfilled (fgColor 00000000), so the banner does not span; merge_cells("A1:E1") yields a single merged range across the row.
  • Header/footer: saving left.text = "Revenue & Costs" serializes to <oddFooter>&LRevenue & Costs</oddFooter> — the lone & enters the code stream — while "Q1 && Q2" serializes with && and renders a literal &. openpyxl does not auto-escape it.

Scoped to a two-bullet note; happy to expand into an example if the maintainers prefer.

Two openpyxl presentation gotchas that silently produce broken output:

- A background fill and long text in a title cell (e.g. A1) do not
  overflow across the row: the fill covers only A1 and the text clips
  at the cell edge in many renderers. Merging the row across the table
  makes both span.
- openpyxl writes header/footer text straight into Excel's field-code
  language, where `&` introduces a field (&C, &P, ...). A literal `&`
  must be doubled to `&&`, or everything after it is dropped.

Both verified against openpyxl 3.1.5 (serialized XML confirms the raw
`&` lands in the code stream while `&&` stays literal).

Refs anthropics#1440
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant