如何在SpreadJS 条件格式应用Duplicate 和 Date Occurring规则

SpreadJS 是一款基于 HTML5 的纯前端电子表格控件,兼容 450 种以上的 Excel 公式,凭借其 “高性能、跨平台、与 Excel 高度兼容”的产品特性,备受以华为、苏宁易购、天弘基金等为代表的企业用户青睐。SpreadJS 为用户带来亲切的 Excel 使用体验的同时,满足 Web Excel 组件开发、表格文档协同编辑、数据填报、Excel 类报表设计等业务场景,极大降低了企业研发成本和项目交付风险。

点击下载SpreadJS最新试用版

使用 Date Occurring 规则

Date Occurring 规则是用来比对日期的。以下代码使用了 Date Occurring 规则。

var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
var rule = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule(GC.Spread.Sheets.ConditionalFormatting.RuleType.DateOccurringRule, \[new GC.Spread.Sheets.Range(0,0,10,1)\], style, null, null, null, null, null, GC.Spread.Sheets.ConditionalFormatting.DateOccurringType.NextWeek);
activeSheet.conditionalFormats.addRule(rule);
var d = new Date();
activeSheet.setValue(0, 0, d);
activeSheet.setValue(1, 0, new Date(d.setDate(d.getDate()+1)));
activeSheet.setValue(2, 0, new Date(d.setDate(d.getDate()+5)));
activeSheet.setValue(3, 0,new Date(d.setDate(d.getDate()+6)));
activeSheet.setValue(4, 0,new Date(d.setDate(d.getDate()+7)));
activeSheet.setValue(5, 0, new Date(d.setDate(d.getDate()+8)));
// OR
var style = new GC.Spread.Sheets.Style();
style.backColor = "red";
activeSheet.conditionalFormats.addDateOccurringRule(GC.Spread.Sheets.ConditionalFormatting.DateOccurringType.NextWeek, style, \[new GC.Spread.Sheets.Range(0,0,10,1)\]);
var d = new Date();
activeSheet.setValue(0, 0, d);
activeSheet.setValue(1, 0, new Date(d.setDate(d.getDate()+1)));
activeSheet.setValue(2, 0, new Date(d.setDate(d.getDate()+5)));
activeSheet.setValue(3, 0,new Date(d.setDate(d.getDate()+6)));
activeSheet.setValue(4, 0,new Date(d.setDate(d.getDate()+7)));
activeSheet.setValue(5, 0, new Date(d.setDate(d.getDate()+8)));

使用 Duplicate 规则

Duplicate 规则用于检查单元格中重复的值。

示例代码

以下代码使用了 duplicate 规则。

var style = new GC.Spread.Sheets.Style();
style.backColor = "yellow";
var ranges=\[new GC.Spread.Sheets.Range(0,0,10,1)\];
activeSheet.conditionalFormats.addDuplicateRule(style, ranges);
activeSheet.setValue(0, 0, 50);
activeSheet.setValue(1, 0, 50);
activeSheet.setValue(2, 0, 11);
activeSheet.setValue(3, 0, 5);
// OR
var style = new GC.Spread.Sheets.Style();
style.backColor = "yellow";
var rule = new GC.Spread.Sheets.ConditionalFormatting.NormalConditionRule();
rule.ruleType(GC.Spread.Sheets.ConditionalFormatting.RuleType.DuplicateRule);
rule.ranges(\[new GC.Spread.Sheets.Range(0,0,10,1)\]);
rule.style(style);
activeSheet.conditionalFormats.addRule(rule);
activeSheet.setValue(0, 0, 50);
activeSheet.setValue(1, 0, 50);
activeSheet.setValue(2, 0, 11);
activeSheet.setValue(3, 0, 5);

本文转载自葡萄城

你可能感兴趣的:(前端,.net,控件,spreadjs)