Created
October 16, 2015 10:13
-
-
Save shamsher31/544cb2c31b7eb06753d8 to your computer and use it in GitHub Desktop.
Export to Excel with multiple sheet
This file contains hidden or 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
var excelbuilder = require('msexcel-builder'); | |
// Create a new workbook file in current working-path | |
var workbook = excelbuilder.createWorkbook('./', 'sample.xlsx') | |
// Create a new worksheet with 10 columns and 12 rows | |
var sheet1 = workbook.createSheet('sheet1', 10, 12); | |
var sheet2 = workbook.createSheet('sheet2', 10, 12); | |
var sheet3 = workbook.createSheet('sheet3', 10, 12); | |
// Fill with headers | |
for (var i = 1; i < 10; i++) { | |
sheet1.set(i, 1, 'test'+i); | |
} | |
for (var p =2; p < 10; p++) { | |
for (var j = 1; j < 10; j++) { | |
sheet1.set(j, p, 'row'+j); | |
sheet1.merge({col:1,row:2},{col:1,row:5}); | |
} | |
} | |
for (var i = 1; i < 10; i++) { | |
sheet2.set(i, 1, 'test'+i); | |
} | |
for (var i = 1; i < 10; i++) { | |
sheet3.set(i, 1, 'test'+i); | |
} | |
// Save it | |
workbook.save(function(ok){ | |
if (!ok) | |
workbook.cancel(); | |
else | |
console.log('congratulations, your workbook created'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment