스타일

SpreadJS는 표 작업을 위한 여러 API를 제공합니다. 이러한 API를 사용하면 관련 데이터의 그룹을 보다 쉽게 관리하고 분석할 수 있습니다.

설명
app.component.ts
index.html
app.component.html
styles.css

표 헤더 또는 푸터를 표시할지 여부, 행 스타일 또는 열 스타일을 번갈아 표시할지 여부, 첫 번째 열 또는 마지막 열을 강조 표시할지 여부를 제어할 수 있습니다. 예:

    var spread = GC.Spread.Sheets.findControl(document.getElementById('ss'));
    var sheet = spread.getActiveSheet();
    var table = sheet.tables.add('table1', 0, 0, 4, 4, tableStyle);
    'table1' === table.name(); //true
    0 === table.headerIndex(); //true
    3 === table.footerIndex(); //true
    table.showHeader(true); //whether to display a header
    table.showFooter(true); //whether to display a footer
    table.bandRows(true); //whether to display an alternating row style
    table.bandColumns(true); //whether to display an alternating column style
    table.highlightFirstColumn(true); //whether to highlight the first column
    table.highlightLastColumn(true); //whether to highlight the last column
    var columnName = table.getColumnName(0); //get the header text with the specified table index.
    table.setColumnName(1, 'column2'); //set the table header text.
    table.setColumnFormula(0, '=SUM(A1:A4)'); //Set the table footer formula with the specified index
    'SUM(B2:B5)' === table.getColumnFormula(0); //Gets the table footer formula with the specified index.

SpreadJS는 기본 제공 표 스타일을 지원하거나 표 스타일을 사용자 정의할 수 있습니다. 예:

    // built-in style
    table.style(GC.Spread.Sheets.Tables.TableThemes.dark1.name());
    // custom style
    var border = new GC.Spread.Sheets.LineBorder();
    var styleInfo = new GC.Spread.Sheets.Tables.TableStyle('red', 'black', '10px arial', border, border, border, border, border, border);
    var customTableStyle = new GC.Spread.Sheets.Tables.TableTheme();
    customTableStyle.headerRowStyle(styleInfo)
    customTableStyle.name('customTableStyle1');
    spread.customTableThemes.add(customTableStyle);
    table.style('customTableStyle1');
    table.getStyleName(); // 'customTableStyle1'
    // set default table theme
    spread.defaultTableTheme('customTableStyle1');

SpreadJS는 표 헤더, 데이터 또는 푸터, 표 열 헤더, 데이터 또는 푸터의 스타일을 사용자 정의하는 기능을 지원합니다. 다음 코드를 사용합니다.

    var tableHeaderStyle = new GC.Spread.Sheets.Style();
    tableHeaderStyle.backColor = "Accent 1 80";
    var tableDataStyle = new GC.Spread.Sheets.Style();
    tableDataStyle.backColor = "Accent 4 80";
    var tableFooterStyle = new GC.Spread.Sheets.Style();
    tableFooterStyle.backColor = "Accent 6 80";
    table.layoutStyle({
        header: tableHeaderStyle,
        data: tableDataStyle,
        footer: tableFooterStyle
    });
    var tableColumnHeaderStyle = new GC.Spread.Sheets.Style();
    tableColumnHeaderStyle.backColor = "Accent 1 40";
    var tableColumnDataStyle = new GC.Spread.Sheets.Style();
    tableColumnDataStyle.backColor = "Accent 4 40";
    var tableColumnFooterStyle = new GC.Spread.Sheets.Style();
    tableColumnFooterStyle.backColor = "Accent 6 40";
    table.columnLayoutStyle(1, {
        header: tableColumnHeaderStyle,
        data: tableColumnDataStyle,
        footer: tableColumnFooterStyle
    });
