SpreadJSは、1つのシートは4つの領域で構成されます。
corner
colHeader
rowHeader
viewport
つまり、シートには行ヘッダと列ヘッダの2つのヘッダがあり、どちらのヘッダも複数行および複数列で作成できます。
ヘッダ行およびヘッダ列のいずれか1つでは、列および行のインデックスを示す自動テキストが各セルに表示されます。自動テキストが表示される行または列を確認したい場合や、指定の行または列に自動テキストを表示させたい場合には、次のようなコードを使用します。
SpreadJSでは、ヘッダの自動テキストとして空白、文字、数字の3タイプを選択できます。
行ヘッダまたは列ヘッダを非表示にすることもできます。次のコードは、行ヘッダ内のすべての行を非表示にします。
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import './styles.css';
import { AppFunc } from './app-func';
import { App } from './app-class';
// 1. Functional Component sample
ReactDOM.render(<AppFunc />, document.getElementById('app'));
// 2. Class Component sample
// ReactDOM.render(<App />, document.getElementById('app'));
import * as React from 'react';
import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react';
import GC from '@mescius/spread-sheets';
import '@mescius/spread-sheets-resources-ja';
GC.Spread.Common.CultureManager.culture("ja-jp");
import './styles.css';
const useState = React.useState, spreadNS = GC.Spread.Sheets;
export function AppFunc() {
const [spread, setSpread] = useState(null);
const initSpread = (spread) => {
setSpread(spread);
let spreadNS = GC.Spread.Sheets;
let 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();
}
const checkRowHeaderVisible = ($event) => {
let sheet = spread.getActiveSheet();
sheet.options.rowHeaderVisible = $event.target.checked;
spread.invalidateLayout();
spread.repaint();
}
const checkColumnHeaderVisible = ($event) => {
let sheet = spread.getActiveSheet();
sheet.options.colHeaderVisible = $event.target.checked;
spread.invalidateLayout();
spread.repaint();
}
const setAutoText = (autoTextInfo) => {
let { headerType, headerAutoTextType } = autoTextInfo;
let sheet = spread.getActiveSheet();
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;
}
}
}
}
return (
<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => initSpread(spread)}>
<Worksheet>
</Worksheet>
</SpreadSheets>
</div>
<PanelFunc
checkRowHeaderVisible={(e) => checkRowHeaderVisible(e)}
checkColumnHeaderVisible={(e) => checkColumnHeaderVisible(e)}
setAutoText={(autoTextInfo) => setAutoText(autoTextInfo)}
></PanelFunc>
</div>
);
}
function CheckBoxInput(props) {
const [checked, setChecked] = useState(props.checked);
return (
<input type="checkbox" id={props.id} checked={checked} onChange={(e) => {
setChecked(e.target.checked);
props.onChange(e)
}} />
);
}
function RadioInput(props) {
let [value, setValue] = useState(props.defaultValue);
let radios = [];
for (let i = 0; i < props.radios.length; i++) {
radios.push(
<input type="radio" name={props.name} value={props.radios[i].value} id={props.radios[i].id}
checked={props.radios[i].value === value ? true : false}
onChange={($event) => {
setValue($event.target.value)
props.onChange($event.target.value);
}} />
);
if (props.radios[i].label) {
radios.push(
<label htmlFor={props.radios[i].id}>{props.radios[i].label}</label>
);
}
}
return radios;
}
function SelectInput(props) {
const [value, setValue] = useState(props.value);
function renderSelectOptions(options) {
let optionElems = [];
for (let i = 0; i < options.length; i++) {
optionElems.push(<option value={options[i].value}>{options[i].text}</option>);
}
return optionElems;
}
return (
<select
id={props.id}
className={props.className}
value={value}
name={props.name}
onChange={(e) => {
setValue(e.target.value);
props.onChange(e);
}}
>
{renderSelectOptions(props.options)}
</select>
);
}
function PanelFunc(props) {
const [headerType, setHeaderType] = useState("row");
const [headerAutoTextType, setHeaderAutoTextType] = useState("letters");
let selectOptions = [
{
value: "blank",
text: "Blank"
}, {
value: "letters",
text: "Letters"
}, {
value: "numbers",
text: "Numbers"
}
];
let radios = [
{
id: "headerTypeRow",
value: "row",
label: "Row"
},
{
id: "headerTypeColumn",
value: "column",
label: "Column"
}
];
return (
<div className="options-container">
<div className="options-row">
<CheckBoxInput id="checkColumnHeaderVisible" checked={true}
onChange={props.checkColumnHeaderVisible}></CheckBoxInput>
<label htmlFor="checkColumnHeaderVisible">列ヘッダを表示する</label>
</div>
<div className="options-row">
<CheckBoxInput id="checkRowHeaderVisible" checked={true}
onChange={props.checkRowHeaderVisible}></CheckBoxInput>
<label htmlFor="checkRowHeaderVisible">行ヘッダを表示する</label>
</div>
<hr />
<div className="options-row">
<label>以下のオプションを使用して、ヘッダの自動テキストの種類を設定します。</label>
</div>
<div className="options-row">
<RadioInput name={"headerType"} defaultValue={"column"} radios={radios} onChange={(value) => {
setHeaderType(value);
}}></RadioInput>
</div>
<div className="options-row">
<label>ヘッダの自動テキストの種類:</label>
</div>
<div className="options-row">
<SelectInput id="headerAutoTextType" value={"letters"} onChange={($event) => {
setHeaderAutoTextType($event.target.value);
}} options={selectOptions}></SelectInput>
<input type="button" value="設定" onClick={() => {
let autoTextInfo = {
headerType: headerType,
headerAutoTextType: headerAutoTextType
};
props.setAutoText(autoTextInfo)
}} />
</div>
</div>
);
}
import * as React from 'react';
import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react';
import GC from '@mescius/spread-sheets';
import '@mescius/spread-sheets-resources-ja';
GC.Spread.Common.CultureManager.culture("ja-jp");
import './styles.css';
const Component = React.Component, useState = React.useState, spreadNS = GC.Spread.Sheets;
export class App extends Component {
constructor(props) {
super(props);
this.spread = null;
this.dataSource = dataSource;
this.autoGenerateColumns = false;
}
render() {
return (
<div class="sample-tutorial">
<div class="sample-spreadsheets">
<SpreadSheets workbookInitialized={spread => this.initSpread(spread)}>
<Worksheet>
</Worksheet>
</SpreadSheets>
</div>
<Panel
checkRowHeaderVisible={(e) => this.checkRowHeaderVisible(e)}
checkColumnHeaderVisible={(e) => this.checkColumnHeaderVisible(e)}
setAutoText={(autoTextInfo) => this.setAutoText(autoTextInfo)}
></Panel>
</div>
);
}
initSpread(spread) {
this.spread = spread;
let spreadNS = GC.Spread.Sheets;
let 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();
}
checkRowHeaderVisible($event) {
let spread = this.spread;
let sheet = spread.getActiveSheet();
sheet.options.rowHeaderVisible = $event.target.checked;
spread.invalidateLayout();
spread.repaint();
}
checkColumnHeaderVisible($event) {
let spread = this.spread;
let sheet = spread.getActiveSheet();
sheet.options.colHeaderVisible = $event.target.checked;
spread.invalidateLayout();
spread.repaint();
}
setAutoText(autoTextInfo) {
let spread = this.spread, { headerType, headerAutoTextType } = autoTextInfo;
let sheet = spread.getActiveSheet();
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 CheckBoxInput(props) {
const [checked, setChecked] = useState(props.checked);
return (
<input type="checkbox" id={props.id} checked={checked} onChange={(e) => {
setChecked(e.target.checked);
props.onChange(e)
}} />
);
}
function RadioInput(props) {
let [value, setValue] = useState(props.defaultValue);
let radios = [];
for (let i = 0; i < props.radios.length; i++) {
radios.push(
<input type="radio" name={props.name} value={props.radios[i].value} id={props.radios[i].id}
checked={props.radios[i].value === value ? true : false}
onChange={($event) => {
setValue($event.target.value)
props.onChange($event.target.value);
}} />
);
if (props.radios[i].label) {
radios.push(
<label htmlFor={props.radios[i].id}>{props.radios[i].label}</label>
);
}
}
return radios;
}
function SelectInput(props) {
const [value, setValue] = useState(props.value);
function renderSelectOptions(options) {
let optionElems = [];
for (let i = 0; i < options.length; i++) {
optionElems.push(<option value={options[i].value}>{options[i].text}</option>);
}
return optionElems;
}
return (
<select
id={props.id}
className={props.className}
value={value}
name={props.name}
onChange={(e) => {
setValue(e.target.value);
props.onChange(e);
}}
>
{renderSelectOptions(props.options)}
</select>
);
}
class Panel extends Component {
constructor(props) {
super(props);
this.headerType = "column";
this.headerAutoTextType = "letters";
}
render() {
let self = this, props = self.props;
let selectOptions = [
{
value: "blank",
text: "Blank"
}, {
value: "letters",
text: "Letters"
}, {
value: "numbers",
text: "Numbers"
}
];
let radios = [
{
id: "headerTypeRow",
value: "row",
label: "Row"
},
{
id: "headerTypeColumn",
value: "column",
label: "Column"
}
];
return (
<div className="options-container">
<div className="options-row">
<CheckBoxInput id="checkColumnHeaderVisible" checked={true}
onChange={props.checkColumnHeaderVisible}></CheckBoxInput>
<label htmlFor="checkColumnHeaderVisible">列ヘッダを表示する</label>
</div>
<div className="options-row">
<CheckBoxInput id="checkRowHeaderVisible" checked={true}
onChange={props.checkRowHeaderVisible}></CheckBoxInput>
<label htmlFor="checkRowHeaderVisible">行ヘッダを表示する</label>
</div>
<hr />
<div className="options-row">
<label>以下のオプションを使用して、ヘッダの自動テキストの種類を設定します。</label>
</div>
<div className="options-row">
<RadioInput name={"headerType"} defaultValue={"column"} radios={radios} onChange={(value) => {
self.headerType = value;
}}></RadioInput>
</div>
<div className="options-row">
<label>ヘッダの自動テキストの種類:</label>
</div>
<div className="options-row">
<SelectInput id="headerAutoTextType" value={"letters"} onChange={($event) => {
self.headerAutoTextType = $event.target.value;
}} options={selectOptions}></SelectInput>
<input type="button" value="設定" onClick={() => {
let autoTextInfo = {
headerType: self.headerType,
headerAutoTextType: self.headerAutoTextType
};
props.setAutoText(autoTextInfo)
}} />
</div>
</div>
);
}
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/ja/react/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/spread/source/data/data.js" type="text/javascript"></script>
<!-- SystemJS -->
<script src="$DEMOROOT$/ja/react/node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('$DEMOROOT$/ja/lib/react/license.js').then(function () {
System.import('./src/app');
});
</script>
</head>
<body>
<div id="app"></div>
</body>
</html>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: calc(100% - 280px);
height: 100%;
overflow: hidden;
float: left;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
#app {
height: 100%;
}
.options-container {
float: right;
width: 280px;
padding: 12px;
height: 100%;
box-sizing: border-box;
background: #fbfbfb;
overflow: auto;
}
.options-row {
font-size: 14px;
padding: 5px;
margin-top: 10px;
}
input {
display: inline-block;
}
input[type="text"] {
width: 200px;
}
label {
margin-bottom: 6px;
}
(function (global) {
System.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true,
react: true
},
meta: {
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-resources-ja': 'npm:@mescius/spread-sheets-resources-ja/index.js',
'@mescius/spread-sheets-react': 'npm:@mescius/spread-sheets-react/index.js',
'@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js',
'react': 'npm:react/umd/react.production.min.js',
'react-dom': 'npm:react-dom/umd/react-dom.production.min.js',
'css': 'npm:systemjs-plugin-css/css.js',
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'jsx'
},
"node_modules": {
defaultExtension: 'js'
},
}
});
})(this);