public void Test46535() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("46535.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(10, c.i); Assert.AreEqual("E1", c.r); ISheet sheet = wb.GetSheet("Test"); ICell cell = sheet.GetRow(0).GetCell(4); 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(10, c.i); Assert.AreEqual("C1", c.r); Assert.AreEqual(CellType.STRING, cell.CellType); cell.SetCellValue("ABC"); Assert.AreEqual(CellType.STRING, cell.CellType); }
public void SerializeCalcChainDocumentTest() { var calcChain = new CT_CalcChain(); { var cell1 = new CT_CalcCell(); cell1.r = "E1"; cell1.i = 1; calcChain.AddC(cell1); } { var cell1 = new CT_CalcCell(); cell1.r = "D1"; calcChain.AddC(cell1); } { var cell1 = new CT_CalcCell(); cell1.r = "C1"; calcChain.AddC(cell1); } using (StringWriter stream = new StringWriter()) { CT_CalcChain_Accessor.serializer.Serialize(stream, calcChain, CT_CalcChain_Accessor.namespaces); string expected = @"<?xml version=""1.0"" encoding=""utf-16""?> <calcChain xmlns=""http://schemas.openxmlformats.org/spreadsheetml/2006/main""> <c r=""E1"" i=""1"" /> <c r=""D1"" /> <c r=""C1"" /> </calcChain>"; Assert.AreEqual(expected, stream.ToString()); } }
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); }