node.js - writeFile not woking in exceljs -
i using exceljs , try write value in cell not working. workbook.xlsx.readfile(filename)
working workbook.xlsx.writefile(filename)
won't.
here code:-
var excel = require('exceljs'); var fs = require('fs') module.exports.summary = function(req, res, next) { try { var filename = process.cwd() + '/template/report/summary.xlsx'; var workbook = new excel.workbook(); workbook.xlsx.writefile(filename) .then(function() { var worksheet = workbook.getworksheet(1); console.log('worksheet',worksheet); var row = worksheet.getrow(5); row.getcell('c').value = new date(); row.commit(); worksheet.commit(); workbook.commit().then(function() { console.log('xls file written.'); }); res.json({ msg: done }) }); } catch (e) { next(e); } }
try code, hope you
//creating new workbook var workbook = new excel.workbook(); //creating sheet particular workbook var sheetname = 'sheet1'; var sheet = workbook.addworksheet(sheetname); //header must in below format sheet.columns = [{key:"name", header:"name}, {key: "age", header: "age"}]; //data must below, key of data must match header. var data = [{name:"kalai", age: 24}, {name:"vignesh", age:24}]; //adding each in sheet for(i in data){ sheet.addrow(data[i]); } //finally creating xlsx file var filename = "sample.xlsx"; workbook.xlsx.writefile(filename).then(function() { callback(null); });
Comments
Post a Comment