표 헤더 또는 푸터를 표시할지 여부, 행 스타일 또는 열 스타일을 번갈아 표시할지 여부, 첫 번째 열 또는 마지막 열을 강조 표시할지 여부를 제어할 수 있습니다. 예: SpreadJS는 기본 제공 표 스타일을 지원하거나 표 스타일을 사용자 정의할 수 있습니다. 예: SpreadJS는 표 헤더, 데이터 또는 푸터, 표 열 헤더, 데이터 또는 푸터의 스타일을 사용자 정의하는 기능을 지원합니다. 다음 코드를 사용합니다.
import { Component, NgModule, enableProdMode } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { 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-ko'; GC.Spread.Common.CultureManager.culture("ko-kr"); import './styles.css'; const spreadNS = GC.Spread.Sheets; const TableStyles = { 0: "Light1", 1: "Light2", 2: "Light3", 3: "Light4", 4: "Light5", 5: "Light6", 6: "Light7", 7: "Light8", 8: "Light9", 9: "Light10", 10: "Light11", 11: "Light12", 12: "Light13", 13: "Light14", 14: "Light15", 15: "Light16", 16: "Light17", 17: "Light18", 18: "Light19", 19: "Light20", 20: "Light21", 21: "Medium1", 22: "Medium2", 23: "Medium3", 24: "Medium4", 25: "Medium5", 26: "Medium6", 27: "Medium7", 28: "Medium8", 29: "Medium9", 30: "Medium10", 31: "Medium11", 32: "Medium12", 33: "Medium13", 34: "Medium14", 35: "Medium15", 36: "Medium16", 37: "Medium17", 38: "Medium18", 39: "Medium19", 40: "Medium20", 41: "Medium21", 42: "Medium22", 43: "Medium23", 44: "Medium24", 45: "Medium25", 46: "Medium26", 47: "Medium27", 48: "Medium28", 49: "Dark1", 50: "Dark2", 51: "Dark3", 52: "Dark4", 53: "Dark5", 54: "Dark6", 55: "Dark7", 56: "Dark8", 57: "Dark9", 58: "Dark10", 59: "Dark11", 60: "None" }; function getArrayOfObject(object: object) { let list = []; for (let key in object) { list.push({ key: key, value: object[key] }); } return list; } function setStyles (sheet: any) { let table = sheet.tables.all()[0]; sheet.suspendPaint(); let tableHeaderStyle = new GC.Spread.Sheets.Style(); tableHeaderStyle.backColor = "Accent 1 80"; let tableDataStyle = new GC.Spread.Sheets.Style(); tableDataStyle.backColor = "Accent 4 80"; let tableFooterStyle = new GC.Spread.Sheets.Style(); tableFooterStyle.backColor = "Accent 6 80"; table.layoutStyle({ header: tableHeaderStyle, data: tableDataStyle, footer: tableFooterStyle }); let tableColumnHeaderStyle = new GC.Spread.Sheets.Style(); tableColumnHeaderStyle.backColor = "Accent 1 40"; let tableColumnDataStyle = new GC.Spread.Sheets.Style(); tableColumnDataStyle.backColor = "Accent 4 40"; let tableColumnFooterStyle = new GC.Spread.Sheets.Style(); tableColumnFooterStyle.backColor = "Accent 6 40"; table.columnLayoutStyle(1, { header: tableColumnHeaderStyle, data: tableColumnDataStyle, footer: tableColumnFooterStyle }); let tableColumn3DataStyle = new GC.Spread.Sheets.Style(); tableColumn3DataStyle.formatter = "0%"; table.columnLayoutStyle(3, { data: tableColumn3DataStyle }); sheet.resumePaint(); } function initCustomThemes(spread: GC.Spread.Sheets.Workbook, tableStylesList: Array<{key: string; value: any;}>) { const theme1 = new GC.Spread.Sheets.Tables.TableTheme(); theme1.name('custom1'); theme1.wholeTableStyle(new GC.Spread.Sheets.Tables.TableStyle('#e0f2f1')); theme1.headerRowStyle(new GC.Spread.Sheets.Tables.TableStyle('#26a69a', '#fff')); theme1.firstRowStripStyle(new GC.Spread.Sheets.Tables.TableStyle('#b2dfdb')); theme1.firstColumnStripStyle(new GC.Spread.Sheets.Tables.TableStyle('#b2dfdb')); theme1.footerRowStyle(new GC.Spread.Sheets.Tables.TableStyle('#26a69a', '#fff')); theme1.highlightFirstColumnStyle(new GC.Spread.Sheets.Tables.TableStyle('#26a69a', '#fff')); theme1.highlightLastColumnStyle(new GC.Spread.Sheets.Tables.TableStyle('#26a69a', '#fff')); const theme2 = new GC.Spread.Sheets.Tables.TableTheme(); theme2.name('custom2'); theme2.wholeTableStyle(new GC.Spread.Sheets.Tables.TableStyle('#ede7f6')); theme2.headerRowStyle(new GC.Spread.Sheets.Tables.TableStyle('#ede7f6', '#000')); theme2.firstRowStripStyle(new GC.Spread.Sheets.Tables.TableStyle('#e1bee7')); theme2.firstColumnStripStyle(new GC.Spread.Sheets.Tables.TableStyle('#e1bee7')); theme2.footerRowStyle(new GC.Spread.Sheets.Tables.TableStyle('#ede7f6', '#000')); spread.customTableThemes.add(theme1); spread.customTableThemes.add(theme2); const customThemes = spread.customTableThemes.all(); if (customThemes && customThemes.length > 0) { customThemes.forEach((theme) => { tableStylesList.push({ key: theme.name(), value: theme.name() }); }); } } @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { spread: GC.Spread.Sheets.Workbook; isShowHeader = true; isHighlightFirstColumn = false; isShowFooter = false; isHighlightLastColumn = false; isBandColumns = false; isBandRows = true; styleType = 'None'; tableStylesList = getArrayOfObject(TableStyles); hostStyle = { width: 'calc(100% - 280px)', height: '100%', overflow: 'hidden', float: 'left' }; constructor() { } initSpread($event: any) { let self = this; self.spread = $event.spread; let spread = this.spread; spread.fromJSON(jsonData); initCustomThemes(spread, self.tableStylesList) let sheet = spread.getActiveSheet(); setStyles(sheet); spread.bind(GC.Spread.Sheets.Events.EnterCell, (eventType: any, data: any) => { if (data) { let activeSheet = spread.getActiveSheet(); let activeTable = activeSheet.tables.find(activeSheet.getActiveRowIndex(), activeSheet.getActiveColumnIndex()); if (activeTable) { let style = activeTable.style(), name = 'None'; if (style) { name = style.name(); } self.styleType = name; } } }); } getActiveSheetTable () { let sheet = this.spread.getActiveSheet(); let table = sheet.tables.find(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()) || sheet.tables.all()[0]; return { sheet, table }; } onShowHeader (e: any) { let { sheet, table } = this.getActiveSheetTable(); if (table) { let checked = e.target.checked; this.isShowHeader = checked; table.showHeader(checked); sheet.invalidateLayout(); sheet.repaint(); } } onShowFooter (e: any) { let { sheet, table } = this.getActiveSheetTable(); if (table) { let checked = e.target.checked; this.isShowFooter = checked; table.showFooter(checked); sheet.invalidateLayout(); sheet.repaint(); } } onHighlightFirstColumn (e: any) { let { sheet, table } = this.getActiveSheetTable(); if (table) { let checked = e.target.checked; this.isHighlightFirstColumn = checked; table.highlightFirstColumn(checked); sheet.invalidateLayout(); sheet.repaint(); } } onHighlightLastColumn (e: any) { let { sheet, table } = this.getActiveSheetTable(); if (table) { let checked = e.target.checked; this.isHighlightLastColumn = checked; table.highlightLastColumn(checked); sheet.invalidateLayout(); sheet.repaint(); } } onBandRows (e: any) { let { sheet, table } = this.getActiveSheetTable(); if (table) { let checked = e.target.checked; this.isBandRows = checked; table.bandRows(checked); sheet.invalidateLayout(); sheet.repaint(); } } onBandColumns (e: any) { let { sheet, table } = this.getActiveSheetTable(); if (table) { let checked = e.target.checked; this.isBandColumns = checked; table.bandColumns(checked); sheet.invalidateLayout(); sheet.repaint(); } } onStyleTypeChange (e: any) { let { sheet, table } = this.getActiveSheetTable(); if (table) { let value = e.target.value; this.styleType = value; table.style(value); sheet.repaint(); } } } @NgModule({ imports: [BrowserModule, SpreadSheetsModule, FormsModule], declarations: [AppComponent], exports: [AppComponent], bootstrap: [AppComponent] }) export class AppModule {} enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule);
<!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$/ko/angular/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="data.js" type="text/javascript"></script> <!-- Polyfills --> <script src="$DEMOROOT$/ko/angular/node_modules/core-js/client/shim.min.js"></script> <script src="$DEMOROOT$/ko/angular/node_modules/zone.js/fesm2015/zone.min.js"></script> <!-- SystemJS --> <script src="$DEMOROOT$/ko/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$/ko/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-spread-sheets> <div class="options-container"> <p>Select the table in the Spread instance and change the style and properties using the checkboxes and drop-down menu.</p> <div class="option-group"> <input type="checkbox" id="showHeader" [checked]="isShowHeader" (change)="onShowHeader($event)" /> <label for="showHeader">Header Row</label> </div> <div class="option-group"> <input type="checkbox" id="highlightFirstColumn" [checked]="isHighlightFirstColumn" (change)="onHighlightFirstColumn($event)" /> <label for="highlightFirstColumn">First Column</label> </div> <div class="option-group"> <input type="checkbox" id="showFooter" [checked]="isShowFooter" (change)="onShowFooter($event)" /> <label for="showFooter">Total Row</label> </div> <div class="option-group"> <input type="checkbox" id="highlightLastColumn" [checked]="isHighlightLastColumn" (change)="onHighlightLastColumn($event)" /> <label for="highlightLastColumn">Last Column</label> </div> <div class="option-group"> <input type="checkbox" id="bandColumns" [checked]="isBandColumns" (change)="onBandColumns($event)" /> <label for="bandColumns">Banded Column</label> </div> <div class="option-group"> <input type="checkbox" id="bandRows" [checked]="isBandRows" (change)="onBandRows($event)" /> <label for="bandRows">Banded Row</label> </div> <div class="option-group"> <label for="tableStyles">Styles:</label> <select id="tableStyles" [(ngModel)]="styleType" (change)="onStyleTypeChange($event)"> <option *ngFor="let item of tableStylesList" [value]="item.value"> {{item.value}} </option> </select> </div> </div> </div>
.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; } .option-group { margin-bottom: 6px; } label { display: inline-block; min-width: 90px; margin-bottom: 6px; } select { padding: 4px 6px; } p { padding: 0 0 12px; margin: 0; } 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-ko': 'npm:@mescius/spread-sheets-resources-ko/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' }, 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);