名前ボックス コンポーネント

SpreadJSは、選択された範囲や項目を表示し、名前を付けた範囲に移動できる、Excelのような名前ボックスを提供します。

はじめに 名前ボックスを作成するには、次の例に示すように、ホストDIV要素を追加し、それをSpreadインスタンスにバインドします: 名前ボックスはUIの動作に合わせて自動的に値を更新しますが、refresh()を使用して名前ボックスの値を手動で更新することもできます。 dispose()を使って名前ボックスを削除することができます。 名前ボックスのオプション 次のオプションで名前ボックスを制御できます: GC.Spread.Sheets.NameBox.INameBoxOptions 名前ボックス オプションの設定 名前ボックスの作成時に設定します。 名前ボックスのインスタンスでオプションを設定します。
import { Component, NgModule, enableProdMode } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { bootstrapApplication, BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 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 '@mescius/spread-sheets-shapes'; import '@mescius/spread-sheets-charts'; import '@mescius/spread-sheets-slicers'; import './styles.css'; function initTable(spread: GC.Spread.Sheets.Workbook) { var dataSource = [ [ "salesman", "product", "date", "amount", "price", "sales" ], [ "Colleen Lee", "desk", new Date("2020-10-08T16:00:00.000Z"), 5, 199, 995 ], [ "Joe Mercer", "pen", new Date("2020-09-15T16:00:00.000Z"), 2, 5, 10 ], [ "Alicia Schmidt", "pencil", new Date("2021-06-22T16:00:00.000Z"), 6, 1.5, 9 ], [ "John Walsh", "chair", new Date("2021-07-19T16:00:00.000Z"), 7, 68, 476 ], [ "David Hale", "notebook", new Date("2021-01-13T16:00:00.000Z"), 7, 3.2, 22.4 ], [ "Gordon Jones", "desk", new Date("2021-03-12T16:00:00.000Z"), 9, 199, 1791 ], [ "Colleen Lee", "pen", new Date("2021-03-06T16:00:00.000Z"), 4, 5, 20 ], [ "Colleen Lee", "pencil", new Date("2020-09-02T16:00:00.000Z"), 10, 1.5, 15 ], [ "Joe Mercer", "chair", new Date("2020-08-09T16:00:00.000Z"), 3, 68, 204 ], [ "Alicia Schmidt", "notebook", new Date("2021-02-08T16:00:00.000Z"), 9, 3.2, 28.8 ], [ "John Walsh", "desk", new Date("2021-07-03T16:00:00.000Z"), 7, 199, 1393 ], [ "David Hale", "pen", new Date("2021-06-27T16:00:00.000Z"), 8, 5, 40 ], [ "Gordon Jones", "pencil", new Date("2020-10-10T16:00:00.000Z"), 2, 1.5, 3 ], [ "Colleen Lee", "chair", new Date("2021-03-04T16:00:00.000Z"), 2, 68, 136 ], [ "Colleen Lee", "notebook", new Date("2021-02-21T16:00:00.000Z"), 11, 3.2, 35.2 ], [ "Joe Mercer", "desk", new Date("2021-06-03T16:00:00.000Z"), 6, 199, 1194 ] ]; var sheet1 = spread.sheets[0]; sheet1.setArray(0, 0, dataSource); var table = sheet1.tables.add("table1", 0, 0, 17, 6, GC.Spread.Sheets.Tables.TableThemes.light9); var sheet2 = spread.sheets[1]; sheet2.setArray(0, 0, dataSource); var table2 = sheet2.tables.add("table2", 0, 0, 17, 6, GC.Spread.Sheets.Tables.TableThemes.light9); //setColumnWidth: sheet1 sheet1.setColumnWidth(0, 90); sheet1.setColumnWidth(1, 80); sheet1.setColumnWidth(2, 130); sheet1.setColumnWidth(3, 70); //setColumWidth: sheet2 sheet2.setColumnWidth(0, 90); sheet2.setColumnWidth(1, 80); sheet2.setColumnWidth(2, 130); sheet2.setColumnWidth(3, 70); } function initSlicer(sheet: GC.Spread.Sheets.Worksheet) { var slicer_name = sheet.slicers.add("salesman", "table1", "Salesman", GC.Spread.Sheets.Slicers.SlicerStyles.light3(), GC.Spread.Sheets.Slicers.SlicerType.table); slicer_name.startRow(0); slicer_name.startColumn(7); slicer_name.startColumnOffset(0); } function initChart(sheet: GC.Spread.Sheets.Worksheet) { var chart = sheet.charts.add("chart1", GC.Spread.Sheets.Charts.ChartType.line, 100, 400, 400, 300, 'C1:D17') } @Component({ standalone: true, imports: [SpreadSheetsModule, BrowserModule, FormsModule], selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { spread: GC.Spread.Sheets.Workbook; nameBox: GC.Spread.Sheets.NameBox.NameBox; hostStyle = { width: '100%', height: 'calc(100% - 25px)', overflow: 'hidden', float: 'left' }; enableAddCustomName = true; enableNavigateToRange = true; showCustomNameList = true; dropDownMaxHeight = 500; constructor() { } initSpread($event: any) { this.spread = $event.spread; let spread = this.spread; let sheet = spread.getActiveSheet(); initTable(spread); initSlicer(sheet); initChart(sheet); spread.addCustomName("workBookName1", "Sheet1!A2:D4", 0, 0, ""); spread.addCustomName("workBookName2", "Sheet2!B3:E6", 0, 0, ""); sheet.addCustomName("sheet1Name1", "C2:D3", 0, 0, ""); sheet.addCustomName("sheet1Name2", "B4:E10", 0, 0, ""); spread.getSheet(1).addCustomName('sheet2Name1', "D4:G6", 0, 0, ""); let nameBox = new GC.Spread.Sheets.NameBox.NameBox('nameBox', spread); this.nameBox = nameBox; } changeProperty (propertyName: string) { let value = this[propertyName]; if (propertyName === 'dropDownMaxHeight') { value = +value; } else { value = !!value; } this.nameBox.options[propertyName] = value; } } 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-container"> <gc-spread-sheets [hostStyle]="hostStyle" (workbookInitialized)="initSpread($event)"> <gc-worksheet> </gc-worksheet> <gc-worksheet> </gc-worksheet> </gc-spread-sheets> </div> <div class="sample-options"> <div class="options-container"> <h3>名前ボックスのコンテナ</h3> <div id="nameBox"></div><br /> <h3>名前ボックスのオプション</h3> <div class="option-row"> <input type="checkbox" id="enableAddCustomName" [(ngModel)]="enableAddCustomName" (change)="changeProperty('enableAddCustomName')"/> <label for="enableAddCustomName">カスタム名の追加を有効にする</label> </div> <div class="option-row"> <input type="checkbox" id="enableNavigateToRange" [(ngModel)]="enableNavigateToRange" (change)="changeProperty('enableNavigateToRange')" /> <label for="enableNavigateToRange">範囲への移動を有効にする</label> </div> <div class="option-row"> <input type="checkbox" id="showCustomNameList" [(ngModel)]="showCustomNameList" (change)="changeProperty('showCustomNameList')" /> <label for="showCustomNameList">カスタム名のリストを表示する</label> </div> <div class="option-row"><br /> ドロップダウンの最大高さ <input type="number" id="dropDownMaxHeight" min="0" step="1" value="500" [(ngModel)]="dropDownMaxHeight" (change)="changeProperty('dropDownMaxHeight')" /> </div> </div> </div> </div>
.sample-options { width: 260px; height: 100%; } .sample-tutorial { position: relative; height: 98vh; overflow: hidden; display: flex; } .sample-container { width: calc(100% - 280px); height: 100%; } .options-container { width: 100%; 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; } #ss { height: 100%; } #nameBox { width: 80%; height: 25px; } label { display: inline-block; } p { font-size: 12px; font-weight: bold; } h3 { white-space: nowrap; } #dropDownMaxHeight { width: 40px; }
(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-shapes': 'npm:@mescius/spread-sheets-shapes/index.js', '@mescius/spread-sheets-slicers': 'npm:@mescius/spread-sheets-slicers/index.js', '@mescius/spread-sheets-charts': 'npm:@mescius/spread-sheets-charts/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);