officegen操作word文档
const officegen = require('officegen')
const fs = require('fs')
let docx = officegen('docx')
docx.on('finalize', function(written) {
console.log(
'完成以创建Microsoft Word文档。'
)
})
docx.on('error', function(err) {
console.log(err)
})
let pObj = docx.createP()
pObj.addText('易于理解的')
pObj.addText(' 带有颜色', { color: '000088' })
pObj.addText(' 和背面颜色。', { color: '00ffff', back: '000088' })
pObj = docx.createP()
pObj.addText('自从 ')
pObj.addText('officegen 0.2.12', {
back: '00ffff',
shdType: 'pct12',
shdColor: 'ff0000'
})
pObj.addText(' 你可以做 ')
pObj.addText('更酷 ', { highlight: true })
pObj.addText('stuff!', { highlight: 'darkGreen' })
pObj = docx.createP()
pObj.addText('甚至添加 ')
pObj.addText('外部链接', { link: 'https://www.try-learning.com/#/' })
pObj.addText('!')
pObj = docx.createP()
pObj.addText('粗体+下划线', { bold: true, underline: true })
pObj = docx.createP({ align: 'center' })
pObj.addText('将文本居中', {
border: 'dotted',
borderSize: 12,
borderColor: '88CCFF'
})
pObj = docx.createP()
pObj.options.align = 'right'
pObj.addText('将此文本向右对齐。')
pObj = docx.createP()
pObj.addText('这两行在同一段落中,')
pObj.addLineBreak()
pObj.addText('但是它们被一个换行符分隔开。')
docx.putPageBreak()
pObj = docx.createP()
pObj.addText('字体仅面向。', { font_face: 'Arial' })
pObj.addText(' 字体的字体和大小。', { font_face: 'Arial', font_size: 40 })
docx.putPageBreak()
pObj = docx.createP()
pObj.addImage('图片地址.jpg')
let out = fs.createWriteStream('example.docx')
out.on('error', function(err) {
console.log(err)
})
docx.generate(out)
officegen操作xlsx表格
const officegen = require('officegen')
const fs = require('fs')
let xlsx = officegen('xlsx')
xlsx.on('finalize', function(written) {
console.log(
'完成以创建Microsoft Excel文档。'
)
})
xlsx.on('error', function(err) {
console.log(err)
})
let sheet = xlsx.makeNewSheet()
sheet.name = 'Officegen Excel'
sheet.setCell('E7', 42)
sheet.setCell('I1', -3)
sheet.setCell('I2', 3.141592653589)
sheet.setCell('G102', '文档 测试!')
sheet.data[0] = []
sheet.data[0][0] = 1
sheet.data[1] = []
sheet.data[1][3] = '一些'
sheet.data[1][4] = '数据'
sheet.data[1][5] = '去'
sheet.data[1][6] = '在这里'
sheet.data[2] = []
sheet.data[2][5] = '更多文本'
sheet.data[2][6] = 900
sheet.data[6] = []
sheet.data[6][2] = 1972
let out = fs.createWriteStream('example.xlsx')
out.on('error', function(err) {
console.log(err)
})
xlsx.generate(out)