Created
April 12, 2019 16:53
-
-
Save natergj/7dd897eec10068d227eea6de5bdaf9b1 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
async function excelDataFiller(rowNumber) { | |
const startIndex = 2; | |
const j = rowNumber + 1; | |
const numDiff = getCountDiff(storage.allCountResults[rowNumber].csdbCount, storage.allCountResults[rowNumber].esCount); | |
const perDiff = (storage.allCountResults[rowNumber].csdbCount - storage.allCountResults[rowNumber].esCount) / storage.allCountResults[rowNumber].csdbCount; | |
/* Column parameters */ | |
ws.column(1).setWidth(30); | |
ws.column(2).setWidth(27); | |
/* Header */ | |
ws.cell(2, 1).string('Institution').style(styles.header), | |
ws.cell(2, 2).string('CD Select').style(styles.header), | |
ws.cell(2, 3).string('CSDB').style(styles.header), | |
ws.cell(2, 4).string('CD').style(styles.header), | |
ws.cell(2, 5).string('Diff').style(styles.header), | |
ws.cell(2, 6).string('Variance').style(styles.header), | |
ws.cell(2, 7).string('Result').style(styles.header) | |
/* Data */ | |
ws.cell(j + startIndex, 1).string(storage.allCountResults[rowNumber].institutionType), | |
ws.cell(j + startIndex, 2).string(storage.allCountResults[rowNumber].selectName), | |
ws.cell(j + startIndex, 3).number(storage.allCountResults[rowNumber].csdbCount), | |
ws.cell(j + startIndex, 4).number(storage.allCountResults[rowNumber].esCount), | |
ws.cell(j + startIndex, 5).number(numDiff), | |
ws.cell(j + startIndex, 6).number(perDiff || 0).style(styles.percentage), // If 0 in both counts it returns NaN, so we just write 0 down to the file. | |
ws.cell(j + startIndex, 7).string(storage.allCountResults[rowNumber].testStatus) | |
} | |
async function excelFileGenerator() { | |
// Move this out of your excelDataFiller function. | |
ws.cell(1, 1, 1, 7, true).date(new Date()); | |
for (let i = 0; i < storage.allCountResults.length; i++) { | |
// await the completion of excelDataFiller on each iteration | |
await excelDataFiller(i) | |
} | |
wb.write('ConnectedDataCounts.xlsx'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment