feat(ooxml): style a cell of an xlsx file - #937
Merged
Merged
Conversation
andiwand
force-pushed
the
feat/ods-cell-style
branch
from
September 28, 2026 18:59
2487baa to
4595df3
Compare
setCellStyle now writes into .xlsx. The writer starts from the xf that the cell shows (its own s, else the row s where the row states customFormat, else the column style), copies it and its font, and applies the delta. It appends a font, a fill and an xf only where no equal one exists, and sets applyFont, applyFill and applyAlignment. A font keeps the child order of CT_Font, and an empty styleSheet first gets the entries that every xf needs. styles.xml is now a written part, so every save writes it from its dom. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NXnz6EZY8YpyiyyE1GpsWy
The registry looked up a column by the first range that ends at or after it, and it did not check where that range starts. So a column in a gap between two `<col>` ranges took the width and the style of the next one. The registry now keeps the first column of each range, and the style writer asks the registry and does not walk `<cols>` again. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tigcf9he3w1aHfNPJoEGsd
The odf and the xlsx style writers each had a copy of `set_attribute`, so `xml::set_attribute` now serves both. The xlsx writer inserts a child through `insert_in_sequence` and spells a colour through `hex_color`, which `ooxml_util` already has. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tigcf9he3w1aHfNPJoEGsd
andiwand
force-pushed
the
feat/xlsx-cell-style
branch
from
September 28, 2026 19:08
eea7d7a to
197bec9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Generated with Claude Code
Step 3 of the cell-formatting plan (#934):
setCellStyleandSheet::set_cell_stylewrite into.xlsx.Change
xfthat the cell shows: its owns, else the rowswhere the row statescustomFormat, else the columnstyle.xfand itsfont, and applies the delta. It appends afont, afilland anxfonly where no equal one exists, so a range of cells with one delta adds onexf. It setsapplyFont,applyFillandapplyAlignment.patternFill solidwithfgColor, the colour the reader of fix(ooxml): an xlsx fill shows its colour, and a font its toggles #935 takes.fill: nullispatternType="none".fontkeeps the child order ofCT_Font, and new collections keep the order ofstyleSheet. An emptystyleSheetfirst gets the entries that everyxfneeds: a font, the two reserved fills, a border, and onexfincellStyleXfsandcellXfs.styles.xmlis now a written part, so every save writes it from its DOM.A fix found on the way
<col>range that ends at or after it, and it did not check where that range starts. A column in a gap between two ranges took the width and the style of the next range, and the new writer would have used that style as its base. The registry now keeps the first column of each range. The regression test fails without the fix.Proof
OoxmlSpreadsheetStyleWritetests: a fill survives a save of an empty style sheet, every text key, a sharedxfis copied, one delta makes onexf/font/fill, a fill taken away, alignment, a cell that the file does not state, the row as base, the column range as base, a covered cell, and the JSON op.sample.xlsxandmultiline.xlsxstyled with six ops each and saved: LibreOffice loads both files and shows the fills, bold, italic, underline, colour, left alignment, a fill taken away, and new cells past the sheet. I have no Excel here, so Excel has not opened these files.