Styles
Styles help you customize cell formats in table views and pivots based on conditions. You can create standalone styles to customize cell attributes, and then add them to formatting rules.
For more information about styles in SuiteAnalytics Workbook, see Conditional Formatting.
You can create a standalone style using workbook.createStyle(options). This method creates a workbook.Style object. You can also provide these optional parameters to workbook.createStyle(options):
-
backgroundColor
– The background color. Use values from the workbook.Color enum, or use workbook.createColor(options) to create a custom color. -
backgroundImage
– The background image. Use values from the workbook.Image enum. -
backgroundPosition
– The background position. Use values from the workbook.Position enum, or use workbook.createPositionPercent(options), workbook.createPositionUnits(options), or workbook.createPositionValues(options) to create a custom position. -
color
– The font color. Use values from the workbook.Color enum, or use workbook.createColor(options) to create a custom color. -
fontSize
– The font size. Use values from the workbook.FontSize enum. -
fontStyle
– The font style. Use values from the workbook.FontStyle enum. -
fontWeight
– The font weight. Use values from the workbook.FontWeight enum. -
textAlign
– The text alignment. Use values from the workbook.TextAlign enum. -
textDecorationColor
– The text decoration color. Use values from the workbook.Color enum, or use workbook.createColor(options) to create a custom color. -
textDecorationLine
– The text decoration line. Use values from the workbook.TextDecorationLine enum. -
textDecorationStyle
– The text decoration style. Use values from the workbook.TextDecorationStyle enum.
var myFirstStyle = workbook.createStyle({
backgroundColor: workbook.createColor({
red: 255,
green: 192,
blue: 203
})
});
var mySecondStyle = workbook.createStyle({
fontSize: workbook.FontSize.LARGE,
fontStyle: workbook.FontStyle.ITALIC,
fontWeight: workbook.FontWeight.BOLD
});
To create a report style, start by creating report style rules using workbook.createReportStyleRule(options), similar to creating conditional formatting rules for a conditional format. This creates a workbook.ReportStyleRule object. You'll need to provide these parameters:
-
expression
– An expression indicating when to apply the style. Create expressions using workbook.createExpression(options). For more information, see Expressions. -
style
– The style to apply when the expression evaluates totrue
. Create styles using workbook.createStyle(options).
var myReportStyleRule = workbook.createReportStyleRule({
expression: workbook.createExpression({
functionId: workbook.ExpressionType.COMPARE,
parameters: {
comparisonType: 'GREATER_OR_EQUAL',
operand1: workbook.createExpression({
functionId: workbook.ExpressionType.MEASURE_VALUE,
parameters: {
measure: myCalculatedMeasure
}
}),
operand2: workbook.createConstant(
workbook.createCurrency({
amount: 1,
id: 'USD'
})
)
}
}),
style: workbook.createStyle({
backgroundColor: workbook.createColor({
red: 255,
green: 192,
blue: 203
})
})
});
When you have your report style rules, use workbook.createReportStyle(options) combine them into a single workbook.ReportStyle object. You'll also need to provide a selector to choose the cell in the pivot where the style will be applied. For more information, see Selectors.
var conditionalRowSelector = workbook.DescendantOrSelfNodesSelector;
var conditionalColumnSelector = workbook.DescendantOrSelfNodesSelector;
var conditionalMeasureSelector = workbook.createMeasureSelector({
measures: [myCalculatedMeasure]
});
var measureValueSelector = workbook.createMeasureValueSelector({
rowSelector: conditionalRowSelector,
columnSelector: conditionalColumnSelector,
measureSelector: conditionalMeasureSelector
});
var myReportStyle = workbook.createReportStyle({
selectors: [measureValueSelector],
rules: [myFirstReportStyleRule, mySecondReportStyleRule]
});