XSSFSheet sheet = (XSSFSheet)getParent(); CellReference ref = getStartCellReference(); if (ref == null) return; CTTableColumns ctTableColumns = getCTTable().getTableColumns(); if(ctTableColumns != null) { for (CTTableColumn col : ctTableColumns.getTableColumnList()) {
updateReferences(); int dataRowCount = getDataRowCount(); if (dataRowCount == newDataRowCount) { return; CellReference tableStart = getStartCellReference(); CellReference tableEnd = getEndCellReference(); SpreadsheetVersion version = getXSSFSheet().getWorkbook().getSpreadsheetVersion(); int newTotalRowCount = getHeaderRowCount() + newDataRowCount + getTotalsRowCount(); CellReference newTableEnd = new CellReference(tableStart.getRow() + newTotalRowCount - 1, tableEnd.getCol()); XSSFRow row = getXSSFSheet().getRow(cellRef.getRow()); if (row != null) { XSSFCell cell = row.getCell(cellRef.getCol()); setCellRef(newTableArea);
for (XSSFTable table : sheet.getTables()) { if (name.equals(table.getName())) { return new AreaReference(table.getStartCellReference(), table.getEndCellReference(), SpreadsheetVersion.EXCEL2007);
@Override protected void commit() throws IOException { PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); writeTo(out); out.close(); }
/** * Get the area reference for the cells which this table covers. The area * includes header rows and totals rows. * * Does not track updates to underlying changes to CTTable To synchronize * with changes to the underlying CTTable, call {@link #updateReferences()}. * * @return the area of the table * @see "Open Office XML Part 4: chapter 3.5.1.2, attribute ref" * @since 3.17 beta 1 */ public AreaReference getCellReferences() { return new AreaReference( getStartCellReference(), getEndCellReference(), SpreadsheetVersion.EXCEL2007 ); }
/** * Get the number of data rows in this table. This does not include any * header rows or totals rows. * * Returns <code>0</code> if the start or end cell references are not set. * * Does not track updates to underlying changes to CTTable To synchronize * with changes to the underlying CTTable, call {@link #updateReferences()}. * * @return the number of data rows * @since 4.0.0 */ public int getDataRowCount() { CellReference from = getStartCellReference(); CellReference to = getEndCellReference(); int rowCount = 0; if (from != null && to != null) { rowCount = (to.getRow() - from.getRow() + 1) - getHeaderRowCount() - getTotalsRowCount(); } return rowCount; }
int columnCount = getColumnCount(); if(columnIndex < 0 || columnIndex > columnCount) { throw new IllegalArgumentException("Column index out of bounds"); for (XSSFTableColumn tableColumn : getColumns()) { if (columnName != null && columnName.equalsIgnoreCase(tableColumn.getName())) { throw new IllegalArgumentException("Column '" + columnName CellReference tableStart = getStartCellReference(); CellReference tableEnd = getEndCellReference(); SpreadsheetVersion version = getXSSFSheet().getWorkbook().getSpreadsheetVersion(); CellReference newTableEnd = new CellReference(tableEnd.getRow(), tableStart.getCol() + newColumnCount - 1); AreaReference newTableArea = new AreaReference(tableStart, newTableEnd, version); setCellRef(newTableArea); updateHeaders(); return getColumns().get(columnIndex);
String commonXPath = table.getCommonXpath(); xpaths.add(commonXPath); tableMappings.put(commonXPath, table); List<XSSFTableColumn> tableColumns = table.getColumns(); XSSFSheet sheet = table.getXSSFSheet(); int startRow = table.getStartCellReference().getRow() + table.getHeaderRowCount(); int endRow = table.getEndCellReference().getRow(); Node tableRootNode = getNodeByXPath(table.getCommonXpath(), doc.getFirstChild(), doc, true); short startColumnIndex = table.getStartCellReference().getCol(); for (XSSFTableColumn tableColumn : tableColumns) { XSSFCell cell = row.getCell(startColumnIndex + tableColumn.getColumnIndex());
if (areaSheetName != null && !areaSheetName.equals(getXSSFSheet().getSheetName())) { int minimumRowCount = 1 + getHeaderRowCount() + getTotalsRowCount(); if (rowCount < minimumRowCount) { throw new IllegalArgumentException("AreaReference needs at least " + minimumRowCount ctTable.getAutoFilter().setRef(ref); updateReferences(); int columnCount = getColumnCount(); int newColumnCount = (tableArea.getLastCell().getCol() - tableArea.getFirstCell().getCol()) + 1; if (newColumnCount > columnCount) { for (int i = columnCount; i < newColumnCount; i++) { createColumn(null, i); removeColumn(i -1); updateHeaders();
String commonXPath = table.getCommonXpath(); xpaths.add(commonXPath); tableMappings.put(commonXPath, table); List<XSSFXmlColumnPr> tableColumns = table.getXmlColumnPrs(); XSSFSheet sheet = table.getXSSFSheet(); int startRow = table.getStartCellReference().getRow(); int endRow = table.getEndCellReference().getRow(); Node tableRootNode = getNodeByXPath(table.getCommonXpath(),doc.getFirstChild(),doc,true); short startColumnIndex = table.getStartCellReference().getCol(); for(int j = startColumnIndex; j<= table.getEndCellReference().getCol();j++) { XSSFCell cell = row.getCell(j); if (cell!=null) {
String commonXPath = table.getCommonXpath(); NodeList result = (NodeList) xpath.evaluate(commonXPath, doc, XPathConstants.NODESET); int rowOffset = table.getStartCellReference().getRow() + table.getHeaderRowCount(); int columnOffset = table.getStartCellReference().getCol(); table.setDataRowCount(result.getLength()); for (XSSFTableColumn tableColumn : table.getColumns()) { XSSFRow row = table.getXSSFSheet().getRow(rowId); if (row == null) { row = table.getXSSFSheet().createRow(rowId); + table.getXSSFSheet().getSheetName()); setCellValue(value, cell, xmlColumnPr.getXmlDataType());
List<XSSFTable> tables = sheet.getTables(); for (XSSFTable t : tables) { System.out.println(t.getDisplayName()); System.out.println(t.getName()); System.out.println(t.getNumerOfMappedColumns()); int startRow = t.getStartCellReference().getRow(); int endRow = t.getEndCellReference().getRow(); System.out.println("startRow = " + startRow); System.out.println("endRow = " + endRow); int startColumn = t.getStartCellReference().getCol(); int endColumn = t.getEndCellReference().getCol();
table.setName("Test"); table.setDisplayName("Test_Table"); table.getCTTable().addNewTableStyleInfo(); table.getCTTable().getTableStyleInfo().setName("TableStyleMedium2"); XSSFTableStyleInfo style = (XSSFTableStyleInfo) table.getStyle(); style.setName("TableStyleMedium2"); style.setShowColumnStripes(false);
/** * Returns the data table with the given name (case insensitive). * * @param name the data table name (case-insensitive) * @return The Data table in the workbook named <tt>name</tt>, or <tt>null</tt> if no table is named <tt>name</tt>. * @since 3.15 beta 2 */ public XSSFTable getTable(String name) { if (name != null && sheets != null) { for (XSSFSheet sheet : sheets) { for (XSSFTable tbl : sheet.getTables()) { if (name.equalsIgnoreCase(tbl.getName())) { return tbl; } } } } return null; }
/** * Remove table references and relations * @param t table to remove */ public void removeTable(XSSFTable t) { long id = t.getCTTable().getId(); Map.Entry<String, XSSFTable> toDelete = null; for (Map.Entry<String, XSSFTable> entry : tables.entrySet()) { if (entry.getValue().getCTTable().getId() == id) toDelete = entry; } if (toDelete != null) { removeRelation(getRelationById(toDelete.getKey()), true); tables.remove(toDelete.getKey()); toDelete.getValue().onTableDelete(); } }
XSSFTable table = rp.getDocumentPart(); tbl.setId(rp.getRelationship().getId()); table.getCTTable().setId(tableNumber); table.setArea(tableArea);
CTTable cttable = table.getCTTable(); table.setDisplayName("table"); cttable.setRef("A1:C4"); cttable.setId(1);
XSSFWorkbook workbook = new XSSFWorkbook(new File("test.xlsx")); int numberOfSheets = workbook.getNumberOfSheets(); for(int sheetIdx = 0; sheetIdx < numberOfSheets; sheetIdx++) { XSSFSheet sheet = workbook.getSheetAt(sheetIdx); List<XSSFTable> tables = sheet.getTables(); for(XSSFTable t : tables) { System.out.println(t.getDisplayName()); System.out.println(t.getName()); System.out.println(t.getNumerOfMappedColumns()); } }
/** * @since 3.15 beta 2 */ public int getEndRowIndex() { return getEndCellReference().getRow(); }
/** * @since 3.15 beta 2 */ public int getStartColIndex() { return getStartCellReference().getCol(); }