Skip to Content
ClassesConditionalFormatDataBarRuleBuilder

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

ParameterTypeDescription
config{ isGradient: boolean; isShowValue: boolean; max: IValueConfig; min: IValueConfig; nativeColor: string; positiveColor: string; }The data bar rule settings.
config.isGradient?booleanWhether the data bar is gradient.
config.isShowValue?booleanWhether to show the value in the cell.
config.maxIValueConfigThe maximum value for the data bar.
config.minIValueConfigThe minimum value for the data bar.
config.nativeColorstringThe color for negative values.
config.positiveColorstringThe 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);