how to use createAndFillWorkbook() in exceljs?

Monece Solis picture Monece Solis · Apr 29, 2015 · Viewed 9.4k times · Source

I followed the documentation

var workbook = createAndFillWorkbook();

and I get this error Object # has no method 'createAndFillWorkbook'

even if I required exceljs already

var Excel = require("exceljs");

What I wanted to do was to create a report but I am somehow confused on the documentation because it does not say here how to use the createAndFillWorkbook() method it just says here to use it right away.

I referred here in the documentation: https://github.com/guyonroche/exceljs#writing-xlsx

Answer

easywaru picture easywaru · May 21, 2015

createAndFillWorkbook(); does not mean a function.(maybe pseudo function)

You must create some workbook then fill content.

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.");
});