소개

수천 행의 데이터가 포함된 시트가 있는 경우 원시 정보를 검토하는 것만으로 패턴과 추세를 보는 것이 매우 어려울 수 있습니다. 스파크라인과 유사하게 조건부 서식은 데이터를 시각화하고 시트를 보다 쉽게 이해할 수 있는 또 다른 방법을 제공합니다.

설명
app.vue
index.html
styles.css

SpreadJS에 조건부 서식을 추가하려면 먼저 conditionalFormats를 사용하여 시트의 조건부 서식을 가져옵니다. 그런 다음 조건부 규칙을 만들고 addRule 메서드를 사용하여 해당 규칙을 추가할 수 있습니다. 또한 addSpecificTextRule, addCellValueRule 등 지정된 규칙의 add 메서드를 사용할 수 있습니다. 예:

    var cfs = sheet.conditionalFormats;
    var style = new GC.Spread.Sheets.Style();
    style.backColor = '#CCFFCC';
    var cvRule = cfs.addCellValueRule(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan, 100, 0, style, [new GC.Spread.Sheets.Range(3, 3, 3, 3)]);

시트에 규칙을 추가한 후 getRule 메서드를 사용하여 규칙 인덱스를 사용하여 규칙을 반환하거나 모든 조건부 규칙을 가져옵니다. 예:

    var cfs = sheet.conditionalFormats;
    //  The new added is at the end.
    var cvRule = cfs.getRule(1);

    // Or get all the conditional rules.
    var rules = cfs.getRules();

조건부 규칙을 제거하려면 removeRule, removeRuleByRange 또는 clearRule 메서드를 사용합니다. 예:

    var cfs = sheet.conditionalFormats;
    cfs.removeRule(cvRule)
    cfs.removeRuleByRange(3, 3, 3, 3);
    cfs.clearRule(); //removes all rules
