question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Append rows to existing table

See original GitHub issue

Hello, 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:open
  • Created 4 years ago
  • Reactions:6
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
phamnuhuyentrangcommented, Jun 18, 2020

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

2reactions
dannycdannydocommented, Apr 13, 2020

Has this bug been fixed? I am getting the same behaviour.

Looks like it is caused by no value for rows in table… rows is referenced in multiple places in tables.js

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found