Skip to content

Keep cell properties in schema order after vm, hm, colspan and cellbg - #203

Merged
cvas22 merged 1 commit into
mainfrom
fix/103-tcpr-child-order
Nov 25, 2026
Merged

cvas22 merged 1 commit into
mainfrom
fix/103-tcpr-child-order

Conversation

@cvas22

@cvas22 cvas22 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

{% vm %} appends w:vMerge right before </w:tcPr>, hm and colspan put w:gridSpan at either end, and cellbg puts w:shd first. 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 each tcPr'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

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
@github-actions github-actions Bot added code Changes to the docform package tests Changes to tests labels Nov 25, 2026
@cvas22
cvas22 merged commit 4629e5d into main Nov 25, 2026
11 checks passed
@cvas22
cvas22 deleted the fix/103-tcpr-child-order branch November 25, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code Changes to the docform package tests Changes to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add {% vm %} merge will create a target doc which can not be opend

1 participant