public void TestXSSFSetArrayFormula_multiCell() { ICellRange <ICell> cells; String formula2 = "456"; XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet)workbook.CreateSheet(); CellRangeAddress range = CellRangeAddress.ValueOf("C4:C6"); cells = sheet.SetArrayFormula(formula2, range); Assert.AreEqual(3, cells.Size); // sheet.SetArrayFormula Creates rows and cells for the designated range /* * From the spec: * For a multi-cell formula, the c elements for all cells except the top-left * cell in that range shall not have an f element; */ // Check that each cell exists and that the formula text is Set correctly on the first cell XSSFCell firstCell = (XSSFCell)cells.TopLeftCell; ConfirmArrayFormulaCell(firstCell, "C4", formula2, "C4:C6"); ConfirmArrayFormulaCell(cells.GetCell(1, 0), "C5"); ConfirmArrayFormulaCell(cells.GetCell(2, 0), "C6"); Assert.AreSame(firstCell, sheet.GetFirstCellInArrayFormula(firstCell)); workbook.Close(); }
public void TestXSSFSetArrayFormula_SingleCell() { ICellRange <ICell> cells; XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet)workbook.CreateSheet(); // 1. Single-cell array formula String formula1 = "123"; CellRangeAddress range = CellRangeAddress.ValueOf("C3:C3"); cells = sheet.SetArrayFormula(formula1, range); Assert.AreEqual(1, cells.Size); // check GetFirstCell... XSSFCell firstCell = (XSSFCell)cells.TopLeftCell; Assert.AreSame(firstCell, sheet.GetFirstCellInArrayFormula(firstCell)); //retrieve the range and check it is the same Assert.AreEqual(range.FormatAsString(), firstCell.GetArrayFormulaRange().FormatAsString()); ConfirmArrayFormulaCell(firstCell, "C3", formula1, "C3"); }