public class ConditionalStyleType
extends java.lang.Object
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 | Field and Description |
|---|---|
static int |
BOTTOM_LEFT_CELL
Specifies formatting of the bottom left cell of a table.
|
static int |
BOTTOM_RIGHT_CELL
Specifies formatting of the bottom right cell of a table.
|
static int |
EVEN_COLUMN_BANDING
Specifies formatting of even-numbered column stripe.
|
static int |
EVEN_ROW_BANDING
Specifies formatting of even-numbered row stripe.
|
static int |
FIRST_COLUMN
Specifies formatting of the first column of a table.
|
static int |
FIRST_ROW
Specifies formatting of the first row of a table.
|
static int |
LAST_COLUMN
Specifies formatting of the last column of a table.
|
static int |
LAST_ROW
Specifies formatting of the last row of a table.
|
static int |
length |
static int |
ODD_COLUMN_BANDING
Specifies formatting of odd-numbered column stripe.
|
static int |
ODD_ROW_BANDING
Specifies formatting of odd-numbered row stripe.
|
static int |
TOP_LEFT_CELL
Specifies formatting of the top left cell of a table.
|
static int |
TOP_RIGHT_CELL
Specifies formatting of the top right cell of a table.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
fromName(java.lang.String conditionalStyleTypeName) |
static java.lang.String |
getName(int conditionalStyleType) |
static int[] |
getValues() |
static java.lang.String |
toString(int conditionalStyleType) |
public static int FIRST_ROW
public static int FIRST_COLUMN
public static int LAST_ROW
public static int LAST_COLUMN
public static int ODD_ROW_BANDING
public static int ODD_COLUMN_BANDING
public static int EVEN_ROW_BANDING
public static int EVEN_COLUMN_BANDING
public static int TOP_LEFT_CELL
public static int TOP_RIGHT_CELL
public static int BOTTOM_LEFT_CELL
public static int BOTTOM_RIGHT_CELL
public static int length