excel4node
excel4node copied to clipboard
writeToBuffer fails with UnhandledPromiseRejectionWarning for trivial workbook
Describe the bug
Calling workbook.writeToBuffer
on a trivial workbook causes an opaque unhandled promise rejection error.
(node:34096) UnhandledPromiseRejectionWarning: Error: TypeError: Cannot read property 'toUpperCase' of undefined
at toUpperCase (/my/project/directory/node_modules/excel4node/source/lib/utils.js:125:21)
at getExcelRowCol (/my/project/directory/node_modules/excel4node/source/lib/utils.js:163:16)
at Array.sort (<anonymous>)
at sort (/my/project/directory/node_modules/excel4node/source/lib/worksheet/builder.js:152:34)
at processRows (/my/project/directory/node_modules/excel4node/source/lib/worksheet/builder.js:186:13)
at processNextRows (/my/project/directory/node_modules/excel4node/source/lib/worksheet/builder.js:189:9)
at new Promise (<anonymous>)
at _addSheetData (/my/project/directory/node_modules/excel4node/source/lib/worksheet/builder.js:144:12)
at /my/project/directory/node_modules/excel4node/source/lib/worksheet/builder.js:548:19
To Reproduce
Repro case. Error does not occur if commenting out the worksheet.cell
line.
const xl = require("excel4node");
async function main() {
const workbook = new xl.Workbook();
const worksheet = workbook.addWorksheet("Test");
const headers = ["hello", "world", "etc"];
for(let i = 0; i < headers.length; i++) {
worksheet.cell(i, 0).string(headers[i]);
}
const buffer = await workbook.writeToBuffer();
return buffer;
}
main().then(() => console.log("ok")).catch(console.error);
Expected behavior
Function should succeed in writing data to a buffer.
Environment:
- OS: OSX 10.9
- Node Version: 12.10.0
- excel4node Version: 1.7.2
So the cause of the error seems to be that the top-left cell is not (0, 0) but (1, 1); giving 0 for a cell coordinate causes the error. I imagine that this must be a common mistake - this really ought to produce a more informative error.
Appears to be a duplicate of #139