How to use createAndFillWorkbook () in exceljs?
I followed the documentation
var workbook = createAndFillWorkbook();
and i get this error Object # has no method 'createAndFillWorkbook'
even if i need exceljs already
var Excel = require("exceljs");
What I wanted to do was create a report, but I somehow got confused in the documentation because it doesn't say how to use the createAndFillWorkbook () method, which it just says here to use it right away.
I mentioned in the documentation here: https://github.com/guyonroche/exceljs#writing-xlsx
+3
source to share
2 answers
createAndFillWorkbook (); does not mean function. (possibly a pseudo-function)
You have to create a workbook and fill it out.
See below.
// create workbook by api.
var workbook = new Excel.Workbook();
// must create one more sheet.
var sheet = workbook.addWorksheet("My Sheet");
// you can create xlsx file now.
workbook.xlsx.writeFile("C:\\somepath\\some.xlsx").then(function() {
console.log("xls file is written.");
});
+8
source to share
var excel = require("exceljs");
var workbook1 = new excel.Workbook();
workbook1.creator = 'Me';
workbook1.lastModifiedBy = 'Me';
workbook1.created = new Date();
workbook1.modified = new Date();
var sheet1 = workbook1.addWorksheet('Sheet1');
var reColumns=[
{header:'FirstName',key:'firstname'},
{header:'LastName',key:'lastname'},
{header:'Other Name',key:'othername'}
];
sheet1.columns = reColumns;
workbook1.xlsx.writeFile("./uploads/error.xlsx").then(function() {
console.log("xlsx file is written.");
});
This is my sample code that works for me.
+4
source to share