SpreadJS에 조건부 서식을 추가하려면 먼저 conditionalFormats를 사용하여 시트의 조건부 서식을 가져옵니다. 그런 다음 조건부 규칙을 만들고 addRule 메서드를 사용하여 해당 규칙을 추가할 수 있습니다. 또한 addSpecificTextRule, addCellValueRule 등 지정된 규칙의 add 메서드를 사용할 수 있습니다. 예: 시트에 규칙을 추가한 후 getRule 메서드를 사용하여 규칙 인덱스를 사용하여 규칙을 반환하거나 모든 조건부 규칙을 가져옵니다. 예: 조건부 규칙을 제거하려면 removeRule, removeRuleByRange 또는 clearRule 메서드를 사용합니다. 예:
<template> <div class="sample-tutorial"> <gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread"> <gc-worksheet></gc-worksheet> </gc-spread-sheets> <div class="options-container"> <p>Select cell(s) that contains rule(s):</p> <div class="option-row"> <input id="ruleCount" style="border: none;" :value="ruleCountDescription" /> </div> <div class="option-row"> <input type="button" id="removeRule" value="Remove the selection's rule" @click="removeRule" /> <input type="button" id="clearRule" value="Remove all the rules" @click="clearRule" /> </div> </div> </div> </template> <script> import Vue from "vue"; import '@mescius/spread-sheets-resources-ko'; GC.Spread.Common.CultureManager.culture("ko-kr"); import "@mescius/spread-sheets-vue"; import GC from "@mescius/spread-sheets"; import "./styles.css"; let App = Vue.extend({ name: "app", data: function () { return { spread: null, ruleCountDescription: "" }; }, methods: { initSpread: function (spread) { this.spread = spread; let spreadNS = GC.Spread.Sheets; let sheet = spread.getSheet(0); sheet.suspendPaint(); let cfs = sheet.conditionalFormats; // sample title sheet.addSpan(1, 1, 1, 7); sheet.setValue(1, 1, "Conditional Format Samples"); sheet.getCell(1, 1).font("24px sans-serif"); sheet.getCell(1, 1).hAlign(spreadNS.HorizontalAlign.center); sheet.setRowHeight(1, 35); // cell value rule let r = 2; let c = 1; let w = 3; let h = 4; sheet.addSpan(r, c, 1, w); sheet.setValue(r, c, "Displays green background: value > 50:"); sheet.getCell(r, c).wordWrap(true); sheet.setRowHeight(r, 40); let increase = 0; for (let row = 0; row < h - 1; row++) { for (let col = 0; col < w; col++) { sheet.setValue(row + 3, col + 1, increase); increase += 10; } } sheet .getRange(r, c, h, w) .setBorder( new spreadNS.LineBorder("Black", spreadNS.LineStyle.dashed), { all: true } ); let style = new spreadNS.Style(); style.backColor = "#CCFFCC"; cfs.addCellValueRule( spreadNS.ConditionalFormatting.ComparisonOperators.greaterThan, 50, 0, style, [new spreadNS.Range(r + 1, c, h - 1, w)] ); r = 2; c = 5; sheet.addSpan(r, c, 1, w); sheet.setValue( r, c, "Displays red background: value >= 60 and value <= 70:" ); sheet.getCell(r, c).wordWrap(true); sheet.setRowHeight(r, 40); increase = 0; for (let row = 0; row < h - 1; row++) { for (let col = 0; col < w; col++) { sheet.setValue(row + r + 1, col + c, increase); increase += 10; } } sheet .getRange(r, c, h, w) .setBorder( new spreadNS.LineBorder("Black", spreadNS.LineStyle.dashed), { all: true } ); style = new spreadNS.Style(); style.backColor = "#FFCCCC"; cfs.addCellValueRule( spreadNS.ConditionalFormatting.ComparisonOperators.between, 60, 70, style, [new spreadNS.Range(r + 1, c, h - 1, w)] ); // 2 color scale rule r = 7; c = 1; sheet.addSpan(r, c, 1, w); sheet.setValue( r, c, "Displays two color gradient represents cell value:" ); sheet.getCell(r, c).wordWrap(true); sheet.setRowHeight(r, 40); increase = 0; for (let row = 0; row < h - 1; row++) { for (let col = 0; col < w; col++) { sheet.setValue(row + r + 1, col + c, increase); increase += 10; } } sheet .getRange(r, c, h, w) .setBorder( new spreadNS.LineBorder("Black", spreadNS.LineStyle.dashed), { all: true } ); cfs.add2ScaleRule( spreadNS.ConditionalFormatting.ScaleValueType.lowestValue, null, "#FF9999", spreadNS.ConditionalFormatting.ScaleValueType.highestValue, null, "#9999FF", [new spreadNS.Range(r + 1, c, h - 1, w)] ); // 3 color scale rule r = 7; c = 5; sheet.addSpan(r, c, 1, w); sheet.setValue( r, c, "Displays three color gradient represents cell value:" ); sheet.getCell(r, c).wordWrap(true); sheet.setRowHeight(r, 40); increase = 0; for (let row = 0; row < h - 1; row++) { for (let col = 0; col < w; col++) { sheet.setValue(row + r + 1, col + c, increase); increase += 10; } } sheet .getRange(r, c, h, w) .setBorder( new spreadNS.LineBorder("Black", spreadNS.LineStyle.dashed), { all: true } ); cfs.add3ScaleRule( spreadNS.ConditionalFormatting.ScaleValueType.lowestValue, null, "#FF9999", spreadNS.ConditionalFormatting.ScaleValueType.number, 100, "#99FF99", spreadNS.ConditionalFormatting.ScaleValueType.highestValue, null, "#9999FF", [new spreadNS.Range(r + 1, c, h - 1, w)] ); r = 12; c = 1; sheet.addSpan(r, c, 1, w); sheet.setValue( r, c, "Display blue background if cell value is in next week:" ); sheet.getCell(r, c).wordWrap(true); sheet.setRowHeight(r, 40); increase = 0; for (let row = 0; row < h - 1; row++) { for (let col = 0; col < w; col++) { sheet.setValue( row + r + 1, col + c, this.addDays(new Date(), increase) ); sheet.setFormatter( row + r + 1, col + c, "yyyy/mm/dd", spreadNS.SheetArea.viewport ); increase += 1; } } sheet .getRange(r, c, h, w) .setBorder( new spreadNS.LineBorder("Black", spreadNS.LineStyle.dashed), { all: true } ); style = new spreadNS.Style(); style.backColor = "#CCCCFF"; cfs.addDateOccurringRule( spreadNS.ConditionalFormatting.DateOccurringType.nextWeek, style, [new spreadNS.Range(r + 1, c, h - 1, w)] ); // specific text rule r = 12; c = 5; sheet.addSpan(r, c, 1, w); sheet.setValue( r, c, 'Display red foreground if cell value contains "o":' ); sheet.getCell(r, c).wordWrap(true); sheet.setRowHeight(r, 40); let data = [ "The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog", "The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog" ]; increase = 0; for (let row = 0; row < h - 1; row++) { for (let col = 0; col < w; col++) { sheet.setValue(row + r + 1, col + c, data[increase]); increase += 1; } } sheet .getRange(r, c, h, w) .setBorder( new spreadNS.LineBorder("Black", spreadNS.LineStyle.dashed), { all: true } ); style = new spreadNS.Style(); style.foreColor = "Red"; style.font = "bold 12px sans-serif"; cfs.addSpecificTextRule( spreadNS.ConditionalFormatting.TextComparisonOperators.contains, "o", style, [new spreadNS.Range(r + 1, c, h - 1, w)] ); // data bar rule r = 17; c = 1; sheet.addSpan(r, c, 1, w); sheet.setValue(r, c, "Display a colored data bar represents cell value:"); sheet.getCell(r, c).wordWrap(true); sheet.setRowHeight(r, 40); increase = 0; for (let row = 0; row < h - 1; row++) { for (let col = 0; col < w; col++) { sheet.setValue(row + r + 1, col + c, increase); increase += 10; } } sheet .getRange(r, c, h, w) .setBorder( new spreadNS.LineBorder("Black", spreadNS.LineStyle.dashed), { all: true } ); let dataBarRule = cfs.addDataBarRule( spreadNS.ConditionalFormatting.ScaleValueType.lowestValue, null, spreadNS.ConditionalFormatting.ScaleValueType.highestValue, null, "green", [new spreadNS.Range(r + 1, c, h - 1, w)] ); dataBarRule.gradient(true); dataBarRule.showBorder(false); dataBarRule.showBarOnly(false); // icon set rule r = 17; c = 5; sheet.addSpan(r, c, 1, w); sheet.setValue(r, c, "Displays an icon represents cell value:"); sheet.getCell(r, c).wordWrap(true); sheet.setRowHeight(r, 40); increase = 0; for (let row = 0; row < h - 1; row++) { for (let col = 0; col < w; col++) { sheet.setValue(row + r + 1, col + c, increase); increase += 10; } } sheet .getRange(r, c, h, w) .setBorder( new spreadNS.LineBorder("Black", spreadNS.LineStyle.dashed), { all: true } ); let iconSetRule = cfs.addIconSetRule( spreadNS.ConditionalFormatting.IconSetType.fiveArrowsColored, [new spreadNS.Range(r + 1, c, h - 1, w)] ); iconSetRule.iconSetType(); iconSetRule.reverseIconOrder(false); iconSetRule.showIconOnly(false); sheet.resumePaint(); this.updateRuleCount(); }, // date occurring rule addDays(date, days) { let dt = new Date( date.getFullYear(), date.getMonth(), date.getDate() + days ); if (days) { if (dt.getDate() === date.getDate()) { dt = new Date(date.getFullYear(), date.getMonth(), date.getDate()); dt.setTime(dt.getTime() + days * 24 * 3600 * 1000); } } return dt; }, removeRule() { let sheet = this.spread.getSheet(0); let cfs = sheet.conditionalFormats; let sels = sheet.getSelections(); if (sels && sels.length > 0) { let sel = sels[0]; cfs.removeRuleByRange(sel.row, sel.col, sel.rowCount, sel.colCount); this.updateRuleCount(); } }, clearRule() { let sheet = this.spread.getSheet(0); let cfs = sheet.conditionalFormats; cfs.clearRule(); this.updateRuleCount(); }, updateRuleCount() { let sheet = this.spread.getSheet(0); let cfs = sheet.conditionalFormats; this.ruleCountDescription = "Rule Count: " + cfs.count(); } } }); new Vue({ render: h => h(App) }).$mount("#app"); </script>
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ko/vue/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- SystemJS --> <script src="$DEMOROOT$/ko/vue/node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); System.import('$DEMOROOT$/ko/lib/vue/license.js'); </script> </head> <body> <div id="app"></div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: calc(100% - 280px); height: 100%; overflow: hidden; float: left; } .options-container { float: right; width: 280px; overflow: auto; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; } .option-row { padding-top: 6px; } input { padding: 4px 8px; margin-bottom: 6px; box-sizing: border-box; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }
(function (global) { System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, meta: { '*.css': { loader: 'css' }, '*.vue': { loader: 'vue-loader' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-resources-ko': 'npm:@mescius/spread-sheets-resources-ko/index.js', '@mescius/spread-sheets-vue': 'npm:@mescius/spread-sheets-vue/index.js', '@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js', 'jszip': 'npm:jszip/dist/jszip.js', 'css': 'npm:systemjs-plugin-css/css.js', 'vue': 'npm:vue/dist/vue.min.js', 'vue-loader': 'npm:systemjs-vue-browser/index.js', 'tiny-emitter': 'npm:tiny-emitter/index.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'js' }, rxjs: { defaultExtension: 'js' }, "node_modules": { defaultExtension: 'js' } } }); })(this);