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()
(请注意,此列表是静态的 - 一旦读取,它不会注意到以后对底层列结构的更改要清除缓存,请调用 updateHeaders())
|
java.lang.String |
getCommonXpath()
Calculates the xpath of the root element for the table.
(计算表的根元素的 xpath。)
|
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable |
getCTTable()
get the underlying CTTable XML bean
(获取底层 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
(检查此 Table 元素是否包含到由 id 标识的映射的单个映射)
|
protected void |
onTableDelete()
Remove relations
(删除关系)
|
void |
readFrom(java.io.InputStream is)
Read table XML from an
InputStream
(从 InputStream 读取表 XML)
|
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() .
(清除由 getStartCellReference() 和 getEndCellReference() 设置的缓存值。)
|
void |
writeTo(java.io.OutputStream out)
write table XML to an
OutputStream
(将表 XML 写入 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 table
(part - 用于初始化表的部分)
java.io.IOException
- If reading data from the part fails.
(java.io.IOException - 如果从部件读取数据失败。)
public void readFrom(java.io.InputStream is) throws java.io.IOException
InputStream
(从 InputStream 读取表 XML)
is
- The stream which provides the XML data for the table.
(is - 为表提供 XML 数据的流。)
java.io.IOException
- If reading from the stream fails
(java.io.IOException - 如果从流中读取失败)
public XSSFSheet getXSSFSheet()
public void writeTo(java.io.OutputStream out) throws java.io.IOException
OutputStream
(将表 XML 写入 OutputStream)
out
- The stream to write the XML data to
(out - 将 XML 数据写入的流)
java.io.IOException
- If writing to the stream fails.
(java.io.IOException - 如果写入流失败。)
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(); }(将内容保存在底层包部分中。默认实现是空的,这意味着包部分保持不变。子类应覆盖并添加逻辑以将“模型”编组到 Ooxml4J。例如,保存通用 XML 条目的代码可能如下所示: protected void commit() throws IOException { PackagePart part = getPackagePart();输出流输出 = part.getOutputStream(); XmlObject bean = getXmlBean(); //保存内存变化的“模型” 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
(java.io.IOException - 如果无法提交更改,子类可能会抛出 IOException)
@Internal(since="POI 3.15 beta 3") public org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable getCTTable()
public boolean mapsTo(long id)
id
- the XSSFMap ID
(id - XSSFMap ID)
public java.lang.String getCommonXpath()
updateHeaders()
must be called.
(计算表的根元素的 xpath。这将是所有映射的 xpath 的公共部分 注意:此函数缓存结果以提高性能。要刷新缓存,必须调用 updateHeaders()。)
public java.util.List<XSSFTableColumn> getColumns()
updateHeaders()
(请注意,此列表是静态的 - 一旦读取,它不会注意到以后对底层列结构的更改要清除缓存,请调用 updateHeaders())
public XSSFTableColumn createColumn(java.lang.String columnName)
columnName
- the unique name of the column, must not be
null
(columnName - 列的唯一名称,不能为空)
public XSSFTableColumn createColumn(java.lang.String columnName, int columnIndex)
columnName
- the unique name of the column, or
null
for a generated name
(columnName - 列的唯一名称,或者为生成的名称为 null)
columnIndex
- the 0-based position of the column in the table
(columnIndex - 表中列的从 0 开始的位置)
java.lang.IllegalArgumentException
- if the column name is not unique or missing or if the column can't be created at the given index
(java.lang.IllegalArgumentException - 如果列名不唯一或缺失,或者无法在给定索引处创建列)
public void removeColumn(XSSFTableColumn column)
column
- the column to remove
(column - 要删除的列)
public void removeColumn(int columnIndex)
columnIndex
- the 0-based position of the column in the table
(columnIndex - 表中列的从 0 开始的位置)
java.lang.IllegalArgumentException
- if no column at the index exists or if the table has only a single column
(java.lang.IllegalArgumentException - 如果索引处不存在列或者表只有一列)
public java.lang.String getName()
Table
public void setName(java.lang.String newName)
newName
- The name of the table.
(newName - 表的名称。)
public java.lang.String getStyleName()
getStyleName
in interface
Table
(接口表中的getStyleName)
public void setStyleName(java.lang.String newStyleName)
newStyleName
- The name of the style.
(newStyleName - 样式的名称。)
public java.lang.String getDisplayName()
public void setDisplayName(java.lang.String name)
name
- to use
(名称 - 使用)
public AreaReference getCellReferences()
updateReferences()
.
(获取此表涵盖的单元格的区域参考。该区域包括标题行和总计行。不跟踪对 CTTable 的基础更改的更新 要与对基础 CTTable 的更改同步,请调用 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.
(设置此表涵盖的单元格的区域参考。该区域包括标题行和总计行。通过调用 updateHeaders() 自动同步任何更改。注意:该区域的宽度应与表格中的列数相同,否则表格可能无效。所有标题行、总计行和至少一个数据行必须适合该区域。使用此方法更新区域不会创建或删除任何列,也不会更改任何单元格值。)
@Internal protected void setCellRef(AreaReference refs)
public void setArea(AreaReference tableArea)
tableArea
- the new area of the table
(tableArea - 表格的新区域)
java.lang.IllegalArgumentException
- if the area is
null
or not
(java.lang.IllegalArgumentException - 如果该区域是否为空)
public AreaReference getArea()
null
if the area has not been initialized
(表的区域;如果该区域尚未初始化,则为 null)
public CellReference getStartCellReference()
updateReferences()
.
(表左上角单元格的引用(请参阅 Open Office XML 第 4 部分:第 3.5.1.2 章,属性 ref) 不跟踪对 CTTable 的基础更改的更新 要与对基础 CTTable 的更改同步,请调用 updateReferences ()。)
public CellReference getEndCellReference()
updateReferences()
.
(表右下角单元格的引用(请参阅 Open Office XML 第 4 部分:第 3.5.1.2 章,属性 ref) 不跟踪对 CTTable 的基础更改的更新 要与对基础 CTTable 的更改同步,请调用 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.
(清除由 getStartCellReference() 和 getEndCellReference() 设置的缓存值。下一次调用 getStartCellReference() 和 getEndCellReference() 将使单元格引用与底层 CTTable 同步。因此这种方法成本低廉。)
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()
.
(获取此表中的总行数,包括所有标题行和所有总计行。 (注意:在此版本中,自动过滤被忽略)如果未设置开始或结束单元格引用,则返回 0。不跟踪对 CTTable 的基础更改的更新 要与对基础 CTTable 的更改同步,请调用 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()
.
(获取此表中的数据行数。这不包括任何标题行或总计行。如果未设置开始或结束单元格引用,则返回 0。不跟踪对 CTTable 的基础更改的更新 要与对基础 CTTable 的更改同步,请调用 updateReferences()。)
public void setDataRowCount(int newDataRowCount)
setArea(AreaReference)
instead.
(设置表格数据区的行数。这不会影响任何标题行或总计行。如果新的行数小于当前行数,多余的行将被清除。如果新行数大于当前行数,则表格下方的单元格将被表格覆盖。要在不覆盖单元格的情况下调整表格大小,请改用 setArea(AreaReference)。)
newDataRowCount
- new row count for the table
(newDataRowCount - 表的新行数)
java.lang.IllegalArgumentException
- if the row count is less than 1
(java.lang.IllegalArgumentException - 如果行数小于 1)
public 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.
(将表格标题与父工作表中的单元格值同步。标头必须同步,否则 Excel 将在启动时显示“发现无法读取的内容”消息。如果同时调用 updateReferences() 和此方法,则应首先调用 updateReferences()。请注意,表必须有标题。要重现在没有标题的 Excel 中插入表格的等价物,请先手动添加值为“Column1”、“Column2”等的单元格。)
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.
(获取此表中具有标题名称列的列的相对列索引。列索引相对于表中最左边的列,从 0 开始索引。如果列不是表中的标题名称,则返回 -1。列标题名称不区分大小写 注意:此函数缓存列名称以提高性能。要刷新缓存(因为列已被移动或列标题已更改),必须调用 updateHeaders()。)
findColumnIndex
in interface
Table
(接口 Table 中的 findColumnIndex)
columnHeader
- the column header name to get the table column index of
(columnHeader - 获取表列索引的列标题名称)
columnHeader
(columnHeader对应的列索引)
public java.lang.String getSheetName()
Table
getSheetName
in interface
Table
(接口表中的getSheetName)
public boolean isHasTotalsRow()
getTotalsRowCount()
> 0 to decide whether or not the totals row is visible.
(注意:这是误导。如果总计行曾经显示过,则规范表明这是真的,而不是当前是否显示。使用 getTotalsRowCount() > 0 来决定总计行是否可见。)
isHasTotalsRow
in interface
Table
(接口 Table 中的 isHasTotalsRow)
getTotalsRowCount()
public int getTotalsRowCount()
getTotalsRowCount
in interface
Table
(接口 Table 中的 getTotalsRowCount)
public int getHeaderRowCount()
getHeaderRowCount
in interface
Table
(接口 Table 中的 getHeaderRowCount)
public int getStartColIndex()
Table
getStartColIndex
in interface
Table
(接口 Table 中的 getStartColIndex)
public int getStartRowIndex()
Table
getStartRowIndex
in interface
Table
(接口 Table 中的 getStartRowIndex)
public int getEndColIndex()
Table
getEndColIndex
in interface
Table
(接口 Table 中的 getEndColIndex)
public int getEndRowIndex()
Table
getEndRowIndex
in interface
Table
(接口 Table 中的 getEndRowIndex)
public TableStyleInfo getStyle()
public boolean contains(CellReference cell)
Table
contains
in interface
Table
(包含在接口表中)
cell
- reference to a possibly undefined cell location
(单元格 - 对可能未定义的单元格位置的引用)
Table.contains(org.apache.poi.ss.usermodel.Cell)
protected void onTableDelete()
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.