Comments (4)
I got the same error, this worked for me:
patchDocument(fs.readFileSync("input.docx"), {
outputType: "nodebuffer",
patches: {
test: {
type: PatchType.PARAGRAPH,
children: [new TextRun("test")],
},
},
}).then((doc) => {
fs.writeFileSync("output.docx", doc);
});
The only problem is that patcher doesn't patch all the keys if the same key is multiple times in the same paragraph doing it this way. Then the fix to that is running it over the same file multiple time: #2267 (comment)
from docx.
Same issue here !
Have some short example :
const file = fs.readFileSync(__dirname+"/../../templates/document.docx")
const doc = await patchDocument({
outputType: "nodebuffer",
data: file,
patches: {
version: {
type: PatchType.PARAGRAPH,
children: [new TextRun("V5555")],
}
}
})
fs.writeFileSync("C:\\PATH\\demo.docx",doc)
The error returned by Node :
*\node_modules\docx\build\index.cjs:16888
}(e3))), e3) : u.Promise.reject(new Error("Can't read the data of '" + r2 + "'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"));
Error: Can't read the data of 'the loaded zip file'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?
from docx.
Maybe there is another way of editing the docx ?
Like rewrite the Buffer before paking, reading the ByteArray and comparing it with a template to catch identical Bytes and replacing it with the content we are looking for.
But it would be very time consuming and a bit complicated tho :)
from docx.
I got the same error, this worked for me:
patchDocument(fs.readFileSync("input.docx"), { outputType: "nodebuffer", patches: { test: { type: PatchType.PARAGRAPH, children: [new TextRun("test")], }, }, }).then((doc) => { fs.writeFileSync("output.docx", doc); });The only problem is that patcher doesn't patch all the keys if the same key is multiple times in the same paragraph doing it this way. Then the fix to that is running it over the same file multiple time: #2267 (comment)
This worked for me too, replacing ALL occurences by using it in a non-promise way :
const doc = await patchDocument(fs.readFileSync("example.docx"), {
outputType: "nodebuffer",
patches: {
version: {
type: PatchType.PARAGRAPH,
children: [new TextRun("V5555")],
},
},
});
fs.writeFileSync("demo.docx",doc)
However it doesnt apply the correspondant style to the new text. (Not sure its part of the patchers usage)
from docx.
Related Issues (20)
- Add accent characters
- The MathIntergral limLoc seems to be wrong
- Doesn't work with bg-black HOT 1
- Couple issues with embedded fonts HOT 3
- how to set field language 'TH' in TextRun HOT 1
- ImageRun not working with data of ArrayBuffer type HOT 6
- Can not find `patchDocument` in browser
- iterate paragraphs HOT 1
- Can I set the font in mathematical formulas to be non-italic?
- Generate Table Of Contents (TOC) programmatically HOT 1
- What I am doing wrong ?
- Inconsistency in bulleted lists between Mac Pages, MSWord, and Google Docs. HOT 1
- can i add background color on entire header section? please suggest me HOT 4
- Use fitText In TextRun HOT 1
- Table of Content manual update option missing
- Table Styling Issue - Default & externalStyles
- Corrupted document when using async await for image load HOT 1
- NPM 8.5.0 Package / wrong types for patchDocument HOT 4
- patchDocument - input.prepForXml Error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docx.