Created
June 23, 2019 01:15
-
-
Save hughsw/abcd4b5554c20a5d8fd40725a1e60aa4 to your computer and use it in GitHub Desktop.
Basic basic bootstrapping example for exceljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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