[]
Sheets.ConditionalFormatting.NormalConditionRule
↳ NormalConditionRule
• 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 |
要应用样式的顶部或底部项的数量 |
▸ condition(value?
): any
获取或设置规则的基本条件
属性名 | 类型 | 说明 |
---|---|---|
value? |
Condition |
规则的基本条件 |
any
如果未设置任何值,则返回规则的基本条件否则,返回条件规则
▸ contains(row
, column
): boolean
确定单元格区域是否包含指定行和列的单元格
属性名 | 类型 | 说明 |
---|---|---|
row |
number |
行索引 |
column |
number |
列索引 |
boolean
如果单元格区域包含指定行和列中的单元格,返回true;否则返回false
▸ createCondition(): Condition
创建条件规则
条件
ConditionRuleBase.createCondition
▸ evaluate(evaluator
, baseRow
, baseColumn
, actual
): Style
如果单元格满足条件,则返回规则的单元格样式
属性名 | 类型 | 说明 |
---|---|---|
evaluator |
Object |
可以计算条件的对象 |
baseRow |
number |
行索引 |
baseColumn |
number |
列索引 |
actual |
Object |
实际值 |
规则的单元格样式
▸ 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(): 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());
▸ 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
▸ isScaleRule(): boolean
此规则是否为缩放规则
boolean
如果此规则是缩放规则,返回true;否则返回false
▸ 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(value?
): any
获取或设置规则的优先级
属性名 | 类型 | 说明 |
---|---|---|
value? |
number |
规则的优先级 |
any
如果未设置任何值,则返回规则的优先级否则,返回条件规则
▸ 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
如果未设置任何值,则返回条件规则区域否则,返回条件规则
▸ 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(): 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
▸ 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(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(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
如果未设置任何值,则返回规则的样式否则,返回条件规则
▸ 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(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(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(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
如果未设置任何值或设置了基行和基列,则返回第一个值;否则,返回数字条件规则