[]
        
(Showing Draft Content)

GC.Spread.Sheets.ConditionalFormatting.ConditionRuleBase

类: ConditionRuleBase

Sheets.ConditionalFormatting.ConditionRuleBase

继承关系

Table of contents

构造方法

方法

构造方法

constructor

new ConditionRuleBase(ruleType, style, ranges)

将格式设置基本规则类表示为指定的样式

参数

属性名 类型 说明
ruleType RuleType 条件格式化规则类型
style Style 规则的样式
ranges Range[] 区域数组

方法

condition

condition(value?): any

获取或设置规则的基本条件

参数

属性名 类型 说明
value? Condition 规则的基本条件

返回值

any

如果未设置任何值,则返回规则的基本条件否则,返回条件规则


contains

contains(row, column): boolean

确定单元格区域是否包含指定行和列的单元格

参数

属性名 类型 说明
row number 行索引
column number 列索引

返回值

boolean

如果单元格区域包含指定行和列中的单元格,返回true;否则返回false


createCondition

createCondition(): Condition

为规则创建条件

返回值

Condition

条件


evaluate

evaluate(evaluator, baseRow, baseColumn, actual): Style

如果单元格满足条件,则返回规则的单元格样式

参数

属性名 类型 说明
evaluator Object 可以计算条件的对象
baseRow number 行索引
baseColumn number 列索引
actual Object 实际值

返回值

Style

规则的单元格样式


getExpected

getExpected(): Style

获取基本规则的样式

代码示例

 //This example uses the getExpected method.
 activeSheet.suspendPaint();
 var style = new GC.Spread.Sheets.Style();
 style.backColor = "green";
 var ranges = [new GC.Spread.Sheets.Range(0, 0, 10, 1)];
 activeSheet.conditionalFormats.addUniqueRule(style, ranges);
 var data = [50, 50, 11, 5, 3, 6, 7, 8, 7, 11];
 var condition = activeSheet.conditionalFormats.getRules()[0];
 for (var i = 0; i < 10;i++){
     activeSheet.setValue(i, 0, data[i]);
 }
 activeSheet.resumePaint();
 console.log(condition.getExpected());

返回值

Style


intersects

intersects(row, column, rowCount, columnCount): boolean

此规则的区域是否与另一个区域相交

代码示例

 //此示例使用Intersects方法
 activeSheet.suspendPaint();
 var style = new GC.Spread.Sheets.Style();
 style.backColor = "green";
 var ranges = [new GC.Spread.Sheets.Range(0, 0, 10, 1)];
 activeSheet.conditionalFormats.addUniqueRule(style, ranges);
 var data = [50, 50, 11, 5, 3, 6, 7, 8, 7, 11];
 var condition = activeSheet.conditionalFormats.getRules()[0];
 for (var i = 0; i < 10; i++) {
     activeSheet.setValue(i, 0, data[i]);
 }
 activeSheet.resumePaint();
 activeSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function(e, info) {
     var selection = info.newSelections[0];
     var result = condition.intersects(selection.row, selection.col, selection.rowCount, selection.colCount);
     if (result) {
         alert("current selection is intersects with condition formatting range");
     } else {
         alert("current selection is not intersects with condition formatting range");
     }
 });

参数

属性名 类型 说明
row number 行索引
column number 列索引
rowCount number 行数
columnCount number 列数

返回值

boolean

如果此规则的区域与另一个区域相交,返回true;否则返回false


isScaleRule

isScaleRule(): boolean

此规则是否为缩放规则

返回值

boolean

如果此规则是缩放规则,返回true;否则返回false


priority

priority(value?): any

获取或设置规则的优先级

参数

属性名 类型 说明
value? number 规则的优先级

返回值

any

如果未设置任何值,则返回规则的优先级否则,返回条件规则


ranges

ranges(value?): any

获取或设置条件规则区域

代码示例

