山西货通九州网络科技有限公司官网 - nodejs 2021-11-16T09:34:00+08:00 Typecho http://www.jiuzhousx.com/feed/atom/tag/nodejs/ <![CDATA[nodejs 生成 word officegen模块使用方法]]> http://www.jiuzhousx.com/inews/n3/officegen.html 2021-11-16T09:34:00+08:00 2021-11-16T09:34:00+08:00 admin https://www.advertdh.com/ 详细文档链接

https://github.com/Ziv-Barber/officegen/blob/87dd5501968501555ea3bee60043affc9f67c1fa/manual/docx/README.md

引用

const officegen = require('officegen');

监听

docx.on('finalize', function(written) {
   console.log(
     'Finish to create a Microsoft Word document.'
   );
});

// Officegen calling this function to report errors:
docx.on('error', function(err) {
  console.log(err);
});
out.on('error', function(err) {
  console.log(err);
});

生成一行

let pObj = docx.createP();

行内添加文字元素

pObj.addText(' and back color.', { color: '00ffff', back: '000088',shdType: 'pct12',shdColor: 'ff0000' ,link: 'https://github.com'});

设置文字对齐方式

pObj.options.align = 'right';

关联文件并导出

const out = fs.createWriteStream('./app/public/example.docx');
docx.generate(out);
]]>
<![CDATA[mongoose 多表查询 使用条件查询]]> http://www.jiuzhousx.com/inews/n3/16.html 2021-06-21T12:16:00+08:00 2021-06-21T12:16:00+08:00 admin https://www.advertdh.com/ aggregate.push({ $lookup: { from: 'examnum', let: { userId: '$_id' }, pipeline: [ { $match: { $expr: { $eq: [ '$exambatchId', mongoose.Types.ObjectId(data.exambatchId) ], }, }, }, { $match: { $expr: { $eq: [ '$userId', '$$userId' ], }, }, }, { $sort: { _id: 1 }, }, { $limit: 1, }, ], as: 'examnum', }, }); ]]>