Repository navigation
Give shapes and text boxes in a loop their own ids - #209
Merged
Merged
Conversation
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
This was referenced Nov 25, 2026
Closed
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.
A shape or text box inside a
{%p for %}comes out with the same ids in every copy.fix_docpr_ids()already renumberswp:docPr, but the shape also haswp14:anchorId(orw14:anchorId) and, in the VML fallback Word writes next to it,v:shape/@idando:spid. Duplicates of those are what makes Word say the file is corrupted and offer to repair it (#22).fix_shape_ids()runs right afterfix_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, itsShapeIDfollows.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 matchingShapeIDs. I couldn't open the result in Word here, so a check from someone with a real template would be welcome.Fixes #22