EPPlusSoftware / EPPlus

EPPlus-Excel spreadsheets for .NET
https://epplussoftware.com
Other
1.77k stars 274 forks source link

ExcelWorksheetView.FreezePanes ignoring hidden rows above or columns to the left of freeze point #786

Open jtrent614 opened 1 year ago

jtrent614 commented 1 year ago

When calling ExcelWorksheetView.FreezePanes(int Row, int Column), the Row and Column coordinates ignore hidden rows/columns and instead count only visible rows/cols.

Steps to reproduce:

XML Examples

image

JanKallman commented 1 year ago

We'll have a look at this.

jtrent614 commented 1 year ago

Thanks Jan. I think this may be related to a similar problem I'm having, which is trying to set something like Worksheet.View.TopLeftCell = "B2" where it also has issues with hidden rows/columns. I'll test this a little more and document it.

JanKallman commented 1 year ago

Ok, I tried this...

        [TestMethod]
        public void FreezePanes()
        {
            using (var p = OpenPackage("Freeze.xlsx", true))
            {
                var ws = p.Workbook.Worksheets.Add("Sheet1");
                ws.Column(1).Hidden = true;
                ws.Row(1).Hidden = true;
                ws.View.FreezePanes(3, 3);
                SaveAndCleanup(p);
            }
        }

This seems to work as expected and freezes on C3

jtrent614 commented 1 year ago
  // Test 1 (row 1/col A already hidden) - FAIL
  var ws = excelFile.Workbook.Worksheets["Sheet1"];
  ws.View.FreezePanes(3, 3);

  // Test 2 - FAIL
  var ws2 = excelFile.Workbook.Worksheets["Sheet2"];
  ws2.Column(1).Hidden = true;
  ws2.Row(1).Hidden = true;
  ws2.View.FreezePanes(3, 3);

  // Test 3 - PASS
  var ws3 = excelFile.Workbook.Worksheets.Add("Sheet3");
  ws3.Column(1).Hidden = true;
  ws3.Row(1).Hidden = true;
  ws3.View.FreezePanes(3, 3);

Looks like the issue is isolated to when when you have a pre-existing worksheet in the file instead of creating the worksheet first. Forgot to mention this is happening in 6.0.8 and 6.1.2.