Skip to content

Commit 429f2f2

Browse files
authored
Bug/i1631 Row/ColumnOffsets (#1633)
* Fix for #1631 column/row offset in shared formulas * Added fixed issues note * add testmethod
1 parent acd83ad commit 429f2f2

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

docs/articles/fixedissues.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Features / Fixed issues - EPPlus 7
22

3+
## Version 7.4.2
4+
* Fixed innacurate relative addresses in cloned formulas in rare cases.
5+
36

47

58
* Deleting and adding a table with multiple worksheets no longer gives the added table an invalid id.

src/EPPlus/FormulaParsing/LexicalAnalysis/FormulaAddress.cs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,21 +206,24 @@ public List<Token> TokensWithFullAddresses
206206

207207
internal SharedFormula Clone()
208208
{
209-
return new SharedFormula(_ws, StartRow, StartCol, EndRow, EndCol, Formula)
210-
{
211-
Index = Index,
212-
FormulaType = FormulaType,
213-
Tokens = Tokens,
214-
RpnTokens = RpnTokens,
215-
Address = Address,
216-
DataTableIsTwoDimesional = DataTableIsTwoDimesional,
217-
IsDataTableRow = IsDataTableRow,
218-
R1CellAddress = R1CellAddress,
219-
R2CellAddress = R2CellAddress,
220-
FirstCellDeleted = FirstCellDeleted,
221-
SecondCellDeleted = SecondCellDeleted,
222-
_ws = _ws,
223-
};
209+
var sh = new SharedFormula(_ws, StartRow, StartCol, EndRow, EndCol, Formula);
210+
211+
sh.Index = Index;
212+
sh.FormulaType = FormulaType;
213+
sh.Tokens = null;
214+
sh.RpnTokens = null;
215+
//sh.Address = Address;
216+
sh.StartColOffset = StartColOffset;
217+
sh.StartRowOffset = StartRowOffset;
218+
//sh.StartCol = StartCol;
219+
sh.DataTableIsTwoDimesional = DataTableIsTwoDimesional;
220+
sh.IsDataTableRow = IsDataTableRow;
221+
sh.R1CellAddress = R1CellAddress;
222+
sh.R2CellAddress = R2CellAddress;
223+
sh.FirstCellDeleted = FirstCellDeleted;
224+
sh.SecondCellDeleted = SecondCellDeleted;
225+
sh._ws = _ws;
226+
return sh;
224227
}
225228
internal Formula GetFormula(int row, int col)
226229
{

src/EPPlusTest/Issues/CopyIssues.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,27 @@ public void s651_2()
6262
}
6363
}
6464
[TestMethod]
65+
public void i1623()
66+
{
67+
using (var p = OpenTemplatePackage("i1623.xlsx"))
68+
{
69+
using (var p2 = OpenPackage("i1623-clone.xlsx", true))
70+
{
71+
var src = p.Workbook.Worksheets.First();
72+
ExcelWorksheet dup = p2.Workbook.Worksheets.Add("dup", src);
73+
for (int col = 1; col < src.Dimension.End.Column; col++)
74+
{
75+
Console.WriteLine($"is equal? :{src.Cells[5, col].FormulaR1C1.Equals(dup.Cells[5, col].FormulaR1C1)},{src.Cells[5, col].FormulaR1C1} => {dup.Cells[5, col].FormulaR1C1}");
76+
}
77+
for (int col = 1; col < src.Dimension.End.Column; col++)
78+
{
79+
Assert.AreEqual(src.Cells[5, col].FormulaR1C1, dup.Cells[5, col].FormulaR1C1);
80+
}
81+
SaveAndCleanup(p2);
82+
}
83+
}
84+
}
85+
[TestMethod]
6586
public void i1645()
6687
{
6788
using (var package = OpenTemplatePackage("i1645.xlsx"))

0 commit comments

Comments
 (0)