com.aspose.words

Class ConditionalStyle

  • java.lang.Object
    • com.aspose.words.ConditionalStyle
  • All Implemented Interfaces:
    java.lang.Cloneable
    public class ConditionalStyle 
    extends java.lang.Object

Represents special formatting applied to some area of a table with assigned table style.

Example:

Shows how to work with certain area styles of a table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Create a table, which we will partially style
Table table = builder.startTable();
builder.insertCell();
builder.write("Cell 1, to be formatted");
builder.insertCell();
builder.write("Cell 2, to be formatted");
builder.endRow();
builder.insertCell();
builder.write("Cell 3, to be left unformatted");
builder.insertCell();
builder.write("Cell 4, to be left unformatted");
builder.endTable();

TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
// There is a different ways how to get conditional styles:
// by conditional style type
tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE);
// by index
tableStyle.getConditionalStyles().get(0).getBorders().setColor(Color.BLACK);
tableStyle.getConditionalStyles().get(0).getBorders().setLineStyle(LineStyle.DOT_DASH);
Assert.assertEquals(tableStyle.getConditionalStyles().get(0).getType(), ConditionalStyleType.FIRST_ROW);
// directly from ConditionalStyleCollection
tableStyle.getConditionalStyles().getFirstRow().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
// To see this in Word document select Total Row checkbox in Design Tab
tableStyle.getConditionalStyles().getLastRow().setBottomPadding(10.0);
tableStyle.getConditionalStyles().getLastRow().setLeftPadding(10.0);
tableStyle.getConditionalStyles().getLastRow().setRightPadding(10.0);
tableStyle.getConditionalStyles().getLastRow().setTopPadding(10.0);
// To see this in Word document select Last Column checkbox in Design Tab
tableStyle.getConditionalStyles().getLastColumn().getFont().setBold(true);

System.out.println(tableStyle.getConditionalStyles().getCount());
System.out.println(tableStyle.getConditionalStyles().get(0).getType());

table = (Table) doc.getChild(NodeType.TABLE, 0, true);
table.setStyle(tableStyle);

doc.save(getArtifactsDir() + "Table.WorkWithTableConditionalStyles.docx");

Property Getters/Setters Summary
BorderCollectiongetBorders()
Gets the collection of default cell borders for the conditional style.
doublegetBottomPadding()
void
setBottomPadding(doublevalue)
           Gets or sets the amount of space (in points) to add below the contents of table cells.
FontgetFont()
Gets the character formatting of the conditional style.
doublegetLeftPadding()
void
setLeftPadding(doublevalue)
           Gets or sets the amount of space (in points) to add to the left of the contents of table cells.
ParagraphFormatgetParagraphFormat()
Gets the paragraph formatting of the conditional style.
doublegetRightPadding()
void
setRightPadding(doublevalue)
           Gets or sets the amount of space (in points) to add to the right of the contents of table cells.
ShadinggetShading()
Gets a Shading object that refers to the shading formatting for this conditional style.
doublegetTopPadding()
void
setTopPadding(doublevalue)
           Gets or sets the amount of space (in points) to add above the contents of table cells.
intgetType()
Gets table area to which this conditional style relates. The value of the property is ConditionalStyleType integer constant.
 
