KO
|
EN
gitlite — search
Search
#nodejs
#cpp
#javascript
#docker
#opensource
#react
#linux
#json
#python
#parallel-computing
#babel
#jest
generate-docx
★ 51
Open GitHub ↗
Generates .docx from template and data
Download README (.md)
Explore Similar Repositories
PandocWordTemplate
:
My personal word template for pandoc
docxplate
:
Generate new docx with params from given docx template.
go-template-docx
:
Template engine for docx documents, with tables, images, loops, charts support and more
docx_template_dart
:
A Docx template engine
docxtpl
:
a word document .docx template plugin to easily populate and generate word documents from templates
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
generate-docx
?
Download (.md)
[](https://travis-ci.org/telemark/generate-docx) [](https://coveralls.io/github/telemarks/generate-docx?branch=master) [](https://github.com/feross/standard) # generate-docx Generates .docx from [template](test/data/testdoc.docx) and [data](test/data/testdata.json) Returns a Buffer or saves the generated file if given path and filename. ## Example save file ### Promises ```js const generateDocx = require('generate-docx') const options = { template: { filePath: 'test/data/testdoc.docx', data: { title: 'This is the title', description: 'Description is good', body: 'My body is my temple' } }, save: { filePath: 'test/data/savedfile.docx' } } generateDocx(options) .then(console.log) .catch(console.error) ``` ### Callback ```js const generateDocx = require('generate-docx') const options = { template: { filePath: 'test/data/testdoc.docx', data: { title: 'This is the title', description: 'Description is good', body: 'My body is my temple' } }, save: { filePath: 'test/data/savedfile.docx' } } generateDocx(options, (error, message) => { if (error) { console.error(error) } else { console.log(message) } }) ``` ## Example return buffer ### Promises ```js const { writeFileSync } = require('fs') const generateDocx = require('generate-docx') const options = { template: { filePath: 'test/data/testdoc.docx', data: { title: 'This is the title', description: 'Description is good', body: 'My body is my temple' } } } generateDocx(options) .then(buf => { writeFileSync('test/data/frombuffer.docx', buf) console.log('File written') }).catch(console.error) ``` ### Callback ```js const { writeFileSync } = require('fs') const generateDocx = require('generate-docx') const options = { template: { filePath: 'test/data/testdoc.docx', data: { title: 'This is the title', description: 'Description is good', body: 'My body is my temple' } } } generateDocx(options, (error, buf) => { if (error) { console.error(error) } else { writeFileSync('test/data/frombuffer.docx', buf) console.log('File written') } }) ``` ## Options If you need to pass an [option object](https://docxtemplater.readthedocs.io/en/latest/configuration.html) to configure docxtemplater you can do using `templateOptions`. For example you can configure docxtemplater to parse `\n` as a linebreak in the document ```js const options = { template: { filePath: 'test/data/testdoc.docx', data: { title: 'This is the title', description: 'Description is good', body: 'My body is \n my temple' } }, templateOptions: { linebreaks: true }, save: { filePath: 'test/data/savedfile.docx' } } ``` ## License [MIT](LICENSE)