[]
        
(Showing Draft Content)

GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule

类: NormalConditionRule

Sheets.ConditionalFormatting.NormalConditionRule

继承关系

Table of contents

构造方法

方法

构造方法

constructor

new NormalConditionRule(ruleType, ranges, style, operator, value1, value2, text, formula, type, rank)

正常的条件规则

代码示例

activeSheet.setArray(0,0,[1,2,3,4,5,6,7,8,9,10]);
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)]);
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
cell.style(style);
activeSheet.conditionalFormats.addRule(cell);
//button
$("#button1").click(function () {
     cell.reset();
     activeSheet.suspendPaint();
     activeSheet.resumePaint();
});

参数

属性名 类型 说明
ruleType RuleType
ranges Range[] 项类型为GC.Spread.Sheets.Range的应用规则的单元格区域
style Style 满足条件时应用于单元格的样式
operator LogicalOperators | ComparisonOperators | TextComparisonOperators 比较运算符
value1 Object 第一个值
value2 Object 第二个值
text string 供比较的文本
formula string 条件公式
type AverageConditionType | DateOccurringType | Top10ConditionType 平均值条件类型
rank number 要应用样式的顶部或底部项的数量

Overrides

ConditionRuleBase.constructor

方法

condition

condition(value?): any

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

参数

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

返回值

any

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

继承自

ConditionRuleBase.condition


contains

contains(row, column): boolean

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

参数

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

返回值

boolean

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

继承自

ConditionRuleBase.contains


createCondition

createCondition(): Condition

创建条件规则

返回值

Condition

条件

Overrides

ConditionRuleBase.createCondition


evaluate

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

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

参数

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

返回值

Style

规则的单元格样式

继承自

ConditionRuleBase.evaluate


formula

formula(formulaOrBaseRow?, baseColumn?): any

获取或设置条件公式

代码示例

//本示例使用formula方法
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
var rule = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
rule.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.formulaRule);
rule.formula("=A1=B1+C1");
rule.ranges([new GC.Spread.Sheets.Range(0, 0, 2, 1)]);
rule.style(style);
activeSheet.conditionalFormats.addRule(rule);
activeSheet.setValue(0, 0, 2,3);
activeSheet.setValue(0, 1, 1,3);
activeSheet.setValue(0, 2,1,3);
activeSheet.setValue(1, 0, 1,3);
var formulaOfTheTopLeftCell = rule.formula();
var formulaOfA1 = rule.formula(0, 0);
var formulaOfA2 = rule.formula(1, 0);

参数

属性名 类型 说明
formulaOrBaseRow? string | number 条件公式或基行
baseColumn? number 基列

返回值

any

如果未设置任何值或设置了基行和基列,则返回条件公式;否则,返回数字条件规则


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

继承自

ConditionRuleBase.getExpected


intersects

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

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

代码示例

 //This example uses the intersects 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();
 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

继承自

ConditionRuleBase.intersects


isScaleRule

isScaleRule(): boolean

此规则是否为缩放规则

返回值

boolean

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

继承自

ConditionRuleBase.isScaleRule


operator

operator(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? ComparisonOperators 比较运算符

返回值

any

如果未设置任何值,则返回比较运算符;否则,返回数字条件规则


priority

priority(value?): any

获取或设置规则的优先级

参数

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

返回值

any

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

继承自

ConditionRuleBase.priority


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

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

继承自

ConditionRuleBase.ranges


rank

rank(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? number 要应用样式的顶部或底部项的数量

返回值

any

如果未设置任何值,则返回要应用样式的顶部或底部项的数量;否则,返回数字条件规则


reset

reset(): void

重置规则

代码示例

activeSheet.setValue(0,0, 1,3);
activeSheet.setValue(1,0, 50,3);
activeSheet.setValue(2,0, 100,3);
activeSheet.setValue(3,0, 2,3);
activeSheet.setValue(4,0, 60,3);
activeSheet.setValue(5,0, 90,3);
activeSheet.setValue(6,0, 3,3);
activeSheet.setValue(7,0, 40,3);
activeSheet.setValue(8,0, 70,3);
activeSheet.setValue(9,0, 5,3);
activeSheet.setValue(10,0, 35,3);
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
style.borderLeft =new GC.Spread.Sheets.LineBorder("blue",GC.Spread.Sheets.LineStyle.medium);
style.borderTop = new GC.Spread.Sheets.LineBorder("blue",GC.Spread.Sheets.LineStyle.medium);
style.borderRight = new GC.Spread.Sheets.LineBorder("blue",GC.Spread.Sheets.LineStyle.medium);
style.borderBottom = new GC.Spread.Sheets.LineBorder("blue",GC.Spread.Sheets.LineStyle.medium);
var rule = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
rule.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.averageRule);
rule.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 3)]);
rule.style(style);
rule.type(GC.Spread.Sheets.ConditionalFormatting.AverageConditionType.above);
activeSheet.conditionalFormats.addRule(rule);
rule.reset();

返回值

void

Overrides

ConditionRuleBase.reset


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

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

继承自

ConditionRuleBase.ruleType


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

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

继承自

ConditionRuleBase.stopIfTrue


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

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

继承自

ConditionRuleBase.style


text

text(value?): any

获取或设置文本以进行比较

代码示例

//本示例创建一个规则
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
var rule = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
rule.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.specificTextRule);
rule.style(style);
rule.text("test");
rule.operator(GC.Spread.Sheets.ConditionalFormatting.TextComparisonOperators.contains);
rule.ranges([new GC.Spread.Sheets.Range(0, 0, 10, 1)]);
activeSheet.conditionalFormats.addRule(rule);
activeSheet.setValue(0, 0, "testing");
activeSheet.setValue(1, 0, "test");
activeSheet.setValue(2, 0, "a");
activeSheet.setValue(3, 0, "t");

参数

属性名 类型 说明
value? string 供比较的文本

返回值

any

如果未设置任何值,则返回进行比较的文本;否则,返回数字条件规则


type

type(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? AverageConditionType 平均值条件类型

返回值

any

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


value1

value1(valueOrBaseRow?, baseColumn?): any

获取或设置第一个值

代码示例

//本示例创建多个规则
activeSheet.setArray(0,0,[[1,10],[2,9], [3,8],[4,7],[5,6],[6,5],[7,4],[8,3],[9,2],[10,1]]);
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("=B1");
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);
var formulaOfTheTopLeftCell = cell.value1();
var formulaOfA5 = cell.value1(4, 0);
var formulaOfA10 = cell.value1(9, 0);

参数

属性名 类型 说明
valueOrBaseRow? any 第一个值或基行
baseColumn? number 基列

返回值

any

如果未设置任何值或设置了基行和基列,则返回第一个值;否则,返回数字条件规则


value2

value2(valueOrBaseRow?, baseColumn?): any

获取或设置第一个值

代码示例

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

参数

属性名 类型 说明
valueOrBaseRow? any 第一个值或基行
baseColumn? number 基列

返回值

any

如果未设置任何值或设置了基行和基列,则返回第一个值;否则,返回数字条件规则