public class XSSFTable extends POIXMLDocumentPart implements Table
POIXMLDocumentPart.RelationPart
isStructuredReference
Constructor and Description |
---|
XSSFTable()
empty implementation, not attached to a workbook/worksheet yet
|
XSSFTable(PackagePart part) |
Modifier and Type | Method and Description |
---|---|
protected void |
commit()
Save the content in the underlying package part.
|
boolean |
contains(CellReference cell)
checks if the given cell is part of the table.
|
XSSFTableColumn |
createColumn(java.lang.String columnName)
Add a new column to the right end of the table.
|
XSSFTableColumn |
createColumn(java.lang.String columnName,
int columnIndex)
Adds a new column to the table.
|
int |
findColumnIndex(java.lang.String columnHeader)
Gets the relative column index of a column in this table having the header name
column . |
AreaReference |
getArea()
Get the area that this table covers.
|
AreaReference |
getCellReferences()
Get the area reference for the cells which this table covers.
|
int |
getColumnCount()
Get the total number of columns in this table.
|
java.util.List<XSSFTableColumn> |
getColumns()
Note this list is static - once read, it does not notice later changes to the underlying column structures
To clear the cache, call
updateHeaders() |
java.lang.String |
getCommonXpath()
Calculates the xpath of the root element for the table.
|
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable |
getCTTable()
get the underlying CTTable XML bean
|
int |
getDataRowCount()
Get the number of data rows in this table.
|
java.lang.String |
getDisplayName() |
CellReference |
getEndCellReference() |
int |
getEndColIndex()
Get the bottom-right column index on the sheet
|
int |
getEndRowIndex()
Get the bottom-right row index
|
int |
getHeaderRowCount() |
java.lang.String |
getName()
Get the name of the table.
|
int |
getRowCount()
Get the total number of rows in this table, including all
header rows and all
totals rows.
|
java.lang.String |
getSheetName()
Returns the sheet name that the table belongs to.
|
CellReference |
getStartCellReference() |
int |
getStartColIndex()
Get the top-left column index relative to the sheet
|
int |
getStartRowIndex()
Get the top-left row index on the sheet
|
TableStyleInfo |
getStyle() |
java.lang.String |
getStyleName() |
int |
getTotalsRowCount() |
XSSFSheet |
getXSSFSheet() |
boolean |
isHasTotalsRow()
Note: This is misleading.
|
boolean |
mapsTo(long id)
Checks if this Table element contains even a single mapping to the map identified by id
|
protected void |
onTableDelete()
Remove relations
|
void |
readFrom(java.io.InputStream is)
Read table XML from an
InputStream |
void |
removeColumn(int columnIndex)
Remove a column from the table.
|
void |
removeColumn(XSSFTableColumn column)
Remove a column from the table.
|
void |
setArea(AreaReference tableArea)
Set the area reference for the cells which this table covers.
|
protected void |
setCellRef(AreaReference refs) |
void |
setCellReferences(AreaReference refs)
Set the area reference for the cells which this table covers.
|
void |
setDataRowCount(int newDataRowCount)
Set the number of rows in the data area of the table.
|
void |
setDisplayName(java.lang.String name)
Changes the display name of the Table
|
void |
setName(java.lang.String newName)
Changes the name of the Table
|
void |
setStyleName(java.lang.String newStyleName)
Changes the name of the Table
|
void |
updateHeaders()
Synchronize table headers with cell values in the parent sheet.
|
void |
updateReferences()
Clears the cached values set by
getStartCellReference()
and getEndCellReference() . |
void |
writeTo(java.io.OutputStream out)
write table XML to an
OutputStream |
_invokeOnDocumentRead, addRelation, createRelationship, createRelationship, createRelationship, getNextPartNumber, getPackagePart, getParent, getRelationById, getRelationId, getRelationPartById, getRelationParts, getRelations, getTargetPart, isCommitted, onDocumentCreate, onDocumentRead, onDocumentRemove, onSave, prepareForCommit, read, rebase, removeRelation, removeRelation, removeRelation, setCommitted, toString
public XSSFTable()
public XSSFTable(PackagePart part) throws java.io.IOException
part
- The part used to initialize the tablejava.io.IOException
- If reading data from the part fails.public void readFrom(java.io.InputStream is) throws java.io.IOException
InputStream
is
- The stream which provides the XML data for the table.java.io.IOException
- If reading from the stream failspublic XSSFSheet getXSSFSheet()
public void writeTo(java.io.OutputStream out) throws java.io.IOException
OutputStream
out
- The stream to write the XML data tojava.io.IOException
- If writing to the stream fails.protected void commit() throws java.io.IOException
POIXMLDocumentPart
Sub-classes should override and add logic to marshal the "model" into Ooxml4J.
For example, the code saving a generic XML entry may look as follows:
protected void commit() throws IOException { PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); XmlObject bean = getXmlBean(); //the "model" which holds changes in memory bean.save(out, DEFAULT_XML_OPTIONS); out.close(); }
commit
in class POIXMLDocumentPart
java.io.IOException
- a subclass may throw an IOException if the changes can't be committed@Internal(since="POI 3.15 beta 3") public org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable getCTTable()
public boolean mapsTo(long id)
id
- the XSSFMap IDpublic java.lang.String getCommonXpath()
updateHeaders()
must be called.public java.util.List<XSSFTableColumn> getColumns()
updateHeaders()
public XSSFTableColumn createColumn(java.lang.String columnName)
columnName
- the unique name of the column, must not be null
public XSSFTableColumn createColumn(java.lang.String columnName, int columnIndex)
columnName
- the unique name of the column, or null
for a generated namecolumnIndex
- the 0-based position of the column in the tablejava.lang.IllegalArgumentException
- if the column name is not unique or missing or if the column
can't be created at the given indexpublic void removeColumn(XSSFTableColumn column)
column
- the column to removepublic void removeColumn(int columnIndex)
columnIndex
- the 0-based position of the column in the tablejava.lang.IllegalArgumentException
- if no column at the index exists or if the table has only a
single columnpublic java.lang.String getName()
Table
public void setName(java.lang.String newName)
newName
- The name of the table.public java.lang.String getStyleName()
getStyleName
in interface Table
public void setStyleName(java.lang.String newStyleName)
newStyleName
- The name of the style.public java.lang.String getDisplayName()
public void setDisplayName(java.lang.String name)
name
- to usepublic AreaReference getCellReferences()
updateReferences()
.public void setCellReferences(AreaReference refs)
updateHeaders()
.
Note: The area's width should be identical to the amount of columns in
the table or the table may be invalid. All header rows, totals rows and
at least one data row must fit inside the area. Updating the area with
this method does not create or remove any columns and does not change any
cell values.@Internal protected void setCellRef(AreaReference refs)
public void setArea(AreaReference tableArea)
tableArea
- the new area of the tablejava.lang.IllegalArgumentException
- if the area is null
or notpublic AreaReference getArea()
null
if the area has not been
initializedpublic CellReference getStartCellReference()
updateReferences()
.public CellReference getEndCellReference()
updateReferences()
.public void updateReferences()
getStartCellReference()
and getEndCellReference()
.
The next call to getStartCellReference()
and
getEndCellReference()
will synchronize the
cell references with the underlying CTTable
.
Thus this method is inexpensive.public int getRowCount()
0
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 updateReferences()
.public int getDataRowCount()
0
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 updateReferences()
.public void setDataRowCount(int newDataRowCount)
setArea(AreaReference)
instead.newDataRowCount
- new row count for the tablejava.lang.IllegalArgumentException
- if the row count is less than 1public int getColumnCount()
public void updateHeaders()
updateReferences()
and
this method, updateReferences()
should be called first.
Note that a Table must have a header. To reproduce
the equivalent of inserting a table in Excel without Headers,
manually add cells with values of "Column1", "Column2" etc first.public int findColumnIndex(java.lang.String columnHeader)
column
.
The column index is relative to the left-most column in the table, 0-indexed.
Returns -1
if column
is not a header name in table.
Column Header names are case-insensitive
Note: this function caches column names for performance. To flush the cache (because columns
have been moved or column headers have been changed), updateHeaders()
must be called.findColumnIndex
in interface Table
columnHeader
- the column header name to get the table column index ofcolumnHeader
public java.lang.String getSheetName()
Table
getSheetName
in interface Table
public boolean isHasTotalsRow()
getTotalsRowCount()
> 0 to decide whether or not the totals row is visible.isHasTotalsRow
in interface Table
getTotalsRowCount()
public int getTotalsRowCount()
getTotalsRowCount
in interface Table
public int getHeaderRowCount()
getHeaderRowCount
in interface Table
public int getStartColIndex()
Table
getStartColIndex
in interface Table
public int getStartRowIndex()
Table
getStartRowIndex
in interface Table
public int getEndColIndex()
Table
getEndColIndex
in interface Table
public int getEndRowIndex()
Table
getEndRowIndex
in interface Table
public TableStyleInfo getStyle()
public boolean contains(CellReference cell)
Table
contains
in interface Table
cell
- reference to a possibly undefined cell locationTable.contains(org.apache.poi.ss.usermodel.Cell)
protected void onTableDelete()
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.