SpreadJSは、1つのシートは4つの領域で構成されます。
corner
colHeader
rowHeader
viewport
つまり、シートには行ヘッダと列ヘッダの2つのヘッダがあり、どちらのヘッダも複数行および複数列で作成できます。
ヘッダ行およびヘッダ列のいずれか1つでは、列および行のインデックスを示す自動テキストが各セルに表示されます。自動テキストが表示される行または列を確認したい場合や、指定の行または列に自動テキストを表示させたい場合には、次のようなコードを使用します。
SpreadJSでは、ヘッダの自動テキストとして空白、文字、数字の3タイプを選択できます。
行ヘッダまたは列ヘッダを非表示にすることもできます。次のコードは、行ヘッダ内のすべての行を非表示にします。
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
var spreadNS = GC.Spread.Sheets;
var sheet = spread.getSheet(0);
sheet.suspendPaint();
//Set rowHeader count and columnHeader count.
sheet.setRowCount(3, spreadNS.SheetArea.colHeader);
sheet.setColumnCount(3, spreadNS.SheetArea.rowHeader);
//Change header "auto text".
sheet.options.colHeaderAutoTextIndex = 2;
sheet.options.colHeaderAutoText = spreadNS.HeaderAutoText.numbers;
//Span three columns with the origin at column header cell (0,0).
sheet.addSpan(0, 0, 10, 1, GC.Spread.Sheets.SheetArea.rowHeader);
sheet.addSpan(0, 1, 5, 1, GC.Spread.Sheets.SheetArea.rowHeader);
sheet.addSpan(5, 1, 5, 1, GC.Spread.Sheets.SheetArea.rowHeader);
sheet.setValue(0, 1, "Sub 1.", GC.Spread.Sheets.SheetArea.rowHeader);
sheet.setValue(5, 1, "Sub 2.", GC.Spread.Sheets.SheetArea.rowHeader);
sheet.setValue(0, 0, "Cat.", GC.Spread.Sheets.SheetArea.rowHeader);
sheet.addSpan(0, 0, 2, 1, GC.Spread.Sheets.SheetArea.colHeader);
sheet.addSpan(0, 1, 1, 2, GC.Spread.Sheets.SheetArea.colHeader);
sheet.addSpan(0, 3, 2, 1, GC.Spread.Sheets.SheetArea.colHeader);
sheet.addSpan(0, 4, 2, 1, GC.Spread.Sheets.SheetArea.colHeader);
sheet.addSpan(0, 5, 2, 1, GC.Spread.Sheets.SheetArea.colHeader);
sheet.addSpan(0, 6, 2, 1, GC.Spread.Sheets.SheetArea.colHeader);
sheet.setValue(0, 0, "No.", GC.Spread.Sheets.SheetArea.colHeader);
sheet.setValue(0, 1, "Company", GC.Spread.Sheets.SheetArea.colHeader);
sheet.setValue(0, 3, "Order ID", GC.Spread.Sheets.SheetArea.colHeader);
sheet.setValue(0, 4, "Customer ID", GC.Spread.Sheets.SheetArea.colHeader);
sheet.setValue(0, 5, "Employee ID", GC.Spread.Sheets.SheetArea.colHeader);
sheet.setValue(0, 6, "Order Date", GC.Spread.Sheets.SheetArea.colHeader);
sheet.setValue(1, 1, "Country", GC.Spread.Sheets.SheetArea.colHeader);
sheet.setValue(1, 2, "Company Name", GC.Spread.Sheets.SheetArea.colHeader);
sheet.getCell(-1, 0).width(40);
sheet.getRange(-1, 1, 1, 6).width(130);
sheet.getRange(-2, 1, 1, 2).width(130);
sheet.resumePaint();
/*
* Show or hide the row header.
*/
_getElementById("chkRowHeaderVisible").addEventListener('click',function () {
var sheet = spread.getActiveSheet();
sheet.options.rowHeaderVisible = this.checked;
spread.invalidateLayout();
spread.repaint();
});
/*
* Show or hide the column header.
*/
_getElementById("chkColumnHeaderVisible").addEventListener('click',function () {
var sheet = spread.getActiveSheet();
sheet.options.colHeaderVisible = this.checked;
spread.invalidateLayout();
spread.repaint();
});
_getElementById("btnSetAutoText").addEventListener('click',function () {
var headerType = document.querySelector("input[name='headerType']:checked").value,
obj=_getElementById("headerAutoTextType"),
headerAutoTextType = obj.options[obj.selectedIndex].value;
if (headerAutoTextType) {
headerAutoTextType = spreadNS.HeaderAutoText[headerAutoTextType];
if (!(headerAutoTextType === undefined)) {
switch (headerType) {
case "row":
sheet.options.rowHeaderAutoText = headerAutoTextType;
break;
case "column":
sheet.options.colHeaderAutoText = headerAutoTextType;
break;
}
}
}
});
};
function _getElementById(id) {
return document.getElementById(id);
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta name="spreadjs culture" content="ja-jp" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-resources-ja/dist/gc.spread.sheets.resources.ja.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="checkbox" id="chkColumnHeaderVisible" checked />
<label for="chkColumnHeaderVisible">列ヘッダを表示する</label>
</div>
<div class="option-row">
<input type="checkbox" id="chkRowHeaderVisible" checked />
<label for="chkRowHeaderVisible">行ヘッダを表示する</label>
</div>
<hr>
<div class="option-row">
<label >以下のオプションを使用して、ヘッダの自動テキストの種類を設定します。</label>
</div>
<div class="option-row">
<input type="radio" name="headerType" value="row" id="headerTypeRow" /><label for="headerTypeRow">行</label>
<input type="radio" name="headerType" value="column" id="headerTypeColumn" checked="checked" /><label for="headerTypeColumn">列</label>
</div>
<div class="option-row">
<label for="headerAutoTextType" style="display:inline-block;">ヘッダの自動テキストの種類:</label>
</div>
<select id="headerAutoTextType" style="padding-left: 5px">
<option value="blank">Blank</option>
<option value="letters" selected="selected">Letters</option>
<option value="numbers">Numbers</option>
</select>
<input type="button" id="btnSetAutoText" value="設定" />
</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 {
margin-bottom: 6px;
}
input {
padding: 4px 6px;
}
input[type=button] {
margin-top: 6px;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}