I am getting data from DB and trying to populate the excel file. Unable to populate the excel file. The code for writing data is as follow.
await users();
console.log("data " + JSON.stringify(test));
workbook1.xlsx.writeFile("testing.xlsx").then(function () {
worksheet.addRow(test);
console.log(test);
});
user function is follow
function users() {
return new Promise(async (resolve, reject) => {
constants.sequelize.query(`SELECT collectionName FROM DB.[collection] WHERE id = '1234567'`).then(user => {
console.log(user);
test = user;
resolve(user);
console.log("out");
}).catch(error => {
reject(error);
});
});
}
And the data in "test" is as follow
[[{"collectionName":"some name"}],[{"collectionName":"another name"}]]
EDIT: it should be worksheet.addRows(test); And should be outside the "writeFile"
I think you should use addRows
not addRow
:
worksheet.addRows(test); // < --------- as 'test' is array of multiple rows
instead of
worksheet.addRow(test);