Skip to content

Commit

Permalink
Merge pull request nissl-lab#107 from jacobmalliet/master
Browse files Browse the repository at this point in the history
Fix issue with removing multiple cells from CalculationChain when iSpecified is false
  • Loading branch information
tonyqus committed Jan 29, 2018
2 parents 735dca7 + 10b9b07 commit e00a750
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions ooxml/XSSF/Model/CalculationChain.cs
Expand Up @@ -105,6 +105,7 @@ public void RemoveItem(int sheetId, String ref1)
if (c[i].iSpecified && i < c.Count - 1 && !c[i + 1].iSpecified)
{
c[i + 1].i = id;
c[i + 1].iSpecified = true;
}
chain.RemoveC(i);
break;
Expand Down
39 changes: 37 additions & 2 deletions testcases/ooxml/XSSF/Model/TestCalculationChain.cs
Expand Up @@ -56,7 +56,42 @@ public void Test46535()
Assert.AreEqual(CellType.String, cell.CellType);
}

[Test]
public void RemoveAllFormulas()
{
XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("TwoFunctions.xlsx");

}
}
CalculationChain chain = wb.GetCalculationChain();
//the bean holding the reference to the formula to be deleted
CT_CalcCell c = chain.GetCTCalcChain().GetCArray(0);
int cnt = chain.GetCTCalcChain().c.Count;
Assert.AreEqual(1, c.i);
Assert.AreEqual("A5", c.r);
Assert.AreEqual(2, cnt);

ISheet sheet = wb.GetSheet("Sheet1");
ICell cell = sheet.GetRow(4).GetCell(0);

Assert.AreEqual(CellType.Formula, cell.CellType);
cell.SetCellFormula(null);

//the count of items is less by one
c = chain.GetCTCalcChain().GetCArray(0);
int cnt2 = chain.GetCTCalcChain().c.Count;
Assert.AreEqual(cnt - 1, cnt2);
//the first item in the calculation chain is the former second one
Assert.AreEqual(1, c.i);
Assert.AreEqual("A4", c.r);
Assert.AreEqual(1, cnt2);

//remove final formula from spread sheet
ICell cell2 = sheet.GetRow(3).GetCell(0);
Assert.AreEqual(CellType.Formula, cell2.CellType);
cell2.SetCellFormula(null);

//the count of items within the chain should be 0
int cnt3 = chain.GetCTCalcChain().c.Count;
Assert.AreEqual(0, cnt3);
}
}
}
Binary file added testcases/test-data/spreadsheet/TwoFunctions.xlsx
Binary file not shown.

0 comments on commit e00a750

Please sign in to comment.