org.apache.poi.xssf.usermodel.XSSFTable类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(307)

本文整理了Java中org.apache.poi.xssf.usermodel.XSSFTable类的一些代码示例,展示了XSSFTable类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XSSFTable类的具体详情如下:
包路径:org.apache.poi.xssf.usermodel.XSSFTable
类名称:XSSFTable

XSSFTable介绍

[英]This class implements the Table Part (Open Office XML Part 4: chapter 3.5.1) Columns of this table may contains mappings to a subtree of an XML. The root element of this subtree can occur multiple times (one for each row of the table). The child nodes of the root element can be only attributes or elements with maxOccurs=1 property set.
[中]此类实现了表部分(Open Office XML第4部分:第3.5.1章),该表的列可能包含到XML子树的映射。此子树的根元素可以出现多次(表的每行一个)。根元素的子节点只能是属性或maxOccurs=1属性集的元素。

代码示例

代码示例来源:origin: org.apache.poi/poi-ooxml

XSSFSheet sheet = (XSSFSheet)getParent();
CellReference ref = getStartCellReference();
if (ref == null) return;
  CTTableColumns ctTableColumns = getCTTable().getTableColumns();
  if(ctTableColumns != null) {
    for (CTTableColumn col : ctTableColumns.getTableColumnList()) {

代码示例来源:origin: org.apache.poi/poi-ooxml

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);

代码示例来源:origin: org.apache.poi/poi-ooxml

for (XSSFTable table : sheet.getTables()) {
  if (name.equals(table.getName())) {
    return new AreaReference(table.getStartCellReference(), table.getEndCellReference(),
        SpreadsheetVersion.EXCEL2007);

代码示例来源:origin: org.apache.poi/poi-ooxml

@Override
protected void commit() throws IOException {
  PackagePart part = getPackagePart();
  OutputStream out = part.getOutputStream();
  writeTo(out);
  out.close();
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * 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
  );
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * 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;
}

代码示例来源:origin: org.apache.poi/poi-ooxml

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);

代码示例来源:origin: org.apache.poi/poi-ooxml

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());

代码示例来源:origin: org.apache.poi/poi-ooxml

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();

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

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) {

代码示例来源:origin: org.apache.poi/poi-ooxml

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());

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: org.apache.poi/poi-examples

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);

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * 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;
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * 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();
  }
}

代码示例来源:origin: org.apache.poi/poi-ooxml

XSSFTable table = rp.getDocumentPart();
tbl.setId(rp.getRelationship().getId());
table.getCTTable().setId(tableNumber);
  table.setArea(tableArea);

代码示例来源:origin: stackoverflow.com

CTTable cttable = table.getCTTable();
table.setDisplayName("table");
cttable.setRef("A1:C4");
cttable.setId(1);

代码示例来源:origin: stackoverflow.com

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());
  }
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * @since 3.15 beta 2
 */
public int getEndRowIndex() {
  return getEndCellReference().getRow();
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * @since 3.15 beta 2
 */
public int getStartColIndex() {
  return getStartCellReference().getCol();
}

相关文章