기본값

SpreadJS는 값이나 수식일 수 있는 셀 기본값 설정을 지원합니다. 기본값/수식이 있는 셀에 데이터를 입력할 수 있으며, 기본값/수식은 재정의되지 않습니다.

defaultValue API는 셀에 기본값/수식을 설정하는 데 사용합니다. 셀이 비어 있으면 기본값을 표시하거나 기본 수식에서 계산된 값을 표시합니다. 빈 셀에 기본값/수식이 적용되어 있는데 사용자가 해당 셀을 편집하면 기본값이 재정의되지 않습니다. API는 다음과 같습니다.
<template> <div class="sample-tutorial"> <gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread"> <gc-worksheet></gc-worksheet> <gc-worksheet /> </gc-spread-sheets> <div class="options-container"> <div class="option-row"> <p> <span>You can set, get the default value and formula for the active cells.</span> </p> </div> <div class="option-row"> <label for="value">Default Value: </label> <input id="value" v-model="value" /> </div> <div class="option-row"> <label for="formula">Default Formula: </label> <div id="formula" spellcheck="false" style="border: 1px solid #808080;width:100%;height:21px;overflow:hidden;"></div> </div> <div class="option-row"> <input type="button" id="btnSetDefault" value="Set Default" title="Set default value and formula to selected item(s)" @click="handleSetDefault" /> </div> <div class="option-row"> <label for="showDefault">Get Default Value: </label> <textarea id="showDefault" cols="31" readonly v-model="showDefault"></textarea> </div> </div> </div> </template> <script> import Vue from 'vue'; import "@mescius/spread-sheets-io"; import '@mescius/spread-sheets-vue' import GC from '@mescius/spread-sheets'; import '@mescius/spread-sheets-resources-ko'; GC.Spread.Common.CultureManager.culture("ko - kr"); import './styles.css'; let getFileUrl = () => { return '$DEMOROOT$/spread/source/data/defaultValue.sjs'; } let App = Vue.extend({ name: "app", data: function () { return { spread: null, fbx: null, value: '', showDefault: '' }; }, methods: { initSpread(spread) { this.spread = spread; this.fbx = new GC.Spread.Sheets.FormulaTextBox.FormulaTextBox(document.getElementById('formula'), {rangeSelectMode: true}); this.fbx.workbook(spread); fetch(getFileUrl()).then(res => res.blob()).then(file => { spread.open(file, () => { let sheet = spread.getActiveSheet(); sheet.suspendPaint(); sheet.suspendCalcService(); for (let i = 0; i < 12; i++) { sheet.getCell(2, 3 + i, 3).defaultValue('=$B3/12'); sheet.getCell(3, 3 + i, 3).defaultValue('=$B4/12'); } sheet.resumeCalcService(); sheet.resumePaint(); this.getDefault(spread); }); }); this.bindEvents(spread); }, bindEvents(spread) { let self = this; spread.bind(GC.Spread.Sheets.Events.SelectionChanged, function () { self.getDefault(spread); }); spread.bind(GC.Spread.Sheets.Events.ActiveSheetChanged, function () { self.getDefault(spread); }); }, handleSetDefault () { let spread = this.spread; let sheet = spread.getActiveSheet(); let value = this.value; let selections = sheet.getSelections(); if (!selections || selections.length === 0) { return; } sheet.suspendPaint(); let length = selections.length; for (let i = 0; i < length; i++) { let sel = selections[i], rowIndex = sel.row, colIndex = sel.col, rowCount = sel.rowCount, colCount = sel.colCount, maxRow = rowIndex + rowCount, maxColumn = colIndex + colCount, r, c; if (rowIndex !== -1 && colIndex !== -1) { for (r = rowIndex; r < maxRow; r++) { for (c = colIndex; c < maxColumn; c++) { sheet.setDefaultValue(r, c, this.fbx.text() || this.convertValue(value)); } } } } sheet.resumePaint(); this.getDefault(spread); }, getDefault (spread) { let sheet = spread.getActiveSheet(), selections = sheet.getSelections(); if (!selections || selections.length === 0) { this.showDefault = ''; return; } let sel = selections[0], row = sel.row, col = sel.col; this.showDefault = sheet.getDefaultValue(row, col) || ''; }, convertValue (value) { if (!value) { return value; } // try to convert to number let num = Number(value); if (!isNaN(num)) { return num; } // try to convert to boolean if (value.toLowerCase() === "true" || value.toLowerCase() === "false") { return value.toLowerCase() === "true"; } // try to convert to date let date = new Date(value); if (!isNaN(date.getTime())) { return date; } return value; } }, computed: { dataSource() { return getData(); } } }); 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"> <script src="$DEMOROOT$/spread/source/data/budget.js" type="text/javascript"></script> <!-- 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 { position: relative; height: 100%; overflow: auto; } .sample::after { display: block; content: ""; clear: both; } .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; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; overflow: auto; } .option-row { font-size: 14px; padding: 5px; margin-top: 10px; } label { display: inline-block; margin-bottom: 6px; } input { padding: 4px; width: 100%; margin: 0 4px 4px 0; box-sizing: border-box; } input[type=button] { width: 30%; } p { background-color: #F4F8EB; padding: 4px; } p span { display: block; } 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-io': 'npm:@mescius/spread-sheets-io/index.js', '@mescius/spread-sheets-vue': 'npm:@mescius/spread-sheets-vue/index.js', '@mescius/spread-sheets-resources-ko': 'npm:@mescius/spread-sheets-resources-ko/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);