Initialize Sheet

Use the addSheet, removeSheet, clearSheets functions to add, remove, clear sheets, or start editing the active sheet name.

Use the following steps to reference Spread and work with the sheets. Similar to other libraries, Sheet requires the following included files: gc.spread.sheets.x.x.x.css gc.spread.sheets.all.x.x.x.min.js Create a sheet using the following code (the parameter is the sheet's name). Add it at the specified position of an existing Spread component. If you want to remove an existing sheet from the Spread component, use the following code. This example code removes the first sheet in the Spread. If you want to remove all the sheets in the Spread component, use the convenient clearSheets method. If you want to customize the sheet's name, use the name methods to get and set the sheet's name. You can also start editing the active sheet name in the sheet tab by executing the built-in command.
<template> <div class="sample-tutorial"> <gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread"> <gc-worksheet></gc-worksheet> </gc-spread-sheets> <div class="options-container"> <div class="panel-title">Sheet Operations</div> <div class="panel-description">Manage worksheets and start editing the active sheet tab name.</div> <div class="option-row"> <span>Adds a sheet after the active one.</span> <input type="button" value="Add Sheet" id="btnAddSheet" @click="addSheet()" /> </div> <div class="option-row"> <span>Removes the active sheet.</span> <input type="button" value="Remove Sheets" id="btnRemoveSheet" @click="removeSheet()" /> </div> <div class="option-row"> <span>Clears all the sheets from the workbook.</span> <input type="button" value="Remove All Sheets" id="btnClearSheets" @click="clearSheet()" /> </div> <div class="option-row"> <span>Starts editing the active sheet name.</span> <input type="button" value="Start Editing" id="btnStartEditSheetName" @click="startEditSheetName()" /> </div> </div> </div> </template> <script setup> import GC from "@mescius/spread-sheets"; import "@mescius/spread-sheets-vue"; let mySpread; let initSpread = function (spread) { mySpread = spread; } let addSheet = function () { let spread = mySpread; let activeIndex = spread.getActiveSheetIndex(); if (activeIndex >= 0) { spread.addSheet(activeIndex + 1); spread.setActiveSheetIndex(activeIndex + 1); } else { spread.addSheet(0); spread.setActiveSheetIndex(0); } } let removeSheet = function () { if (mySpread.getSheetCount() > 0) { mySpread.removeSheet(mySpread.getActiveSheetIndex()); } } let clearSheet = function () { mySpread.clearSheets(); } let startEditSheetName = function () { mySpread.commandManager().execute({ cmd: 'startEditSheetName' }); } </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: 18px 16px; height: 100%; box-sizing: border-box; background: #f7f9fc; border-left: 1px solid #d7dee8; overflow: auto; color: #263445; } .panel-title { margin-bottom: 6px; color: #172033; font-size: 18px; font-weight: 600; } .panel-description { margin-bottom: 16px; color: #5c6b7a; font-size: 13px; line-height: 1.45; } .option-row { margin-bottom: 12px; padding: 12px; border: 1px solid #dfe5ee; border-radius: 6px; background: #fff; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04); font-size: 14px; line-height: 1.35; } .option-row span { display: block; margin-bottom: 10px; } input { padding: 6px 10px; } input[type=button] { display: block; width: 100%; border: 1px solid #9bb2cf; border-radius: 4px; background: #fff; color: #1f4f82; cursor: pointer; font-weight: 600; } input[type=button]:hover { background: #edf5ff; border-color: #6f98c8; } input[type=button]:focus { outline: 2px solid #8ec5ff; outline-offset: 1px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } </style>
<!DOCTYPE html> <html 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$/en/vue3/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/en/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$/en/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/', 'cdn:': 'https://cdn.mescius.io/demoapps/packages/spreadjs/19.2.2-master-2026-09-02-2133/' }, 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': 'cdn:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-resources-en': 'cdn:@mescius/spread-sheets-resources-en/index.js', '@mescius/spread-sheets-vue': 'cdn:@mescius/spread-sheets-vue/index.js' }, meta: { '*.css': { loader: 'systemjs-plugin-css' }, '*.vue': { loader: "../plugin-vue/index.js" } } }); })(this);