-
Notifications
You must be signed in to change notification settings - Fork 284
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
Formula Corruption During Row/Column Insertion in Server-Generated Excel Workbook #1748
Comments
It's also occurring for cells that contain formulas such as:
Here's the XML:
|
Thanks, we will look at it and get back to you. |
Yes, this is a bug. I will provide a fix shortly. [TestMethod]
public void i1748()
{
using var package = new ExcelPackage();
var formula = "SUMIF($I$3:$L$3,1,INDEX($I:$I,ROW()):INDEX($L:$L,ROW()))";
var formulaLong = "IF(COLUMN()-COLUMN($J23)>(COUNTA('#CompaniesAndConsolidations'!$A:$A)+1),0,IF(K$5=\"TopConsolidation\",SUMIFS(INDEX(23:23,1,COLUMN()+1):INDEX(23:23,1,COLUMN($L23)),INDEX($7:$7,1,COLUMN()+1):INDEX($7:$7,1,COLUMN($L23)),K$2,INDEX($6:$6,1,COLUMN()+1):INDEX($6:$6,1,COLUMN($L23)),FALSE),IF(K$5=\"SubConsolidation\",SUMIFS(INDEX(23:23,1,COLUMN()+1):INDEX(23:23,1,COLUMN($L23)),INDEX($8:$8,1,COLUMN()+1):INDEX($8:$8,1,COLUMN($L23)),K$2,INDEX($6:$6,1,COLUMN()+1):INDEX($6:$6,1,COLUMN($L23)),FALSE),IF(K$5=\"DivisionalConsolidation\",SUMIFS(INDEX(23:23,1,COLUMN()+1):INDEX(23:23,1,COLUMN($L23)),INDEX($9:$9,1,COLUMN()+1):INDEX($9:$9,1,COLUMN($L23)),K$2,INDEX($6:$6,1,COLUMN()+1):INDEX($6:$6,1,COLUMN($L23)),FALSE),-SUMIFS('#TrialBalance_CY'!$E:$E,'#TrialBalance_CY'!$A:$A,K$2,'#TrialBalance_CY'!$G:$G,\"IncomeStatement\")))))";
var ws = package.Workbook.Worksheets.Add("Sheet1");
ws.Cells["A1"].Formula = formula;
ws.Cells["A2"].Formula = formulaLong;
ws.InsertRow(1,1);
var formulaInserted = "SUMIF($I$4:$L$4,1,INDEX($I:$I,ROW()):INDEX($L:$L,ROW()))";
Assert.AreEqual(formulaInserted, ws.Cells["A2"].Formula);
var formulaLongInserted = "IF(COLUMN()-COLUMN($J24)>(COUNTA('#CompaniesAndConsolidations'!$A:$A)+1),0,IF(K$6=\"TopConsolidation\",SUMIFS(INDEX(24:24,1,COLUMN()+1):INDEX(24:24,1,COLUMN($L24)),INDEX($8:$8,1,COLUMN()+1):INDEX($8:$8,1,COLUMN($L24)),K$3,INDEX($7:$7,1,COLUMN()+1):INDEX($7:$7,1,COLUMN($L24)),FALSE),IF(K$6=\"SubConsolidation\",SUMIFS(INDEX(24:24,1,COLUMN()+1):INDEX(24:24,1,COLUMN($L24)),INDEX($9:$9,1,COLUMN()+1):INDEX($9:$9,1,COLUMN($L24)),K$3,INDEX($7:$7,1,COLUMN()+1):INDEX($7:$7,1,COLUMN($L24)),FALSE),IF(K$6=\"DivisionalConsolidation\",SUMIFS(INDEX(24:24,1,COLUMN()+1):INDEX(24:24,1,COLUMN($L24)),INDEX($10:$10,1,COLUMN()+1):INDEX($10:$10,1,COLUMN($L24)),K$3,INDEX($7:$7,1,COLUMN()+1):INDEX($7:$7,1,COLUMN($L24)),FALSE),-SUMIFS('#TrialBalance_CY'!$E:$E,'#TrialBalance_CY'!$A:$A,K$3,'#TrialBalance_CY'!$G:$G,\"IncomeStatement\")))))";
Assert.AreEqual(formulaLongInserted, ws.Cells["A3"].Formula);
} |
Please try the fix using our develop7 Nuget feed as described here... https://github.com/EPPlusSoftware/EPPlus/wiki/Using-our-develop-Nuget-feed |
@JanKallman After using the NuGet feed as requested, my issue appeared resolved. However, I encountered an "Unterminated string" exception. This was addressed by a fix in #1689, implemented in version 7.5.1. |
Hi, I just wanted to follow up on this. I'm still getting the unterminated string exception using that feed. |
Sorry for the delayed answer. EPPlus/src/EPPlusTest/WorkSheetTests.cs Line 2209 in 4453b44
Is this the same formula you are getting your exception on? |
@JanKallman Happy new year! Thanks for the update. Has this been updated in the newest EPPLUS version? My team is planning on release to Production for our app, but this issue is the only thing holding it back. |
@JanKallman Hi there! Any update? |
EPPlus usage
Commercial use (I have a commercial license)
Environment
Windows
Epplus version
7.5.2
Spreadsheet application
Excel
Description
The workbook is generated server-side using a solution built in .NET8, and the issue occurs when rows or columns are inserted into the worksheet. Specifically, this affects cells containing formulas that use dynamic range references, such as:
The affected formulas seem to lose critical syntax elements (e.g., the
":"
in range references like+1):INDEX(
during processing, resulting in broken formulas with#REF!
errors in the generated file.Observations:
Relevant Code:
This issue likely stems from the interaction of the following code sections:
Row Generation and Copying:
wks.InsertRow(templateRow.Start.Row, insertCount, templateRow.Start.Row);
This insertion logic is followed by a copy-paste of formulas, which seems to corrupt the tokenized formula.
Formula Replacement:
string newFormula = oldFormula.Replace(CFWConstants.AdjustmentReferenceSheetName, replace);
cell.Value = newFormula;
Expected Behavior:
Actual Behavior:
#REF!
errorsSteps to Reproduce:
Full code snippet:
The text was updated successfully, but these errors were encountered: