Class: ConditionalFormatDataBarRuleBuilder
Extends
ConditionalFormatRuleBaseBuilder
Methods
copy()
copy(): ConditionalFormatDataBarRuleBuilder
Deep clone a current builder.
Returns
ConditionalFormatDataBarRuleBuilder
A new instance of the builder with the same settings as the original.
Example
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
// Create a conditional formatting rule that adds a data bar to cells with values between -100 and 100 in the range A1:D10.
// positive values are green and negative values are red.
const fRange = fWorksheet.getRange('A1:D10');
const builder = fWorksheet.newConditionalFormattingRule()
.setDataBar({
min: { type: 'num', value: -100 },
max: { type: 'num', value: 100 },
positiveColor: '#00FF00',
nativeColor: '#FF0000',
isShowValue: true
})
.setRanges([fRange.getRange()]);
fWorksheet.addConditionalFormattingRule(builder.build());
// Copy the rule and apply it to a new range.
const newRange = fWorksheet.getRange('F1:F10');
const newBuilder = builder.copy()
.setRanges([newRange.getRange()]);
fWorksheet.addConditionalFormattingRule(newBuilder.build());
Overrides
ConditionalFormatRuleBaseBuilder.copy
setDataBar()
setDataBar(config): ConditionalFormatDataBarRuleBuilder
Set data bar rule.
Parameters
Parameter | Type | Description |
---|---|---|
config | { isGradient : boolean ; isShowValue : boolean ; max : IValueConfig ; min : IValueConfig ; nativeColor : string ; positiveColor : string ; } | The data bar rule settings. |
config.isGradient ? | boolean | Whether the data bar is gradient. |
config.isShowValue ? | boolean | Whether to show the value in the cell. |
config.max | IValueConfig | The maximum value for the data bar. |
config.min | IValueConfig | The minimum value for the data bar. |
config.nativeColor | string | The color for negative values. |
config.positiveColor | string | The color for positive values. |
Returns
ConditionalFormatDataBarRuleBuilder
This builder for chaining.
Example
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
// Create a conditional formatting rule that adds a data bar to cells with values between -100 and 100 in the range A1:D10.
// positive values are green and negative values are red.
const fRange = fWorksheet.getRange('A1:D10');
const rule = fWorksheet.newConditionalFormattingRule()
.setDataBar({
min: { type: 'num', value: -100 },
max: { type: 'num', value: 100 },
positiveColor: '#00FF00',
nativeColor: '#FF0000',
isShowValue: true
})
.setRanges([fRange.getRange()])
.build();
fWorksheet.addConditionalFormattingRule(rule);