dtjohnson / xlsx-populate

Excel XLSX parser/generator written in JavaScript with Node.js and browser support, jQuery/d3-style method chaining, encryption, and a focus on keeping existing workbook features and styles in tact.
MIT License
956 stars 183 forks source link

Writing an empty list to a cell results in an error #323

Open sentientmachin3 opened 3 years ago

sentientmachin3 commented 3 years ago

To reproduce this bug you just need to try to write an empty list to a cell. This results in an error Cannot read property 'length' of undefined.

I think I already have spotted out the problem, here:

.case("array", values => {
                const numRows = values.length;
                const numCols = values[0].length; <---
                const range = this.rangeTo(this.relativeCell(numRows - 1, numCols - 1));
                return range.value(values);
            })

If the list is empty, the values[0] is undefined, which means it is impossible to read the property length.