Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addresses in named ranges do not become invalid when the range itself is deleted #880

Open
1 of 3 tasks
Pankraty opened this issue May 29, 2018 · 1 comment · May be fixed by #1658
Open
1 of 3 tasks

Addresses in named ranges do not become invalid when the range itself is deleted #880

Pankraty opened this issue May 29, 2018 · 1 comment · May be fixed by #1658

Comments

@Pankraty
Copy link
Member

Read and complete the full issue template

Do you want to request a feature or report a bug?

  • Bug
  • Feature

If you are logging a possible bug or feature request, please test with the latest development build first.

Version of ClosedXML

0.93

What is the current behavior?

Say, we have a named range referring to the range A1:B2. If rows from 1 to 5 are deleted the named range starts to refer to A1:B1. If, instead, first two columns are deleted the named range becomes A1:A2.

What is the expected behavior or new feature?

The named range should become invalid: e.g. Sheet1!#REF!.

Did this work in previous versions of our tool? Which versions?

No

Notes

This issue should be addressed together with #686.

Also, I noticed that when multiple rows are deleted (e.g. ws.Rows(1, 100).Delete();) the formula shifting is performed for every single row. This may be improved by doing a single shift for the specified number of rows. Same is true for columns.

Reproducibility

Code to reproduce problem:

[Test]
public void NamedRangeBecomesInvalidOnRangeDeleting()
{
    using (var wb = new XLWorkbook())
    {
        var ws = wb.Worksheets.Add("Sheet 1");
        ws.Range("A1:B2").AddToNamed("Simple", XLScope.Workbook);
        wb.NamedRanges.Add("Compound", new XLRanges
        {
            ws.Range("C1:D2"),
            ws.Range("A10:D15")
        });

        ws.Rows(1,5).Delete();

        Assert.AreEqual(2, wb.NamedRanges.Count());
        Assert.AreEqual(0, wb.NamedRanges.ValidNamedRanges().Count());
        Assert.AreEqual("'Sheet 1'!#REF!", wb.NamedRanges.ElementAt(0).RefersTo);
        Assert.AreEqual("'Sheet 1'!#REF!,'Sheet 1'!A5:D10", wb.NamedRanges.ElementAt(0).RefersTo);
    }
}
  • I attached a sample spreadsheet. (You can drag files on to this issue)
@igitur
Copy link
Member

igitur commented May 31, 2018

Perfect time to refactor that RangeList into something else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants