Axles
Node.JS Excel-Export
Fork of node-excel-export
to use xlsx
instead
of xlsx-style
in order to support hyperlinks and other
features being lost by that fork not staying current.
Installation
npm install axles
Usage
- Check here, for more styling
const excel = require('axles');
const styles = {
headerDark: {
fill: {
fgColor: {
rgb: 'FF000000'
}
},
font: {
color: {
rgb: 'FFFFFFFF'
},
sz: 14,
bold: true,
underline: true
}
},
cellPink: {
fill: {
fgColor: {
rgb: 'FFFFCCFF'
}
}
},
cellGreen: {
fill: {
fgColor: {
rgb: 'FF00FF00'
}
}
}
};
const heading = [
[{value: 'a1', style: styles.headerDark}, {value: 'b1', style: styles.headerDark}, {value: 'c1', style: styles.headerDark}],
['a2', 'b2', 'c2']
];
const specification = {
customer_name: {
displayName: 'Customer',
headerStyle: styles.headerDark,
cellStyle: function(value, row) {
return (row.status_id == 1) ? styles.cellGreen : {fill: {fgColor: {rgb: 'FFFF0000'}}};
},
width: 120
},
status_id: {
displayName: 'Status',
headerStyle: styles.headerDark,
cellFormat: function(value, row) {
return (value == 1) ? 'Active' : 'Inactive';
},
width: '10'
},
note: {
displayName: 'Description',
headerStyle: styles.headerDark,
cellStyle: styles.cellPink,
width: 220
}
}
const 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'}
]
const merges = [
{ start: { row: 1, column: 1 }, end: { row: 1, column: 10 } },
{ start: { row: 2, column: 1 }, end: { row: 2, column: 5 } },
{ start: { row: 2, column: 6 }, end: { row: 2, column: 10 } }
]
const report = excel.buildExport(
[
{
name: 'Report',
heading,
merges,
specification,
data: dataset
}
]
);
res.attachment('report.xlsx');
return res.send(report);