I'm trying to use exceljs to create a excel file of mongodb collection. This is what i'm trying to do This is my mongodb collecton
{
"id": "01",
"make": "toyota",
"year": [
2005,
2006,
2007,
2008,
2009,
2010
],
"model": "fortuner",
"type": "a"
}
{
"id": "02",
"make": "toyota",
"year": [
2005,
2006,
2007,
2008,
2009,
2010
],
"model": "land cruiser 200",
"type": "b"
}
{
"id": "03",
"make": "toyota",
"year": [
2005,
2006,
2007,
2008,
2009,
2010
],
"model": "land cruiser 200",
"type": "e"
}
,and i want to create excel file from this collection
ID Make Year Model Type
01 toyota 2005-2010 a xxxx
02 nissan 2000-2006 b xxxx
In XLSX official documentation they said to use
Writing Workbooks
nodejs write to file:
/* output format determined by filename */
XLSX.writeFile(workbook, 'out.xlsx');
/* at this point, out.xlsx is a file that you can distribute */
write to binary string (using FileSaver.js):
/* bookType can be 'xlsx' or 'xlsm' or 'xlsb' */
var wopts = { bookType:'xlsx', bookSST:false, type:'binary' };
var wbout = XLSX.write(workbook,wopts);
function s2ab(s) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
return buf;
}
/* the saveAs call downloads a file on the local machine */
saveAs(new Blob([s2ab(wbout)],{type:""}), "test.xlsx")
i can't get good idea about how to use this. Does anyone know how to do this ?