Repository navigation
Keep cell properties in schema order after vm, hm, colspan and cellbg - #203
Merged
Merged
Conversation
These tags drop vMerge, gridSpan and shd at a fixed spot in w:tcPr. When the cell also has borders or vertical alignment that order is invalid and Word won't open the file. Sort the tcPr children back into schema order after rendering, which covers all four tags at once. Fixes #103
This was referenced Nov 25, 2026
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.
{% vm %}appendsw:vMergeright before</w:tcPr>,hmandcolspanputw:gridSpanat either end, andcellbgputsw:shdfirst. That's fine for a plain cell, but once the cell has borders or vertical alignment the children are out of schema order and Word refuses to open the document. The template attached to the original report has 17 such cells.Instead of patching each regex, the body tree now gets one pass after
fix_tables()that sorts eachtcPr's children into CT_TcPr order. Elements it doesn't know about stay right after whatever they followed. Cells that are already in order are left alone.The new tests style the cells with borders and vAlign and check the order for vm, hm, colspan and cellbg; all four fail on main. I also rendered the reporter's template, which now has no out-of-order cells, but I haven't opened it in Word. Headers and footers aren't covered since they're rendered as strings; table cell tags there are rare, happy to follow up if needed.
Fixes #103