ワークシートにアクセスするには、WorkbookオブジェクトのgetSheetメソッドでワークブックのインデックスを使用するか、getSheetFromNameメソッドでワークシートのタブ名を使用します。例として:
WorkbookオブジェクトのgetActiveSheetメソッドを使用して、現在のアクティブなワークシートのインスタンスを取得します。
アクティブなワークシートを変更するには、setActiveSheetIndexメソッドを使用して、目的のシートのインデックスを指定します。 例として:
ワークシートへの参照を取得したら、デモに示されるようなカスタマイズにそれを使用できます。
ワークブックシートを操作する、その他の便利な方法:
addSheet:ワークブックの特定の位置に名前付きシートを追加します。
getSheetCount:ワークブック内のシートの数を取得し、それを使用してワークブックにシートを追加します。
removeSheetおよびclearSheets:インデックスでシートを削除するか、ワークブックのすべてのシートをクリアします。
getActiveSheetIndex:アクティブなシートのインデックスを取得します。
changeSheetIndex:アクティブなシートを別のインデックスに変更します。
<template>
<div class="sample-tutorial">
<gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread">
<gc-worksheet></gc-worksheet>
<gc-worksheet></gc-worksheet>
<gc-worksheet></gc-worksheet>
</gc-spread-sheets>
<div class="options-container">
<div class="option-row">
<label>以下のボタンを使用して、現在のワークブックからすべてのシートを追加、削除、またはクリアします。</label>
</div>
<div class="option-row">
<input type="button" value="シートを追加" id="btnAddSheet" @click="addSheet($event)" />
<input type="button" value="シートを削除" id="btnRemoveSheet" @click="removeSheet($event)" />
<input type="button" value="シートをクリア" id="btnClearSheets" @click="clearSheets($event)" />
</div>
<div class="option-row">
<label>アクティブシートのインデックス:</label>
<input type="text" id="activeSheetIndex" v-model="activeSheetIndex" />
<input type="button" id="btnSetActiveSheetIndex" value="設定" @click="setActiveSheetIndex($event)" />
</div>
<div class="option-row">
<label>このボタンをクリックすると、現在のアクティブなシートが、指定したインデックスのシートに切り替わります。</label>
</div>
<div class="option-row">
<label>変更するシートのインデックス</label>
<label>シートの名前:</label>
<input type="text" v-model="sheetName" />
<label>ターゲットのインデックス:</label>
<input type="text" v-model="targetIndex" />
<input type="button" value="設定" @click="changeSheetIndex($event)" />
</div>
</div>
</div>
</template>
<script setup>
import GC from "@mescius/spread-sheets";
import { ref } from "vue";
import "@mescius/spread-sheets-vue";
import '@mescius/spread-sheets-resources-ja';
GC.Spread.Common.CultureManager.culture("ja-jp");
let spread = null;
const activeSheetIndex = ref(0);
const sheetName = ref('Sheet1');
const targetIndex = ref(2);
const initSpread = (s) => spread = s;
const addSheet = () => {
const activeIndex = spread.getActiveSheetIndex();
if (activeIndex >= 0) {
spread.addSheet(activeIndex + 1);
spread.setActiveSheetIndex(activeIndex + 1);
}
else {
spread.addSheet(0);
spread.setActiveSheetIndex(0);
}
}
const removeSheet = () => {
const activeIndex = spread.getActiveSheetIndex();
if (activeIndex >= 0) {
spread.removeSheet(activeIndex);
}
}
const clearSheets = () => {
spread.clearSheets();
}
const setActiveSheetIndex = () => {
let index = activeSheetIndex.value;
if (!isNaN(index)) {
index = parseInt(index);
if (0 <= index && index < spread.getSheetCount()) {
spread.setActiveSheetIndex(index);
}
}
}
const changeSheetIndex = () => {
let index = targetIndex.value;
if (!isNaN(index)) {
index = parseInt(index);
if (0 <= index && index <= spread.getSheetCount()) {
spread.changeSheetIndex(sheetName.value, index);
}
}
}
</script>
<style scoped>
#app {
height: 100%;
}
.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: block;
margin-bottom: 3px;
margin-top: 3px;
}
input {
padding: 4px 6px;
}
input[type=button] {
margin-top: 6px;
display: block;
width: 100%;
text-align: center;
}
input[type=text] {
width: 230px;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right:0;
}
</style>
<!DOCTYPE html>
<html lang="en" style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>SpreadJS VUE</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css"
href="$DEMOROOT$/ja/vue3/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/ja/vue3/node_modules/systemjs/dist/system.src.js"></script>
<script src="./systemjs.config.js"></script>
<script src="./compiler.js" type="module"></script>
<script>
var System = SystemJS;
System.import("./src/app.js");
System.import('$DEMOROOT$/ja/lib/vue3/license.js');
</script>
</head>
<body>
<div id="app"></div>
</body>
</html>
(function (global) {
SystemJS.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
packageConfigPaths: [
'./node_modules/*/package.json',
"./node_modules/@mescius/*/package.json",
"./node_modules/@babel/*/package.json",
"./node_modules/@vue/*/package.json"
],
map: {
'vue': "npm:vue/dist/vue.esm-browser.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",
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-resources-ja': 'npm:@mescius/spread-sheets-resources-ja/index.js',
'@mescius/spread-sheets-vue': 'npm:@mescius/spread-sheets-vue/index.js'
},
meta: {
'*.css': { loader: 'systemjs-plugin-css' },
'*.vue': { loader: "../plugin-vue/index.js" }
}
});
})(this);