Comments (1)
Hello,
I remember someone doing something very similar a few years back. (Maybe it was you ?). I could'n t find whether it was on a github issue or per email.
I think the way he did it at the time was, before passing the data to docxtemplater, he would open the word/document.xml, and add unique ids to each <w:t> tag.
Then you could generate your docx from that same zip file.
Something like this (untested code, but likely should work) :
const zip = new JSZip(buf);
const text = zip.file("word/document.xml").asText();
const { DOMParser, XMLSerializer } = require('@xmldom/xmldom')
const document = new DOMParser().parseFromString(text, "text/xml");
const textTags = document.getElementsByTagName("w:t");
let trackedId = 1;
for (let i = 0, len = textTags.length; i < len; i++) {
const textTag = textTags[i];
textTag.setAttribute("_trackedId", trackedId++)
}
const newText = new XMLSerializer().serializeToString(document);
zip.file("word/document.xml", newText);
const doc = new Docxtemplater(zip, { paragraphLoop: true, linebreaks: true });
doc.render({
first_name: "John",
});
I'm not exactly sure how you then convert your XML to HTML and keep the tags, if you have more insights, please post them here so that future users can also benefit from this !
from docxtemplater.
Related Issues (20)
- dropUnsupportedFileTypesModules called twice by constructor HOT 3
- Cannot resolve @Name placeholder HOT 2
- Chart Module: Unexpected Behavior with Null Value in Data HOT 3
- Differentiate between conditions and loops when getting tags HOT 1
- Conditional assignment doesn't work as expected HOT 1
- Page break propogates to all elements inside div HOT 5
- Numbering for conditional text HOT 3
- Question: Importing ExpressionParser in TypeScript. HOT 6
- When I write a tag in complex content, it doesn't work HOT 4
- HTMLModule Dependencies causing errors HOT 1
- paragraphLoop doesn't seem to work HOT 2
- ChartModule + ErrorLocationModule HOT 2
- Bun.sh HOT 1
- Trying to setup angular parser, but is failing with compilation error. HOT 8
- getSize 返回一个promsie ,word预览正常,但是导出word图片丢失 HOT 2
- Compile (tsx) issue with TxtTemplater HOT 1
- Slides demo is broken HOT 1
- According to Microsoft Word, the generated file is corrupted. Cannot open it. HOT 12
- Duplicate content of a word file (in one page) 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 docxtemplater.