-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.component.ts
More file actions
35 lines (30 loc) · 1.1 KB
/
app.component.ts
File metadata and controls
35 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Component } from '@angular/core';
import { exportPivotGrid } from 'devextreme/excel_exporter';
import { Workbook } from 'devextreme-exceljs-fork';
import { saveAs } from 'file-saver';
import { AdventureWorksService } from './adventureworks.service';
import type { PivotGridDataSource } from './app.types';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
providers: [AdventureWorksService],
})
export class AppComponent {
title = 'Getting Started with DevExtreme Angular PivotGrid';
dataSource: PivotGridDataSource;
constructor(service: AdventureWorksService) {
this.dataSource = service.getPivotGridDataSource();
}
exportGrid(e: any): void {
const workbook = new Workbook();
const worksheet = workbook.addWorksheet('Sales');
exportPivotGrid({
component: e.component,
worksheet,
}).then(() => workbook.xlsx.writeBuffer().then((buffer: ArrayBuffer) => {
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'Sales.xlsx');
})).catch(() => undefined);
e.cancel = true;
}
}