3

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

Monece Solis
  • 683
  • 2
  • 6
  • 23

2 Answers2

11

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.");
});
easywaru
  • 1,073
  • 9
  • 17
5
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 which works for me.

Karthik
  • 129
  • 2
  • 8