ConditionalStyleCollection class

ConditionalStyleCollection class

Represents a collection of ConditionalStyle objects. To learn more, visit the Working with Tables documentation article.

Remarks

It is not possible to add or remove items from this collection. It contains permanent set of items: one item for each value of the ConditionalStyleType enumeration type.

Properties

NameDescription
bottomLeftCellGets the bottom left cell style.
bottomRightCellGets the bottom right cell style.
countGets the number of conditional styles in the collection.
evenColumnBandingGets the even column banding style.
evenRowBandingGets the even row banding style.
firstColumnGets the first column style.
firstRowGets the first row style.
lastColumnGets the last column style.
lastRowGets the last row style.
oddColumnBandingGets the odd column banding style.
oddRowBandingGets the odd row banding style.
this[]
this[]
topLeftCellGets the top left cell style.
topRightCellGets the top right cell style.

Methods

NameDescription
clearFormatting()Clears all conditional styles of the table style.

Examples

Shows how to work with certain area styles of a table.

let doc = new aw.Document();
let builder = new aw.DocumentBuilder(doc);

let 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.
let tableStyle = doc.styles.add(aw.StyleType.Table, "MyTableStyle1").asTableStyle();

// 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.conditionalStyles.at(aw.ConditionalStyleType.FirstRow).shading.backgroundPatternColor = "#F0F8FF";

// 2 -  By index:
tableStyle.conditionalStyles.at(0).borders.color = "#000000";
tableStyle.conditionalStyles.at(0).borders.lineStyle = aw.LineStyle.DotDash;
expect(tableStyle.conditionalStyles.at(0).type).toEqual(aw.ConditionalStyleType.FirstRow);

// 3 -  As a property:
tableStyle.conditionalStyles.firstRow.paragraphFormat.alignment = aw.ParagraphAlignment.Center;

// Apply padding and text formatting to conditional styles.
tableStyle.conditionalStyles.lastRow.bottomPadding = 10;
tableStyle.conditionalStyles.lastRow.leftPadding = 10;
tableStyle.conditionalStyles.lastRow.rightPadding = 10;
tableStyle.conditionalStyles.lastRow.topPadding = 10;
tableStyle.conditionalStyles.lastColumn.font.bold = true;

// List all possible style conditions.
for (var currentStyle of tableStyle.conditionalStyles)
{
    if (currentStyle != null) console.log(currentStyle.type);
}

// Apply the custom style, which contains all conditional styles, to the table.
table.style = tableStyle;

// Our style applies some conditional styles by default.
expect(table.styleOptions).toEqual(aw.Tables.TableStyleOptions.FirstRow | aw.Tables.TableStyleOptions.FirstColumn | aw.Tables.TableStyleOptions.RowBands);

// We will need to enable all other styles ourselves via the "StyleOptions" property.
table.styleOptions = table.styleOptions | aw.Tables.TableStyleOptions.LastRow | aw.Tables.TableStyleOptions.LastColumn;

doc.save(base.artifactsDir + "Table.conditionalStyles.docx");

See Also