Node.JS Excel-Export
Nice little module that is assisting when creating excel exports from datasets. It takes normal array-of-objects dataset plus a json report specification and builds excel(.xlsx) file. It supports styling and re-formating of the data on the fly. Check the example usage for more information.
Installation
npm install node-excel-export
Usage
var excel = require('node-excel-export');
var styles = {
headerDark: {
fill: {
fgColor: {
rgb: 'FF000000'
}
},
font: {
color: {
rgb: 'FFFFFFFF'
},
sz: 14,
bold: true,
underline: true
}
},
cellPink: {
fill: {
fgColor: {
rgb: 'FFFFCCFF'
}
}
}
};
var specification = {
customer_name: {
displayName: 'Customer',
headerStyle: styles.headerDark
},
status_id: {
displayName: 'Status',
headerStyle: styles.headerDark,
cellFormat: function(value) {
return (value == 1) ? 'Active' : 'Inactive';
}
},
note: {
displayName: 'Description',
headerStyle: styles.headerDark,
cellStyle: styles.cellPink
}
}
var dataset = [
{customer_name: 'IBM', status_id: 1, note: 'some note', misc: 'not shown'},
{customer_name: 'HP', status_id: 0, note: 'some note'},
{customer_name: 'MS', status_id: 0, note: 'some note', misc: 'not shown'}
]
var report = excel.buildExport(
[
{
name: 'Sheet name',
specification: specification,
data: dataset
}
]
);
res.attachment('export.xlsx');
return res.send(excel_export);