Append rows to existing table
See original GitHub issueHello, I’m having an issue when appending new rows to existing table
const workbook = new ExcelJS.Workbook()
workbook.xlsx.readFile(filename).then(async function () {
let worksheet = workbook.getWorksheet(1)
let table = worksheet.getTable('MyTable')
table.addRow(['One','Two'])
table.commit()
await workbook.xlsx.writeFile(filename)
})
I’m getting this error :
TypeError: Cannot read property 'length' of undefined
at Table.get height [as height] (C:\Users\SatSuki\Desktop\FootScrap\node_modules\exceljs\lib\doc\table.js:88:32)
at Table.get filterHeight [as filterHeight] (C:\Users\SatSuki\Desktop\FootScrap\node_modules\exceljs\lib\doc\table.js:93:21)
at Table.get tableHeight [as tableHeight] (C:\Users\SatSuki\Desktop\FootScrap\node_modules\exceljs\lib\doc\table.js:98:21)
at Table.cacheState (C:\Users\SatSuki\Desktop\FootScrap\node_modules\exceljs\lib\doc\table.js:272:35)
at Table.addRow (C:\Users\SatSuki\Desktop\FootScrap\node_modules\exceljs\lib\doc\table.js:322:14)
at C:\Users\SatSuki\Desktop\FootScrap\spread.js:62:27
at process._tickCallback (internal/process/next_tick.js:68:7)
When appending just after creating the table it works fine.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:13 (1 by maintainers)
Top Results From Across the Web
Add a cell, row, or column to a table - Microsoft Support
Click in a cell above or below where you want to add a row. · Under Table Tools, on the Layout tab, do...
Read more >Insert Into SQL – How to Insert Into a Table Query [Example ...
If you want to add data to your SQL table, then you can use the INSERT statement. Here is the basic syntax for...
Read more >SQL INSERT - Insert One or More Rows into a Table - zentut
SQL INSERT statement – insert one row into a table · First, the table, which you want to insert a new row, in...
Read more >SQL Server append table to an existing table - Stack Overflow
I need to append rows from one table to an existing table. I am thinking something like following but this gives an error...
Read more >Add rows to existing tables - Fusion Tables Help
Add rows to existing tables · Use Edit > Add Row to enter a new row one-at-a-time · Use File > Import more...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello, Though I have updated ExcelJs in latest version but I still get the same problem about appending rows to existing table. My code is like
const Excel = require('exceljs'); const workbook = new Excel.Workbook(); await workbook.xlsx.readFile(filepath + '/template_file.xlsx'); const mysheet = workbook.getWorksheet('MyWorksheet'); mysheet.unprotect(); const mytable = mysheet.getTable('MyTable'); for (var i: number = 0; i< myArray.length; i++) { mytable.addRow([ myArray[i].field1, myArray[i].field2 ]); } mytable.commit();
When I test with console.log(mytable) and I got
Table { worksheet: undefined, table: { name: 'MyTable', displayName: 'MyTable', tableRef: 'A1:N2', totalsRow: false, headerRow: false, columns: [ [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object] ], autoFilterRef: 'A1:N2', style: { theme: 'TableStyleMedium2', showFirstColumn: false, showLastColumn: false, showRowStripes: true, showColumnStripes: false } } }
Thanks in advance for your help
Looks like it is caused by no value for rows in table… rows is referenced in multiple places in tables.js