You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a table, it's possible to define the rows array, but still leave it empty. ExcelJS will not warn that this will be an issue, but it will result in the Excel file being corrupted. One changed line of code in the validate() method in the Table class should resolve this issue.
Lib version: 9.4.2
Steps To Reproduce
Run the Jest unit test (below) to a project with exceljs installed.
Open the generated EmptyRowsTableTest.xlsx file.
User will receive the following error message: "We found a problem with some content in 'BadTablenameTest.xlsx'. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes."
If you click "Yes" for the repairs, Excel will present the message: "Repaired Records: Table from /xl/tables/table1.xml part (Table)". However, the table will not be created in the file.
importExcelfrom"exceljs";importpathfrom"path";describe("addTable()",()=>{it("should not allow an empty rows array",async()=>{constexcelDoc=newExcel.Workbook();constaccountSheet=excelDoc.addWorksheet("Accounts");accountSheet.addTable({name: "Bob_s_Accounts",ref: "A1",headerRow: true,totalsRow: false,style: {theme: "TableStyleMedium2",showRowStripes: true,},columns: [{name: "Name",filterButton: true},{name: "Description",filterButton: true},{name: "Credit Limit",filterButton: true},{name: "Account Type",filterButton: true},],rows: [],// EMPTY ROWS ARRAY -- currently this is permitted, but it will corrupt the Excel file});expect(excelDoc).toBeInstanceOf(Excel.Workbook);awaitexcelDoc.xlsx.writeFile(path.join(__dirname,"../../data/EmptyRowsTableTest.xlsx"));});});
The expected behaviour:
When the developer tries to create a Table without populating the rows array, a runtime error should result: "Table must have row definitions."
Possible solution (optional, but very helpful):
Update the validate() function to check that the rows array is not only defined by also populated:
assert(table.rows&&table.rows.length>0,'Table must have row definitions');
The text was updated successfully, but these errors were encountered:
🐛 Bug Report
When creating a table, it's possible to define the rows array, but still leave it empty. ExcelJS will not warn that this will be an issue, but it will result in the Excel file being corrupted. One changed line of code in the validate() method in the Table class should resolve this issue.
Lib version: 9.4.2
Steps To Reproduce
The expected behaviour:
When the developer tries to create a Table without populating the rows array, a runtime error should result: "Table must have row definitions."
Possible solution (optional, but very helpful):
Update the validate() function to check that the rows array is not only defined by also populated:
The text was updated successfully, but these errors were encountered: