Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments in template in FOR cause 'unreadable content' when opening created Word doc #324

Open
rbuhrs opened this issue Aug 17, 2023 · 2 comments
Labels

Comments

@rbuhrs
Copy link

rbuhrs commented Aug 17, 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.

image

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

@jjhbw
Copy link
Collaborator

jjhbw commented Aug 18, 2023

Great find! I agree that this is a bug.

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.

No easy fix comes to mind, though.

@jjhbw jjhbw added the bug label Aug 18, 2023
@rbuhrs
Copy link
Author

rbuhrs commented Aug 18, 2023

Clear, thanks for looking into this!

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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants