워크시트에서 배열을 더 쉽게 조작할 수 있도록 SpreadJS에는 11개 배열 조작 함수로 구성된 컬렉션이 있습니다.
배열 결합
데이터 결합은 어려울 수 있는데, 데이터 소스의 크기가 유연한 경우 특히 그렇습니다. VSTACK과 HSTACK을 사용하면 동적 배열을 쉽게 결합하여 데이터를 세로 또는 가로로 누적할 수 있습니다.
VSTACK - 세로로 배열 누적
HSTACK- 가로로 배열 누적
배열 셰이프 지정
데이터의 "셰이프"를 변경하는 것은 어려울 수 있는데, 배열에서 목록으로 변경하는 경우가 특히 어렵고 그 반대의 경우도 마찬가지입니다. 2차원 배열을 간단한 목록으로 변환하려는 경우에는 TOROW와 TOCOL을 사용하여 2D 배열을 데이터의 단일 행 또는 열로 변환합니다.
WRAPROWS 및 WRAPCOLS 함수를 사용하여 반대 작업을 수행합니다. 선택한 너비/높이 제한에 도달하면 (이 문서의 텍스트처럼) 데이터를 다음 행으로 "래핑"하여 지정된 너비 또는 높이의 2D 배열을 만듭니다.
TOROW - 하나의 행으로 배열 반환
TOCOL - 하나의 열로 배열 반환
WRAPROWS - 행 배열을 2D 배열로 래핑
WRAPCOLS - 행 배열을 2D 배열로 래핑
배열 크기 조정
TAKE 및 DROP 함수를 사용하면 배열 시작 지점 또는 끝 지점에서 유지하거나 제거할 행 수를 지정하여 배열을 줄일 수 있습니다.
CHOOSEROWS 또는 CHOOSECOLS를 사용하면 인덱스로 배열의 특정 행 또는 열을 선택할 수 있습니다.
EXPAND를 사용하면 배열을 선택한 크기로 늘릴 수 있습니다. 추가 공간을 채울 값과 새로운 차원만 제공하면 됩니다.
TAKE - 배열 시작 또는 끝에서 행 또는 열 반환
DROP - 배열 시작 또는 끝에서 행 또는 열 드롭
CHOOSEROWS - 배열에서 지정된 행 반환
CHOOSECOLS - 배열에서 지정된 열 반환
EXPAND - 지정된 치수로 배열 확장
import { Component, NgModule, enableProdMode } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
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, SheetArea = spreadNS.SheetArea;
@Component({
selector: 'app-component',
templateUrl: 'src/app.component.html'
})
export class AppComponent {
spread: GC.Spread.Sheets.Workbook;
hostStyle = {
width: '100%',
height: '100%',
overflow: 'hidden',
float: 'left'
};
constructor() {}
initSpread($event: any) {
var data = [
{
sheetName: 'VSTACK',
cells: [
[{v:"Data",s:"title"}],
["A","B","C",null,"AA","BB","CC"],
["D","E","F",null,"DD","EE","FF"],
[{v:"Formula",s:"title"}],
["=FORMULATEXT(A7)"],
[{v:"Result",s:"title"}],
["=VSTACK(A2:C3,E2:G3)"]
],
columnsWidth: [69]
},
{
sheetName: 'HSTACK',
cells: [
[{v:"Data",s:"title"}],
["A","B","C",null,"AA","BB","CC"],
["D","E","F",null,"DD","EE","FF"],
[{v:"Formula",s:"title"}],
["=FORMULATEXT(A7)"],
[{v:"Result",s:"title"}],
["=HSTACK(A2:C3,E2:G3)"]
],
columnsWidth: [69]
},
{
sheetName: 'TOROW',
cells: [
[{v:"Data",s:"title"}],
["Ben","Peter","Mary","Sam"],
["John","Hillary","Jenny","James"],
["Agnes","Harry","Felicity","Joe"],
[{v:"Formula",s:"title"}],
["=FORMULATEXT(A8)"],
[{v:"Result",s:"title"}],
["=TOROW(A2:D4)"]
],
columnsWidth: [69]
},
{
sheetName: 'TOCOL',
cells: [
[{v:"Data",s:"title"}],
["Ben","Peter","Mary","Sam"],
["John","Hillary","Jenny","James"],
["Agnes","Harry","Felicity","Joe"],
[{v:"Formula",s:"title"}],
["=FORMULATEXT(A8)"],
[{v:"Result",s:"title"}],
["=TOCOL(A2:D4)"]
],
columnsWidth: [69]
},
{
sheetName: 'WRAPROWS',
cells: [
[{v:"Data",s:"title"}],
["A","B","C","D","E","F","G"],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B5)"],
[{v:"Result",s:"title"}, "=WRAPROWS(A2:G2,3)"],
[],
[],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B10)"],
[{v:"Result",s:"title"}, '=WRAPROWS(A2:G2,3,"x")'],
],
columnsWidth: [69]
},
{
sheetName: 'WRAPCOLS',
cells: [
[{v:"Data",s:"title"}],
["A","B","C","D","E","F","G"],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B5)"],
[{v:"Result",s:"title"}, "=WRAPCOLS(A2:G2,3)"],
[],
[],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B10)"],
[{v:"Result",s:"title"}, '=WRAPCOLS(A2:G2,3,"x")'],
],
columnsWidth: [69]
},
{
sheetName: 'TAKE',
cells: [
[{v:"Data",s:"title"}],
[1,2,3],
[4,5,6],
[7,8,9],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B7)"],
[{v:"Result",s:"title"}, "=TAKE(A2:C4,2)"],
[],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B11)"],
[{v:"Result",s:"title"}, '=TAKE(A2:C4,,2)'],
[],
[],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B16)"],
[{v:"Result",s:"title"}, '=TAKE(A2:C4,-2)'],
[],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B20)"],
[{v:"Result",s:"title"}, '=TAKE(A2:C4,2,2)'],
],
columnsWidth: [69]
},
{
sheetName: 'DROP',
cells: [
[{v:"Data",s:"title"}],
[1,2,3],
[4,5,6],
[7,8,9],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B7)"],
[{v:"Result",s:"title"}, "=DROP(A2:C4,2)"],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B10)"],
[{v:"Result",s:"title"}, '=DROP(A2:C4,,2)'],
[],
[],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B15)"],
[{v:"Result",s:"title"}, '=DROP(A2:C4,-2)'],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B18)"],
[{v:"Result",s:"title"}, '=DROP(A2:C4,2,2)'],
],
columnsWidth: [69]
},
{
sheetName: 'CHOOSEROWS',
cells: [
[{v:"Data",s:"title"}],
[1,2],
[3,4],
[5,6],
[7,8],
[9,10],
[11,12],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B10)"],
[{v:"Result",s:"title"}, "=CHOOSEROWS(A2:B7,1,3,5,1)"],
[],
[],
[],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B16)"],
[{v:"Result",s:"title"}, '=CHOOSEROWS(A2:B7,-1,-2)'],
],
columnsWidth: [69]
},
{
sheetName: 'CHOOSECOLS',
cells: [
[{v:"Data",s:"title"}],
[1,2,3,4,5],
[6,7,8,9,10],
[11,12,13,14,15],
[16,17,18,19,20],
[21,22,23,24,25],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B9)"],
[{v:"Result",s:"title"}, "=CHOOSECOLS(A2:E6,1,3,5,1)"],
[],
[],
[],
[],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B16)"],
[{v:"Result",s:"title"}, '=CHOOSECOLS(A2:E6,-1,-2)'],
],
columnsWidth: [69]
},
{
sheetName: 'EXPAND',
cells: [
[{v:"Data",s:"title"}],
[1,2],
[3,4],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B6)"],
[{v:"Result",s:"title"}, "=EXPAND(A2:B3,3,3)"],
[],
[],
[],
[{v:"Formula",s:"title"}, "=FORMULATEXT(B11)"],
[{v:"Result",s:"title"}, '=EXPAND(A2:B3,3,3, "-")'],
],
columnsWidth: [69]
},
];
let workbook = this.spread = $event.spread;
workbook.options.allowDynamicArray = true;
workbook.suspendPaint();
workbook.suspendCalcService();
this.initStyles(workbook);
workbook.setSheetCount(data.length);
for (var i = 0; i < data.length; i++) {
var sheetData = data[i];
var sheet = workbook.sheets[i];
sheet.name(sheetData.sheetName);
this.setCells(sheet, sheetData.cells, 0, 0);
this.setColumnsWidth(sheet, sheetData.columnsWidth);
}
workbook.resumeCalcService();
workbook.resumePaint();
}
initStyles(workbook: GC.Spread.Sheets.Workbook) {
var style = new GC.Spread.Sheets.Style();
style.name = 'title';
style.font = 'normal bold 16px Segoe UI';
style.foreColor = "#172b4d";
workbook.addNamedStyle(style);
}
setCells(sheet: GC.Spread.Sheets.Worksheet, cells: any[], rowIndex: number, colIndex: number) {
for(var i = 0; i < cells.length; i++) {
var row = cells[i];
var r = rowIndex + i;
for (var j = 0; j < row.length; j++) {
var cell = row[j];
var c = colIndex + j;
if (cell === null) {
continue;
}
if (typeof cell === "object") {
if (cell.v !== undefined) {
sheet.setValue(r, c, cell.v);
}
if (cell.s !== undefined) {
sheet.setStyle(r, c, cell.s)
}
} else if (cell[0] === '=') {
sheet.setFormula(r, c, cell);
} else {
sheet.setValue(r, c, cell);
}
}
}
}
setColumnsWidth(sheet: GC.Spread.Sheets.Worksheet, columnsWidth: number[]) {
if (!columnsWidth) {
return;
}
for (var i = 0; i < columnsWidth.length; i++) {
sheet.setColumnWidth(i, columnsWidth[i]);
}
}
}
@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">
<!-- 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-worksheet>
</gc-worksheet>
</gc-spread-sheets>
</div>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.options-container {
float: right;
width: 280px;
padding: 12px;
height: 100%;
box-sizing: border-box;
background: #fbfbfb;
overflow: auto;
}
.options-row {
font-size: 14px;
padding: 5px;
margin-top: 10px;
}
input {
padding: 4px 6px;
display: inline-block;
}
input[type="text"] {
width: 200px;
}
label {
display: block;
margin-bottom: 6px;
}
input[type=button] {
margin-top: 6px;
display: block;
width:216px;
}
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-angular': 'npm:@mescius/spread-sheets-angular/fesm2020/mescius-spread-sheets-angular.mjs',
'@mescius/spread-sheets-resources-ko': 'npm:@mescius/spread-sheets-resources-ko/index.js',
'@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);