Angular 스프레드시트 하이퍼링크
Angular 스프레드시트 구성 요소를 사용하면 Excel 통합 문서에 기존 하이퍼링크를 표시할 수 있을 뿐 아니라 통합 문서의 웹사이트, 파일 디렉터리, 심지어 다른 워크시트에 링크할 수 있는 새로운 하이퍼링크를 삽입할 수도 있습니다.
Angular Spreadsheet Hyperlinks Example
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 { ExcelUtility } from "./ExcelUtility" ;
@Component ({
standalone : false ,
selector : "app-root" ,
styleUrls : ["./app.component.scss" ],
templateUrl : "./app.component.html"
})
export class AppComponent implements OnInit {
@ViewChild ("spreadsheet" , { static : true })
public spreadsheet: IgxSpreadsheetComponent;
constructor ( ) { }
public ngOnInit ( ) {
const excelFile = "https://static.infragistics.com/xplatform/excel/Hyperlinks.xlsx" ;
ExcelUtility.loadFromUrl(excelFile).then((w ) => {
this .spreadsheet.workbook = w;
});
}
}
ts コピー <div class ="container vertical" >
<igx-spreadsheet #spreadsheet height ="100%" width ="100%" > </igx-spreadsheet >
</div >
html コピー
Like this sample? Get access to our complete Ignite UI for Angular toolkit and start building your own apps in minutes. Download it for free.
Hyperlinks Overview
하이퍼링크가 다음에 추가됩니다. IgxSpreadsheetComponent
액세스하여 제어 Hyperlinks
하이퍼링크를 배치할 워크시트의 컬렉션입니다. 이 컬렉션에는 Add
소요되는 메소드 WorksheetHyperlink
여기서는 셀 주소, 탐색할 하이퍼링크 URL, 표시 텍스트 및 선택적으로 마우스를 올리면 표시할 도구 설명을 정의할 수 있습니다.
Dependencies
하이퍼링크를 사용하도록 Angular 스프레드시트 컨트롤을 설정할 때 다음과 같이 WorksheetHyperlink
클래스를 가져와야 합니다.
import { WorksheetHyperlink } from 'igniteui-angular-excel' ;
ts
Code Snippet
다음 코드 조각은 Angular IgxSpreadsheetComponent
컨트롤에서 현재 보고 있는 워크시트에 하이퍼링크를 추가하는 방법을 보여줍니다.
this .spreadsheet.activeWorksheet.hyperlinks().add(new WorksheetHyperlink("A1" , "http://ko.infragistics.com" , "Infragistics" , "Infragistics Home Page" ));
ts
API References