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.

Worksheet.spliceRows has inconsistent results based on splice count

See original GitHub issue

I am using exceljs 1.6.2.

I am seeing completely contradicting results based on how large of a number I pass in for the count argument for spliceRows.

First case, in which it seems to work as expected:

const spliceStart = 3; // Start removing at row three.
const countBefore = this._worksheet.rowCount; // 233

this._worksheet.spliceRows(spliceStart, 2); // Remove 2 rows.

const countAfter = this._worksheet.rowCount; // 231
const diff = countBefore - countAfter; // 2

Second case, in which count seems to be how many rows it keeps rather than how many it removes:

const spliceStart = 3; // Start removing at row three.
const countBefore = this._worksheet.rowCount; // 233

this._worksheet.spliceRows(spliceStart, 200); // Remove 200 rows.

const countAfter = this._worksheet.rowCount; // 202
const diff = countBefore - countAfter; // 31

What I really need is to remove all rows past row 2, but that actually results in NO rows being removed:

const lastRowToKeep = 2; // Start removing rows after row two.
const spliceStart = lastRowToKeep + 1; // Start removing at row three.
const countBefore = this._worksheet.rowCount; // 233
const spliceCount = countBefore - lastRowToKeep; // 231

this._worksheet.spliceRows(spliceStart, spliceCount); // Remove 231 rows.

const countAfter = this._worksheet.rowCount; // 233
const diff = countBefore - countAfter; // 0

I have no idea what to make of these results.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
iva2kcommented, Jan 28, 2021

Reviewing the code of spliceRows() - basically if number of rows remaining after the deleted part is less than count, nothing happens.

There needs to be another loop in spliceRows() that would delete all the rows that should be deleted but are not handled by the loop that copies existing rows over to where deleted rows are.

As it stands now, spliceRows() is useless to delete rows at the end of the worksheet.

1reaction
laizezhongcommented, Nov 18, 2019

I had the same issue. for my test data it worked correctly when I always remove one row at a time, in a loop. e.g. if I want to remove 5 rows:

for (let i = 0; i < 5; i++) {
  worksheet.spliceRows(2, 1);
}

loop is to slow,when I splice 20000 rows,it cost 40min

Read more comments on GitHub >

github_iconTop Results From Across the Web

Worksheet.spliceRows has inconsistent results based on ...
I am using exceljs 1.6.2. I am seeing completely contradicting results based on how large of a number I pass in for the...
Read more >
exceljs - npm
A count of the number of columns that have values. Page Setup ⬆. All properties that can affect the printing of a sheet...
Read more >
Ways to count values in a worksheet - Microsoft Support
Count cells in a range based on multiple conditions by using the COUNTIFS function. The COUNTIFS function is similar to the COUNTIF function...
Read more >
Add rows before the column header using excel.js module + ...
I have tried a lot of things to get the sheet.columns functionality to leave the first row ... spliceRows(1, 0, titleValues1,titleValues2);.
Read more >
V~anEddy - William J. Hughes Technical Center - FAA
current lap splice inspections at transport aircraft maintenance facilities, reliability ... The result of AANC's efforts is a three volume document, ...
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