Skip to content

Table DeleteRow deletes whole worksheet rows (and breaks named ranges) when the table starts in column A and is past row 16384 #2591

Open

Description

@stellis

EPPlus usage

Commercial use (I have a commercial license)

Environment

Windows 11

Epplus version

8.7.2

Spreadsheet application

Excel

Description

(This happens in 8.7.2, and the code looks the same in 9.0 preview.)

If a table starts in column A and you delete rows from it that end at row 16384 or further down, EPPlus deletes the entire worksheet rows instead of just the table's rows. We noticed two things go wrong:

  • anything to the right of the table on those rows is deleted, and anything to the right below them moves up
  • a workbook-level name that points at a table column, like Table1[Flag], gets saved as a plain range with no sheet name, e.g. $B$5:$B$16387. Excel then says the file has a problem, repairs it and drops the name ("Removed Records: Named range from /xl/workbook.xml part").

If the table starts in column B instead, or the deleted rows end at row 16383, it works fine.

I think it comes from this line in ExcelRangeBase.Delete(eShiftTypeDelete shift):

else if (shift == eShiftTypeDelete.EntireRow || (_fromCol <= 1 && _toRow >= ExcelPackage.MaxColumns))

_toRow is compared with MaxColumns (16384). Should that be _toCol?

The name part seems to follow from that: the whole-row path calls ExcelNamedRangeCollection.Delete with 0 as the column limits, so the name's Address is replaced with the shifted range. _table is still set on the name though, and SetNameElement writes Address rather than FullAddress when Table != null, so the sheet name is lost on save.

Steps to reproduce:

  1. Make a sheet with a table at A4:B16390 and a workbook-level name FlagColumn = Table1[Flag].
  2. Save and reopen the package, so the name is read from the file the way it would be from a workbook made in Excel.
  3. Delete the last 3 rows of the table with DeleteRow(16383, 3).
  4. Save and look at xl/workbook.xml, and at D16389.
using var package = new ExcelPackage();
var sheet = package.Workbook.Worksheets.Add("Sheet1");
sheet.Cells["A4"].Value = "Item";
sheet.Cells["B4"].Value = "Flag";
for (var row = 5; row <= 16390; row++)
{
    sheet.Cells[row, 1].Value = "Item " + row;
    sheet.Cells[row, 2].Value = "Y";
}
sheet.Cells["D16389"].Value = "next to the table";
sheet.Tables.Add(sheet.Cells["A4:B16390"], "Table1");
package.Workbook.Names.AddFormula("FlagColumn", "Table1[Flag]");

// save and reopen so the name is loaded from the file
using var reopened = new ExcelPackage(new MemoryStream(package.GetAsByteArray()));
var table = reopened.Workbook.Worksheets["Sheet1"].Tables["Table1"];
table.DeleteRow(16383, 3); // the last 3 rows, 16388-16390

File.WriteAllBytes("out.xlsx", reopened.GetAsByteArray());

Expected: <definedName name="FlagColumn">Table1[Flag]</definedName>, and D16389 still says "next to the table".

What we get: <definedName name="FlagColumn">$B$5:$B$16387</definedName>, and D16389 is empty.

Activity

  1. JanKallman commented on Oct 21, 2026

    @JanKallman
    Contributor

    Thanks for the detailed description of this issue.
    This is a bug. I will provide a fix shortly.

  2. added theissue type on Oct 21, 2026
  3. self-assigned this
    on Oct 21, 2026
  4. JanKallman commented on Oct 21, 2026

    @JanKallman
    Contributor

    This is a bug. I will provide a fix shortly.

  5. JanKallman commented on Oct 21, 2026

    @JanKallman
    Contributor

    I have added a fix for this issue. Please see linked PR.

  6. moved this from Backlog to PR Backlog in Bug Trackeron Oct 21, 2026
  7. added a commit that references this issue on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions