개요

TableSheet는 워크시트에서 데이터 범위로 렌더링될 수 있습니다.

이 데이터 범위에는 TableSheet의 동일한 인스턴스가 포함되어 있습니다. 즉, 동일한 상태를 공유한다는 의미입니다.

이 데이터 범위는 대부분의 TableSheet 기능도 상속합니다.

설명
app.jsx
app-func.jsx
app-class.jsx
index.html
styles.css

사용법

아래 코드는 워크시트에서 TableSheet를 렌더링합니다.

var tableSheetName = "TableSheet1";
var dataRangeName = "TableSheetDataRange";
var dataRangeStartRow = 2;
var dataRangeStartCol = 2;
sheet.dataRanges.add(dataRangeName, tableSheetName, new GC.Spread.Sheets.Range(dataRangeStartRow, dataRangeStartCol, -1, -1));

이 데모의 기능

  • 기본 렌더링
  • 값 읽기 및 쓰기
  • 원격 CRUD
  • 스타일
  • 조건부 서식
  • 행 작업
  • 관계
  • 조회 열
  • 계산 열
  • 컨텍스트 메뉴
  • 선택
  • 필터
  • 정렬
사용법 아래 코드는 워크시트에서 TableSheet를 렌더링합니다. 이 데모의 기능 기본 렌더링 값 읽기 및 쓰기 원격 CRUD 스타일 조건부 서식 행 작업 관계 조회 열 계산 열 컨텍스트 메뉴 선택 필터 정렬
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'));
/*REPLACE_MARKER*/ /*DO NOT DELETE THESE COMMENTS*/ import * as React from 'react'; import * as ReactDOM from 'react-dom'; import GC from '@mescius/spread-sheets'; import '@mescius/spread-sheets-shapes'; import '@mescius/spread-sheets-datacharts-addon'; import "@mescius/spread-sheets-tablesheet"; import { SpreadSheets } from '@mescius/spread-sheets-react'; import '@mescius/spread-sheets-resources-ko'; GC.Spread.Common.CultureManager.culture("ko-kr"); import './styles.css'; export function AppFunc() { let initSpread = function(spread) { spread.suspendPaint(); var sheet = spread.getActiveSheet(); initTableSheet(spread, function(tableSheet) { spread.setActiveSheet(sheet.name()); setDashboard(sheet); var dataRange = registerTableSheetIntoWorksheet(tableSheet, sheet); beautifySheet(sheet, dataRange); addDataCharts(sheet); spread.undoManager().clear(); }); spread.resumePaint(); } return ( <div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => initSpread(spread)}> </SpreadSheets> </div> </div> ); } function setDashboard(sheet) { sheet.getCell(1, 1) .value("Product Dashboard") .font("20px Calibri") .fontWeight("bold"); sheet.setRowHeight(1, 30); sheet.addSpan(1, 1, 1, 9); sheet.addSpan(16, 1, 1, 9); } async function initTableSheet(spread, callback) { spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader; //init a data manager var dataManager = spread.dataManager(); var categoryAPI = getBaseApiUrl() + "/Category"; var categoryTable = dataManager.addTable("categoryTable", { remote: { read: { url: categoryAPI } } }); var supplierAPI = getBaseApiUrl() + "/Supplier"; var supplierTable = dataManager.addTable("supplierTable", { remote: { read: { url: supplierAPI } } }); var productAPI = getBaseApiUrl() + "/Product"; var productTable = dataManager.addTable("productTable", { autoSync: true, remote: { read: { url: productAPI }, update: { url: productAPI, method: "PUT" }, create: { url: productAPI }, delete: { url: productAPI } }, schema: { columns: { CategoryId: { lookup: { name: "category", columns: [ { value: "Id", width: 100 }, { value: "CategoryName", width: 160 }, { value: "Description", width: 400 } ] } }, SupplierId: { lookup: { name: "supplier", columns: [ { value: "Id", width: 100 }, { value: "CompanyName", width: 180 }, { value: "ContactName", width: 140 }, { value: "ContactTitle", width: 140 }, { value: "ContactTitle", width: 140 }, { value: "City", width: 100 }, { value: "Address", width: 140 }, { value: "Phone", width: 100 } ] } }, TotalPrice: { caption: "Total Price", dataType: "formula", value: "=[@UnitPrice]*[@UnitsInStock]" } } } }); dataManager.addRelationship(productTable, "CategoryId", "category", categoryTable, "Id", "product"); dataManager.addRelationship(productTable, "SupplierId", "supplier", supplierTable, "Id", "product"); //init a table sheet var tableSheet = spread.addSheetTab(0, "MyTableSheet", GC.Spread.Sheets.SheetType.tableSheet); tableSheet.applyTableTheme(GC.Spread.Sheets.Tables.TableThemes.professional15); tableSheet.rowActionOptions([]); //bind a view to the table sheet await categoryTable.fetch(); await supplierTable.fetch(); await productTable.fetch(); var nameStyle = { fontWeight: "bold" }; var relationStyle = { foreColor: "#818181" }; var formulaRule = { ruleType: "formulaRule", formula: "@>1000", style: { foreColor: "orange" } }; var myView = productTable.addView("myView", [ { value: "ProductName", caption: "Name", width: 250, style: nameStyle }, { value: "QuantityPerUnit", caption: "Quantity Per Unit", width: 140 }, { value: "SupplierId", caption: "Supplier Id", width: 140 }, { value: "supplier.CompanyName", caption: "Supplier Company", width: 200, style: relationStyle, headerStyle: relationStyle }, { value: "CategoryId", caption: "Category Id", width: 140 }, { value: "category.CategoryName", caption: "Category Name", width: 140, style: relationStyle, headerStyle: relationStyle }, { value: "UnitPrice", caption: "Unit Price", width: 140 }, { value: "UnitsInStock", caption: "Units In Stock", width: 140 }, { value: "TotalPrice", caption: "Total Price", conditionalFormats: [formulaRule] } ]); tableSheet.setDataView(myView); spread.suspendPaint(); callback && callback(tableSheet); spread.resumePaint(); return tableSheet; } function registerTableSheetIntoWorksheet (tableSheet, sheet) { var name = tableSheet.name() + "_DataRange"; var row = 17; var col = 1; var dataRange = sheet.dataRanges.add(name, tableSheet.name(), new GC.Spread.Sheets.Range(row, col, -1, -1)); return dataRange; } function addDataCharts (sheet) { var columnChart = sheet.dataCharts.add("columnChart", 62, 50, 694, 281, GC.Spread.Sheets.DataCharts.DataChartType.column); columnChart.setChartConfig(columnChartConfig); var pieChart = sheet.dataCharts.add("pieChart", 762, 50, 360, 281, GC.Spread.Sheets.DataCharts.DataChartType.pie); pieChart.setChartConfig(pieChartConfig); } function beautifySheet(sheet, dataRange) { var range = dataRange.range(); for (var i = range.row; i < range.row + range.rowCount; i++) { sheet.autoFitRow(i); } for (var i = range.col; i < range.col + range.colCount; i++) { sheet.autoFitColumn(i); } } function getBaseApiUrl() { return window.location.href.match(/http.+spreadjs\/learn-spreadjs\//)[0] + 'server/api'; }
/*REPLACE_MARKER*/ /*DO NOT DELETE THESE COMMENTS*/ import * as React from 'react'; import * as ReactDOM from 'react-dom'; import GC from '@mescius/spread-sheets'; import '@mescius/spread-sheets-shapes'; import '@mescius/spread-sheets-datacharts-addon'; import "@mescius/spread-sheets-tablesheet"; import { SpreadSheets } from '@mescius/spread-sheets-react'; import '@mescius/spread-sheets-resources-ko'; GC.Spread.Common.CultureManager.culture("ko-kr"); import './styles.css'; const Component = React.Component; function _getElementById(id) { return document.getElementById(id); } export class App extends Component { constructor(props) { super(props); } render() { return ( <div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => this.initSpread(spread)}> </SpreadSheets> </div> </div> ); } initSpread(spread) { spread.suspendPaint(); var sheet = spread.getActiveSheet(); initTableSheet(spread, function(tableSheet) { spread.setActiveSheet(sheet.name()); setDashboard(sheet); var dataRange = registerTableSheetIntoWorksheet(tableSheet, sheet); beautifySheet(sheet, dataRange); addDataCharts(sheet); spread.undoManager().clear(); }); spread.resumePaint(); } } function setDashboard(sheet) { sheet.getCell(1, 1) .value("Product Dashboard") .font("20px Calibri") .fontWeight("bold"); sheet.setRowHeight(1, 30); sheet.addSpan(1, 1, 1, 9); sheet.addSpan(16, 1, 1, 9); } async function initTableSheet(spread, callback) { spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader; //init a data manager var dataManager = spread.dataManager(); var categoryAPI = getBaseApiUrl() + "/Category"; var categoryTable = dataManager.addTable("categoryTable", { remote: { read: { url: categoryAPI } } }); var supplierAPI = getBaseApiUrl() + "/Supplier"; var supplierTable = dataManager.addTable("supplierTable", { remote: { read: { url: supplierAPI } } }); var productAPI = getBaseApiUrl() + "/Product"; var productTable = dataManager.addTable("productTable", { autoSync: true, remote: { read: { url: productAPI }, update: { url: productAPI, method: "PUT" }, create: { url: productAPI }, delete: { url: productAPI } }, schema: { columns: { CategoryId: { lookup: { name: "category", columns: [ { value: "Id", width: 100 }, { value: "CategoryName", width: 160 }, { value: "Description", width: 400 } ] } }, SupplierId: { lookup: { name: "supplier", columns: [ { value: "Id", width: 100 }, { value: "CompanyName", width: 180 }, { value: "ContactName", width: 140 }, { value: "ContactTitle", width: 140 }, { value: "ContactTitle", width: 140 }, { value: "City", width: 100 }, { value: "Address", width: 140 }, { value: "Phone", width: 100 } ] } }, TotalPrice: { caption: "Total Price", dataType: "formula", value: "=[@UnitPrice]*[@UnitsInStock]" } } } }); dataManager.addRelationship(productTable, "CategoryId", "category", categoryTable, "Id", "product"); dataManager.addRelationship(productTable, "SupplierId", "supplier", supplierTable, "Id", "product"); //init a table sheet var tableSheet = spread.addSheetTab(0, "MyTableSheet", GC.Spread.Sheets.SheetType.tableSheet); tableSheet.applyTableTheme(GC.Spread.Sheets.Tables.TableThemes.professional15); tableSheet.rowActionOptions([]); //bind a view to the table sheet await categoryTable.fetch(); await supplierTable.fetch(); await productTable.fetch(); var nameStyle = { fontWeight: "bold" }; var relationStyle = { foreColor: "#818181" }; var formulaRule = { ruleType: "formulaRule", formula: "@>1000", style: { foreColor: "orange" } }; var myView = productTable.addView("myView", [ { value: "ProductName", caption: "Name", width: 250, style: nameStyle }, { value: "QuantityPerUnit", caption: "Quantity Per Unit", width: 140 }, { value: "SupplierId", caption: "Supplier Id", width: 140 }, { value: "supplier.CompanyName", caption: "Supplier Company", width: 200, style: relationStyle, headerStyle: relationStyle }, { value: "CategoryId", caption: "Category Id", width: 140 }, { value: "category.CategoryName", caption: "Category Name", width: 140, style: relationStyle, headerStyle: relationStyle }, { value: "UnitPrice", caption: "Unit Price", width: 140 }, { value: "UnitsInStock", caption: "Units In Stock", width: 140 }, { value: "TotalPrice", caption: "Total Price", conditionalFormats: [formulaRule] } ]); tableSheet.setDataView(myView); spread.suspendPaint(); callback && callback(tableSheet); spread.resumePaint(); return tableSheet; } function registerTableSheetIntoWorksheet (tableSheet, sheet) { var name = tableSheet.name() + "_DataRange"; var row = 17; var col = 1; var dataRange = sheet.dataRanges.add(name, tableSheet.name(), new GC.Spread.Sheets.Range(row, col, -1, -1)); return dataRange; } function addDataCharts (sheet) { var columnChart = sheet.dataCharts.add("columnChart", 62, 50, 694, 281, GC.Spread.Sheets.DataCharts.DataChartType.column); columnChart.setChartConfig(columnChartConfig); var pieChart = sheet.dataCharts.add("pieChart", 762, 50, 360, 281, GC.Spread.Sheets.DataCharts.DataChartType.pie); pieChart.setChartConfig(pieChartConfig); } function beautifySheet(sheet, dataRange) { var range = dataRange.range(); for (var i = range.row; i < range.row + range.rowCount; i++) { sheet.autoFitRow(i); } for (var i = range.col; i < range.col + range.colCount; i++) { sheet.autoFitColumn(i); } } function getBaseApiUrl() { return window.location.href.match(/http.+spreadjs\/learn-spreadjs\//)[0] + 'server/api'; }
<!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/react/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- SystemJS --> <script src="$DEMOROOT$/ko/react/node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script src="../columnChartConfig.js" type="text/javascript"></script> <script src="../pieChartConfig.js" type="text/javascript"></script> <script> System.import('$DEMOROOT$/ko/lib/react/license.js').then(function () { System.import('./src/app'); }); </script> </head> <body> <div id="app" style="height: 100%;"></div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: 100%; height: 100%; overflow: hidden; float: left; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }
(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-ko': 'npm:@mescius/spread-sheets-resources-ko/index.js', '@mescius/spread-sheets-shapes': 'npm:@mescius/spread-sheets-shapes/index.js', '@mescius/spread-sheets-datacharts-addon': 'npm:@mescius/spread-sheets-datacharts-addon/index.js', '@mescius/spread-sheets-tablesheet': 'npm:@mescius/spread-sheets-tablesheet/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);