斜線分割型セル

斜線分割型セル は、セルを斜線で分割する機能を提供します。SpreadJS を使用してレポートを設計する際に、レポートヘッダーのセルに複数のラベルを表示する場合に便利です。

以下のコードで、斜線分割型セルを作成します。 divergeDirection メソッドを使用して、斜線分割型セルの分割方向を取得および設定できます。分割方向の値は、DivergeDirection 列挙体です。 topLeftToBottomRight: 左上から右下方向への分割を表します。 bottomLeftToTopRight: 左下から右上方向への分割を表します。 斜線分割型セルの値は、ワークシートのセルの値に依存します。setValueメソッドを使用して、セルの値を設定できます。セルの値が文字列の場合、項目を区切るためにコンマ (,) を使用する必要があります。この場合、各項目にコンマを含めることはできません。 セルの値を文字列配列で設定すると、各項目にコンマを含めることができます。配列の項目が文字列でない場合は、項目の値は文字列に変換されます lineBorderメソッドを使用して、斜線分割型セルの斜線のスタイルを設定することができます。
import { Component, NgModule, enableProdMode } from '@angular/core'; import { bootstrapApplication, BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { FormsModule } from '@angular/forms'; import { SpreadSheetsModule } from '@mescius/spread-sheets-angular'; import GC from '@mescius/spread-sheets'; import '@mescius/spread-sheets-resources-ja'; GC.Spread.Common.CultureManager.culture("ja-jp"); import './styles.css'; const spreadNS = GC.Spread.Sheets; @Component({ standalone: true, imports: [SpreadSheetsModule, BrowserModule, FormsModule], selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { hostStyle = { width: 'calc(100% - 280px)', height: '100%', overflow: 'hidden', float: 'left' }; spread: GC.Spread.Sheets.Workbook; divergeDirection: GC.Spread.Sheets.CellTypes.DivergeDirection = 0; valueText:string=''; lineColor:string='black'; lineStyle: GC.Spread.Sheets.LineStyle=1; lineStyleOptions: {[key:number]:string} = {}; async initSpread($event: any) { this.spread = $event.spread; this.spread.suspendPaint(); this.spread.setSheetCount(1); var sheet1 = this.spread.getSheet(0); this.initSheet(sheet1); this.spread.resumePaint(); Array.from({ length: 13 }, (_, index) => index + 1).forEach(i=> this.lineStyleOptions[i] = GC.Spread.Sheets.LineStyle[i]); } initSheet(sheet:GC.Spread.Sheets.Worksheet){ var diagonal11 = new spreadNS.CellTypes.Diagonal(); sheet.setCellType(1, 1, diagonal11); sheet.setValue(1, 1, "Diverge From:,Diagonal Cells,Item Count"); sheet.setColumnWidth(1, 150); sheet.setRowHeight(1, 80); sheet.setColumnWidth(2, 150); sheet.setColumnWidth(3, 150); sheet.setValue(1, 2, "topLeftToBottomRight"); sheet.setValue(1, 3, "bottomLeftToTopRight"); sheet.setValue(2, 1, "Items Count = 2"); sheet.setRowHeight(2, 80); sheet.setValue(3, 1, "Items Count = 3"); sheet.setRowHeight(3, 100); sheet.setValue(4, 1, "Items Count > 3"); sheet.setRowHeight(4, 150); var style = new spreadNS.Style(); style.vAlign = 1; sheet.setStyle(1, -1, style); sheet.setStyle(-1, 1, style); var LT2BR2 = new spreadNS.CellTypes.Diagonal(); sheet.setCellType(2, 2, LT2BR2); sheet.setValue(2, 2, "Top Title, Bottom Title"); var LT2BR3 = new spreadNS.CellTypes.Diagonal(); sheet.setCellType(3, 2, LT2BR3); sheet.setValue(3, 2, "Top Title,Middle Title,Bottom Title"); var LT2BR4 = new spreadNS.CellTypes.Diagonal(); sheet.setCellType(4, 2, LT2BR4); sheet.setValue(4, 2, "Top Title,Middle Title1,Middle Title2,Middle Title3,Bottom Title"); var BL2TR4 = new spreadNS.CellTypes.Diagonal(); BL2TR4.divergeDirection(spreadNS.CellTypes.DivergeDirection.bottomLeftToTopRight); sheet.setCellType(4, 3, BL2TR4); sheet.setValue(4, 3, "Top Title,Middle Title1,Middle Title2,Middle Title3,Bottom Title"); var BL2TR3 = new spreadNS.CellTypes.Diagonal(); BL2TR3.divergeDirection(spreadNS.CellTypes.DivergeDirection.bottomLeftToTopRight); sheet.setCellType(3, 3, BL2TR3); sheet.setValue(3, 3, "Top Title,Middle Title,Bottom Title"); var BL2TR2 = new spreadNS.CellTypes.Diagonal(); BL2TR2.divergeDirection(spreadNS.CellTypes.DivergeDirection.bottomLeftToTopRight); sheet.setCellType(2, 3, BL2TR2); sheet.setValue(2, 3, "Top Title,Bottom Title"); sheet.bind(spreadNS.Events.SelectionChanged, () => { var sels = sheet.getSelections(); if (sels && sels.length > 0) { var sel = getActualRange(sels[0], sheet.getRowCount(), sheet.getColumnCount()); var diagonalCellType = sheet.getCellType(sel.row, sel.col); if (!(diagonalCellType instanceof spreadNS.CellTypes.Diagonal)) { diagonalCellType = new spreadNS.CellTypes.Diagonal(); } var lineBorder = diagonalCellType.lineBorder(); var cellValue = sheet.getValue(sel.row, sel.col); this.divergeDirection = diagonalCellType.divergeDirection() ? diagonalCellType.divergeDirection() : 0; this.valueText= cellValue ? cellValue : ''; this.lineColor= lineBorder && lineBorder.color ? lineBorder.color : "black"; this.lineStyle= lineBorder && lineBorder.style ? lineBorder.style : 1; sheet.repaint(); } }); } updateDiagonalCell(e: MouseEvent){ var sheet = this.spread.getActiveSheet(); var sels = sheet.getSelections(); if (sels && sels.length > 0) { var sel = getActualRange(sels[0], sheet.getRowCount(), sheet.getColumnCount()); var diagonal = new spreadNS.CellTypes.Diagonal(); diagonal.divergeDirection(Number(this.divergeDirection)); diagonal.lineBorder(new spreadNS.LineBorder(this.lineColor, Number(this.lineStyle))); sheet.setCellType(sel.row, sel.col, diagonal); sheet.setValue(sel.row, sel.col, this.valueText); } } } function getActualRange(range, maxRowCount, maxColCount) { var row = range.row < 0 ? 0 : range.row; var col = range.col < 0 ? 0 : range.col; var rowCount = range.rowCount < 0 ? maxRowCount : range.rowCount; var colCount = range.colCount < 0 ? maxColCount : range.colCount; return new spreadNS.Range(row, col, rowCount, colCount); } 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"> <gc-spread-sheets [hostStyle]="hostStyle" (workbookInitialized)="initSpread($event)"> <gc-worksheet></gc-worksheet> </gc-spread-sheets> <div class="options-container"> <label>斜線分割型セルを選択し、以下の項目を入力して各オプションを設定します。</label> <div class="option-row"> <label for="divergeDirection">分割方向: </label> <select id="divergeDirection" [(ngModel)]="divergeDirection"> <option value="0" selected="selected">topLeftToBottomRight</option> <option value="1">bottomLeftToTopRight</option> </select> </div> <div class="option-row"> <label for="valueText">文字列をコンマ区切りで入力します。(例)Top,Bottom:</label> <input id="valueText" type="text" [(ngModel)]="valueText" /> </div> <div class="option-row"> <label for="lineStyle">斜線のスタイル:</label> <select id="lineStyle" [(ngModel)]="lineStyle"> <option *ngFor="let item of lineStyleOptions | keyvalue" [value]="item.key">{{ item.value }}</option> </select> </div> <div class="option-row"> <label for="lineColor">斜線の色:</label> <input type="color" id="lineColor" [(ngModel)]="lineColor" /> </div> <div class="option-row"> <label></label> <input type="button" id="btnUpdate" value="更新" (click)="updateDiagonalCell($event)" /> </div> </div> </div>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: calc(100% - 280px); height: 90%; overflow: hidden; float: left; } .options-container { float: right; width: 280px; overflow: auto; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; } .option-row{ padding-bottom: 12px; } label { padding-bottom: 4px; display: block; } input, select { width: 100%; padding: 4px 8px; box-sizing: border-box; } input[type=color]{ padding: 0; box-sizing: border-box; width: 100%; } 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', 'tslib': 'npm:tslib/tslib.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', '@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-tablesheet': 'npm:@mescius/spread-sheets-tablesheet/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);