Vue Common - Utils - excelExporter
An object that serves as a namespace for the methods that export DevExtreme UI components to Excel.
exportDataGrid(options)
Exports grid data to Excel.
Export settings.
This method requires ExcelJS v4+ to export data and FileSaver v2.0.2+ to save files.
You can call this method at any point in your application. In the example below, this method is called in the onExporting function that is executed before data is exported. The cancel parameter is enabled to prevent the built-in export. As a result, the DataGrid is exported to a single worksheet.
- <template>
- <DxDataGrid ...
- @exporting="onExporting">
- <DxExport
- :enabled="true"
- />
- </DxDataGrid>
- </template>
- <script>
- import 'devextreme/dist/css/dx.light.css';
- import { DxDataGrid, DxExport } from 'devextreme-vue/data-grid';
- import { exportDataGrid } from 'devextreme/excel_exporter';
- import { Workbook } from 'exceljs';
- import saveAs from 'file-saver';
- export default {
- components: {
- DxDataGrid,
- DxExport
- },
- methods: {
- onExporting(e) {
- const workbook = new Workbook();
- const worksheet = workbook.addWorksheet('Main sheet');
- exportDataGrid({
- component: e.component,
- worksheet: worksheet
- }).then(function() {
- workbook.xlsx.writeBuffer()
- .then(function(buffer) {
- saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'DataGrid.xlsx');
- });
- });
- e.cancel = true;
- }
- }
- }
- </script>
See Also
exportPivotGrid(options)
Exports pivot grid data to Excel.
Export settings.
This method requires ExcelJS v4+ to export data and FileSaver v2.0.2+ to save files.
You can call this method at any point in your application. In the example below, this method is called in the onExporting function that is executed before data is exported. The cancel parameter is enabled to prevent the built-in export. As a result, the PivotGrid is exported to a single worksheet.
- <template>
- <DxPivotGrid ...
- @exporting="onExporting">
- <DxExport
- :enabled="true"
- />
- </DxPivotGrid>
- </template>
- <script>
- import 'devextreme/dist/css/dx.light.css';
- import { DxPivotGrid, DxExport } from 'devextreme-vue/pivot-grid';
- import { exportPivotGrid } from 'devextreme/excel_exporter';
- import { Workbook } from 'exceljs';
- import saveAs from 'file-saver';
- export default {
- components: {
- DxPivotGrid,
- DxExport
- },
- methods: {
- onExporting(e) {
- const workbook = new Workbook();
- const worksheet = workbook.addWorksheet('Main sheet');
- exportPivotGrid({
- component: e.component,
- worksheet: worksheet
- }).then(function() {
- workbook.xlsx.writeBuffer()
- .then(function(buffer) {
- saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'PivotGrid.xlsx');
- });
- });
- e.cancel = true;
- }
- }
- }
- </script>