Skip to content

Commit 58e2096

Browse files
authored
Bug/dimensionbyvalueissue (#2033)
* Fixed an issue where ExcelWorksheet.DimensionByValue returned the wrong address * Small fix for RangeInfo when Worksheet is empty * Fixed failing test
1 parent 34c800b commit 58e2096

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/EPPlus/Core/CellStore/CellStore.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,6 @@ public void Dispose()
11751175

11761176
internal bool NextCell(ref int row, ref int col)
11771177
{
1178-
11791178
return NextCell(ref row, ref col, 0, 0, ExcelPackage.MaxRows, ExcelPackage.MaxColumns);
11801179
}
11811180
internal bool NextCell(ref int row, ref int col, int minRow, int minColPos, int maxRow, int maxColPos)
@@ -1543,6 +1542,11 @@ internal bool GetPrevCell(ref int row, ref int colPos, int startRow, int startCo
15431542
}
15441543

15451544
var c = colPos - 1;
1545+
if (c < 0 && endColPos > colPos && row>1)
1546+
{
1547+
c = endColPos;
1548+
row--;
1549+
}
15461550
if (c >= startColPos)
15471551
{
15481552
while (c != colPos)

src/EPPlus/FormulaParsing/Ranges/RangeInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public RangeInfo(FormulaRangeAddress address)
6868
public RangeInfo(ExcelWorksheet ws, int fromRow, int fromCol, int toRow, int toCol, ParsingContext ctx, int extRef = -1)
6969
{
7070
var address = new ExcelAddressBase(fromRow, fromCol, toRow, toCol);
71-
address._ws = ws.Name;
71+
address._ws = ws?.Name;
7272
SetAddress(ws, address, ctx);
7373
_addresses[0].ExternalReferenceIx = extRef;
7474
}

src/EPPlusTest/Issues/WorksheetIssues.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,5 +840,19 @@ public void s843()
840840

841841
sheet.Cells["C3"].AddComment("Test"); // NullReferenceException
842842
}
843+
[TestMethod]
844+
public void DimensionByValueIssue()
845+
{
846+
using (var p = OpenTemplatePackage("DimensionByValueError.xlsx"))
847+
{
848+
var ws = p.Workbook.Worksheets["Technical"];
849+
var dv = ws.DimensionByValue;
850+
Assert.AreEqual("C3", dv.Start.Address);
851+
Assert.AreEqual("M60", dv.End.Address);
852+
Assert.AreEqual("C3", ws.FirstValueCell.Address);
853+
Assert.AreEqual("J60", ws.LastValueCell.Address);
854+
SaveAndCleanup(p);
855+
}
856+
}
843857
}
844858
}

0 commit comments

Comments
 (0)