Pivot report style
Now that we have the required selectors, we can create the report style. This report style uses expressions to determine whether the calculated measure value (Sum Credit minus Sum Debit) in a cell is greater than or equal to 1 US dollar (USD). If this condition is true, the cell color is changed to pink.
Use workbook.createReportStyleRule(options) to create a report style rule, then use workbook.createReportStyle(options) to create the report style based on the rules you provide. The workbook.createReportStyle(options) method also accepts a selector, and we provide the measure value selector we created in the previous section.
var rule = nWorkbook.createReportStyleRule({
expression: nWorkbook.createExpression({
functionId: workbook.ExpressionType.COMPARE,
parameters: {
comparisonType: "GREATER_OR_EQUAL",
operand1: nWorkbook.createExpression({
functionId: workbook.ExpressionType.MEASURE_VALUE,
parameters: {
measure: calculatedMeasure
}
}),
operand2: nWorkbook.createConstant(nWorkbook.createCurrency({
amount: 1,
id: "USD"})
)
}
}),
style: nWorkbook.createStyle({
backgroundColor: nWorkbook.createColor({
red: 255,
green: 192,
blue: 203
})
})
});
var reportStyle = nWorkbook.createReportStyle({
selectors: [measureValueSelector],
rules: [rule]
});