Skip to content

Commit

Permalink
Fixes incorrect circular reference exception - #905
Browse files Browse the repository at this point in the history
  • Loading branch information
JanKallman committed Jun 14, 2023
1 parent 83e33c3 commit 0b14384
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ private static void FollowChain(DependencyChain depChain, ILexer lexer, ExcelWor
adr.SetRCFromTable(ws._package, new ExcelAddressBase(f.Row, f.Column, f.Row, f.Column));
}

if (ws!=null && adr.WorkSheetName.Equals(ws.Name, StringComparison.OrdinalIgnoreCase) && string.IsNullOrEmpty(adr._wb) && adr.Collide(new ExcelAddressBase(f.Row, f.Column, f.Row, f.Column))!=ExcelAddressBase.eAddressCollition.No)
if (adr.WorkSheetName.Equals((f.ws ?? ws)?.Name,
StringComparison.OrdinalIgnoreCase) && string.IsNullOrEmpty(adr._wb) && adr.Collide(new ExcelAddressBase(f.Row, f.Column, f.Row, f.Column))!=ExcelAddressBase.eAddressCollition.No)
{
var tt = t.GetTokenTypeFlags() | TokenType.CircularReference;
f.Tokens[f.tokenIx] = t.CloneWithNewTokenType(tt);
Expand Down
18 changes: 18 additions & 0 deletions src/EPPlusTest/FormulaParsing/CircularReferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,23 @@ public void IfShouldIgnoreCircularRefWhenIgnoredArg()
Assert.AreEqual(6, sheet.Cells["B4"].Value);
}
}
[TestMethod]
public void ReferenceToOtherSheetShouldNotGenerateACircularReference()
{
using (var package = new ExcelPackage())
{
var sheet1 = package.Workbook.Worksheets.Add("Sheet1");
var sheet2 = package.Workbook.Worksheets.Add("Sheet2");

sheet1.Cells["A1"].Value = 1d;
sheet1.Cells["A2"].Value = 3d;
sheet1.Cells["A3"].Formula = "=Sheet2!A1";

sheet2.Cells["A1"].Formula = "=Sheet1!A1";

package.Workbook.Calculate();
}
}

}
}
10 changes: 10 additions & 0 deletions src/EPPlusTest/Issues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5003,6 +5003,16 @@ public void s474()
OfficeOpenXml.DataValidation.Contracts.IExcelDataValidationList validationList =
sheet.DataValidations.AddListValidation(sheet.Cells[startRow, columnCount, sheetRows - 1, columnCount].Address);

SaveAndCleanup(p);
}
}
[TestMethod]
public void I892()
{
using (var p = OpenTemplatePackage("TEST_20230607.xlsx"))
{
p.Encryption.Password = "P@ssw0rd";

SaveAndCleanup(p);
}
}
Expand Down

0 comments on commit 0b14384

Please sign in to comment.