public void TestCTTableStyleInfo() { XSSFWorkbook outputWorkbook = new XSSFWorkbook(); XSSFSheet sheet = outputWorkbook.CreateSheet() as XSSFSheet; //Create XSSFTable outputTable = sheet.CreateTable(); outputTable.DisplayName = ("Test"); CT_Table outputCTTable = outputTable.GetCTTable(); //Style configurations CT_TableStyleInfo outputStyleInfo = outputCTTable.AddNewTableStyleInfo(); outputStyleInfo.name = ("TableStyleLight1"); outputStyleInfo.showColumnStripes = (false); outputStyleInfo.showRowStripes = (true); XSSFWorkbook inputWorkbook = XSSFTestDataSamples.WriteOutAndReadBack(outputWorkbook) as XSSFWorkbook; List <XSSFTable> tables = (inputWorkbook.GetSheetAt(0) as XSSFSheet).GetTables(); Assert.AreEqual(1, tables.Count, "Tables number"); XSSFTable inputTable = tables[0]; Assert.AreEqual(outputTable.DisplayName, inputTable.DisplayName, "Table display name"); CT_TableStyleInfo inputStyleInfo = inputTable.GetCTTable().tableStyleInfo; Assert.AreEqual(outputStyleInfo.name, inputStyleInfo.name, "Style name"); Assert.AreEqual(outputStyleInfo.showColumnStripes, inputStyleInfo.showColumnStripes, "Show column stripes"); Assert.AreEqual(outputStyleInfo.showRowStripes, inputStyleInfo.showRowStripes, "Show row stripes"); }
public void Test56170() { IWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("56170.xlsx"); XSSFSheet sheet = (XSSFSheet)wb.GetSheetAt(0); IWorkbook wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb); ICell cell; // add some contents to table so that the table will need expansion IRow row = sheet.GetRow(0); wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb); cell = row.CreateCell(0); wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb); cell.SetCellValue("demo1"); wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb); cell = row.CreateCell(1); wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb); cell.SetCellValue("demo2"); wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb); cell = row.CreateCell(2); wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb); cell.SetCellValue("demo3"); wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb); row = sheet.GetRow(1); cell = row.CreateCell(0); cell.SetCellValue("demo1"); cell = row.CreateCell(1); cell.SetCellValue("demo2"); cell = row.CreateCell(2); cell.SetCellValue("demo3"); wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb); // expand table XSSFTable table = sheet.GetTables()[0]; CellReference startRef = table.StartCellReference; CellReference endRef = table.EndCellReference; table.GetCTTable().@ref = (new CellRangeAddress(startRef.Row, 1, startRef.Col, endRef.Col).FormatAsString()); wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb); Assert.IsNotNull(wbRead); /*FileOutputStream stream = new FileOutputStream("c:\\temp\\output.xlsx"); * workbook.Write(stream); * stream.Close();*/ }
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 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); }