public void GetRowCount() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sh = wb.CreateSheet() as XSSFSheet; XSSFTable table = sh.CreateTable() as XSSFTable; CT_Table ctTable = table.GetCTTable(); Assert.AreEqual(0, table.RowCount); ctTable.@ref = "B2:B2"; // update cell references to clear the cache table.UpdateReferences(); Assert.AreEqual(1, table.RowCount); ctTable.@ref = "B2:B12"; // update cell references to clear the cache table.UpdateReferences(); Assert.AreEqual(11, table.RowCount); }
public void TestTableFormulas() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("StructuredReferences.xlsx"); try { IFormulaEvaluator eval = new XSSFFormulaEvaluator(wb); XSSFSheet tableSheet = wb.GetSheet("Table") as XSSFSheet; XSSFSheet formulaSheet = wb.GetSheet("Formulas") as XSSFSheet; Confirm(eval, tableSheet.GetRow(5).GetCell(0), 49); Confirm(eval, formulaSheet.GetRow(0).GetCell(0), 209); Confirm(eval, formulaSheet.GetRow(1).GetCell(0), "one"); // test changing a table value, to see if the caches are properly Cleared // Issue 59814 // this test passes before the fix for 59814 tableSheet.GetRow(1).GetCell(1).SetCellValue("ONEA"); Confirm(eval, formulaSheet.GetRow(1).GetCell(0), "ONEA"); // test Adding a row to a table, issue 59814 IRow newRow = tableSheet.GetRow(7); if (newRow == null) { newRow = tableSheet.CreateRow(7); } newRow.CreateCell(0, CellType.Formula).CellFormula = (/*setter*/ "\\_Prime.1[[#This Row],[@Number]]*\\_Prime.1[[#This Row],[@Number]]"); newRow.CreateCell(1, CellType.String).SetCellValue("thirteen"); newRow.CreateCell(2, CellType.Numeric).SetCellValue(13); // update Table XSSFTable table = wb.GetTable("\\_Prime.1"); AreaReference newArea = new AreaReference(table.StartCellReference, new CellReference(table.EndRowIndex + 1, table.EndColIndex)); String newAreaStr = newArea.FormatAsString(); table.GetCTTable().@ref = (/*setter*/ newAreaStr); table.GetCTTable().autoFilter.@ref = (/*setter*/ newAreaStr); table.UpdateHeaders(); table.UpdateReferences(); // these fail before the fix for 59814 Confirm(eval, tableSheet.GetRow(7).GetCell(0), 13 * 13); Confirm(eval, formulaSheet.GetRow(0).GetCell(0), 209 + 13 * 13); } finally { wb.Close(); } }
public void GetCellReferences() { // make sure that cached start and end cell references // can be synchronized with the underlying CTTable XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sh = wb.CreateSheet() as XSSFSheet; XSSFTable table = sh.CreateTable() as XSSFTable; CT_Table ctTable = table.GetCTTable(); ctTable.@ref = "B2:E8"; Assert.AreEqual(new CellReference("B2"), table.StartCellReference); Assert.AreEqual(new CellReference("E8"), table.EndCellReference); // At this point start and end cell reference are cached // and may not follow changes to the underlying CTTable ctTable.@ref = "C1:M3"; Assert.AreEqual(new CellReference("B2"), table.StartCellReference); Assert.AreEqual(new CellReference("E8"), table.EndCellReference); // Force a synchronization between CTTable and XSSFTable // start and end cell references table.UpdateReferences(); Assert.AreEqual(new CellReference("C1"), table.StartCellReference); Assert.AreEqual(new CellReference("M3"), table.EndCellReference); }