Skip to content

Commit d443860

Browse files
committed
Improved Code Style of Angular 2+ Demo [ci skip]
1 parent 9358214 commit d443860

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

demos/angular2/src/app/sheetjs.component.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import * as XLSX from 'xlsx';
66

77
import { saveAs } from 'file-saver';
88

9-
type AOA = Array<Array<any> >;
9+
type AOA = Array<Array<any>>;
1010

11-
function s2ab(s:string):ArrayBuffer {
11+
function s2ab(s: string): ArrayBuffer {
1212
const buf = new ArrayBuffer(s.length);
1313
const view = new Uint8Array(buf);
1414
for (let i = 0; i !== s.length; ++i) {
@@ -33,17 +33,16 @@ function s2ab(s:string):ArrayBuffer {
3333
})
3434

3535
export class SheetJSComponent {
36-
data:AOA = [[1,2],[3,4]];
37-
wopts:XLSX.WritingOptions = { bookType:'xlsx', type:'binary' };
38-
fileName:string = "SheetJS.xlsx";
36+
data: AOA = [[1,2],[3,4]];
37+
wopts: XLSX.WritingOptions = { bookType:'xlsx', type:'binary' };
38+
fileName: string = "SheetJS.xlsx";
3939

40-
public onFileChange(evt:any) {
41-
const scope = this;
40+
onFileChange(evt: any) {
4241
/* wire up file reader */
43-
const target:DataTransfer = (<DataTransfer>(evt.target));
44-
if(target.files.length != 1) throw new Error("Cannot upload multiple files on the entry");
42+
const target: DataTransfer = <DataTransfer>(evt.target);
43+
if(target.files.length != 1) { throw new Error("Cannot upload multiple files on the entry") };
4544
const reader = new FileReader();
46-
reader.onload = function (e:any) {
45+
reader.onload = (e: any) => {
4746
/* read workbook */
4847
const bstr = e.target.result;
4948
const wb = XLSX.read(bstr, {type:'binary'});
@@ -52,13 +51,13 @@ export class SheetJSComponent {
5251
const wsname = wb.SheetNames[0];
5352
const ws = wb.Sheets[wsname];
5453

55-
/* save data to scope */
56-
scope.data = (<AOA>(XLSX.utils.sheet_to_json(ws, {header:1})));
54+
/* save data */
55+
this.data = <AOA>(XLSX.utils.sheet_to_json(ws, {header:1}));
5756
};
5857
reader.readAsBinaryString(target.files[0]);
5958
}
6059

61-
export():void {
60+
export(): void {
6261
/* generate worksheet */
6362
const ws = XLSX.utils.aoa_to_sheet(this.data);
6463

0 commit comments

Comments
 (0)