var style = new GC.Spread.Sheets.Style();
style.backColor = "green";
var ranges = [new GC.Spread.Sheets.Range(0, 0, 10, 1)];
activeSheet.conditionalFormats.addUniqueRule(style, ranges);
activeSheet.setValue(0, 0, 50);
activeSheet.setValue(1, 0, 50);
activeSheet.setValue(2, 0, 11);
activeSheet.setValue(3, 0, 5);

参数

属性名 类型 说明
value? Range[] 条件规则区域

返回值

any

如果未设置任何值,则返回条件规则区域否则,返回条件规则


reset

reset(): void

重置规则

代码示例

 activeSheet.setArray(0, 0, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
 var style = new GC.Spread.Sheets.Style();
 style.backColor = "red";
 style.foreColor = "black";
 var cell = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
 cell.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.cellValueRule);
 cell.operator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan);
 cell.value1(2);
 cell.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
 cell.style(style);
 activeSheet.conditionalFormats.addRule(cell);
 var style = new GC.Spread.Sheets.Style();
 style.cellButtons = [{
     caption: "Reset",
     useButtonStyle: true,
     width: 60,
     command: function(sheet) {
         cell.reset();
         sheet.resumePaint();
     }
 }];
 activeSheet.setStyle(16, 4, style);

返回值

void


ruleType

ruleType(value?): any

获取或设置条件规则类型

代码示例

//本示例使用ruleType方法
activeSheet.setArray(0,0,[1,2,3,4,5,6,7,8,9,10]);
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
style.foreColor = "black";
var cell = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
cell.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.cellValueRule);
cell.operator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan);
cell.value1(5);
cell.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
cell.style(style);
activeSheet.conditionalFormats.addRule(cell);
var style1 = new GC.Spread.Sheets.Style();
style1.foreColor = "red";
var top = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
top.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.top10Rule);
top.type(GC.Spread.Sheets.ConditionalFormatting.Top10ConditionType.top);
top.rank(3);
top.style(style1);
top.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
top.stopIfTrue(true);
activeSheet.conditionalFormats.addRule(top);

参数

属性名 类型 说明
value? RuleType 条件规则类型

返回值

any

如果未设置任何值,则返回条件规则类型否则,返回条件规则


stopIfTrue

stopIfTrue(value?): any

获取或设置是否在此规则之前应用优先级较低的规则

代码示例

//本示例应用了多个规则
activeSheet.setArray(0,0,[1,2,3,4,5,6,7,8,9,10]);
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
style.foreColor = "black";
var cell = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
cell.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.cellValueRule);
cell.operator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan);
cell.value1(5);
cell.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
cell.style(style);
activeSheet.conditionalFormats.addRule(cell);
var style1 = new GC.Spread.Sheets.Style();
style1.foreColor = "red";
var top = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
top.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.top10Rule);
top.type(GC.Spread.Sheets.ConditionalFormatting.Top10ConditionType.top);
top.rank(3);
top.style(style1);
top.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
top.stopIfTrue(true);
activeSheet.conditionalFormats.addRule(top);

参数

属性名 类型 说明
value? boolean 是否在此规则之前应用优先级较低的规则

返回值

any

如果未设置任何值,则返回在此规则之前是否应用优先级较低的规则;否则,返回条件规则


style

style(value?): any

获取或设置规则的样式

代码示例

//本示例应用了多个规则
activeSheet.setArray(0,0,[1,2,3,4,5,6,7,8,9,10]);
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
style.foreColor = "black";
var cell = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
cell.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.cellValueRule);
cell.operator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan);
cell.value1(5);
cell.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
cell.style(style);
activeSheet.conditionalFormats.addRule(cell);
var style1 = new GC.Spread.Sheets.Style();
style1.foreColor = "red";
var top = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
top.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.top10Rule);
top.type(GC.Spread.Sheets.ConditionalFormatting.Top10ConditionType.top);
top.rank(3);
top.style(style1);
top.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
top.stopIfTrue(true);
activeSheet.conditionalFormats.addRule(top);

参数

属性名 类型 说明
value? Style 规则的样式

返回值

any

如果未设置任何值,则返回规则的样式否则,返回条件规则