Created
September 7, 2018 06:37
-
-
Save Hobart2967/5bfbe9da3b4980c2a8b56fb3bc410ad2 to your computer and use it in GitHub Desktop.
excel4node
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
| module.exports = function(argsPassed) { | |
| var excel = require('excel4node'); | |
| var path = require('path'); | |
| // Create a new instance of a Workbook class | |
| var workbook = new excel.Workbook(); | |
| // Add Worksheets to the workbook | |
| var worksheet = workbook.addWorksheet('Sheet 1'); | |
| var worksheet2 = workbook.addWorksheet('Sheet 2'); | |
| // Create a reusable style | |
| var style = workbook.createStyle({ | |
| font: { | |
| color: '#FF0800', | |
| size: 12 | |
| }, | |
| numberFormat: '$#,##0.00; ($#,##0.00); -' | |
| }); | |
| // Set value of cell A1 to 100 as a number type styled with paramaters of style | |
| worksheet.cell(1,1).number(100).style(style); | |
| // Set value of cell B1 to 300 as a number type styled with paramaters of style | |
| worksheet.cell(1,2).number(200).style(style); | |
| // Set value of cell C1 to a formula styled with paramaters of style | |
| worksheet.cell(1,3).formula('A1 + B1').style(style); | |
| // Set value of cell A2 to 'string' styled with paramaters of style | |
| worksheet.cell(2,1).string('string').style(style); | |
| // Set value of cell A3 to true as a boolean type styled with paramaters of style but with an adjustment to the font size. | |
| worksheet.cell(3,1).bool(true).style(style).style({font: {size: 14}}); | |
| const filePath = path.resolve(path.join(process.cwd(), argsPassed.export)); | |
| console.log(`Saving file to path ${filePath}`); | |
| workbook.write(filePath, function(err, stats) { | |
| if (err) { | |
| console.error(err); | |
| } else { | |
| console.log(stats); // Prints out an instance of a node.js fs.Stats object | |
| } | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment