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) |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· .NET Core 中如何实现缓存的预热?
· 三行代码完成国际化适配,妙~啊~
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?