使用 “sheet.visible()” 方法和 sheetTabVisible 来改变工作表是否可见或获取工作表的可见状态。
可见状态:
hidden:工作表标签被隐藏,等于false。
visible:工作表标签可见,等于true,为sheetTabVisible的默认值。
veryHidden:工作表选项卡深度隐藏。
如果你想在Spread组件中获得一个sheet的可见状态,你只需要下面的代码:
如果你想在 Spread 控件隐藏一个表单, 你只需要执行以下代码:
如果你想在 Spread 组件中深度隐藏一个工作表(这意味着它不能通过 UI 取消隐藏),你只需要执行以下代码:
window.onload = function() {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
initSpread(spread);
document.getElementById("btnVisible").addEventListener('click',function() {
for (var i = 0; i < spread.sheets.length; i++) {
if (spread.sheets[i].visible() === 0) {
spread.sheets[i].visible(true);
break;
}
}
});
document.getElementById("btnInvisible").addEventListener('click',function() {
var sheet = spread.getActiveSheet();
if (sheet) {
var activeIndex = spread.getActiveSheetIndex();
if (activeIndex - 1 >= 0) {
spread.setActiveSheetIndex(activeIndex - 1);
}
sheet.visible(false);
}
});
document.getElementById("btnShowVeryHidden").addEventListener('click',function() {
for (var i = 0; i < spread.sheets.length; i++) {
if (spread.sheets[i].visible() === 2) {
spread.sheets[i].visible(true);
break;
}
}
});
document.getElementById("btnVeryHidden").addEventListener('click',function() {
var sheet = spread.getActiveSheet();
if (sheet) {
var activeIndex = spread.getActiveSheetIndex();
if (activeIndex - 1 >= 0) {
spread.setActiveSheetIndex(activeIndex - 1);
}
sheet.visible(2);
}
});
};
function initSpread(spread) {
var sheet = spread.getActiveSheet();
}
<!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$/spread/source/data/data.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">
<input type="button" id="btnVisible" value="Show Sheet" />
</div>
<div class="option-row">
<input type="button" id="btnInvisible" value="Hide Sheet" />
</div>
<div class="option-row">
<input type="button" id="btnVeryHidden" value="Very Hide Sheet" />
</div>
<div class="option-row">
<input type="button" id="btnShowVeryHidden" value="Show Very Hide Sheet" />
</div>
</div>
</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;
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: 6px;
}
input {
padding: 4px 6px;
}
input[type=button] {
margin-top: 6px;
display: block;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}