Skip to Content
ClassesConditionalFormatColorScaleRuleBuilder

Class: ConditionalFormatColorScaleRuleBuilder

Extends

  • ConditionalFormatRuleBaseBuilder

Methods

copy()

copy(): ConditionalFormatColorScaleRuleBuilder

Deep clone a current builder.

Returns

ConditionalFormatColorScaleRuleBuilder

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 color scale to cells with values between 0 and 100 in the range A1:D10. // The color scale is green for 0, yellow for 50, and red for 100. const fRange = fWorksheet.getRange('A1:D10'); const builder = fWorksheet.newConditionalFormattingRule() .setColorScale([ { index: 0, color: '#00FF00', value: { type: 'num', value: 0 } }, { index: 1, color: '#FFFF00', value: { type: 'num', value: 50 } }, { index: 2, color: '#FF0000', value: { type: 'num', value: 100 } } ]) .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

setColorScale()

setColorScale(config): ConditionalFormatColorScaleRuleBuilder

Set color scale rule.

Parameters

ParameterTypeDescription
configIColorScaleThe color scale rule settings.

Returns

ConditionalFormatColorScaleRuleBuilder

This builder for chaining.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); // Create a conditional formatting rule that adds a color scale to cells with values between 0 and 100 in the range A1:D10. // The color scale is green for 0, yellow for 50, and red for 100. const fRange = fWorksheet.getRange('A1:D10'); const rule = fWorksheet.newConditionalFormattingRule() .setColorScale([ { index: 0, color: '#00FF00', value: { type: 'num', value: 0 } }, { index: 1, color: '#FFFF00', value: { type: 'num', value: 50 } }, { index: 2, color: '#FF0000', value: { type: 'num', value: 100 } } ]) .setRanges([fRange.getRange()]) .build(); fWorksheet.addConditionalFormattingRule(rule);