public class ConditionalStyleCollection
Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
Property Getters/Setters Summary | ||
---|---|---|
ConditionalStyle | getBottomLeftCell() | |
Gets the bottom left cell style.
|
||
ConditionalStyle | getBottomRightCell() | |
Gets the bottom right cell style.
|
||
int | getCount() | |
Gets the number of conditional styles in the collection.
|
||
ConditionalStyle | getEvenColumnBanding() | |
Gets the even column banding style.
|
||
ConditionalStyle | getEvenRowBanding() | |
Gets the even row banding style.
|
||
ConditionalStyle | getFirstColumn() | |
Gets the first column style.
|
||
ConditionalStyle | getFirstRow() | |
Gets the first row style.
|
||
ConditionalStyle | getLastColumn() | |
Gets the last column style.
|
||
ConditionalStyle | getLastRow() | |
Gets the last row style.
|
||
ConditionalStyle | getOddColumnBanding() | |
Gets the odd column banding style.
|
||
ConditionalStyle | getOddRowBanding() | |
Gets the odd row banding style.
|
||
ConditionalStyle | getTopLeftCell() | |
Gets the top left cell style.
|
||
ConditionalStyle | getTopRightCell() | |
Gets the top right cell style.
|
||
ConditionalStyle | get(int index) | |
Retrieves a |
||
ConditionalStyle | getByConditionalStyleType(int conditionalStyleType) | |
Retrieves a |
Method Summary | ||
---|---|---|
void | clearFormatting() | |
Clears all conditional styles of the table style.
|
||
java.util.Iterator<ConditionalStyle> | iterator() | |
Returns an enumerator object that can be used to iterate over all conditional styles in the collection.
|
public ConditionalStyle getBottomLeftCell()
Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
public ConditionalStyle getBottomRightCell()
Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
public int getCount()
Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
public ConditionalStyle getEvenColumnBanding()
Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
public ConditionalStyle getEvenRowBanding()
Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
public ConditionalStyle getFirstColumn()
Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
public ConditionalStyle getFirstRow()
Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
public ConditionalStyle getLastColumn()
Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
public ConditionalStyle getLastRow()
Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
public ConditionalStyle getOddColumnBanding()
Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
public ConditionalStyle getOddRowBanding()
Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
public ConditionalStyle getTopLeftCell()
Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
public ConditionalStyle getTopRightCell()
Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
public ConditionalStyle get(int index)
index
- Zero-based index of the conditional style to retrieve.Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
public ConditionalStyle getByConditionalStyleType(int conditionalStyleType)
conditionalStyleType
- A ConditionalStyleType value.Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");
public void clearFormatting()
Example:
Shows how to reset conditional table styles.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table and give it conditional styling on border colors based on the row being the first or last 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"); tableStyle.getConditionalStyles().getFirstRow().getBorders().setColor(Color.RED); tableStyle.getConditionalStyles().getLastRow().getBorders().setColor(Color.BLUE); // Conditional styles can be cleared for specific parts of the table tableStyle.getConditionalStyles().get(0).clearFormatting(); Assert.assertEquals(tableStyle.getConditionalStyles().getFirstRow().getBorders().getColor().getRGB(), 0); // Also, they can be cleared for the entire table tableStyle.getConditionalStyles().clearFormatting(); Assert.assertEquals(tableStyle.getConditionalStyles().getLastRow().getBorders().getColor().getRGB(), 0);
public java.util.Iterator<ConditionalStyle> iterator()
Example:
Shows how to work with certain area styles of a table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a table 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 cells of the table based on a predicate, // such as the cells being in the last row // We can access these conditional styles by style type like this tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // The same conditional style can be accessed 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()); // It can also be found in the ConditionalStyles collection as an attribute 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 conditional style to the table table.setStyle(tableStyle); // Changes to the first row are enabled by the table's style options be default, // but need to be manually enabled for some other parts, such as the last column/row table.setStyleOptions(table.getStyleOptions() | TableStyleOptions.LAST_ROW | TableStyleOptions.LAST_COLUMN); doc.save(getArtifactsDir() + "Table.ConditionalStyles.docx");