Class: ConditionalFormatIconSetRuleBuilder
Extends
ConditionalFormatRuleBaseBuilder
Methods
copy()
copy(): ConditionalFormatIconSetRuleBuilder
Deep clone a current builder.
Returns
ConditionalFormatIconSetRuleBuilder
A new instance of the builder with the same settings as the original.
Example
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
// Create a 3-arrow icon set conditional formatting rule in the range A1:D10.
// The first arrow is green for values greater than 20.
// The second arrow is yellow for values greater than 10.
// The third arrow is red for values less than or equal to 10.
const fRange = fWorksheet.getRange('A1:D10');
const builder = fWorksheet.newConditionalFormattingRule()
.setIconSet({
iconConfigs: [
{ iconType: '3Arrows', iconId: '0', operator: univerAPI.Enum.ConditionFormatNumberOperatorEnum.greaterThan, value: { type: 'num', value: 20 } },
{ iconType: '3Arrows', iconId: '1', operator: univerAPI.Enum.ConditionFormatNumberOperatorEnum.greaterThan, value: { type: 'num', value: 10 } },
{ iconType: '3Arrows', iconId: '2', operator: univerAPI.Enum.ConditionFormatNumberOperatorEnum.lessThanOrEqual, value: { type: 'num', value: 10 } }
],
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
setIconSet()
setIconSet(config): ConditionalFormatIconSetRuleBuilder
Set up icon set conditional formatting rule.
Parameters
Parameter | Type | Description |
---|---|---|
config | { iconConfigs : IIconSet ; isShowValue : boolean ; } | The icon set conditional formatting rule settings. |
config.iconConfigs | IIconSet | The icon configurations. iconId property is a string indexing of a group icons. |
config.isShowValue | boolean | Whether to show the value in the cell. |
Returns
ConditionalFormatIconSetRuleBuilder
This builder for chaining.
Example
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
// Create a 3-arrow icon set conditional formatting rule in the range A1:D10.
// The first arrow is green for values greater than 20.
// The second arrow is yellow for values greater than 10.
// The third arrow is red for values less than or equal to 10.
const fRange = fWorksheet.getRange('A1:D10');
const builder = fWorksheet.newConditionalFormattingRule();
console.log(builder.getIconMap()); // icons key-value map
const rule = builder.setIconSet({
iconConfigs: [
{ iconType: '3Arrows', iconId: '0', operator: univerAPI.Enum.ConditionFormatNumberOperatorEnum.greaterThan, value: { type: 'num', value: 20 } },
{ iconType: '3Arrows', iconId: '1', operator: univerAPI.Enum.ConditionFormatNumberOperatorEnum.greaterThan, value: { type: 'num', value: 10 } },
{ iconType: '3Arrows', iconId: '2', operator: univerAPI.Enum.ConditionFormatNumberOperatorEnum.lessThanOrEqual, value: { type: 'num', value: 10 } }
],
isShowValue: true,
})
.setRanges([fRange.getRange()])
.build();
fWorksheet.addConditionalFormattingRule(rule);