轉(zhuǎn)帖|使用教程|編輯:鮑佳佳|2020-07-27 10:05:11.937|閱讀 320 次
概述:本文主要講述的是SpreadJS的條件格式教程中Formula 規(guī)則 和 Icon set 規(guī)則的作用以及如何用代碼實現(xiàn)。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
SpreadJS是一款基于 HTML5 的純前端電子表格控件,兼容 450 種以上的 Excel 公式,憑借其 “高性能、跨平臺、與 Excel 高度兼容”的產(chǎn)品特性,備受以華為、蘇寧易購、天弘基金等為代表的企業(yè)用戶青睞。SpreadJS 為用戶帶來親切的 Excel 使用體驗的同時,滿足 Web Excel 組件開發(fā)、表格文檔協(xié)同編輯、數(shù)據(jù)填報、Excel 類報表設(shè)計等業(yè)務(wù)場景,極大降低了企業(yè)研發(fā)成本和項目交付風(fēng)險。
DateFormula 規(guī)則可以讓你使用公式來檢查單元格的條件。
以下代碼創(chuàng)建了 Formula 規(guī)則。
var style = new GC.Spread.Sheets.Style(); style.backColor = "red"; var ranges = [new GC.Spread.Sheets.Range(0, 0, 2, 1)]; activeSheet.conditionalFormats.addFormulaRule("=A1=B1+C1", style, ranges); activeSheet.setValue(0, 0, 2,3); activeSheet.setValue(0, 1, 1,3); activeSheet.setValue(0, 2,1,3); activeSheet.setValue(1, 0, 1,3); // OR 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);
Icon Set 規(guī)則可以基于單元格中的值來顯示圖標(biāo),如下圖所示:
你可以使用iconSetType 方法和IconSetType枚舉來指定圖標(biāo)的樣式。你也可以使用reverseIconOrder方法來反轉(zhuǎn)圖標(biāo)的樣式。或者使用 showIconOnly方法設(shè)置只顯示圖標(biāo)還是圖標(biāo)和數(shù)據(jù)一起顯示。或自行創(chuàng)建一系列的圖標(biāo)。
以下代碼創(chuàng)建了 Icon Set 規(guī)則:
activeSheet.setValue(0,0,1,3); activeSheet.setValue(1,0,15,3); activeSheet.setValue(2,0,25,3); activeSheet.setValue(3,0,-1,3); var iconSetRule = new GC.Spread.Sheets.ConditionalFormatting.IconSetRule(); iconSetRule.ranges([new GC.Spread.Sheets.Range(0,0,4,1)]); iconSetRule.iconSetType(GC.Spread.Sheets.ConditionalFormatting.IconSetType.FourTrafficLights); var iconCriteria = iconSetRule.iconCriteria(); iconCriteria[0] = new GC.Spread.Sheets.ConditionalFormatting.IconCriterion(true, GC.Spread.Sheets.ConditionalFormatting.IconValueType.Number, 1); iconCriteria[1] = new GC.Spread.Sheets.ConditionalFormatting.IconCriterion(true, GC.Spread.Sheets.ConditionalFormatting.IconValueType.Number, 10); iconCriteria[2] = new GC.Spread.Sheets.ConditionalFormatting.IconCriterion(true, GC.Spread.Sheets.ConditionalFormatting.IconValueType.Number, 20); iconSetRule.reverseIconOrder(false); iconSetRule.showIconOnly(false); activeSheet.conditionalFormats.addRule(iconSetRule);
以下代碼在 Icon Set 規(guī)則中創(chuàng)建了自定義圖標(biāo)。
activeSheet.setValue(0,0,1,3); activeSheet.setValue(1,0,15,3); activeSheet.setValue(2,0,25,3); activeSheet.setValue(3,0,-1,3); var base = GC.Spread.Sheets.ConditionalFormatting.IconSetRule.getIcon; GC.Spread.Sheets.ConditionalFormatting.IconSetRule.getIcon = function (iconSetType, iconIndex) { var icon = base.apply(this, arguments); if (iconSetType === GC.Spread.Sheets.ConditionalFormatting.IconSetType.ThreeArrowsColored) { if (iconIndex === 0) { return "images/Star2.png"; } else if (iconIndex === 1){ return "images/Rating4.png"; } else if (iconIndex === 2) { return "images/Box4.png"; } } return icon; }; var iconSetRule = new GC.Spread.Sheets.ConditionalFormatting.IconSetRule(); iconSetRule.ranges([new GC.Spread.Sheets.Range(0,0,4,1)]); iconSetRule.iconSetType(GC.Spread.Sheets.ConditionalFormatting.IconSetType.ThreeArrowsColored); var iconCriteria = iconSetRule.iconCriteria(); iconCriteria[0] = new GC.Spread.Sheets.ConditionalFormatting.IconCriterion(true, GC.Spread.Sheets.ConditionalFormatting.IconValueType.Number, 1); iconCriteria[1] = new GC.Spread.Sheets.ConditionalFormatting.IconCriterion(true, GC.Spread.Sheets.ConditionalFormatting.IconValueType.Number, 10); iconCriteria[2] = new GC.Spread.Sheets.ConditionalFormatting.IconCriterion(true, GC.Spread.Sheets.ConditionalFormatting.IconValueType.Number, 20); iconSetRule.reverseIconOrder(false); iconSetRule.showIconOnly(false); activeSheet.conditionalFormats.addRule(iconSetRule);
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: