Skip to content

Instantly share code, notes, and snippets.

@hughsw
Created June 23, 2019 01:15
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 hughsw/abcd4b5554c20a5d8fd40725a1e60aa4 to your computer and use it in GitHub Desktop.
Save hughsw/abcd4b5554c20a5d8fd40725a1e60aa4 to your computer and use it in GitHub Desktop.
Basic basic bootstrapping example for exceljs
// See: https://gist.github.com/nealrs/4bdcb6316665338d9a1f7c2b690d6a19
const Excel = require('exceljs');
// create workbook & add worksheet
const workbook = new Excel.Workbook();
const worksheet = workbook.addWorksheet('Discography');
// add column headers
worksheet.columns = [
{ header: 'Album', key: 'album'},
{ header: 'Year', key: 'year'}
];
// add row using keys
worksheet.addRow({album: "Taylor Swift", year: 2006});
// add rows the dumb way
worksheet.addRow(["Fearless", 2008]);
// add an array of rows
const rows = [
["Speak Now", 2010],
{album: "Red", year: 2012}
];
worksheet.addRows(rows);
// edit cells directly
worksheet.getCell('A6').value = "1989";
worksheet.getCell('B6').value = 2014;
// save workbook to disk
const spreadsheetName = 'taylor_swift.xlsx';
workbook.xlsx.writeFile(spreadsheetName).then(() => console.log(`saved spreadsheet: ${spreadsheetName}`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment