Skip to content

feat(xls-codec): read and write a cell's own horizontal/vertical alignment - #912

Merged
Mearman merged 3 commits into
mainfrom
feat/xls-cell-alignment
Sep 4, 2026
Merged

feat(xls-codec): read and write a cell's own horizontal/vertical alignment#912
Mearman merged 3 commits into
mainfrom
feat/xls-cell-alignment

Conversation

@Mearman

@Mearman Mearman commented Sep 4, 2026

Copy link
Copy Markdown
Member

CellXF/StyleXF's leading word (word1) carries alc/alcV -- horizontal and vertical alignment -- and this reader skipped it entirely while the writer always packed the same General/Bottom defaults. Both now resolve through the identical alc<->Alignment and alcV<->verticalAlignment mapping (xf-colors.ts's resolveHorizontalAlignment/horizAlignTokenFor and resolveVerticalAlignment/vertAlignTokenFor), mirroring ooxml.js's own xlsx alignment policy: only the four HorizAlign members with a real Alignment counterpart survive (left/center/right/justify), and only the two VertAlign members with a verticalAlignment counterpart survive (top/middle).

The (format, decoration) XF-interning pair write.ts already carried becomes a (format, alignment, verticalAlignment, decoration) tuple, so two cells sharing all four still share one XF record. written-cells.ts's cellCarriesDecoration is renamed cellCarriesFormatting and widened to treat a non-default alignment the same way it already treats a background or a border: a blank cell carrying only alignment now gets a real Blank record instead of being silently dropped.

Verified against real LibreOffice 26.2.5.2 in both directions: every Alignment/verticalAlignment member this package writes opens in LibreOffice with the correct fo:text-align/style:vertical-align, and a LibreOffice-authored .xls with real alignment reads back correctly through this package's own reader.

Part of #815

…nment

CellXF/StyleXF's leading word (word1) carries alc/alcV -- horizontal
and vertical alignment -- and this reader skipped it entirely while
the writer always packed the same General/Bottom defaults. Both now
resolve through the identical alc<->Alignment and alcV<->
verticalAlignment mapping (xf-colors.ts's resolveHorizontalAlignment/
horizAlignTokenFor and resolveVerticalAlignment/vertAlignTokenFor),
mirroring ooxml.js's own xlsx alignment policy: only the four
HorizAlign members with a real Alignment counterpart survive
(left/center/right/justify; ALCGEN/ALCFILL/ALCCONTCTR/ALCDIST all read
as the value-kind default), and only the two VertAlign members with a
verticalAlignment counterpart survive (top/middle; ALCVBOT/ALCVJUST/
ALCVDIST all read as the schema's own documented bottom default).

The (format, decoration) XF-interning pair write.ts already carried
becomes a (format, alignment, verticalAlignment, decoration) tuple, so
two cells sharing all four still share one XF record. written-cells.ts's
cellCarriesDecoration is renamed cellCarriesFormatting and widened to
treat a non-default alignment the same way it already treats a
background or a border: a blank cell carrying only alignment now gets
a real Blank record instead of being silently dropped, and the reader
keeps such a cell on the way back in rather than treating it as an
undecorated blank with nothing to say.
…t assumed it was never read

cellXfTrailer's own word1 was hardcoded to 0, on the stated assumption
that the reader never acted on the payload's leading alignment word --
true when it was written, but a real Excel-written "no explicit
alignment" XF actually carries alcV=ALCVBOT(2), not 0. With the reader
now resolving that word for real, a bare 0 decodes as genuine top
alignment (ALCVTOP=0), and several pre-existing tests that used
cellXfTrailer() as a "plain, undecorated XF" shorthand started
resolving an alignment they never meant to state. cellXfTrailer now
defaults alc/alcV to General/Bottom, matching what a real Excel-written
XF with no explicit alignment carries, and takes optional alc/alcV
overrides for a test that wants to state one.

New coverage in write.test.ts: every Alignment/verticalAlignment member
round-trips, absence stays absent, alignment shares an XF with
decoration on the same cell, an alignment-only empty cell earns a real
Blank record (and one with neither alignment nor decoration still
writes nothing), and two cells sharing an alignment share one XF entry.
Adds a Cell alignment section mirroring Cell decoration and Print
settings, including the same LibreOffice 26.2.5.2 verification bar in
both directions -- every Alignment/verticalAlignment member written by
this package opens in LibreOffice with the correct fo:text-align/
style:vertical-align, and a LibreOffice-authored .xls with real
alignment reads back correctly through this package's own reader.

Removes alignment from the Writer scope and Read-side gaps tables' own
gap lists, since it is no longer one -- only per-cell fonts remain
alongside formulas there. Updates the root README's and documents.js's
own Fidelity-table description of xls-codec's write coverage to match:
xls's writer already never touched per-cell fonts (alongside formulas
and images), and alignment now joins background/borders/print
settings/metadata as a construct that survives xls<->xlsx/ods crossings
rather than one of the reasons those pairs are rated below xlsx<->ods.
@Mearman
Mearman marked this pull request as ready for review September 4, 2026 12:35
@Mearman
Mearman merged commit 55493cb into main Sep 4, 2026
17 checks passed
@Mearman
Mearman deleted the feat/xls-cell-alignment branch September 4, 2026 12:35
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review Completed 2026-09-04T12:38:35.148582Z 7a5111f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 6.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant