Skip to content

Give shapes and text boxes in a loop their own ids - #209

Merged
cvas22 merged 1 commit into
mainfrom
fix/22-shape-ids-in-loops
Nov 25, 2026
Merged

cvas22 merged 1 commit into
mainfrom
fix/22-shape-ids-in-loops

Conversation

@cvas22

@cvas22 cvas22 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

A shape or text box inside a {%p for %} comes out with the same ids in every copy. fix_docpr_ids() already renumbers wp:docPr, but the shape also has wp14:anchorId (or w14:anchorId) and, in the VML fallback Word writes next to it, v:shape/@id and o:spid. Duplicates of those are what makes Word say the file is corrupted and offer to repair it (#22).

fix_shape_ids() runs right after fix_docpr_ids() and only touches duplicates: the first copy keeps the template's ids, and each later copy gets a new unique value. If an OLE object next to a renamed shape pointed at its old id, its ShapeID follows.

The test builds a text box the way Word stores it (DrawingML plus VML fallback) inside a loop of three, and checks that anchorId, shape id, spid and docPr id are each unique. It fails on main with three copies of 1A2B3C4D. I checked the rendered embedded-object sample still has matching ShapeIDs. I couldn't open the result in Word here, so a check from someone with a real template would be welcome.

Fixes #22

fix_docpr_ids() renumbers wp:docPr, but a shape or text box also has an
anchorId and a VML fallback with its own id and o:spid. A loop copied
them as is, so the copies clashed and Word reported the file as
corrupted. Copies now get new unique ids; the first one keeps the ids
from the template, and an OLE object's ShapeID follows its shape.

Fixes #22
@github-actions github-actions Bot added code Changes to the docform package tests Changes to tests labels Nov 25, 2026
@cvas22
cvas22 merged commit c415934 into main Nov 25, 2026
11 checks passed
@cvas22
cvas22 deleted the fix/22-shape-ids-in-loops branch November 25, 2026 17:32
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.

Shapes in a for loop

1 participant