public class TableStyle extends Style
To learn more, visit the Working with Tables documentation article.
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
| Modifier and Type | Method and Description |
|---|---|
void |
clearCellAttrs() |
void |
clearRowAttrs() |
java.lang.Object |
fetchCellAttr(int key) |
java.lang.Object |
fetchInheritedBorderAttr(int key) |
java.lang.Object |
fetchInheritedCellAttr(int key) |
java.lang.Object |
fetchInheritedRowAttr(int key) |
java.lang.Object |
fetchInheritedShadingAttr(int key) |
java.lang.Object |
fetchRowAttr(int key) |
int |
getAlignment()
Specifies the alignment for the table style.
|
boolean |
getAllowBreakAcrossPages()
Gets a flag indicating whether text in a table row is allowed to split across a page break.
|
boolean |
getBidi()
Gets whether this is a style for a right-to-left table.
|
BorderCollection |
getBorders()
Gets the collection of default cell borders for the style.
|
double |
getBottomPadding()
Gets the amount of space (in points) to add below the contents of table cells.
|
double |
getCellSpacing()
Gets the amount of space (in points) between the cells.
|
int |
getColumnStripe()
Gets a number of columns to include in the banding when the style specifies odd/even columns banding.
|
ConditionalStyleCollection |
getConditionalStyles()
Collection of conditional styles that may be defined for this table style.
|
java.lang.Object |
getDirectBorderAttr(int key) |
java.lang.Object |
getDirectCellAttr(int key) |
java.lang.Object |
getDirectRowAttr(int key) |
double |
getLeftIndent()
Gets the value that represents the left indent of a table.
|
double |
getLeftPadding()
Gets the amount of space (in points) to add to the left of the contents of table cells.
|
double |
getRightPadding()
Gets the amount of space (in points) to add to the right of the contents of table cells.
|
int |
getRowStripe()
Gets a number of rows to include in the banding when the style specifies odd/even row banding.
|
Shading |
getShading()
Gets a
Shading object that refers to the shading formatting for table cells. |
double |
getTopPadding()
Gets the amount of space (in points) to add above the contents of table cells.
|
int |
getVerticalAlignment()
Specifies the vertical alignment for the cells.
|
void |
resetToDefaultAttrs() |
void |
setAlignment(int value)
Specifies the alignment for the table style.
|
void |
setAllowBreakAcrossPages(boolean value)
Sets a flag indicating whether text in a table row is allowed to split across a page break.
|
void |
setBidi(boolean value)
Sets whether this is a style for a right-to-left table.
|
void |
setBorderAttr(int key,
java.lang.Object value) |
void |
setBottomPadding(double value)
Sets the amount of space (in points) to add below the contents of table cells.
|
void |
setCellAttr(int key,
java.lang.Object value) |
void |
setCellSpacing(double value)
Sets the amount of space (in points) between the cells.
|
void |
setColumnStripe(int value)
Sets a number of columns to include in the banding when the style specifies odd/even columns banding.
|
void |
setLeftIndent(double value)
Sets the value that represents the left indent of a table.
|
void |
setLeftPadding(double value)
Sets the amount of space (in points) to add to the left of the contents of table cells.
|
void |
setRightPadding(double value)
Sets the amount of space (in points) to add to the right of the contents of table cells.
|
void |
setRowAttr(int key,
java.lang.Object value) |
void |
setRowStripe(int value)
Sets a number of rows to include in the banding when the style specifies odd/even row banding.
|
void |
setTopPadding(double value)
Sets the amount of space (in points) to add above the contents of table cells.
|
void |
setVerticalAlignment(int value)
Specifies the vertical alignment for the cells.
|
clearParaAttrs, clearRunAttrs, equals, fetchInheritedParaAttr, fetchInheritedRunAttr, fetchParaAttr, getAliases, getAutomaticallyUpdate, getBaseStyleName, getBuiltIn, getDirectParaAttr, getDirectParaAttr, getDirectRunAttr, getDirectRunAttr, getDocument, getFont, getLinkedStyleName, getList, getListFormat, getLocked, getName, getNextParagraphStyleName, getParagraphFormat, getPriority, getSemiHidden, getStyleIdentifier, getStyles, getType, getUnhideWhenUsed, isHeading, isQuickStyle, isQuickStyle, memberwiseClone, remove, removeParaAttr, removeRunAttr, setAutomaticallyUpdate, setBaseStyleName, setLinkedStyleName, setLocked, setName, setNextParagraphStyleName, setParaAttr, setPriority, setRunAttr, setSemiHidden, setUnhideWhenUsedpublic java.lang.Object getDirectCellAttr(int key)
public java.lang.Object fetchCellAttr(int key)
public java.lang.Object fetchInheritedCellAttr(int key)
public void setCellAttr(int key,
java.lang.Object value)
public void clearCellAttrs()
public java.lang.Object getDirectRowAttr(int key)
public java.lang.Object fetchRowAttr(int key)
public java.lang.Object fetchInheritedRowAttr(int key)
public void setRowAttr(int key,
java.lang.Object value)
public void clearRowAttrs()
public void resetToDefaultAttrs()
public java.lang.Object getDirectBorderAttr(int key)
public java.lang.Object fetchInheritedBorderAttr(int key)
public void setBorderAttr(int key,
java.lang.Object value)
public java.lang.Object fetchInheritedShadingAttr(int key)
public boolean getAllowBreakAcrossPages()
Remarks:
The default value is true.
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
public void setAllowBreakAcrossPages(boolean value)
Remarks:
The default value is true.
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
value - A flag indicating whether text in a table row is allowed to split across a page break.public BorderCollection getBorders()
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
public double getLeftPadding()
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
public void setLeftPadding(double value)
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
value - The amount of space (in points) to add to the left of the contents of table cells.public double getRightPadding()
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
public void setRightPadding(double value)
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
value - The amount of space (in points) to add to the right of the contents of table cells.public double getTopPadding()
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
public void setTopPadding(double value)
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
value - The amount of space (in points) to add above the contents of table cells.public double getBottomPadding()
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
public void setBottomPadding(double value)
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
value - The amount of space (in points) to add below the contents of table cells.public int getAlignment()
Remarks:
The default value is TableAlignment.LEFT.
Examples:
Shows how to set the position of a table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Below are two ways of aligning a table horizontally.
// 1 - Use the "Alignment" property to align it to a location on the page, such as the center:
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAlignment(TableAlignment.CENTER);
tableStyle.getBorders().setColor(Color.BLUE);
tableStyle.getBorders().setLineStyle(LineStyle.SINGLE);
// Insert a table and apply the style we created to it.
Table table = builder.startTable();
builder.insertCell();
builder.write("Aligned to the center of the page");
builder.endTable();
table.setPreferredWidth(PreferredWidth.fromPoints(300.0));
table.setStyle(tableStyle);
// 2 - Use the "LeftIndent" to specify an indent from the left margin of the page:
tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle2");
tableStyle.setLeftIndent(55.0);
tableStyle.getBorders().setColor(Color.GREEN);
tableStyle.getBorders().setLineStyle(LineStyle.SINGLE);
table = builder.startTable();
builder.insertCell();
builder.write("Aligned according to left indent");
builder.endTable();
table.setPreferredWidth(PreferredWidth.fromPoints(300.0));
table.setStyle(tableStyle);
doc.save(getArtifactsDir() + "Table.SetTableAlignment.docx");
int value. The returned value is one of TableAlignment constants.public void setAlignment(int value)
Remarks:
The default value is TableAlignment.LEFT.
Examples:
Shows how to set the position of a table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Below are two ways of aligning a table horizontally.
// 1 - Use the "Alignment" property to align it to a location on the page, such as the center:
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAlignment(TableAlignment.CENTER);
tableStyle.getBorders().setColor(Color.BLUE);
tableStyle.getBorders().setLineStyle(LineStyle.SINGLE);
// Insert a table and apply the style we created to it.
Table table = builder.startTable();
builder.insertCell();
builder.write("Aligned to the center of the page");
builder.endTable();
table.setPreferredWidth(PreferredWidth.fromPoints(300.0));
table.setStyle(tableStyle);
// 2 - Use the "LeftIndent" to specify an indent from the left margin of the page:
tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle2");
tableStyle.setLeftIndent(55.0);
tableStyle.getBorders().setColor(Color.GREEN);
tableStyle.getBorders().setLineStyle(LineStyle.SINGLE);
table = builder.startTable();
builder.insertCell();
builder.write("Aligned according to left indent");
builder.endTable();
table.setPreferredWidth(PreferredWidth.fromPoints(300.0));
table.setStyle(tableStyle);
doc.save(getArtifactsDir() + "Table.SetTableAlignment.docx");
value - The corresponding int value. The value must be one of TableAlignment constants.public double getCellSpacing()
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
public void setCellSpacing(double value)
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
value - The amount of space (in points) between the cells.public boolean getBidi()
Remarks:
When true, the cells in rows are laid out right to left.
The default value is false.
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
public void setBidi(boolean value)
Remarks:
When true, the cells in rows are laid out right to left.
The default value is false.
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
value - Whether this is a style for a right-to-left table.public double getLeftIndent()
Examples:
Shows how to set the position of a table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Below are two ways of aligning a table horizontally.
// 1 - Use the "Alignment" property to align it to a location on the page, such as the center:
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAlignment(TableAlignment.CENTER);
tableStyle.getBorders().setColor(Color.BLUE);
tableStyle.getBorders().setLineStyle(LineStyle.SINGLE);
// Insert a table and apply the style we created to it.
Table table = builder.startTable();
builder.insertCell();
builder.write("Aligned to the center of the page");
builder.endTable();
table.setPreferredWidth(PreferredWidth.fromPoints(300.0));
table.setStyle(tableStyle);
// 2 - Use the "LeftIndent" to specify an indent from the left margin of the page:
tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle2");
tableStyle.setLeftIndent(55.0);
tableStyle.getBorders().setColor(Color.GREEN);
tableStyle.getBorders().setLineStyle(LineStyle.SINGLE);
table = builder.startTable();
builder.insertCell();
builder.write("Aligned according to left indent");
builder.endTable();
table.setPreferredWidth(PreferredWidth.fromPoints(300.0));
table.setStyle(tableStyle);
doc.save(getArtifactsDir() + "Table.SetTableAlignment.docx");
public void setLeftIndent(double value)
Examples:
Shows how to set the position of a table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Below are two ways of aligning a table horizontally.
// 1 - Use the "Alignment" property to align it to a location on the page, such as the center:
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAlignment(TableAlignment.CENTER);
tableStyle.getBorders().setColor(Color.BLUE);
tableStyle.getBorders().setLineStyle(LineStyle.SINGLE);
// Insert a table and apply the style we created to it.
Table table = builder.startTable();
builder.insertCell();
builder.write("Aligned to the center of the page");
builder.endTable();
table.setPreferredWidth(PreferredWidth.fromPoints(300.0));
table.setStyle(tableStyle);
// 2 - Use the "LeftIndent" to specify an indent from the left margin of the page:
tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle2");
tableStyle.setLeftIndent(55.0);
tableStyle.getBorders().setColor(Color.GREEN);
tableStyle.getBorders().setLineStyle(LineStyle.SINGLE);
table = builder.startTable();
builder.insertCell();
builder.write("Aligned according to left indent");
builder.endTable();
table.setPreferredWidth(PreferredWidth.fromPoints(300.0));
table.setStyle(tableStyle);
doc.save(getArtifactsDir() + "Table.SetTableAlignment.docx");
value - The value that represents the left indent of a table.public Shading getShading()
Shading object that refers to the shading formatting for table cells.
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
Shading object that refers to the shading formatting for table cells.public int getVerticalAlignment()
Remarks:
The default value is CellVerticalAlignment.TOP.
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
int value. The returned value is one of CellVerticalAlignment constants.public void setVerticalAlignment(int value)
Remarks:
The default value is CellVerticalAlignment.TOP.
Examples:
Shows how to create custom style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
tableStyle.setVerticalAlignment(CellVerticalAlignment.CENTER);
table.setStyle(tableStyle);
// Setting the style properties of a table may affect the properties of the table itself.
Assert.assertTrue(table.getBidi());
Assert.assertEquals(5.0d, table.getCellSpacing());
Assert.assertEquals("MyTableStyle1", table.getStyleName());
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
value - The corresponding int value. The value must be one of CellVerticalAlignment constants.public int getRowStripe()
Examples:
Shows how to create conditional table styles that alternate between rows.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// We can configure a conditional style of a table to apply a different color to the row/column,
// based on whether the row/column is even or odd, creating an alternating color pattern.
// We can also apply a number n to the row/column banding,
// meaning that the color alternates after every n rows/columns instead of one.
// Create a table where single columns and rows will band the columns will banded in threes.
Table table = builder.startTable();
for (int i = 0; i < 15; i++) {
for (int j = 0; j < 4; j++) {
builder.insertCell();
builder.writeln(MessageFormat.format("{0} column.", (j % 2 == 0 ? "Even" : "Odd")));
builder.write(MessageFormat.format("Row banding {0}.", (i % 3 == 0 ? "start" : "continuation")));
}
builder.endRow();
}
builder.endTable();
// Apply a line style to all the borders of the table.
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOUBLE);
// Set the two colors, which will alternate over every 3 rows.
tableStyle.setRowStripe(3);
tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.ODD_ROW_BANDING).getShading().setBackgroundPatternColor(Color.BLUE);
tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.EVEN_ROW_BANDING).getShading().setBackgroundPatternColor(Color.CYAN);
// Set a color to apply to every even column, which will override any custom row coloring.
tableStyle.setColumnStripe(1);
tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.EVEN_COLUMN_BANDING).getShading().setBackgroundPatternColor(Color.RED);
table.setStyle(tableStyle);
// The "StyleOptions" property enables row banding by default.
Assert.assertEquals(TableStyleOptions.FIRST_ROW | TableStyleOptions.FIRST_COLUMN | TableStyleOptions.ROW_BANDS,
table.getStyleOptions());
// Use the "StyleOptions" property also to enable column banding.
table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.COLUMN_BANDS);
doc.save(getArtifactsDir() + "Table.AlternatingRowStyles.docx");
public void setRowStripe(int value)
Examples:
Shows how to create conditional table styles that alternate between rows.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// We can configure a conditional style of a table to apply a different color to the row/column,
// based on whether the row/column is even or odd, creating an alternating color pattern.
// We can also apply a number n to the row/column banding,
// meaning that the color alternates after every n rows/columns instead of one.
// Create a table where single columns and rows will band the columns will banded in threes.
Table table = builder.startTable();
for (int i = 0; i < 15; i++) {
for (int j = 0; j < 4; j++) {
builder.insertCell();
builder.writeln(MessageFormat.format("{0} column.", (j % 2 == 0 ? "Even" : "Odd")));
builder.write(MessageFormat.format("Row banding {0}.", (i % 3 == 0 ? "start" : "continuation")));
}
builder.endRow();
}
builder.endTable();
// Apply a line style to all the borders of the table.
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOUBLE);
// Set the two colors, which will alternate over every 3 rows.
tableStyle.setRowStripe(3);
tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.ODD_ROW_BANDING).getShading().setBackgroundPatternColor(Color.BLUE);
tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.EVEN_ROW_BANDING).getShading().setBackgroundPatternColor(Color.CYAN);
// Set a color to apply to every even column, which will override any custom row coloring.
tableStyle.setColumnStripe(1);
tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.EVEN_COLUMN_BANDING).getShading().setBackgroundPatternColor(Color.RED);
table.setStyle(tableStyle);
// The "StyleOptions" property enables row banding by default.
Assert.assertEquals(TableStyleOptions.FIRST_ROW | TableStyleOptions.FIRST_COLUMN | TableStyleOptions.ROW_BANDS,
table.getStyleOptions());
// Use the "StyleOptions" property also to enable column banding.
table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.COLUMN_BANDS);
doc.save(getArtifactsDir() + "Table.AlternatingRowStyles.docx");
value - A number of rows to include in the banding when the style specifies odd/even row banding.public int getColumnStripe()
Examples:
Shows how to create conditional table styles that alternate between rows.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// We can configure a conditional style of a table to apply a different color to the row/column,
// based on whether the row/column is even or odd, creating an alternating color pattern.
// We can also apply a number n to the row/column banding,
// meaning that the color alternates after every n rows/columns instead of one.
// Create a table where single columns and rows will band the columns will banded in threes.
Table table = builder.startTable();
for (int i = 0; i < 15; i++) {
for (int j = 0; j < 4; j++) {
builder.insertCell();
builder.writeln(MessageFormat.format("{0} column.", (j % 2 == 0 ? "Even" : "Odd")));
builder.write(MessageFormat.format("Row banding {0}.", (i % 3 == 0 ? "start" : "continuation")));
}
builder.endRow();
}
builder.endTable();
// Apply a line style to all the borders of the table.
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOUBLE);
// Set the two colors, which will alternate over every 3 rows.
tableStyle.setRowStripe(3);
tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.ODD_ROW_BANDING).getShading().setBackgroundPatternColor(Color.BLUE);
tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.EVEN_ROW_BANDING).getShading().setBackgroundPatternColor(Color.CYAN);
// Set a color to apply to every even column, which will override any custom row coloring.
tableStyle.setColumnStripe(1);
tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.EVEN_COLUMN_BANDING).getShading().setBackgroundPatternColor(Color.RED);
table.setStyle(tableStyle);
// The "StyleOptions" property enables row banding by default.
Assert.assertEquals(TableStyleOptions.FIRST_ROW | TableStyleOptions.FIRST_COLUMN | TableStyleOptions.ROW_BANDS,
table.getStyleOptions());
// Use the "StyleOptions" property also to enable column banding.
table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.COLUMN_BANDS);
doc.save(getArtifactsDir() + "Table.AlternatingRowStyles.docx");
public void setColumnStripe(int value)
Examples:
Shows how to create conditional table styles that alternate between rows.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// We can configure a conditional style of a table to apply a different color to the row/column,
// based on whether the row/column is even or odd, creating an alternating color pattern.
// We can also apply a number n to the row/column banding,
// meaning that the color alternates after every n rows/columns instead of one.
// Create a table where single columns and rows will band the columns will banded in threes.
Table table = builder.startTable();
for (int i = 0; i < 15; i++) {
for (int j = 0; j < 4; j++) {
builder.insertCell();
builder.writeln(MessageFormat.format("{0} column.", (j % 2 == 0 ? "Even" : "Odd")));
builder.write(MessageFormat.format("Row banding {0}.", (i % 3 == 0 ? "start" : "continuation")));
}
builder.endRow();
}
builder.endTable();
// Apply a line style to all the borders of the table.
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOUBLE);
// Set the two colors, which will alternate over every 3 rows.
tableStyle.setRowStripe(3);
tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.ODD_ROW_BANDING).getShading().setBackgroundPatternColor(Color.BLUE);
tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.EVEN_ROW_BANDING).getShading().setBackgroundPatternColor(Color.CYAN);
// Set a color to apply to every even column, which will override any custom row coloring.
tableStyle.setColumnStripe(1);
tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.EVEN_COLUMN_BANDING).getShading().setBackgroundPatternColor(Color.RED);
table.setStyle(tableStyle);
// The "StyleOptions" property enables row banding by default.
Assert.assertEquals(TableStyleOptions.FIRST_ROW | TableStyleOptions.FIRST_COLUMN | TableStyleOptions.ROW_BANDS,
table.getStyleOptions());
// Use the "StyleOptions" property also to enable column banding.
table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.COLUMN_BANDS);
doc.save(getArtifactsDir() + "Table.AlternatingRowStyles.docx");
value - A number of columns to include in the banding when the style specifies odd/even columns banding.public ConditionalStyleCollection getConditionalStyles()
Examples:
Shows how to work with certain area styles of a table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Cell 1");
builder.insertCell();
builder.write("Cell 2");
builder.endRow();
builder.insertCell();
builder.write("Cell 3");
builder.insertCell();
builder.write("Cell 4");
builder.endTable();
// Create a custom table style.
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
// Conditional styles are formatting changes that affect only some of the table's cells
// based on a predicate, such as the cells being in the last row.
// Below are three ways of accessing a table style's conditional styles from the "ConditionalStyles" collection.
// 1 - By style type:
tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE);
// 2 - By index:
tableStyle.getConditionalStyles().get(0).getBorders().setColor(Color.BLACK);
tableStyle.getConditionalStyles().get(0).getBorders().setLineStyle(LineStyle.DOT_DASH);
Assert.assertEquals(ConditionalStyleType.FIRST_ROW, tableStyle.getConditionalStyles().get(0).getType());
// 3 - As a property:
tableStyle.getConditionalStyles().getFirstRow().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
// Apply padding and text formatting to conditional styles.
tableStyle.getConditionalStyles().getLastRow().setBottomPadding(10.0);
tableStyle.getConditionalStyles().getLastRow().setLeftPadding(10.0);
tableStyle.getConditionalStyles().getLastRow().setRightPadding(10.0);
tableStyle.getConditionalStyles().getLastRow().setTopPadding(10.0);
tableStyle.getConditionalStyles().getLastColumn().getFont().setBold(true);
// List all possible style conditions.
Iterator<ConditionalStyle> enumerator = tableStyle.getConditionalStyles().iterator();
while (enumerator.hasNext()) {
ConditionalStyle currentStyle = enumerator.next();
if (currentStyle != null) System.out.println(currentStyle.getType());
}
// Apply the custom style, which contains all conditional styles, to the table.
table.setStyle(tableStyle);
// Our style applies some conditional styles by default.
Assert.assertEquals(TableStyleOptions.FIRST_ROW | TableStyleOptions.FIRST_COLUMN | TableStyleOptions.ROW_BANDS,
table.getStyleOptions());
// We will need to enable all other styles ourselves via the "StyleOptions" property.
table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN);
doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
ConditionalStyleCollection value.