当你选择并轻击选择区域时,会显示一个触摸工具栏。
你可以使用内置工具栏选项: Paste, Cut, Copy, and AutoFill。
你也可以自定义一个触摸工具栏选项并加入到触摸工具栏中。
你可以调用 text 方法来获取或设置选项的文本,调用 font 方法设置选项文本的字体,使用foreColor 方法设置选项文本的前景色。
在你添加触摸工具栏选项之后,你可以调用 getItem 和 getItems 方法来获得这些选项。你也可以删除一些选项或者清除所有选项。
你可以通过提供的应用程序接口来自定义工具栏选项。例如:
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), {sheetCount: 3});
initSpread(spread);
};
function _getElementById(id) {
return document.getElementById(id);
}
function initSpread(spread) {
var sheet = spread.sheets[0];
_getElementById('addItem').onclick = function () {
var name = _getElementById('name').value;
if (!name) {
alert("Please input a name for toolbar item.")
}
var text = _getElementById('text').value;
var image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8' +
'YQUAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAABMklEQVRIS7XSMUpDQRDG8YCt' +
'FxDsbb1H4lW8wnt38BA2VmIfC0mhhYVVIJXybC0U0gibbx47w+zm290nPIsfbDY7/4GQRQjhX9HLOdHL' +
'OdHLOdFL5ut243UQMnI3fu/nkg81OhxDeVyNS/xc8qFGBmOAhb3OzyWRGhnMQkV+LonU/Dxt1yzG+Dk7' +
'bJ5fSrrtbrfGm7B/e6fBnDZFa0EHQXwMA55NWyI9VVtgcTVxSa9NUVpwFFeNJT1YU7AFxbgqLBnjrQXN' +
'uNIl+Hc9+nhtwVkeaYn/riSYswMGVnmg4ReufYyxAx5P/nngG64giTF2wOP7ONwywCXITBJj7IDHn8CC' +
'3iucwxgXPsbYAY97YFH1AKdgceFjjB3iQGnJDZxAEhc+xtDL3MXyLvyVzh7F5hUWB34T0LLVazuTAAAA' +
'AElFTkSuQmCC';
var item = new GC.Spread.Sheets.Touch.TouchToolStripItem(name, text, image, function () {
spread.touchToolStrip.close();
alert("Runing clearing...");
});
spread.touchToolStrip.add(item);
};
_getElementById('removeItem').onclick = function () {
var name = _getElementById('name').value;
if (!name) {
alert("Please input the name which item to be removed.");
}
spread.touchToolStrip.remove(name);
};
_getElementById('clear').onclick = function () {
spread.touchToolStrip.clear();
}
_getElementById('addSeparator').onclick = function () {
spread.touchToolStrip.add(new GC.Spread.Sheets.Touch.TouchToolStripSeparator());
};
_getElementById('setFont').onclick = function () {
var font = _getElementById('font').value;
if (!font) {
alert("Please input a font for item text.");
}
var name = _getElementById('name').value;
var item = spread.touchToolStrip.getItem(name);
if (item) {
item.font(font);
}
};
_getElementById('setForeColor').onclick = function () {
var foreColor = _getElementById('color').value;
if (!foreColor) {
alert("Please input a color for item text.");
}
var name = _getElementById('name').value;
var item = spread.touchToolStrip.getItem(name);
if (item) {
item.foreColor(foreColor);
}
};
};
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta name="spreadjs culture" content="zh-cn" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css"
href="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/dist/gc.spread.sheets.all.min.js"
type="text/javascript"></script>
<script
src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets-resources-zh/dist/gc.spread.sheets.resources.zh.min.js"
type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="sample-tutorial">
<div id="ss" class="sample-spreadsheets"></div>
<div class="options-container">
<div class="option-row">
<span>Select a cell using a touch enabled device.Select that cell again to view the customizable touch
toolstrip.
</span>
</div>
<div class="option-row">
<span>Customize Toolstrip</span>
</div>
<div class="option-row">
<span>Add new menu item:</span>
</div>
<div class="option-row">
<label for="name">Name:</label>
<input id="name" value="demo_clear" />
</div>
<div class="option-row">
<label for="text">Text:</label>
<input id="text" value="clear" />
</div>
<div class="option-row">
<input type="button" value="Add Item" id="addItem" class="toolbar-setting" />
<input type="button" value="Add Separator" id="addSeparator" class="toolbar-setting" />
</div>
<span>Toolstrip Item Style:</span>
<div class="option-row">
<input id="font" value="18px Arial" />
<input type="button" id="setFont" value="Set Font"
title="Set font for toolstrip item with specified name" />
</div>
<div class="option-row">
<input id="color" value="red" />
<input type="button" id="setForeColor" value="Set Fore Color"
title="Set fore color for toolstrip item with specified name" />
</div>
<div class="option-row">
<input type="button" value="Remove Toolstrip Item" id="removeItem" />
<input type="button" value="Clear All Toolstrip Items" id="clear" />
</div>
</div>
</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;
}
label {
display: inline-block;
min-width: 80px;
}
input,
select {
padding: 4px 8px;
margin-top: 6px;
width: 100%;
box-sizing: border-box;
}
.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;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}