Answer the question
In order to leave comments, you need to log in
How to fill a word template using js?
There is a ready-made Word template, how can I fill it out on the site using a form into which data is entered created in js? After filling out the form, the completed template is downloaded from the server.
What library is required to perform these tasks? If she's needed.
Answer the question
In order to leave comments, you need to log in
Read the off.doc of the small software . And so, here is a lib on npm
In the docx template, mark fields for insertion {field1} {field2}, etc. close
In your
docx program, open it as a regular archive, extract the word/document.xml file from it.
Edit with a replacement as plain text. (First, using regular expressions, extra '<.*?>')
For example, I tried directly in JSzip
function isprXML(xmlfile) {
// //почистить шаблон до правильного вида переменных {field1}
var re = /({.*?})/sg;
var re2 = /(<.*?>)/g;;
let result = xmlfile.match(re) || [];
let newres = [];
result.forEach(element => {
var newel = element.replace(re2, "");
xmlfile = xmlfile.replace(element, newel);
});
return xmlfile;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question