Styles
The content in this help topic applies to SuiteScript 2.x.
Styles let you change the format of cells in table views and pivots based on conditions that you specify. You can create standalone styles that format the color, font size, font style, and other attributes in a cell, and you can add these standalone styles to conditional formatting rules and report style rules (for pivots).
For more information about styles in SuiteAnalytics Workbook, see Conditional Formatting.
To create a standalone style, use workbook.createStyle(options). This method creates a workbook.Style object. You can provide the following 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, first use workbook.createReportStyleRule(options) to create report style rules, similar to creating conditional formatting rules for a conditional format. This method creates a workbook.ReportStyleRule object. When you use this method, you must provide the following parameters:
-
expression
– An expression indicating when to apply the style. Use workbook.createExpression(options) to create expressions. For more information, see Expressions. -
style
– The style to apply when the expression evaluates totrue
. Use workbook.createStyle(options) to create styles.
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
})
})
});
After you create a set of report style rules, use workbook.createReportStyle(options) to assemble the set of rules into a single workbook.ReportStyle object. In addition to the report style rules, you must provide a selector that selects the cell in the pivot to apply the style to. 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]
});