Method Summary
voidclearFormatting()
Clears formatting of this conditional style.
 

    • Property Getters/Setters Detail

      • getBorders

        public BorderCollection getBorders()
        
        Gets the collection of default cell borders for the conditional style.

        Example:

        Shows how to work with certain area styles of a table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a table, which we will partially style
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Cell 1, to be formatted");
        builder.insertCell();
        builder.write("Cell 2, to be formatted");
        builder.endRow();
        builder.insertCell();
        builder.write("Cell 3, to be left unformatted");
        builder.insertCell();
        builder.write("Cell 4, to be left unformatted");
        builder.endTable();
        
        TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
        // There is a different ways how to get conditional styles:
        // by conditional style type
        tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE);
        // by index
        tableStyle.getConditionalStyles().get(0).getBorders().setColor(Color.BLACK);
        tableStyle.getConditionalStyles().get(0).getBorders().setLineStyle(LineStyle.DOT_DASH);
        Assert.assertEquals(tableStyle.getConditionalStyles().get(0).getType(), ConditionalStyleType.FIRST_ROW);
        // directly from ConditionalStyleCollection
        tableStyle.getConditionalStyles().getFirstRow().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        // To see this in Word document select Total Row checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastRow().setBottomPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setLeftPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setRightPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setTopPadding(10.0);
        // To see this in Word document select Last Column checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastColumn().getFont().setBold(true);
        
        System.out.println(tableStyle.getConditionalStyles().getCount());
        System.out.println(tableStyle.getConditionalStyles().get(0).getType());
        
        table = (Table) doc.getChild(NodeType.TABLE, 0, true);
        table.setStyle(tableStyle);
        
        doc.save(getArtifactsDir() + "Table.WorkWithTableConditionalStyles.docx");
      • getBottomPadding/setBottomPadding

        public double getBottomPadding() / public void setBottomPadding(double value)
        
        Gets or sets the amount of space (in points) to add below the contents of table cells.

        Example:

        Shows how to work with certain area styles of a table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a table, which we will partially style
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Cell 1, to be formatted");
        builder.insertCell();
        builder.write("Cell 2, to be formatted");
        builder.endRow();
        builder.insertCell();
        builder.write("Cell 3, to be left unformatted");
        builder.insertCell();
        builder.write("Cell 4, to be left unformatted");
        builder.endTable();
        
        TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
        // There is a different ways how to get conditional styles:
        // by conditional style type
        tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE);
        // by index
        tableStyle.getConditionalStyles().get(0).getBorders().setColor(Color.BLACK);
        tableStyle.getConditionalStyles().get(0).getBorders().setLineStyle(LineStyle.DOT_DASH);
        Assert.assertEquals(tableStyle.getConditionalStyles().get(0).getType(), ConditionalStyleType.FIRST_ROW);
        // directly from ConditionalStyleCollection
        tableStyle.getConditionalStyles().getFirstRow().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        // To see this in Word document select Total Row checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastRow().setBottomPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setLeftPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setRightPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setTopPadding(10.0);
        // To see this in Word document select Last Column checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastColumn().getFont().setBold(true);
        
        System.out.println(tableStyle.getConditionalStyles().getCount());
        System.out.println(tableStyle.getConditionalStyles().get(0).getType());
        
        table = (Table) doc.getChild(NodeType.TABLE, 0, true);
        table.setStyle(tableStyle);
        
        doc.save(getArtifactsDir() + "Table.WorkWithTableConditionalStyles.docx");
      • getFont

        public Font getFont()
        
        Gets the character formatting of the conditional style.

        Example:

        Shows how to work with certain area styles of a table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a table, which we will partially style
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Cell 1, to be formatted");
        builder.insertCell();
        builder.write("Cell 2, to be formatted");
        builder.endRow();
        builder.insertCell();
        builder.write("Cell 3, to be left unformatted");
        builder.insertCell();
        builder.write("Cell 4, to be left unformatted");
        builder.endTable();
        
        TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
        // There is a different ways how to get conditional styles:
        // by conditional style type
        tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE);
        // by index
        tableStyle.getConditionalStyles().get(0).getBorders().setColor(Color.BLACK);
        tableStyle.getConditionalStyles().get(0).getBorders().setLineStyle(LineStyle.DOT_DASH);
        Assert.assertEquals(tableStyle.getConditionalStyles().get(0).getType(), ConditionalStyleType.FIRST_ROW);
        // directly from ConditionalStyleCollection
        tableStyle.getConditionalStyles().getFirstRow().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        // To see this in Word document select Total Row checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastRow().setBottomPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setLeftPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setRightPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setTopPadding(10.0);
        // To see this in Word document select Last Column checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastColumn().getFont().setBold(true);
        
        System.out.println(tableStyle.getConditionalStyles().getCount());
        System.out.println(tableStyle.getConditionalStyles().get(0).getType());
        
        table = (Table) doc.getChild(NodeType.TABLE, 0, true);
        table.setStyle(tableStyle);
        
        doc.save(getArtifactsDir() + "Table.WorkWithTableConditionalStyles.docx");
      • getLeftPadding/setLeftPadding

        public double getLeftPadding() / public void setLeftPadding(double value)
        
        Gets or sets the amount of space (in points) to add to the left of the contents of table cells.

        Example:

        Shows how to work with certain area styles of a table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a table, which we will partially style
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Cell 1, to be formatted");
        builder.insertCell();
        builder.write("Cell 2, to be formatted");
        builder.endRow();
        builder.insertCell();
        builder.write("Cell 3, to be left unformatted");
        builder.insertCell();
        builder.write("Cell 4, to be left unformatted");
        builder.endTable();
        
        TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
        // There is a different ways how to get conditional styles:
        // by conditional style type
        tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE);
        // by index
        tableStyle.getConditionalStyles().get(0).getBorders().setColor(Color.BLACK);
        tableStyle.getConditionalStyles().get(0).getBorders().setLineStyle(LineStyle.DOT_DASH);
        Assert.assertEquals(tableStyle.getConditionalStyles().get(0).getType(), ConditionalStyleType.FIRST_ROW);
        // directly from ConditionalStyleCollection
        tableStyle.getConditionalStyles().getFirstRow().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        // To see this in Word document select Total Row checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastRow().setBottomPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setLeftPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setRightPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setTopPadding(10.0);
        // To see this in Word document select Last Column checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastColumn().getFont().setBold(true);
        
        System.out.println(tableStyle.getConditionalStyles().getCount());
        System.out.println(tableStyle.getConditionalStyles().get(0).getType());
        
        table = (Table) doc.getChild(NodeType.TABLE, 0, true);
        table.setStyle(tableStyle);
        
        doc.save(getArtifactsDir() + "Table.WorkWithTableConditionalStyles.docx");
      • getParagraphFormat

        public ParagraphFormat getParagraphFormat()
        
        Gets the paragraph formatting of the conditional style.

        Example:

        Shows how to work with certain area styles of a table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a table, which we will partially style
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Cell 1, to be formatted");
        builder.insertCell();
        builder.write("Cell 2, to be formatted");
        builder.endRow();
        builder.insertCell();
        builder.write("Cell 3, to be left unformatted");
        builder.insertCell();
        builder.write("Cell 4, to be left unformatted");
        builder.endTable();
        
        TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
        // There is a different ways how to get conditional styles:
        // by conditional style type
        tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE);
        // by index
        tableStyle.getConditionalStyles().get(0).getBorders().setColor(Color.BLACK);
        tableStyle.getConditionalStyles().get(0).getBorders().setLineStyle(LineStyle.DOT_DASH);
        Assert.assertEquals(tableStyle.getConditionalStyles().get(0).getType(), ConditionalStyleType.FIRST_ROW);
        // directly from ConditionalStyleCollection
        tableStyle.getConditionalStyles().getFirstRow().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        // To see this in Word document select Total Row checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastRow().setBottomPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setLeftPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setRightPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setTopPadding(10.0);
        // To see this in Word document select Last Column checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastColumn().getFont().setBold(true);
        
        System.out.println(tableStyle.getConditionalStyles().getCount());
        System.out.println(tableStyle.getConditionalStyles().get(0).getType());
        
        table = (Table) doc.getChild(NodeType.TABLE, 0, true);
        table.setStyle(tableStyle);
        
        doc.save(getArtifactsDir() + "Table.WorkWithTableConditionalStyles.docx");
      • getRightPadding/setRightPadding

        public double getRightPadding() / public void setRightPadding(double value)
        
        Gets or sets the amount of space (in points) to add to the right of the contents of table cells.

        Example:

        Shows how to work with certain area styles of a table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a table, which we will partially style
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Cell 1, to be formatted");
        builder.insertCell();
        builder.write("Cell 2, to be formatted");
        builder.endRow();
        builder.insertCell();
        builder.write("Cell 3, to be left unformatted");
        builder.insertCell();
        builder.write("Cell 4, to be left unformatted");
        builder.endTable();
        
        TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
        // There is a different ways how to get conditional styles:
        // by conditional style type
        tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE);
        // by index
        tableStyle.getConditionalStyles().get(0).getBorders().setColor(Color.BLACK);
        tableStyle.getConditionalStyles().get(0).getBorders().setLineStyle(LineStyle.DOT_DASH);
        Assert.assertEquals(tableStyle.getConditionalStyles().get(0).getType(), ConditionalStyleType.FIRST_ROW);
        // directly from ConditionalStyleCollection
        tableStyle.getConditionalStyles().getFirstRow().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        // To see this in Word document select Total Row checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastRow().setBottomPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setLeftPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setRightPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setTopPadding(10.0);
        // To see this in Word document select Last Column checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastColumn().getFont().setBold(true);
        
        System.out.println(tableStyle.getConditionalStyles().getCount());
        System.out.println(tableStyle.getConditionalStyles().get(0).getType());
        
        table = (Table) doc.getChild(NodeType.TABLE, 0, true);
        table.setStyle(tableStyle);
        
        doc.save(getArtifactsDir() + "Table.WorkWithTableConditionalStyles.docx");
      • getShading

        public Shading getShading()
        
        Gets a Shading object that refers to the shading formatting for this conditional style.

        Example:

        Shows how to work with certain area styles of a table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a table, which we will partially style
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Cell 1, to be formatted");
        builder.insertCell();
        builder.write("Cell 2, to be formatted");
        builder.endRow();
        builder.insertCell();
        builder.write("Cell 3, to be left unformatted");
        builder.insertCell();
        builder.write("Cell 4, to be left unformatted");
        builder.endTable();
        
        TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
        // There is a different ways how to get conditional styles:
        // by conditional style type
        tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE);
        // by index
        tableStyle.getConditionalStyles().get(0).getBorders().setColor(Color.BLACK);
        tableStyle.getConditionalStyles().get(0).getBorders().setLineStyle(LineStyle.DOT_DASH);
        Assert.assertEquals(tableStyle.getConditionalStyles().get(0).getType(), ConditionalStyleType.FIRST_ROW);
        // directly from ConditionalStyleCollection
        tableStyle.getConditionalStyles().getFirstRow().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        // To see this in Word document select Total Row checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastRow().setBottomPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setLeftPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setRightPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setTopPadding(10.0);
        // To see this in Word document select Last Column checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastColumn().getFont().setBold(true);
        
        System.out.println(tableStyle.getConditionalStyles().getCount());
        System.out.println(tableStyle.getConditionalStyles().get(0).getType());
        
        table = (Table) doc.getChild(NodeType.TABLE, 0, true);
        table.setStyle(tableStyle);
        
        doc.save(getArtifactsDir() + "Table.WorkWithTableConditionalStyles.docx");
      • getTopPadding/setTopPadding

        public double getTopPadding() / public void setTopPadding(double value)
        
        Gets or sets the amount of space (in points) to add above the contents of table cells.

        Example:

        Shows how to work with certain area styles of a table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a table, which we will partially style
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Cell 1, to be formatted");
        builder.insertCell();
        builder.write("Cell 2, to be formatted");
        builder.endRow();
        builder.insertCell();
        builder.write("Cell 3, to be left unformatted");
        builder.insertCell();
        builder.write("Cell 4, to be left unformatted");
        builder.endTable();
        
        TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
        // There is a different ways how to get conditional styles:
        // by conditional style type
        tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE);
        // by index
        tableStyle.getConditionalStyles().get(0).getBorders().setColor(Color.BLACK);
        tableStyle.getConditionalStyles().get(0).getBorders().setLineStyle(LineStyle.DOT_DASH);
        Assert.assertEquals(tableStyle.getConditionalStyles().get(0).getType(), ConditionalStyleType.FIRST_ROW);
        // directly from ConditionalStyleCollection
        tableStyle.getConditionalStyles().getFirstRow().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        // To see this in Word document select Total Row checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastRow().setBottomPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setLeftPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setRightPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setTopPadding(10.0);
        // To see this in Word document select Last Column checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastColumn().getFont().setBold(true);
        
        System.out.println(tableStyle.getConditionalStyles().getCount());
        System.out.println(tableStyle.getConditionalStyles().get(0).getType());
        
        table = (Table) doc.getChild(NodeType.TABLE, 0, true);
        table.setStyle(tableStyle);
        
        doc.save(getArtifactsDir() + "Table.WorkWithTableConditionalStyles.docx");
      • getType

        public int getType()
        
        Gets table area to which this conditional style relates. The value of the property is ConditionalStyleType integer constant.

        Example:

        Shows how to work with certain area styles of a table.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a table, which we will partially style
        Table table = builder.startTable();
        builder.insertCell();
        builder.write("Cell 1, to be formatted");
        builder.insertCell();
        builder.write("Cell 2, to be formatted");
        builder.endRow();
        builder.insertCell();
        builder.write("Cell 3, to be left unformatted");
        builder.insertCell();
        builder.write("Cell 4, to be left unformatted");
        builder.endTable();
        
        TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
        // There is a different ways how to get conditional styles:
        // by conditional style type
        tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE);
        // by index
        tableStyle.getConditionalStyles().get(0).getBorders().setColor(Color.BLACK);
        tableStyle.getConditionalStyles().get(0).getBorders().setLineStyle(LineStyle.DOT_DASH);
        Assert.assertEquals(tableStyle.getConditionalStyles().get(0).getType(), ConditionalStyleType.FIRST_ROW);
        // directly from ConditionalStyleCollection
        tableStyle.getConditionalStyles().getFirstRow().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        // To see this in Word document select Total Row checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastRow().setBottomPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setLeftPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setRightPadding(10.0);
        tableStyle.getConditionalStyles().getLastRow().setTopPadding(10.0);
        // To see this in Word document select Last Column checkbox in Design Tab
        tableStyle.getConditionalStyles().getLastColumn().getFont().setBold(true);
        
        System.out.println(tableStyle.getConditionalStyles().getCount());
        System.out.println(tableStyle.getConditionalStyles().get(0).getType());
        
        table = (Table) doc.getChild(NodeType.TABLE, 0, true);
        table.setStyle(tableStyle);
        
        doc.save(getArtifactsDir() + "Table.WorkWithTableConditionalStyles.docx");
    • Method Detail

      • clearFormatting

        public void clearFormatting()
        Clears formatting of this conditional style.

        Example:

        Shows how to reset all 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);
        
        // You can reset styles from the specific table area
        tableStyle.getConditionalStyles().get(0).clearFormatting();
        Assert.assertEquals(tableStyle.getConditionalStyles().getFirstRow().getBorders().getColor().getRGB(), 0);
        
        // Or clear all table styles
        tableStyle.getConditionalStyles().clearFormatting();
        Assert.assertEquals(tableStyle.getConditionalStyles().getLastRow().getBorders().getColor().getRGB(), 0);