public void GetTable() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("WithTable.xlsx"); XSSFTable table1 = wb.GetTable("Tabella1"); Assert.IsNotNull(table1, "Tabella1 was not found in workbook"); Assert.AreEqual("Tabella1", table1.Name, "Table name"); Assert.AreEqual("Foglio1", table1.SheetName, "Sheet name"); // Table lookup should be case-insensitive Assert.AreSame(table1, wb.GetTable("TABELLA1"), "Case insensitive table name lookup"); // If workbook does not contain any data tables matching the provided name, getTable should return null Assert.IsNull(wb.GetTable(null), "Null table name should not throw NPE"); Assert.IsNull(wb.GetTable("Foglio1"), "Should not be able to find non-existent table"); // If a table is added after getTable is called it should still be reachable by XSSFWorkbook.getTable // This test makes sure that if any caching is done that getTable never uses a stale cache XSSFTable table2 = (wb.GetSheet("Foglio2") as XSSFSheet).CreateTable(); table2.Name = "Table2"; Assert.AreSame(table2, wb.GetTable("Table2"), "Did not find Table2"); // If table name is modified after getTable is called, the table can only be found by its new name // This test makes sure that if any caching is done that getTable never uses a stale cache table1.Name = "Table1"; Assert.AreSame(table1, wb.GetTable("TABLE1"), "Did not find Tabella1 renamed to Table1"); wb.Close(); }
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 GetNumberOfMappedColumns() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("StructuredReferences.xlsx"); XSSFTable table = wb.GetTable("\\_Prime.1"); Assert.AreEqual(3, table.NumberOfMappedColumns); wb.Close(); }
public void GetStartRowIndex() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("StructuredReferences.xlsx"); XSSFTable table = wb.GetTable("\\_Prime.1"); Assert.AreEqual(0, table.StartRowIndex); wb.Close(); }
public void IsHasTotalsRow() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("StructuredReferences.xlsx"); XSSFTable table = wb.GetTable("\\_Prime.1"); Assert.IsFalse(table.IsHasTotalsRow); wb.Close(); }
public void GetSheetName() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("StructuredReferences.xlsx"); XSSFTable table = wb.GetTable("\\_Prime.1"); Assert.AreEqual("Table", table.SheetName); wb.Close(); }
public void GetEndCellReference() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("StructuredReferences.xlsx"); XSSFTable table = wb.GetTable("\\_Prime.1"); Assert.AreEqual(new CellReference("C7"), table.EndCellReference); wb.Close(); }
public void FindColumnIndexIsRelativeToTableNotSheet() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("DataTableCities.xlsx"); XSSFTable table = wb.GetTable("SmallCity"); // Make sure that XSSFTable.findColumnIndex returns the column index relative to the first // column in the table, not the column number in the sheet Assert.AreEqual(0, table.FindColumnIndex("City")); // column I in worksheet but 0th column in table Assert.AreEqual(1, table.FindColumnIndex("Latitude")); Assert.AreEqual(2, table.FindColumnIndex("Longitude")); Assert.AreEqual(3, table.FindColumnIndex("Population")); wb.Close(); }
public void GetAndSetDisplayName() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("StructuredReferences.xlsx"); XSSFTable table = wb.GetTable("\\_Prime.1"); Assert.AreEqual("\\_Prime.1", table.DisplayName); table.DisplayName = null; Assert.IsNull(table.DisplayName); Assert.AreEqual("\\_Prime.1", table.Name); // name and display name are different table.DisplayName = "Display name"; Assert.AreEqual("Display name", table.DisplayName); Assert.AreEqual("\\_Prime.1", table.Name); // name and display name are different wb.Close(); }
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 FindColumnIndex() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("StructuredReferences.xlsx"); // FIXME: use a worksheet where upper left cell of table is not A1 so that we test // that XSSFTable.findColumnIndex returns the column index relative to the first // column in the table, not the column number in the sheet XSSFTable table = wb.GetTable("\\_Prime.1"); Assert.IsNotNull(table); Assert.AreEqual(0, table.FindColumnIndex("calc='#*'#"), "column header has special escaped characters"); Assert.AreEqual(1, table.FindColumnIndex("Name")); Assert.AreEqual(2, table.FindColumnIndex("Number")); Assert.AreEqual(2, table.FindColumnIndex("NuMbEr"), "case insensitive"); // findColumnIndex should return -1 if no column header name matches Assert.AreEqual(-1, table.FindColumnIndex(null)); Assert.AreEqual(-1, table.FindColumnIndex("")); Assert.AreEqual(-1, table.FindColumnIndex("one")); wb.Close(); }
/** * @return the list of all Tables that provide a map rule to this mapping */ public List <XSSFTable> GetRelatedTables() { List <XSSFTable> tables = new List <XSSFTable>(); int sheetNumber = mapInfo.Workbook.NumberOfSheets; foreach (ISheet sheet in mapInfo.Workbook) { foreach (RelationPart rp in ((XSSFSheet)sheet).RelationParts) { if (rp.Relationship.RelationshipType.Equals(XSSFRelation.TABLE.Relation)) { XSSFTable table = rp.DocumentPart as XSSFTable; if (table.MapsTo(ctMap.ID)) { tables.Add(table); } } } } return(tables); }
public List <XSSFTable> GetRelatedTables() { List <XSSFTable> xssfTableList = new List <XSSFTable>(); int numberOfSheets = this.mapInfo.Workbook.NumberOfSheets; for (int index = 0; index < numberOfSheets; ++index) { foreach (POIXMLDocumentPart relation in ((POIXMLDocumentPart)this.mapInfo.Workbook.GetSheetAt(index)).GetRelations()) { if (relation.GetPackageRelationship().RelationshipType.Equals(XSSFRelation.TABLE.Relation)) { XSSFTable xssfTable = (XSSFTable)relation; if (xssfTable.MapsTo((long)this.ctMap.ID)) { xssfTableList.Add(xssfTable); } } } } return(xssfTableList); }
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); }
/** * @return the list of all Tables that provide a map rule to this mapping */ public List <XSSFTable> GetRelatedTables() { List <XSSFTable> tables = new List <XSSFTable>(); int sheetNumber = mapInfo.Workbook.NumberOfSheets; for (int i = 0; i < sheetNumber; i++) { XSSFSheet sheet = (XSSFSheet)mapInfo.Workbook.GetSheetAt(i); foreach (POIXMLDocumentPart p in sheet.GetRelations()) { if (p.GetPackageRelationship().RelationshipType.Equals(XSSFRelation.TABLE.Relation)) { XSSFTable table = (XSSFTable)p; if (table.MapsTo(ctMap.ID)) { tables.Add(table); } } } } return(tables); }
public string GetCommonXpath() { if (this.commonXPath == null) { Array arr = (Array)null; foreach (CT_TableColumn ctTableColumn in this.ctTable.tableColumns.tableColumn) { if (ctTableColumn.xmlColumnPr != null) { string[] strArray = ctTableColumn.xmlColumnPr.xpath.Split('/'); if (arr == null) { arr = (Array)strArray; } else { int num = arr.Length > strArray.Length ? strArray.Length : arr.Length; for (int index = 0; index < num; ++index) { if (!arr.GetValue(index).Equals((object)strArray[index])) { arr = Arrays.AsList(arr).GetRange(0, index).ToArray(typeof(string)); break; } } } } } this.commonXPath = ""; for (int index = 1; index < arr.Length; ++index) { XSSFTable xssfTable = this; xssfTable.commonXPath = xssfTable.commonXPath + "/" + arr.GetValue(index); } } return(this.commonXPath); }
internal XSSFTableColumn(XSSFTable table, CT_TableColumn ctTableColumn) { this.table = table; this.ctTableColumn = ctTableColumn; }
public XSSFXmlColumnPr(XSSFTable table, CT_TableColumn ctTableColum, CT_XmlColumnPr CT_XmlColumnPr) { this.table = table; this.ctTableColumn = ctTableColum; this.ctXmlColumnPr = CT_XmlColumnPr; }