jQuery/JS Common - Utils - excelExporter
exportDataGrid(options)
This method requires ExcelJS v4.4.0+ to export data and FileSaver v2.0.2+ to save files. If you apply CSP rules, refer to the ExcelJS CSP Treats section to read more about potential vulnerabilities.
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. As a result, the DataGrid is exported to a single worksheet.
- $('#gridContainer').dxDataGrid({
- export: {
- enabled: true
- },
- onExporting: function(e) {
- const workbook = new ExcelJS.Workbook();
- const worksheet = workbook.addWorksheet('Main sheet');
- DevExpress.excelExporter.exportDataGrid({
- worksheet: worksheet,
- component: e.component
- }).then(function() {
- workbook.xlsx.writeBuffer().then(function(buffer) {
- saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'DataGrid.xlsx');
- });
- });
- }
- });
- <head>
- <!-- ... -->
- <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.4.0/polyfill.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/exceljs/4.4.0/exceljs.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.2/FileSaver.min.js"></script>
- <!-- reference the DevExtreme sources here -->
- </head>
See Also
exportPivotGrid(options)
This method requires ExcelJS v4.4.0+ to export data and FileSaver v2.0.2+ to save files. If you apply CSP rules, refer to the ExcelJS CSP Treats section to read more about potential vulnerabilities.
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.
- $('#gridContainer').dxPivotGrid({
- export: {
- enabled: true
- },
- onExporting: function(e) {
- const workbook = new ExcelJS.Workbook();
- const worksheet = workbook.addWorksheet('Main sheet');
- DevExpress.excelExporter.exportPivotGrid({
- worksheet: worksheet,
- component: e.component
- }).then(function() {
- workbook.xlsx.writeBuffer().then(function(buffer) {
- saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'PivotGrid.xlsx');
- });
- });
- }
- });
- <head>
- <!-- ... -->
- <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.4.0/polyfill.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/exceljs/4.4.0/exceljs.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.2/FileSaver.min.js"></script>
- <!-- reference the DevExtreme sources here -->
- </head>
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.