|
[App.component.ts]
public toolbarClick(args: ClickEventArgs): void {
switch (args.item.text) {
case 'Excel Export':
const GridExport: Promise<any> = this.grid.excelExport({}, true);
GridExport.then((workbook: any) => {
// here we can access the workbook and set the number of rows should be freeze
workbook.worksheets[0].freeze = { row: 1 };
const book: Workbook = new Workbook(workbook, 'xlsx');
book.save('Export.xlsx');
});
}
} |
|
[App.component.html]
<div class="control-section">
<ejs-grid #grid [dataSource]='data' (dataBound)="databound($event)" allowPaging='true'
height=400 [toolbar]='toolbar' (toolbarClick)='toolbarClick($event)' [allowExcelExport]='true'>
. . .
</ejs-grid>
</div>
|
|
[App.component.ts]
public databound () {
var sum = 0;
this.grid.autoFitColumns();
let columns = this.grid.getColumns();
for (var i = 0; i< columns.length; i++) {
sum = sum + parseInt(columns[i].width as any);
}
this.grid.width = sum;
} |
There are many tricks to export data to Excel without any hassle but I want to share some easy and effective ones with you.
Method #1: Using Export Wizard
Method #2: Exporting Data To Excel From A Button
Method 3# Exporting Report Data To Excel
Method 4# Export SQL Data To Excel
To get detail about these methods of exporting data to Excel read this post: Export Data To Excel