The following sample shows how to make a shape a Text Box.
Every autoShape can be changed to a text box.
<template>
<div class="sample-tutorial">
<gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread">
</gc-spread-sheets>
<div class="options-container">
<div class="options-title">Options</div>
<div class="options-tips">{{ optionsTipsRef }}</div>
<input type="checkbox" id="isTextBoxOption" v-model="isTextBox" @change="handleIsTextBoxChange"
:disabled="!isShapeSelected" />
<label for="isTextBoxOption">isTextBox</label>
<br />
<input type="checkbox" id="resizeToFitTextOption" v-model="resizeToFitText" @change="handleresizeToFitTextChange"
:disabled="!isShapeSelected" />
<label for="resizeToFitTextOption">resizeToFitText</label>
</div>
</div>
</template>
<script setup>
import GC from "@mescius/spread-sheets";
import { ref } from "vue";
import "@mescius/spread-sheets-vue";
import '@mescius/spread-sheets-shapes';
let spreadObj;
const shapeTips = "Text Box With resizeToFitText\nPlease try typing some text here.";
const optionsTips = "Please select a shape and try to modify the options.";
function setTextBox(shape) {
let shapeStyle = shape.style();
shapeStyle.fill.color = 'white';
shapeStyle.textEffect.color = 'black';
shapeStyle.line.color = 'black';
shape.style(shapeStyle);
shape.isTextBox(true);
}
let isTextBox = ref(false);
let resizeToFitText = ref(false);
let isShapeSelected = ref(false);
const initSpread = (spread) => {
spreadObj = spread;
let sheet = spread.getActiveSheet();
addShape();
sheet.bind(GC.Spread.Sheets.Events.ShapeSelectionChanged, undefined, (type, data) => {
let shape = data.shape;
if (shape && shape.isSelected()) {
isTextBox.value = shape.isTextBox();
resizeToFitText.value = shape.style().textFrame.resizeToFitText;
isShapeSelected.value = true;
} else {
isShapeSelected.value = false;
}
});
}
function addShape() {
const sheet = spreadObj.getActiveSheet();
let textBox = sheet.shapes.add('', GC.Spread.Sheets.Shapes.AutoShapeType.rectangle, 100, 50);
setTextBox(textBox);
textBox.text("Text Box");
let textBox2 = sheet.shapes.add('', GC.Spread.Sheets.Shapes.AutoShapeType.rectangle, 350, 50, 250);
textBox2.text(shapeTips);
setTextBox(textBox2);
let style = textBox2.style();
style.textFrame.resizeToFitText = true;
textBox2.style(style);
}
function handleIsTextBoxChange() {
let shapes = spreadObj.getActiveSheet().shapes.all();
shapes.filter((shape) => shape.isSelected()).forEach((shape) => {
shape.isTextBox(isTextBox.value);
});
}
function handleresizeToFitTextChange() {
let shapes = spreadObj.getActiveSheet().shapes.all();
shapes.filter((shape) => shape.isSelected()).forEach((shape) => {
let shapeStyle = shape.style();
shapeStyle.textFrame.resizeToFitText = resizeToFitText.value;
shape.style(shapeStyle);
});
}
</script>
<style scoped>
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
#app {
width: 100%;
height: 100%;
}
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: calc(100% - 250px);
height: 100%;
/* overflow: hidden; */
}
.options-container {
position: absolute;
top: 0px;
right: 0px;
width: 250px;
height: 100%;
padding: 12px;
box-sizing: border-box;
background: #fbfbfb;
overflow: auto;
user-select: none;
}
.options-title {
font-size: larger;
font-weight: bolder;
margin-bottom: 10px;
}
.options-tips {
margin-bottom: 10px;
}
</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/'
},
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-shapes': 'npm:@mescius/spread-sheets-shapes/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);