확인란 셀을 만들려면 다음 예를 따르십시오.
CheckBox는 세 가지 상태의 확인란을 지원할 수 있습니다. isThreeState 메서드를 사용하여 확인란이 세 가지 상태를 지원하는지 여부를 가져오고 설정할 수 있습니다. 예:
세 가지 상태는 true, false 또는 indeterminate입니다. 모든 상태에는 자체 텍스트가 있으며 textTrue, textFalse 및 textIndeterminate 메서드를 사용하여 이러한 상태의 텍스트를 가져오고 설정할 수 있습니다. 예:
caption 메서드를 사용하여 확인란 셀의 캡션을 가져오고 설정할 수 있습니다. textAlign 메서드를 사용하여 확인란과 관련된 텍스트 정렬을 가져오고 설정합니다. 설정은 CheckBoxTextAlign 열거 값입니다.
top: 텍스트가 체크박스의 위쪽에 있습니다.
bottom: 텍스트가 체크박스의 아래쪽에 있습니다.
left: 텍스트가 체크박스의 왼쪽에 있습니다.
right: 텍스트가 체크박스의 오른쪽에 있습니다.
boxSize 메서드를 사용하여 체크박스 크기를 가져와 설정할 수 있습니다. cellType으로 숫자 또는 "auto"를 설정할 수 있습니다.
셀 스타일 "wordWrap”이 true로 설정되고 셀 너비가 텍스트에 충분하지 않다면 텍스트는 줄바꿈되어 표시됩니다.
<template>
<div class="sample-tutorial">
<gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread">
<gc-worksheet></gc-worksheet>
</gc-spread-sheets>
<div class="options-container">
<label>Select the check box cell in Spread and edit its options with these text boxes.</label>
<div class="option-row" v-if="hasCaption === null || hasCaption">
<label for="caption">caption:</label>
<input id="caption" type="text" v-model="caption" />
</div>
<div class="option-row" v-if="hasCaption === null || !hasCaption">
<label for="textTrue">textTrue:</label>
<input id="textTrue" type="text" v-model="textTrue" />
</div>
<div class="option-row" v-if="hasCaption === null || !hasCaption">
<label for="textIndeterminate">textIndeterminate(for 3-state option):</label>
<input id="textIndeterminate" type="text" v-model="textIndeterminate" />
</div>
<div class="option-row" v-if="hasCaption === null || !hasCaption">
<label for="textFalse">textFalse:</label>
<input id="textFalse" type="text" v-model="textFalse" />
</div>
<div class="option-row" v-if="hasCaption === null || !hasCaption">
<label for="boxSize">boxSize:</label>
<input id="boxSize" type="text" v-model="boxSize" />
</div>
<div class="option-row">
<label>textAlign:</label>
<select id="textAlign" v-model="textAlign">
<option value="0">top</option>
<option value="1">bottom</option>
<option value="2">left</option>
<option value="3">right</option>
</select>
</div>
<div class="option-row" v-if="hasCaption === null || !hasCaption">
<input id="isThreeState" type="checkbox" checked="checked" v-model="isThreeState" />
<label for="isThreeState">isThreeState:</label>
</div>
<div class="option-row">
<input type="button" id="setProperty" value="Update" :disabled="disabled" @click="propertyChange($event, true)" />
</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";
const spreadNS = GC.Spread.Sheets;
let App = Vue.extend({
name: "app",
data: function() {
return {
caption: '',
textTrue: 'textTrue',
textIndeterminate: 'textIndeterminate',
textFalse: 'textFalse',
textAlign: 'top',
isThreeState: true,
disabled: false,
hasCaption: null,
spread: null,
boxSize: 12,
};
},
methods: {
initSpread(spread) {
this.spread = spread;
const sheet = spread.getSheet(0);
sheet.bind(spreadNS.Events.SelectionChanged, (e) => {
this.propertyChange(e);
});
sheet.suspendPaint();
sheet.setColumnWidth(1, 120);
sheet.setColumnWidth(2, 130);
sheet.setRowHeight(1, 35);
sheet.setValue(1, 1, "caption");
sheet.getCell(1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign.center).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("green");
const captionCellType = new GC.Spread.Sheets.CellTypes.CheckBox();
captionCellType.caption("Caption");
sheet.setCellType(1, 2, captionCellType);
sheet.getCell(1, 2).hAlign(GC.Spread.Sheets.HorizontalAlign.center).vAlign(GC.Spread.Sheets.VerticalAlign.center);
sheet.setRowHeight(3, 35);
sheet.setValue(3, 1, "threeState");
sheet.getCell(3, 1).hAlign(GC.Spread.Sheets.HorizontalAlign.center).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("red");
const threeStateCellType = new GC.Spread.Sheets.CellTypes.CheckBox();
threeStateCellType.isThreeState(false);
threeStateCellType.textTrue("Checked!");
threeStateCellType.textFalse("Check Me!");
sheet.setCellType(3, 2, threeStateCellType);
sheet.getCell(3, 2).hAlign(GC.Spread.Sheets.HorizontalAlign.center).vAlign(GC.Spread.Sheets.VerticalAlign.center);
sheet.setRowHeight(5, 35);
sheet.setValue(5, 1, "textAlign");
sheet.getCell(5, 1).hAlign(GC.Spread.Sheets.HorizontalAlign.center).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("blue");
const textAlignCellType = new GC.Spread.Sheets.CellTypes.CheckBox();
textAlignCellType.isThreeState(false);
textAlignCellType.caption("textAlign");
textAlignCellType.textAlign(GC.Spread.Sheets.CellTypes.CheckBoxTextAlign.bottom);
sheet.setCellType(5, 2, textAlignCellType);
sheet.getCell(5, 2).hAlign(GC.Spread.Sheets.HorizontalAlign.center).vAlign(GC.Spread.Sheets.VerticalAlign.center);
sheet.setRowHeight(7, 35);
sheet.setValue(7, 1, "text wrap");
sheet.getCell(7, 1).hAlign(GC.Spread.Sheets.HorizontalAlign.center).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("orange");
const textWrapCellType = new GC.Spread.Sheets.CellTypes.CheckBox();
textWrapCellType.caption("This is a long long text");
sheet.setCellType(7, 2, textWrapCellType);
sheet.getCell(7, 2).wordWrap(true);
sheet.resumePaint();
},
propertyChange(e, settings) {
const sheet = this.spread.getActiveSheet();
const sels = sheet.getSelections();
if (sels && sels.length > 0) {
const sel = this.getActualRange(sels[0], sheet.getRowCount(), sheet.getColumnCount());
const checkboxCellType = sheet.getCellType(sel.row, sel.col);
if (!(checkboxCellType instanceof spreadNS.CellTypes.CheckBox)) {
this.disabled = true;
return;
}
if (!settings) {
this.disabled = false;
this.hasCaption = checkboxCellType.caption() ? true : false;
this.caption = checkboxCellType.caption();
this.textTrue = checkboxCellType.textTrue();
this.textIndeterminate = checkboxCellType.textIndeterminate();
this.textFalse = checkboxCellType.textFalse();
this.textAlign = checkboxCellType.textAlign();
this.isThreeState = checkboxCellType.isThreeState();
this.boxSize = checkboxCellType.boxSize();
} else {
checkboxCellType.caption(this.caption);
checkboxCellType.textTrue(this.textTrue);
checkboxCellType.textIndeterminate(this.textIndeterminate);
checkboxCellType.textFalse(this.textFalse);
checkboxCellType.textAlign(Number(this.textAlign));
checkboxCellType.isThreeState(this.isThreeState);
var boxSize = Number(this.boxSize);
if (isNaN(boxSize)) {
checkboxCellType.boxSize(this.boxSize);
} else {
checkboxCellType.boxSize(boxSize);
}
}
}
sheet.repaint();
},
getActualRange(range, maxRowCount, maxColCount) {
const row = range.row < 0 ? 0 : range.row;
const col = range.col < 0 ? 0 : range.col;
const rowCount = range.rowCount < 0 ? maxRowCount : range.rowCount;
const colCount = range.colCount < 0 ? maxColCount : range.colCount;
return new spreadNS.Range(row, col, rowCount, colCount);
}
}
});
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;
}
.sample-options{
z-index: 1000;
}
.option {
padding-bottom: 6px;
}
.option-row {
font-size: 14px;
padding: 5px;
}
.checkbox {
padding-right: 12px;
display: inline-block;
}
label {
padding-bottom: 4px;
display: block;
}
input, select {
width: 100%;
padding: 4px 8px;
box-sizing: border-box;
}
input[type=checkbox] {
width: auto;
}
input[type=checkbox]+label {
display: inline-block;
width: auto;
}
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);