次のコードを使用して、ラジオボタンリスト型セルを作成します。
ラジオボタンリスト型セルは、さまざまなスタイルの設定をサポートしています。
directionを使用して垂直または水平レイアウトを適用し、textAlignを使用してラベルテキストを左または右に揃えることができます。
isFlowLayout、maxRowCount、maxColumnCountを使用してフローレイアウトを設定できます。また、itemSpacingを使用してリスト項目間のスペースを設定できます。
import { Component, NgModule, enableProdMode } from '@angular/core';
import { bootstrapApplication, BrowserModule } from '@angular/platform-browser';
import GC from '@mescius/spread-sheets';
import '@mescius/spread-sheets-resources-ja';
GC.Spread.Common.CultureManager.culture("ja-jp");
import { FormsModule } from '@angular/forms';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { SpreadSheetsModule } from '@mescius/spread-sheets-angular';
import './styles.css';
const spreadNS = GC.Spread.Sheets;
@Component({
standalone: true,
imports: [BrowserModule, SpreadSheetsModule, FormsModule],
selector: 'app-component',
templateUrl: 'src/app.component.html'
})
export class AppComponent {
methods4html = {
objectKeys: Object.keys,
number: Number
};
hostStyle = {
width: 'calc(100% - 280px)',
height: '100%',
overflow: 'hidden',
float: 'left'
};
itemsList: any[] = [];
directionList = this.getEnumArray(GC.Spread.Sheets.CellTypes.Direction);
direction = 0;
alignList = this.getEnumArray(GC.Spread.Sheets.CellTypes.TextAlign);
textAlign = 2;
flowLayout = true;
maxRowCount = 2;
maxColumnCount = 2;
itemHorizontalSpacing = 8;
itemVerticalSpacing = 2;
boxSize = 12;
spread: GC.Spread.Sheets.Workbook;
initSpread($event: any) {
this.spread = $event.spread;
const sheet = this.spread.getSheet(0);
sheet.suspendPaint();
const radio = new GC.Spread.Sheets.CellTypes.RadioButtonList();
radio.items([
{ text: "sample1", value: "0" },
{ text: "sample2", value: "1" },
{ text: "sample3", value: "2" },
]);
sheet.setCellType(0, 1, radio);
sheet.defaults.rowHeight = 50;
sheet.defaults.colWidth = 200;
sheet.resumePaint();
}
initEvent($event: any) {
const spread = $event.spread;
spread.bind(GC.Spread.Sheets.Events.SelectionChanged, () => {
const sheet = spread.getActiveSheet();
const row = sheet.getActiveRowIndex();
const column = sheet.getActiveColumnIndex();
const cellType = sheet.getCellType(row, column);
if (cellType instanceof GC.Spread.Sheets.CellTypes.RadioButtonList) {
this.readSetting(cellType);
} else {
this.readSetting(new GC.Spread.Sheets.CellTypes.RadioButtonList());
}
});
}
onItemsAdd() {
const d = new Date();
d.setMonth(d.getMonth() + this.itemsList.length);
const str = d.getFullYear() + "-" + (d.getMonth() + 1);
this.itemsList.push({ text: str, value: str });
}
onItemsRemove() {
this.itemsList.pop();
}
readSetting(cellType: GC.Spread.Sheets.CellTypes.RadioButtonList) {
if (!cellType) {
cellType = new GC.Spread.Sheets.CellTypes.RadioButtonList();
}
const items = cellType.items();
this.itemsList = items;
this.direction = cellType.direction();
this.textAlign = cellType.textAlign();
this.flowLayout = cellType.isFlowLayout();
this.maxRowCount = cellType.maxRowCount();
this.maxColumnCount = cellType.maxColumnCount();
const { horizontal: itemHorizontalSpacing, vertical: itemVerticalSpacing } = cellType.itemSpacing();
this.itemHorizontalSpacing = itemHorizontalSpacing;
this.itemVerticalSpacing = itemVerticalSpacing;
}
applySetting() {
const sheet = this.spread.getActiveSheet();
const row = sheet.getActiveRowIndex();
const column = sheet.getActiveColumnIndex();
const cellType = new GC.Spread.Sheets.CellTypes.RadioButtonList();
cellType.items(this.itemsList);
cellType.direction(this.methods4html.number(this.direction));
cellType.textAlign(this.methods4html.number(this.textAlign));
cellType.isFlowLayout(this.methods4html.number(this.flowLayout));
cellType.maxRowCount(this.methods4html.number(this.maxRowCount));
cellType.maxColumnCount(this.methods4html.number(this.maxColumnCount));
cellType.itemSpacing({ horizontal: this.methods4html.number(this.itemHorizontalSpacing), vertical: this.methods4html.number(this.itemVerticalSpacing) });
var boxSize = Number(this.boxSize);
if (isNaN(boxSize)) {
cellType.boxSize(this.boxSize);
} else {
cellType.boxSize(boxSize);
}
sheet.getCell(row, column).cellType(cellType);
}
getEnumArray(spreadEnum: any) {
const newEnum = {};
for (const key of this.methods4html.objectKeys(spreadEnum)) {
if ( isNaN( this.methods4html.number(key) ) ) {
newEnum[key] = spreadEnum[key];
}
}
return newEnum;
}
}
enableProdMode();
bootstrapApplication(AppComponent);
<!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/angular/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<!-- Polyfills -->
<script src="$DEMOROOT$/ja/angular/node_modules/core-js/client/shim.min.js"></script>
<script src="$DEMOROOT$/ja/angular/node_modules/zone.js/fesm2015/zone.min.js"></script>
<!-- SystemJS -->
<script src="$DEMOROOT$/ja/angular/node_modules/systemjs/dist/system.js"></script>
<script src="systemjs.config.js"></script>
<script>
// workaround to load 'rxjs/operators' from the rxjs bundle
System.import('rxjs').then(function (m) {
System.import('@angular/compiler');
System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators));
System.import('$DEMOROOT$/ja/lib/angular/license.ts');
System.import('./src/app.component');
});
</script>
</head>
<body>
<app-component></app-component>
</body>
</html>
<div class="sample-tutorial">
<div class="sample-tutorial">
<gc-spread-sheets [hostStyle]="hostStyle" (workbookInitialized)="initSpread($event); initEvent($event); readSetting();">
<gc-worksheet></gc-worksheet>
<gc-worksheet></gc-worksheet>
</gc-spread-sheets>
<div class="options-container">
<div class="option-row">
<p>以下のオプションを変更し、設定ボタンを押して変更を適用します。</p>
<label>アイテム:</label>
</div>
<div class="option-row">
<select id="items" size="5">
<option *ngFor="let item of itemsList, index" [value]="index">{{ item.text }}</option>
</select>
<input type="button" id="addItem" value="追加" (click)="onItemsAdd()" />
<input type="button" id="removeItem" value="削除" (click)="onItemsRemove()" />
</div>
<hr>
<div class="option-row">
<label>方向:</label>
</div>
<div class="option-row">
<div class="radio-item" *ngFor="let key of methods4html.objectKeys(directionList)">
<input type="radio" name="direction" [id]="'direction-' + key" [(ngModel)]="direction" [value]="directionList[key]"/><label [for]="'direction-' + key">{{ key }}</label>
</div>
</div>
<div class="option-row">
<label>テキスト位置:</label>
</div>
<div class="option-row">
<div class="radio-item" *ngFor="let key of methods4html.objectKeys(alignList)">
<input type="radio" name="textAlign" [id]="'textAlign-' + key" [(ngModel)]="textAlign" [value]="alignList[key]"/><label [for]="'textAlign-' + key">{{ key }}</label>
</div>
</div>
<hr>
<div class="option-row">
<label for="flowLayout">フローレイアウト</label>
<input id="flowLayout" type="checkbox" [(ngModel)]="flowLayout" />
</div>
<div class="option-row" id="rowCountDiv" *ngIf="!flowLayout && methods4html.number(direction) === 1">
<label for="rowCount">最大行数:</label>
<input type="text" id="rowCount" [(ngModel)]="maxRowCount" />
</div>
<div class="option-row" id="columnCountDiv" *ngIf="!flowLayout && methods4html.number(direction) === 0">
<label for="columnCount">最大列数:</label>
<input type="text" id="columnCount" [(ngModel)]="maxColumnCount" />
</div>
<div class="option-row">
<label for="space-horizontal">水平方向の間隔:</label>
<input type="text" id="space-horizontal" [(ngModel)]="itemHorizontalSpacing" />
</div>
<div class="option-row">
<label for="space-vertical">垂直方向の間隔:</label>
<input type="text" id="space-vertical" [(ngModel)]="itemVerticalSpacing" />
</div>
<hr>
<div class="option-row">
<label for="boxSize">ラジオボタンの大きさ:</label>
<input type="text" id="boxSize" class="boxSize" [(ngModel)]="boxSize" />
</div>
<div class="option-row">
<input type="button" id="setProperty" value="設定" (click)="applySetting()" />
</div>
</div>
</div>
</div>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: calc(100% - 280px);
height: 100%;
overflow: hidden;
float: left;
}
.boxSize {
display: block;
}
.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;
}
.option-row {
padding-bottom: 5px;
}
label {
display:inline-block;
}
input{
padding: 4px 8px;
box-sizing: border-box;
}
select{
width: 100%;
}
input[type="checkbox"] + label {
display: inline-block;
width: auto;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
(function (global) {
System.config({
transpiler: 'ts',
typescriptOptions: {
tsconfig: true
},
meta: {
'typescript': {
"exports": "ts"
},
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'core-js': 'npm:core-js/client/shim.min.js',
'zone': 'npm:zone.js/fesm2015/zone.min.js',
'rxjs': 'npm:rxjs/dist/bundles/rxjs.umd.min.js',
'@angular/core': 'npm:@angular/core/fesm2022',
'@angular/common': 'npm:@angular/common/fesm2022/common.mjs',
'@angular/compiler': 'npm:@angular/compiler/fesm2022/compiler.mjs',
'@angular/platform-browser': 'npm:@angular/platform-browser/fesm2022/platform-browser.mjs',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/fesm2022/platform-browser-dynamic.mjs',
'@angular/common/http': 'npm:@angular/common/fesm2022/http.mjs',
'@angular/router': 'npm:@angular/router/fesm2022/router.mjs',
'@angular/forms': 'npm:@angular/forms/fesm2022/forms.mjs',
'jszip': 'npm:jszip/dist/jszip.min.js',
'typescript': 'npm:typescript/lib/typescript.js',
'ts': './plugin.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',
'tslib':'npm:tslib/tslib.js',
'@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-angular': 'npm:@mescius/spread-sheets-angular/fesm2020/mescius-spread-sheets-angular.mjs',
'@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'ts',
meta: {
"*.component.ts": {
loader: "system.component-loader.js"
}
}
},
rxjs: {
defaultExtension: 'js'
},
"node_modules": {
defaultExtension: 'js'
},
"node_modules/@angular": {
defaultExtension: 'mjs'
},
"@mescius/spread-sheets-angular": {
defaultExtension: 'mjs'
},
'@angular/core': {
defaultExtension: 'mjs',
main: 'core.mjs'
}
}
});
})(this);