public class XWPFTable extends java.lang.Object implements IBodyElement, ISDTContents
Sketch of XWPFTable class. Only table's text is being hold.
Specifies the contents of a table present in the document. A table is a set of paragraphs (and other block-level content) arranged in rows and columns.
Modifier and Type | Class and Description |
---|---|
static class |
XWPFTable.XWPFBorderType |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_PERCENTAGE_WIDTH |
protected IBody |
part |
static java.lang.String |
REGEX_PERCENTAGE |
static java.lang.String |
REGEX_WIDTH_VALUE |
protected java.util.List<XWPFTableRow> |
tableRows |
protected java.lang.StringBuilder |
text |
Constructor and Description |
---|
XWPFTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl table,
IBody part) |
XWPFTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl table,
IBody part,
int row,
int col) |
Modifier and Type | Method and Description |
---|---|
void |
addNewCol()
add a new column for each row in this table
|
void |
addNewRowBetween(int start,
int end)
Deprecated.
4.0.0 due to lack of implementation.
|
void |
addRow(XWPFTableRow row)
add a new Row to the table
|
boolean |
addRow(XWPFTableRow row,
int pos)
add a new Row to the table
at position pos
|
XWPFTableRow |
createRow()
create a new XWPFTableRow object with as many cells as the number of columns defined in that moment
|
IBody |
getBody() |
java.lang.String |
getBottomBorderColor()
Get bottom border color
|
int |
getBottomBorderSize()
Get bottom border size
|
int |
getBottomBorderSpace()
Get bottom border spacing
|
XWPFTable.XWPFBorderType |
getBottomBorderType()
Get bottom border type
|
int |
getCellMarginBottom() |
int |
getCellMarginLeft() |
int |
getCellMarginRight() |
int |
getCellMarginTop() |
int |
getColBandSize() |
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl |
getCTTbl() |
BodyElementType |
getElementType()
returns the type of the BodyElement Table
|
java.lang.String |
getInsideHBorderColor()
Get inside horizontal border color
|
int |
getInsideHBorderSize()
Get inside horizontal border size
|
int |
getInsideHBorderSpace()
Get inside horizontal border spacing
|
XWPFTable.XWPFBorderType |
getInsideHBorderType()
Get inside horizontal border type
|
java.lang.String |
getInsideVBorderColor()
Get inside vertical border color
|
int |
getInsideVBorderSize()
Get inside vertical border size
|
int |
getInsideVBorderSpace()
Get inside vertical border spacing
|
XWPFTable.XWPFBorderType |
getInsideVBorderType()
Get inside vertical border type
|
java.lang.String |
getLeftBorderColor()
Get Left border color
|
int |
getLeftBorderSize()
Get Left border size
|
int |
getLeftBorderSpace()
Get Left border spacing
|
XWPFTable.XWPFBorderType |
getLeftBorderType()
Get Left border type
|
int |
getNumberOfRows() |
POIXMLDocumentPart |
getPart()
returns the part of the bodyElement
|
BodyType |
getPartType()
returns the partType of the bodyPart which owns the bodyElement
|
java.lang.String |
getRightBorderColor()
Get Right border color
|
int |
getRightBorderSize()
Get Right border size
|
int |
getRightBorderSpace()
Get Right border spacing
|
XWPFTable.XWPFBorderType |
getRightBorderType()
Get Right border type
|
XWPFTableRow |
getRow(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow row)
returns the XWPFRow which belongs to the CTRow row
if this row is not existing in the table null will be returned
|
XWPFTableRow |
getRow(int pos) |
int |
getRowBandSize() |
java.util.List<XWPFTableRow> |
getRows() |
java.lang.String |
getStyleID()
get the StyleID of the table
|
TableRowAlign |
getTableAlignment()
Returns the current table alignment or NULL
|
java.lang.String |
getText()
Convenience method to extract text in cells.
|
java.lang.String |
getTopBorderColor()
Get top border color
|
int |
getTopBorderSize()
Get top border size
|
int |
getTopBorderSpace()
Get top border spacing
|
XWPFTable.XWPFBorderType |
getTopBorderType()
Get top border type
|
int |
getWidth()
Get the width value as an integer.
|
double |
getWidthDecimal()
Get the table width as a decimal value.
|
protected static double |
getWidthDecimal(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth ctWidth)
Get the width as a decimal value.
|
TableWidthType |
getWidthType()
Get the width type for the table, as an
STTblWidth.Enum value. |
protected static TableWidthType |
getWidthType(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth ctWidth)
Get the width type from the width value
|
XWPFTableRow |
insertNewTableRow(int pos)
inserts a new tablerow
|
void |
removeBorders()
Remove all borders from table
|
void |
removeBottomBorder()
Remove bottom borders for table
|
void |
removeInsideHBorder()
Remove inside horizontal borders for table
|
void |
removeInsideVBorder()
Remove inside vertical borders for table
|
void |
removeLeftBorder()
Remove left borders for table
|
void |
removeRightBorder()
Remove right borders for table
|
boolean |
removeRow(int pos)
Remove a row at position pos from the table
|
void |
removeTableAlignment()
Removes the table alignment attribute from a table
|
void |
removeTopBorder()
Remove top borders for table
|
void |
setBottomBorder(XWPFTable.XWPFBorderType type,
int size,
int space,
java.lang.String rgbColor)
Set Bottom borders for table
|
void |
setCellMargins(int top,
int left,
int bottom,
int right) |
void |
setColBandSize(int size) |
void |
setInsideHBorder(XWPFTable.XWPFBorderType type,
int size,
int space,
java.lang.String rgbColor)
Set Inside horizontal borders for a table
|
void |
setInsideVBorder(XWPFTable.XWPFBorderType type,
int size,
int space,
java.lang.String rgbColor)
Set Inside Vertical borders for table
|
void |
setLeftBorder(XWPFTable.XWPFBorderType type,
int size,
int space,
java.lang.String rgbColor)
Set Left borders for table
|
void |
setRightBorder(XWPFTable.XWPFBorderType type,
int size,
int space,
java.lang.String rgbColor)
Set Right borders for table
|
void |
setRowBandSize(int size) |
void |
setStyleID(java.lang.String styleName)
Set the table style.
|
void |
setTableAlignment(TableRowAlign tra)
Set table alignment to specified
TableRowAlign |
void |
setTopBorder(XWPFTable.XWPFBorderType type,
int size,
int space,
java.lang.String rgbColor)
Set Top borders for table
|
void |
setWidth(int width)
Set the width in 20ths of a point (twips).
|
void |
setWidth(java.lang.String widthValue)
Set the width to the value "auto", an integer value (20ths of a point), or a percentage ("nn.nn%").
|
protected static void |
setWidthPercentage(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth ctWidth,
java.lang.String widthValue)
Set the underlying table width value to a percentage value.
|
void |
setWidthType(TableWidthType widthType)
Set the width value type for the table.
|
protected static void |
setWidthType(TableWidthType widthType,
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth ctWidth)
Set the width type if different from current width type
|
protected static void |
setWidthValue(java.lang.String widthValue,
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth ctWidth)
Set the width value from a string
|
public static final java.lang.String REGEX_PERCENTAGE
public static final java.lang.String DEFAULT_PERCENTAGE_WIDTH
public static final java.lang.String REGEX_WIDTH_VALUE
protected java.lang.StringBuilder text
protected final java.util.List<XWPFTableRow> tableRows
protected IBody part
public XWPFTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl table, IBody part, int row, int col)
public XWPFTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl table, IBody part)
@Internal public org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl getCTTbl()
public java.lang.String getText()
To get all text within a table, see XWPFWordExtractor's appendTableText as an example.
@Deprecated @Removal @NotImplemented public void addNewRowBetween(int start, int end)
public void addNewCol()
public XWPFTableRow createRow()
public XWPFTableRow getRow(int pos)
pos
- - index of the rowpublic int getWidth()
If the width type is AUTO, DXA, or NIL, the value is 20ths of a point. If the width type is PCT, the value is the percentage times 50 (e.g., 2500 for 50%).
public void setWidth(int width)
width
- Width value (20ths of a point)public int getNumberOfRows()
public TableRowAlign getTableAlignment()
TableRowAlign
enumpublic void setTableAlignment(TableRowAlign tra)
TableRowAlign
tra
- TableRowAlign
to setpublic void removeTableAlignment()
public java.lang.String getStyleID()
public void setStyleID(java.lang.String styleName)
styleName
- - the style name to apply to this tablepublic XWPFTable.XWPFBorderType getInsideHBorderType()
XWPFTable.XWPFBorderType
of the inside horizontal borders or null if missingpublic int getInsideHBorderSize()
public int getInsideHBorderSpace()
public java.lang.String getInsideHBorderColor()
public XWPFTable.XWPFBorderType getInsideVBorderType()
XWPFTable.XWPFBorderType
of the inside vertical borders or null if missingpublic int getInsideVBorderSize()
public int getInsideVBorderSpace()
public java.lang.String getInsideVBorderColor()
public XWPFTable.XWPFBorderType getTopBorderType()
XWPFTable.XWPFBorderType
of the top borders or null if missingpublic int getTopBorderSize()
public int getTopBorderSpace()
public java.lang.String getTopBorderColor()
public XWPFTable.XWPFBorderType getBottomBorderType()
XWPFTable.XWPFBorderType
of the bottom borders or null if missingpublic int getBottomBorderSize()
public int getBottomBorderSpace()
public java.lang.String getBottomBorderColor()
public XWPFTable.XWPFBorderType getLeftBorderType()
XWPFTable.XWPFBorderType
of the Left borders or null if missingpublic int getLeftBorderSize()
public int getLeftBorderSpace()
public java.lang.String getLeftBorderColor()
public XWPFTable.XWPFBorderType getRightBorderType()
XWPFTable.XWPFBorderType
of the Right borders or null if missingpublic int getRightBorderSize()
public int getRightBorderSpace()
public java.lang.String getRightBorderColor()
public int getRowBandSize()
public void setRowBandSize(int size)
public int getColBandSize()
public void setColBandSize(int size)
public void setInsideHBorder(XWPFTable.XWPFBorderType type, int size, int space, java.lang.String rgbColor)
type
- - XWPFTable.XWPFBorderType
e.g. single, double, thicksize
- - Specifies the width of the current border. The width of this border is
specified in measurements of eighths of a point, with a minimum value of two (onefourth
of a point) and a maximum value of 96 (twelve points). Any values outside this
range may be reassigned to a more appropriate value.space
- - Specifies the spacing offset that shall be used to place this border on the tablergbColor
- - This color may either be presented as a hex value (in RRGGBB format),
or auto to allow a consumer to automatically determine the border color as appropriate.public void setInsideVBorder(XWPFTable.XWPFBorderType type, int size, int space, java.lang.String rgbColor)
type
- - XWPFTable.XWPFBorderType
e.g. single, double, thicksize
- - Specifies the width of the current border. The width of this border is
specified in measurements of eighths of a point, with a minimum value of two (onefourth
of a point) and a maximum value of 96 (twelve points). Any values outside this
range may be reassigned to a more appropriate value.space
- - Specifies the spacing offset that shall be used to place this border on the tablergbColor
- - This color may either be presented as a hex value (in RRGGBB format),
or auto to allow a consumer to automatically determine the border color as appropriate.public void setTopBorder(XWPFTable.XWPFBorderType type, int size, int space, java.lang.String rgbColor)
type
- - XWPFTable.XWPFBorderType
e.g. single, double, thicksize
- - Specifies the width of the current border. The width of this border is
specified in measurements of eighths of a point, with a minimum value of two (onefourth
of a point) and a maximum value of 96 (twelve points). Any values outside this
range may be reassigned to a more appropriate value.space
- - Specifies the spacing offset that shall be used to place this border on the tablergbColor
- - This color may either be presented as a hex value (in RRGGBB format),
or auto to allow a consumer to automatically determine the border color as appropriate.public void setBottomBorder(XWPFTable.XWPFBorderType type, int size, int space, java.lang.String rgbColor)
type
- - XWPFTable.XWPFBorderType
e.g. single, double, thicksize
- - Specifies the width of the current border. The width of this border is
specified in measurements of eighths of a point, with a minimum value of two (onefourth
of a point) and a maximum value of 96 (twelve points). Any values outside this
range may be reassigned to a more appropriate value.space
- - Specifies the spacing offset that shall be used to place this border on the tablergbColor
- - This color may either be presented as a hex value (in RRGGBB format),
or auto to allow a consumer to automatically determine the border color as appropriate.public void setLeftBorder(XWPFTable.XWPFBorderType type, int size, int space, java.lang.String rgbColor)
type
- - XWPFTable.XWPFBorderType
e.g. single, double, thicksize
- - Specifies the width of the current border. The width of this border is
specified in measurements of eighths of a point, with a minimum value of two (onefourth
of a point) and a maximum value of 96 (twelve points). Any values outside this
range may be reassigned to a more appropriate value.space
- - Specifies the spacing offset that shall be used to place this border on the tablergbColor
- - This color may either be presented as a hex value (in RRGGBB format),
or auto to allow a consumer to automatically determine the border color as appropriate.public void setRightBorder(XWPFTable.XWPFBorderType type, int size, int space, java.lang.String rgbColor)
type
- - XWPFTable.XWPFBorderType
e.g. single, double, thicksize
- - Specifies the width of the current border. The width of this border is
specified in measurements of eighths of a point, with a minimum value of two (onefourth
of a point) and a maximum value of 96 (twelve points). Any values outside this
range may be reassigned to a more appropriate value.space
- - Specifies the spacing offset that shall be used to place this border on the tablergbColor
- - This color may either be presented as a hex value (in RRGGBB format),
or auto to allow a consumer to automatically determine the border color as appropriate.public void removeInsideHBorder()
public void removeInsideVBorder()
public void removeTopBorder()
public void removeBottomBorder()
public void removeLeftBorder()
public void removeRightBorder()
public void removeBorders()
public int getCellMarginTop()
public int getCellMarginLeft()
public int getCellMarginBottom()
public int getCellMarginRight()
public void setCellMargins(int top, int left, int bottom, int right)
public void addRow(XWPFTableRow row)
row
- the row which should be addedpublic boolean addRow(XWPFTableRow row, int pos)
row
- the row which should be addedpublic XWPFTableRow insertNewTableRow(int pos)
pos
- public boolean removeRow(int pos) throws java.lang.IndexOutOfBoundsException
pos
- position the Row in the Tablejava.lang.IndexOutOfBoundsException
public java.util.List<XWPFTableRow> getRows()
public BodyElementType getElementType()
getElementType
in interface IBodyElement
IBodyElement.getElementType()
public IBody getBody()
getBody
in interface IBodyElement
public POIXMLDocumentPart getPart()
getPart
in interface IBodyElement
IBody.getPart()
public BodyType getPartType()
getPartType
in interface IBodyElement
IBody.getPartType()
public XWPFTableRow getRow(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow row)
public double getWidthDecimal()
If the width type is DXA or AUTO, then the value will always have a fractional part of zero (because these values are really integers). If the with type is percentage, then value may have a non-zero fractional part.
protected static double getWidthDecimal(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth ctWidth)
This method is also used by table cells.
ctWidth
- Width value to evaluate.public TableWidthType getWidthType()
STTblWidth.Enum
value.
A table width can be specified as an absolute measurement (an integer
number of twips), a percentage, or the value "AUTO".protected static TableWidthType getWidthType(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth ctWidth)
ctWidth
- CTTblWidth to evalutepublic void setWidth(java.lang.String widthValue)
widthValue
- String matching one of "auto", [0-9]+, or [0-9]+(\.[0-9]+)%.protected static void setWidthValue(java.lang.String widthValue, org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth ctWidth)
widthValue
- The width value stringctWidth
- CTTblWidth to set the value on.protected static void setWidthPercentage(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth ctWidth, java.lang.String widthValue)
ctWidth
- The CTTblWidth to set the value onwidthValue
- String width value in form "33.3%" or an integer that is 50 times desired percentage value (e.g,
2500 for 50%)public void setWidthType(TableWidthType widthType)
If the width type is changed from the current type and the currently-set value is not consistent with the new width type, the value is reset to the default value for the specified width type.
widthType
- Width typeprotected static void setWidthType(TableWidthType widthType, org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth ctWidth)
widthType
- The new width typectWidth
- CTTblWidth to set the type onCopyright 2020 The Apache Software Foundation or its licensors, as applicable.