Created
October 21, 2016 21:25
-
-
Save lisamariewatkins/f0719706bdd5f22fe0ac52c9f8ff900e to your computer and use it in GitHub Desktop.
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'); | |
| var quote = { | |
| Name: 'TEST', | |
| Account__c: '001m000000VrHEu', | |
| Opportunity__c: '006m0000005awRR' | |
| }; | |
| var quoteProducts = [{ | |
| Name: 'TEST1', | |
| Product: 'Prod' | |
| }, { | |
| Name: 'TEST2', | |
| Product: 'Prod2' | |
| }]; | |
| var workbook = excelbuilder.createWorkbook("C:\\Users\\Lisa Watkins\\Desktop", 'quote.xlsx'); | |
| var quoteSheet = workbook.createSheet('Quote', 10, 2); | |
| setQuoteSheet(quoteSheet, quote); | |
| var quoteProductSheet = workbook.createSheet('Quote Products', 10, 5); | |
| setQuoteProductsSheet(quoteProductSheet, quoteProducts); | |
| workbook.save(function(ok){ | |
| if(!ok){ | |
| workbook.cancel(); | |
| } | |
| else{ | |
| console.log('Workbook created.'); | |
| } | |
| }); | |
| function setQuoteSheet(sheet, fields){ | |
| //sets column headers | |
| for(var i=0;i<Object.keys(fields).length;i++){ | |
| sheet.set((i+1), 1, Object.keys(fields)[i]); | |
| } | |
| //sets all the data | |
| var count = 1; | |
| for(var key in fields){ | |
| sheet.set(count, 2, fields[key]); | |
| count++; | |
| } | |
| } | |
| function setQuoteProductsSheet(sheet, records){ | |
| //sets column headers | |
| console.log(Object.keys(records[0])); | |
| var keys = Object.keys(records[0]); | |
| var header = 1; | |
| for(var i=0;i<keys.length;i++){ | |
| sheet.set(header, 1, Object.keys(records[0])[i]); | |
| header++; | |
| } | |
| //sets data | |
| var dataColumn = 1; | |
| var dataRow = 2; | |
| for(var i=0; i<records.length;i++){ | |
| for (var key in records[i]){ | |
| sheet.set(dataColumn, dataRow, records[i][key]); | |
| dataColumn++; | |
| } | |
| dataRow++; | |
| dataColumn =1; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment