public class ConditionalStyle
extends java.lang.Object
implements java.lang.Cloneable
To learn more, visit the Working with Tables documentation article.
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");
| Modifier and Type | Method and Description |
|---|---|
void |
clearFormatting()
Clears formatting of this conditional style.
|
void |
clearParaAttrs() |
void |
clearRunAttrs() |
boolean |
equals(java.lang.Object obj)
Compares this conditional style with the specified object.
|
java.lang.Object |
fetchInheritedBorderAttr(int key) |
java.lang.Object |
fetchInheritedParaAttr(int key) |
java.lang.Object |
fetchInheritedRunAttr(int key) |
java.lang.Object |
fetchInheritedShadingAttr(int key) |
java.lang.Object |
fetchParaAttr(int key) |
BorderCollection |
getBorders()
Gets the collection of default cell borders for the conditional style.
|
double |
getBottomPadding()
Gets the amount of space (in points) to add below the contents of table cells.
|
java.lang.Object |
getDirectBorderAttr(int key) |
java.lang.Object |
getDirectParaAttr(int key) |
java.lang.Object |
getDirectParaAttr(int key,
int revisionsView) |
java.lang.Object |
getDirectRunAttr(int key) |
java.lang.Object |
getDirectRunAttr(int key,
int revisionsView) |
Font |
getFont()
Gets the character formatting of the conditional style.
|
double |
getLeftPadding()
Gets the amount of space (in points) to add to the left of the contents of table cells.
|
ParagraphFormat |
getParagraphFormat()
Gets the paragraph formatting of the conditional style.
|
double |
getRightPadding()
Gets the amount of space (in points) to add to the right of the contents of table cells.
|
Shading |
getShading()
Gets a
Shading object that refers to the shading formatting for this conditional style. |
double |
getTopPadding()
Gets the amount of space (in points) to add above the contents of table cells.
|
int |
getType()
Gets table area to which this conditional style relates.
|
int |
hashCode() |
protected java.lang.Object |
memberwiseClone() |
void |
removeParaAttr(int key) |
void |
removeRunAttr(int key) |
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 |
setLeftPadding(double value)
Sets the amount of space (in points) to add to the left of the contents of table cells.
|
void |
setParaAttr(int key,
java.lang.Object value) |
void |
setRightPadding(double value)
Sets the amount of space (in points) to add to the right of the contents of table cells.
|
void |
setRunAttr(int key,
java.lang.Object value) |
void |
setTopPadding(double value)
Sets the amount of space (in points) to add above the contents of table cells.
|
public void clearFormatting()
Examples:
Shows how to reset conditional table styles.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("First row");
builder.endRow();
builder.insertCell();
builder.write("Last row");
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
table.setStyle(tableStyle);
// Set the table style to color the borders of the first row of the table in red.
tableStyle.getConditionalStyles().getFirstRow().getBorders().setColor(Color.RED);
// Set the table style to color the borders of the last row of the table in blue.
tableStyle.getConditionalStyles().getLastRow().getBorders().setColor(Color.BLUE);
// Below are two ways of using the "ClearFormatting" method to clear the conditional styles.
// 1 - Clear the conditional styles for a specific part of a table:
tableStyle.getConditionalStyles().get(0).clearFormatting();
Assert.assertEquals(0, tableStyle.getConditionalStyles().getFirstRow().getBorders().getColor().getRGB());
// 2 - Clear the conditional styles for the entire table:
tableStyle.getConditionalStyles().clearFormatting();
Assert.assertEquals(tableStyle.getConditionalStyles().getLastRow().getBorders().getColor().getRGB(), 0);
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic 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 void setParaAttr(int key,
java.lang.Object value)
public void removeParaAttr(int key)
public void clearParaAttrs()
public java.lang.Object fetchInheritedParaAttr(int key)
public java.lang.Object getDirectParaAttr(int key)
public java.lang.Object getDirectParaAttr(int key,
int revisionsView)
public java.lang.Object fetchParaAttr(int key)
public java.lang.Object getDirectRunAttr(int key)
public java.lang.Object getDirectRunAttr(int key,
int revisionsView)
public java.lang.Object fetchInheritedRunAttr(int key)
public void setRunAttr(int key,
java.lang.Object value)
public void removeRunAttr(int key)
public void clearRunAttrs()
public ParagraphFormat getParagraphFormat()
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");
public Font getFont()
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");
public Shading getShading()
Shading object that refers to the shading formatting for this conditional style.
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");
Shading object that refers to the shading formatting for this conditional style.public BorderCollection getBorders()
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");
public double getLeftPadding()
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");
public void setLeftPadding(double value)
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");
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 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");
public void setRightPadding(double value)
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");
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 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");
public void setTopPadding(double value)
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");
value - The amount of space (in points) to add above the contents of table cells.public double getBottomPadding()
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");
public void setBottomPadding(double value)
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");
value - The amount of space (in points) to add below the contents of table cells.public int getType()
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");
ConditionalStyleType constants.protected java.lang.Object memberwiseClone()