
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
generate-docx
Advanced tools
Generates .docx from template and data
Returns a Buffer or saves the generated file if given path and filename.
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)
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)
}
})
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)
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')
}
})
If you need to pass an option object to configure docxtemplater you can do using templateOptions
.
For example you can configure docxtemplater to parse \n
as a linebreak in the document
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'
}
}
FAQs
Generates .docx from template and data
The npm package generate-docx receives a total of 12 weekly downloads. As such, generate-docx popularity was classified as not popular.
We found that generate-docx demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.