Web Components スプレッドシートのアクティブ化
Web Components Spreadsheet コンポーネントは、コントロールで現在アクティブなセル、ペイン、およびワークシートを決定できるプロパティを公開します。これは、ユーザーがコントロール内で移動または編集している場所を判断するのに役立ちます。
Web Components スプレッドシートのアクティブ化の例
import { saveAs } from "file-saver";
import { Workbook } from 'igniteui-webcomponents-excel';
import { WorkbookFormat } from 'igniteui-webcomponents-excel';
import { WorkbookSaveOptions } from 'igniteui-webcomponents-excel';
import { WorkbookLoadOptions } from 'igniteui-webcomponents-excel';
import { IgcExcelXlsxModule } from 'igniteui-webcomponents-excel';
import { IgcExcelCoreModule } from 'igniteui-webcomponents-excel';
import { IgcExcelModule } from 'igniteui-webcomponents-excel';
IgcExcelCoreModule.register();
IgcExcelModule.register();
IgcExcelXlsxModule.register();
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, new WorkbookLoadOptions(), (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, new WorkbookLoadOptions(), (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);
}
});
}
}
tsimport { ExcelUtility } from './ExcelUtility';
import { IgcSpreadsheetModule } from 'igniteui-webcomponents-spreadsheet';
import { IgcSpreadsheetComponent } from 'igniteui-webcomponents-spreadsheet';
import { IgcSpreadsheetActiveCellChangedEventArgs } from 'igniteui-webcomponents-spreadsheet';
import { SpreadsheetCell } from 'igniteui-webcomponents-spreadsheet';
import { ModuleManager } from 'igniteui-webcomponents-core';
ModuleManager.register(IgcSpreadsheetModule);
export class SpreadsheetActivation {
private spreadsheet: IgcSpreadsheetComponent;
private activateText: string = "";
constructor() {
this.onSpreadsheetActiveCellChanged = this.onSpreadsheetActiveCellChanged.bind(this);
this.onActiveCellAddressTextBoxChanged = this.onActiveCellAddressTextBoxChanged.bind(this);
this.onActivateCellBtnClick = this.onActivateCellBtnClick.bind(this);
this.spreadsheet = document.getElementById('spreadsheet') as IgcSpreadsheetComponent;
this.spreadsheet.activeCellChanged = this.onSpreadsheetActiveCellChanged;
let path = 'https://static.infragistics.com/xplatform/excel/SalesData.xlsx';
ExcelUtility.loadFromUrl(path).then((w) => {
this.spreadsheet.workbook = w;
});
document.getElementById('activateCellBtn')!.addEventListener('click', this.onActivateCellBtnClick);
document.getElementById('activateCellTextBox')!.addEventListener('change', this.onActiveCellAddressTextBoxChanged);
}
onSpreadsheetActiveCellChanged(s: IgcSpreadsheetComponent, e: IgcSpreadsheetActiveCellChangedEventArgs) {
document.getElementById('activeCellLabel')!.textContent = 'Current Active Cell: ' + e.newValue.toString();
}
onActivateCellBtnClick() {
this.spreadsheet.activeCell = new SpreadsheetCell(this.activateText);
}
onActiveCellAddressTextBoxChanged(e: any) {
this.activateText = e.target.value;
}
}
new SpreadsheetActivation();
ts<!DOCTYPE html>
<html>
<head>
<title>SpreadsheetActivation</title>
<meta charset="UTF-8" />
<link rel="shortcut icon" href="https://static.infragistics.com/xplatform/images/browsers/wc.png" >
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Kanit&display=swap" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium Web" />
<link rel="stylesheet" href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" type="text/css" />
</head>
<body>
<div id="root">
<div class="container sample">
<div class="options horizontal">
<input id="activateCellTextBox" class="options-text" type="text" />
<button id="activateCellBtn" class="options-button">Activate Cell</button>
<label id="activeCellLabel" class="options-label"> Current Active Cell: </label>
</div>
<igc-spreadsheet id="spreadsheet" width="100%" height="calc(100% - 2.5rem)">
</igc-spreadsheet>
</div>
</div>
<!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><script src="src/index.ts"></script><% } %>
</body>
</html>
html/* shared styles are loaded from: */
/* https://static.infragistics.com/xplatform/css/samples */
css
このサンプルが気に入りましたか? 完全な Ignite UI for Web Componentsツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
アクティベーションの概要
Web Components IgcSpreadsheetComponent
コントロールのアクティブ化は、スプレッドシートの現在の workbook
のセル、ペイン、およびワークシート間で分割されます。3 つの アクティブなプロパティは以下のとおりです。
activeCell
: スプレッドシートのアクティブ セルを設定します。設定するには、SpreadsheetCell
の新しいインスタンスを作成し、そのセルに関する列と行、またはセルの文字列アドレスなどの情報を渡す必要があります。activePane
: スプレッドシート コントロールの現在アクティブなワークシートのアクティブ ペインを返します。activeWorksheet
: スプレッドシート コントロールのworkbook
内のアクティブ ワークシートを返すか、設定します。これは、スプレッドシートに添付されているworkbook
内の既存のワークシートに設定することで設定できます。
コード スニペット
次のコード スニペットは、IgcSpreadsheetComponent
コントロールのセルとワークシートのアクティブ化の設定を示しています。
this.spreadsheet.activeWorksheet = this.spreadsheet.workbook.worksheets(1);
this.spreadsheet.activeCell = new SpreadsheetCell("C5");
ts