Skip to content

Instantly share code, notes, and snippets.

@macrat
Created September 12, 2017 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macrat/4b08ebb8ee1f26cf99ba7b78323bce61 to your computer and use it in GitHub Desktop.
Save macrat/4b08ebb8ee1f26cf99ba7b78323bce61 to your computer and use it in GitHub Desktop.
node.jsでExcel生成
const excel = require('exceljs');
let workbook = new excel.Workbook()
workbook.creator = 'MacRat';
workbook.created = new Date(2000, 1, 1);
workbook.modified = new Date();
let sheet = workbook.addWorksheet('The sheet');
sheet.columns = [
{ header: 'ID', key: 'id', width: 10 },
{ header: 'Value', key: 'value', width: 10 },
{ header: 'Percent', key: 'percent', width: 10, style: {numFmt: '0.00%'} },
{ header: 'Sum', key: 'sum', width: 10 },
];
sheet.addRow({id: 0, value: 10, percent: {formula: 'B2/10'}, sum: {formula: 'B2'}});
sheet.addRow({id: 1, value: 20, percent: {sharedFormula: 'C2'}, sum: {formula: 'B3+D2'}});
sheet.addRow({id: 2, value: 2, percent: {sharedFormula: 'C2'}, sum: {sharedFormula: 'D3'}});
sheet.addRow({id: 3, value: 8, percent: {sharedFormula: 'C2'}, sum: {sharedFormula: 'D3'}});
sheet.autoFilter = 'A1:C5';
sheet.getRow(1).fill = {
type: 'pattern',
pattern: 'solid',
fgColor: {argb:'FF000000'},
};
sheet.getRow(1).alignment = {horizontal: 'center'};;
sheet.getRow(1).font = { bold: true, color: {argb: 'FFFFFFFF'} };
workbook.xlsx.writeFile('output.xlsx').then(() => console.log('wrote'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment