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.

Cannot remove the last row with .spliceRows()

See original GitHub issue

Hi,

Consider following code:

let Excel = require('exceljs');
let wb = new Excel.Workbook();
let ws = wb.addWorksheet('sheet1');

ws.addRow(['1.1', '1.2', '1.3']);
ws.addRow(['2.1', '2.2', '2.3']);
ws.addRow(['3.1', '3.2', '3.3']);

console.log('rows total: ', ws.rowCount);
for (let i = 1; i <= 3; i++) {
  console.log(i, ':', ws.getRow(i).values);
}

ws.spliceRows(3, 1);

console.log('rows total: ', ws.rowCount);
for (let i = 1; i <= 3; i++) {
  console.log(i, ':', ws.getRow(i).values);
}

Output before splice:

rows total:  3
1 ':' [ , '1.1', '1.2', '1.3' ]
2 ':' [ , '2.1', '2.2', '2.3' ]
3 ':' [ , '3.1', '3.2', '3.3' ]

Output after splice:

rows total:  3
1 ':' [ , '1.1', '1.2', '1.3' ]
2 ':' [ , '2.1', '2.2', '2.3' ]
3 ':' [ , '3.1', '3.2', '3.3' ]

The expectation is that after splice it will be:

rows total:  2
1 ':' [ , '1.1', '1.2', '1.3' ]
2 ':' [ , '2.1', '2.2', '2.3' ]
3 ':' []

Analogy with arrays:

let a = [1,2,3];
a.splice(2,1);
console.log(a); // => [1,2]

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
GW-GhostWolfcommented, Jul 8, 2021

Using version 4.2.1, still not fixed. My work around was to add a blank row to the bottom of the worksheet before trying to delete.

lastRow = worksheet.rowCount;
worksheet.insertRow(lastRow + 1,[]);
worksheet.spliceRows(lastRow, 1);
0reactions
iva2kcommented, Jul 12, 2021

@GW-GhostWolf Adding just one row may be not enough if number of rows deleted is more than one. Let’s bump it up so the PR is merged.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cant delete last row of data table using vba
Hi. I'm using VBA code in EXCEL developer to delete an entry in a table using the following: SheetName.Range("FirstDataCell").
Read more >
Core API reference - JavaScript Data Grid - Handsontable
Removes rows, starting from the last row. 'insert_col_start', Inserts columns before the index column. Inserts columns before the first column.
Read more >
exceljs - npm
Once a worksheet is added to a workbook, it cannot be removed. Once a row is committed, it is no longer accessible since...
Read more >
exceljs - npm.io
Use the worksheet id to remove the sheet from workbook. ... Equal to the row number of the last row that has values....
Read more >
How to delete the last row of data of a pandas dataframe
df.drop(df.tail(n).index,inplace=True) # drop last n rows ... () method and it work but not as kool and readable as using [n:-n], hope that...
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