You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a template contains notes in a FOR loop the creation of the document succeeds, but when you open the document Word shows a 'unreadable content' error.
I checked in the XML of the corrupt .docx file that your test generates, and apparently each comment is connected to a piece of text in document.xml using a unique ID. The comments themselves are stored in separate xml files. I think Word does not like it when a comment ID refers to multiple pieces of text in the document, which is the case after our FOR loop creates copies of the text snippets.
It probably won't need a fix, as I can't think of a use case for comments in a FOR loop, but good to know this can lead to issues.
An easy workaround is available, we can just delete the comment in the FOR, or move it somewhere else out of the loop. That will solve the issue.
jjhbw
changed the title
Notes in template in FOR cause 'unreadable content' when opening created Word doc
Comments in template in FOR cause 'unreadable content' when opening created Word doc
Aug 31, 2023
@jjhbw as discussed
When a template contains notes in a FOR loop the creation of the document succeeds, but when you open the document Word shows a 'unreadable content' error.
A created a test for this here https://github.com/rbuhrs/docx-templates/blob/acf973a22cf9e4ed20d6ac8d2d4aec63bf981aef/src/__tests__/templating.test.ts#L133
It creates a document in the test directory, which shows the error when you open it in Word
The text was updated successfully, but these errors were encountered: