@Component({
selector: 'nzo-sheet',
templateUrl: './nzo-sheet.component.html',
styleUrls: ['./nzo-sheet.component.less']
})
export class NzoSheetComponent implements OnInit, AfterViewInit {
@ViewChild('spreadsheet', { static: false})
public spreadsheetObj: SpreadsheetComponent;
public query: Query = null;
public rowsTotal: number;
public colsTotal: number;
public colsLetter: string;
@Input() title: string = 'Sheet1';
@Input() data: Object[] = [{}];
@Input() columns: NzoSheetColumn[] = [];
public openUrl = 'https://ej2services.syncfusion.com/production/web-services/api/spreadsheet/open';
public saveUrl = 'https://ej2services.syncfusion.com/production/web-services/api/spreadsheet/save';
constructor(
private deep: DeepService,
private fmt: FormatService,
) { }
ngOnInit() {
if (this.columns.length>0) {
this.query = new Query().select(this.deep.get(this.columns, 'index')).take(200);
}
// total rows count
this.rowsTotal = this.data.length + 1; // +1 for header
// total columns count
this.colsTotal = this.columns.length || Object.keys(this.data[0]).length;
// last column letter
this.colsLetter = this.fmt.convertNumberToLetter(this.colsTotal);
}
ngAfterViewInit(): void {
this.spreadsheetObj.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, `A1:${this.colsLetter}1`);
}
created() {
console.log('***', `A1:${this.colsLetter}${this.rowsTotal}`);
}
}
-------- NzoSheetComponent End ------------
-------- nzo-sheet.component.html -----------
<ejs-spreadsheet #spreadsheet [openUrl]="openUrl" [saveUrl]="saveUrl" (created)="created()" style="height: 100%;">
<e-sheets>
<e-sheet [name]="title">
<e-ranges>
<e-range [dataSource]="data" [query]="query"></e-range>
</e-ranges>
<e-columns>
<e-column *ngFor="let c of columns" [width]=c.width></e-column>
</e-columns>
</e-sheet>
</e-sheets>
</ejs-spreadsheet>
-------- nzo-sheet.component.html end -----------