Angular 명령 사용
Angular Spreadsheet 구성 요소를 사용하면 스프레드시트의 다양한 기능을 활성화하기 위한 명령을 수행할 수 있습니다. 이 주제에서는 명령을 사용하여 컨트롤에서 다양한 작업을 수행하는 방법을 설명합니다. 많은 명령은 활성 셀, 행 또는 워크시트를 기반으로 작업을 수행합니다. 예를 들어 이러한 명령 두 가지는 ZoomIn 및 ZoomOut입니다. 전체 목록은 SpreadsheetAction 열거형을 참조하세요.
Angular 명령 작업 예제
EXAMPLE
DATA
MODULES
TS
HTML
SCSS
import { saveAs } from "file-saver" ;
import { Workbook } from "igniteui-angular-excel" ;
import { WorkbookFormat } from "igniteui-angular-excel" ;
import { WorkbookSaveOptions } from "igniteui-angular-excel" ;
export class ExcelUtility {
public static getExtension (format: WorkbookFormat ) {
switch (format) {
case WorkbookFormat.StrictOpenXml:
case WorkbookFormat.Excel2007:
return ".xlsx" ;
case WorkbookFormat.Excel2007MacroEnabled:
return ".xlsm" ;
case WorkbookFormat.Excel2007MacroEnabledTemplate:
return ".xltm" ;
case WorkbookFormat.Excel2007Template:
return ".xltx" ;
case WorkbookFormat.Excel97To2003:
return ".xls" ;
case WorkbookFormat.Excel97To2003Template:
return ".xlt" ;
}
}
public static load(file: File): Promise <Workbook> {
return new Promise <Workbook>((resolve, reject ) => {
ExcelUtility.readFileAsUint8Array(file).then((a ) => {
Workbook.load(a, null , (w ) => {
resolve(w);
}, (e ) => {
reject(e);
});
}, (e ) => {
reject(e);
});
});
}
public static loadFromUrl(url: string ): Promise <Workbook> {
return new Promise <Workbook>((resolve, reject ) => {
const req = new XMLHttpRequest();
req.open("GET" , url, true );
req.responseType = "arraybuffer" ;
req.onload = (d ) => {
const data = new Uint8Array (req.response);
Workbook.load(data, null , (w ) => {
resolve(w);
}, (e ) => {
reject(e);
});
};
req.send();
});
}
public static save(workbook: Workbook, fileNameWithoutExtension : string ): Promise <string > {
return new Promise <string >((resolve, reject ) => {
const opt = new WorkbookSaveOptions();
opt.type = "blob" ;
workbook.save(opt, (d ) => {
const fileExt = ExcelUtility.getExtension(workbook.currentFormat);
const fileName = fileNameWithoutExtension + fileExt;
saveAs(d as Blob, fileName);
resolve(fileName);
}, (e ) => {
reject(e);
});
});
}
private static readFileAsUint8Array(file: File): Promise <Uint8Array > {
return new Promise <Uint8Array >((resolve, reject ) => {
const fr = new FileReader();
fr.onerror = (e ) => {
reject(fr.error);
};
if (fr.readAsBinaryString) {
fr.onload = (e ) => {
const rs = (fr as any ).resultString;
const str: string = rs != null ? rs : fr.result;
const result = new Uint8Array (str.length);
for (let i = 0 ; i < str.length; i++) {
result[i] = str.charCodeAt(i);
}
resolve(result);
};
fr.readAsBinaryString(file);
} else {
fr.onload = (e ) => {
resolve(new Uint8Array (fr.result as ArrayBuffer ));
};
fr.readAsArrayBuffer(file);
}
});
}
}
ts コピー import { NgModule } from "@angular/core" ;
import { FormsModule } from "@angular/forms" ;
import { CommonModule } from "@angular/common" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import { ExcelUtility } from "./ExcelUtility" ;
import { IgxExcelModule } from "igniteui-angular-excel" ;
import { IgxSpreadsheetModule } from "igniteui-angular-spreadsheet" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
],
imports : [
BrowserModule,
BrowserAnimationsModule,
CommonModule,
FormsModule,
IgxExcelModule,
IgxSpreadsheetModule
],
providers : [ExcelUtility],
schemas : []
})
export class AppModule {}
ts コピー import { Component, OnInit, ViewChild } from "@angular/core" ;
import { IgxSpreadsheetComponent } from "igniteui-angular-spreadsheet" ;
import { SpreadsheetAction } from "igniteui-angular-spreadsheet" ;
import { ExcelUtility } from "./ExcelUtility" ;
@Component ({
standalone : false ,
selector : "app-root" ,
styleUrls : ["./app.component.scss" ],
templateUrl : "./app.component.html"
})
export class AppComponent implements OnInit {
@ViewChild ("spreadsheet" , { read : IgxSpreadsheetComponent, static : true })
public spreadsheet: IgxSpreadsheetComponent;
constructor ( ) { }
public ngOnInit ( ) {
const excelFile = "https://static.infragistics.com/xplatform/excel/SalesData.xlsx" ;
ExcelUtility.loadFromUrl(excelFile).then((w ) => {
this .spreadsheet.workbook = w;
});
}
public zoomIn(): void {
this .spreadsheet.executeAction(SpreadsheetAction.ZoomIn);
}
public zoomOut(): void {
this .spreadsheet.executeAction(SpreadsheetAction.ZoomOut);
}
}
ts コピー <div class ="container vertical" >
<div class ="options horizontal" >
<input class ="options-item" id ="zoomIn" value ="Zoom In" type ="button" (click )="zoomIn()" >
<input class ="options-item" id ="zoomOut" value ="Zoom Out" type ="button" (click )="zoomOut()" >
</div >
<div class ="container" >
<igx-spreadsheet #spreadsheet height ="100%" width ="100%" >
</igx-spreadsheet >
</div >
</div >
html コピー
종속성
명령을 사용하기 전에 SpreadsheetAction
가져오고 싶을 것입니다.
import { IgxSpreadsheetComponent } from 'igniteui-angular-spreadsheet' ;
import { SpreadsheetAction } from 'igniteui-angular-spreadsheet' ;
ts
용법
다음 스니펫은 데이터 유효성 검사 규칙을 설정하는 방법을 보여줍니다.
@ViewChild ("spreadsheet" , { read : IgxSpreadsheetComponent })
public spreadsheet: IgxSpreadsheetComponent;
public zoomIn(): void {
this .spreadsheet.executeAction(SpreadsheetAction.ZoomIn);
}
public zoomOut(): void {
this .spreadsheet.executeAction(SpreadsheetAction.ZoomOut);
}
ts
API 참조
ExecuteAction
SpreadsheetAction