[]
Sheets.ConditionalFormatting.StateRule
↳ StateRule
• new StateRule(ruleType
, state
, style?
, ranges?
)
状态规则
代码示例
// 在整个工作表中添加一个红色背景的行状态规则
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
var stateRule = new GC.Spread.Sheets.ConditionalFormatting.StateRule(GC.Spread.Sheets.ConditionalFormatting.RuleType.rowStateRule, style, [new GC.Spread.Sheets.Range(-1, -1, -1, -1)]);
activeSheet.conditionalFormats.addRule(cell);
// add a row state rule with two styles to different corresponding ranges
var stateRule = new GC.Spread.Sheets.ConditionalFormatting.StateRule(
GC.Spread.Sheets.ConditionalFormatting.RuleType.rowStateRule,
[new GC.Spread.Sheets.Style("green"), new GC.Spread.Sheets.Style("red")],
[new GC.Spread.Sheets.Range(1, 1, 10, 5)\uff0c new GC.Spread.Sheets.Range(1, 7, 10, 5)]
);
属性名 | 类型 | 说明 |
---|---|---|
ruleType |
RuleType |
状态规则类型,它将是GC.Spread.Sheet.ConditionalFormatting.RuleType.rowStateRule或GC.Spread.Sheet.ConditionalFormatting.RuleType.columnStateRule |
state |
RowColumnStates |
状态 |
style? |
Style | Style [] |
满足状态时应用于单元格的样式 It could an array of styles. |
ranges? |
Range [] |
项类型为GC.Spread.Sheets.Range的应用规则的单元格区域 |
▸ 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 |
实际值 |
规则的单元格样式
▸ 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
▸ isRow(): boolean
获取此状态规则是否将应用于行的方向
boolean
该状态规则是否适用于行方向,否则,将适用于列方向
▸ isScaleRule(): boolean
此规则是否为缩放规则
boolean
如果此规则是缩放规则,返回true;否则返回false
▸ 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
如果未设置任何值,则返回条件规则区域否则,返回条件规则
▸ 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(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
如果未设置任何值,则返回条件规则类型否则,返回条件规则
▸ state(value?
): RowColumnStates
获取或设置规则状态
属性名 | 类型 | 说明 |
---|---|---|
value? |
RowColumnStates |
状态 |
规则状态
▸ 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
如果未设置任何值,则返回规则的样式否则,返回条件规则