-
[node] Excel file exportPrograming/javascript 2019. 11. 21. 17:52
I need to get the excel data which is the result of db query.
And I've got it successfully by using 'node-excel-export' module.
[Source Code]
main.js
const exportExcel = require('./excel_export').exportExcel; ... function run() { ... const qData = getLogs(); // QUERY exportExcel(qData); ... } run();
excel_export.js
const excel = require('node-excel-export'); ... const exportExcel = (dataset) => { const report = excel.buildExport( [ { name: 'Report', heading: heading, merges: merges, specification: specification, data: dataset } ] ); fs.stat(__dirname + `/report.xlsx`, (err, stat) => { if (err) { fs.writeFile(__dirname + `/report.xlsx`, report, `utf8`, function (err) { }); } else { fs.appendFile(__dirname + `/report.xlsx`, report, `utf8`, function (err) { }); } }); return report; } module.exports.exportExcel = exportExcel;
[RUN]
$ node main.js
'Programing > javascript' 카테고리의 다른 글
How to NaN to 0 in javascript? (0) 2019.12.11 [typescript] Start express with typescript (0) 2019.12.06 [javascript] histogram modules (0) 2019.11.26 [typescript] histogram algorithm (0) 2019.11.26 [javascript] yyyy-mm-dd to date convert (0) 2019.10.18