-
-
Notifications
You must be signed in to change notification settings - Fork 486
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
Inline patchDocument replacement #2028
Comments
Can you send me the test.docx? and I will investigate |
Here we go, thank you: https://we.tl/t-O8D2l0ikE2 |
More insights incoming. As soon as I have multiple patches i.e. multiple keys in TypeError: Cannot read properties of undefined (reading 'text')
at Ba (/site/node_modules/docx/build/index.js:2:327108)
at Ha (/site/node_modules/docx/build/index.js:2:328126)
at i (/site/node_modules/docx/build/index.js:2:330638)
at i.next (<anonymous>)
at o (/site/node_modules/docx/build/index.js:2:332428) Looks like patching only one placeholder e.g. |
Nice observations, will look into this tonight |
Thanks! Let me know if you need more manual testing. As far as we've played with it, it's not bound to the Word on Mac — we are reproducing the same issue with templates created on Windows, too. |
Created a PR to fix the issue and wrote tests around it: I used your document for the testing If you discover anymore issues with other scenarios, let me know |
May I reopen? Here is the minimum docx to reproduce the error below:
My patches: {
"salutation": {
"type": "paragraph",
"children": [
{
"rootKey": "w:r",
"root": [
{
"rootKey": "w:rPr",
"root": [
{
"rootKey": "w:rFonts",
"root": [
{
"rootKey": "_attr",
"root": {
"ascii": "Trebuchet MS",
"cs": "Trebuchet MS",
"eastAsia": "Trebuchet MS",
"hAnsi": "Trebuchet MS"
},
"xmlKeys": {
"ascii": "w:ascii",
"cs": "w:cs",
"eastAsia": "w:eastAsia",
"hAnsi": "w:hAnsi",
"hint": "w:hint"
}
}
]
}
]
},
{
"rootKey": "w:t",
"root": [
{
"rootKey": "_attr",
"root": { "space": "preserve" },
"xmlKeys": { "space": "xml:space" }
},
"Mr"
]
}
],
"properties": {
"rootKey": "w:rPr",
"root": [
{
"rootKey": "w:rFonts",
"root": [
{
"rootKey": "_attr",
"root": {
"ascii": "Trebuchet MS",
"cs": "Trebuchet MS",
"eastAsia": "Trebuchet MS",
"hAnsi": "Trebuchet MS"
},
"xmlKeys": {
"ascii": "w:ascii",
"cs": "w:cs",
"eastAsia": "w:eastAsia",
"hAnsi": "w:hAnsi",
"hint": "w:hint"
}
}
]
}
]
}
}
]
},
"first-name": {
"type": "paragraph",
"children": [
{
"rootKey": "w:r",
"root": [
{
"rootKey": "w:rPr",
"root": [
{
"rootKey": "w:rFonts",
"root": [
{
"rootKey": "_attr",
"root": {
"ascii": "Trebuchet MS",
"cs": "Trebuchet MS",
"eastAsia": "Trebuchet MS",
"hAnsi": "Trebuchet MS"
},
"xmlKeys": {
"ascii": "w:ascii",
"cs": "w:cs",
"eastAsia": "w:eastAsia",
"hAnsi": "w:hAnsi",
"hint": "w:hint"
}
}
]
}
]
},
{
"rootKey": "w:t",
"root": [
{
"rootKey": "_attr",
"root": { "space": "preserve" },
"xmlKeys": { "space": "xml:space" }
},
"John"
]
}
],
"properties": {
"rootKey": "w:rPr",
"root": [
{
"rootKey": "w:rFonts",
"root": [
{
"rootKey": "_attr",
"root": {
"ascii": "Trebuchet MS",
"cs": "Trebuchet MS",
"eastAsia": "Trebuchet MS",
"hAnsi": "Trebuchet MS"
},
"xmlKeys": {
"ascii": "w:ascii",
"cs": "w:cs",
"eastAsia": "w:eastAsia",
"hAnsi": "w:hAnsi",
"hint": "w:hint"
}
}
]
}
]
}
}
]
}
} Any of those applied separately works okay. Thank you for looking into this! |
Ok, thanks for investigating, I will do investigating my side too and create a fix |
Do you patch with a JSON object, or you do patch with |
I am patching like this: // lib
export const font = 'Trebuchet MS';
export const getPatches = (fields: { [key: string]: string }) => {
const patches: { [key: string]: IPatch } = {};
for (const field in fields) {
patches[field] = {
type: PatchType.PARAGRAPH,
children: [new TextRun({ text: fields[field], font })]
};
}
return patches;
};
// exec
const patches = getPatches({
salutation: 'Mr',
'first-name': 'John'
}); |
I can't seem to reproduce the issue, I have even created a demo here to try and describe the problem, but it worked flawlessly: https://github.com/dolanmiu/docx/blob/master/demo/88-template-document.ts Can you send the word document? So I can invesatigate on that? |
Did you check this file: https://github.com/dolanmiu/docx/files/11059898/test.docx ? |
Fixed in #2053 Using that example document you provided as well |
I'm running into a problem where a simple docx template like
Hello {{name}}, how are you?
, being patched with:becomes
MaxHello, howare you?
Is it a known thing?
simple-template.docx
from demos works fine for me though, but only as long as I am not moving patchable placeholders around.I am editing using latest MS Word on Mac.
The text was updated successfully, but these errors were encountered: