-
Data Grid
- Overview
-
Data Binding
-
Paging and Scrolling
-
Editing
-
Grouping
-
Filtering and Sorting
- Focused Row
-
Row Drag & Drop
-
Selection
-
Columns
- State Persistence
-
Appearance
-
Templates
-
Data Summaries
-
Master-Detail
-
Export to PDF
-
Export to Excel
-
Adaptability
- Keyboard Navigation
-
Pivot Grid
- Overview
-
Data Binding
-
Field Chooser
-
Features
-
Export to Excel
-
Tree List
- Overview
-
Data Binding
- Sorting
- Paging
-
Editing
- Node Drag & Drop
- Focused Row
-
Selection
-
Filtering
-
Column Customization
- State Persistence
- Adaptability
- Keyboard Navigation
-
Scheduler
- Overview
-
Data Binding
-
Views
-
Features
- Virtual Scrolling
-
Grouping
-
Customization
- Adaptability
-
Html Editor
-
Chat
-
Diagram
- Overview
-
Data Binding
-
Featured Shapes
-
Custom Shapes
-
Document Capabilities
-
User Interaction
- UI Customization
- Adaptability
-
Charts
- Overview
-
Data Binding
-
Area Charts
-
Bar Charts
- Bullet Charts
-
Doughnut Charts
-
Financial Charts
-
Line Charts
-
Pie Charts
-
Point Charts
-
Polar and Radar Charts
-
Range Charts
-
Sparkline Charts
-
Tree Map
-
Funnel and Pyramid Charts
- Sankey Chart
-
Combinations
-
More Features
-
Export
-
Selection
-
Tooltips
-
Zooming
-
-
Gantt
- Overview
-
Data
-
UI Customization
- Strip Lines
- Export to PDF
- Sorting
-
Filtering
-
Reporting
- AI-powered Extensions
-
Interaction
-
Report Types
-
Data binding
-
Real-life Reports
-
Layout Features
-
Report Controls
-
Web-specific Features
-
Rich Text Editor
- Overview
- Load/Save
- Document Protection
-
Templates
- Autocorrect
-
Customization
- Simple View
-
Spreadsheet
- Overview
-
Open a Document
- Export And Printing
-
Features
-
UI Customization
-
Gauges
- Overview
-
Data Binding
-
Bar Gauge
-
Circular Gauge
-
Linear Gauge
-
Navigation
- Overview
- Accordion
-
Menu
- Multi View
-
Drawer
-
Tab Panel
-
Tabs
-
Toolbar
- Pagination
-
Tree View
- Right-to-Left Support
-
Layout
-
Tile View
- Splitter
-
Gallery
- Scroll View
- Resizable
-
-
Editors
- Overview
- Autocomplete
-
Calendar
- Check Box
- Color Box
- Date Box
-
Date Range Box
-
Drop Down Box
-
Number Box
-
Select Box
- Switch
-
Tag Box
- Text Area
- Text Box
- Validation
- Custom Text Editor Buttons
- Right-to-Left Support
- Editor Appearance Variants
-
Forms and Multi-Purpose
- Overview
- Button Group
- Field Set
-
Filter Builder
-
Form
- Radio Group
-
Range Selector
- Numeric Scale (Lightweight)
- Numeric Scale
- Date-Time Scale (Lightweight)
- Date-Time Scale
- Logarithmic Scale
- Discrete scale
- Custom Formatting
- Use Range Selection for Calculation
- Use Range Selection for Filtering
- Image on Background
- Chart on Background
- Customized Chart on Background
- Chart on Background with Series Template
- Range Slider
- Slider
-
Sortable
-
File Management
-
File Manager
- Overview
-
File System Types
-
Customization
-
File Uploader
-
-
Actions and Lists
-
Maps
- Overview
-
Map
-
Vector Map
-
Dialogs and Notifications
-
Localization
Related Demos:
Your search did not match any results.
Data Grid - Export Multiple Grids
The exportDataGrid() method allows users to export multiple grids to one Excel document. Grids are exported consequently in a chain of Promises.
In this demo, this functionality is used to export two DataGrids into separate worksheets in the same workbook. Starting position of each exported grid is set using the topLeftCell property.
Use the customizeCell method to customize the exported worksheets.
Was this demo helpful?
Feel free to share demo-related thoughts here.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Thank you for the feedback!
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Backend API
@section ExternalDependencies {
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.10.1/polyfill.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/exceljs/4.3.0/exceljs.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
}
<div id="exportContainer">
@(Html.DevExtreme().Button()
.Text("Export multiple grids")
.Icon("xlsxfile")
.OnClick("exportGrids"))
</div>
@(Html.DevExtreme().TabPanel()
.ID("tabPanel")
.DataSource(new[] {
new { text = "Price" },
new { text = "Rating" }
})
.ItemTemplate(new JS("tabPanelTemplate"))
.ItemTitleTemplate(@<text><span class="dx-tab-text"><%- text %></span></text>)
.DeferRendering(false))
<script>
var priceCaption = "Price";
var ratingCaption = "Rating";
function tabPanelTemplate(itemData, itemIndex, itemElement) {
if (itemData.text === priceCaption) {
var $gridContainer = $("<div id='priceDataGrid'>");
itemElement.append($gridContainer);
$gridContainer.dxDataGrid({
width: "100%",
columns: [
{ dataField: "Product_ID", caption: "ID", width: 50 },
{ dataField: "Product_Name", caption: "Name" },
{ dataField: "Product_Sale_Price", caption: "Sale Price", dataType: "number", format: "currency" },
{ dataField: "Product_Retail_Price", caption: "Retail Price", dataType: "number", format: "currency" }
],
showBorders: true,
rowAlternationEnabled: true,
dataSource: {
store: {
type: "odata",
version: 2,
url: "https://js.devexpress.com/Demos/DevAV/odata/Products",
key: "Product_ID"
},
select: ["Product_ID", "Product_Name", "Product_Sale_Price", "Product_Retail_Price"],
filter: ["Product_ID", "<", 10]
}
});
}
if (itemData.text === "Rating") {
var $gridContainer = $("<div id='ratingDataGrid'>");
itemElement.append($gridContainer);
$gridContainer.dxDataGrid({
width: "100%",
columns: [
{ dataField: "Product_ID", caption: "ID", width: 50 },
{ dataField: "Product_Name", caption: "Name" },
{ dataField: "Product_Consumer_Rating", caption: "Rating" },
{ dataField: "Product_Category", caption: "Category" }
],
showBorders: true,
rowAlternationEnabled: true,
dataSource: {
store: {
type: "odata",
version: 2,
url: "https://js.devexpress.com/Demos/DevAV/odata/Products"
},
select: ["Product_ID", "Product_Name", "Product_Consumer_Rating", "Product_Category"],
filter: ["Product_ID", "<", 10]
}
});
}
}
function exportGrids() {
var dataGrid1 = $("#priceDataGrid").dxDataGrid("instance");
var dataGrid2 = $("#ratingDataGrid").dxDataGrid("instance");
var workbook = new ExcelJS.Workbook();
var priceSheet = workbook.addWorksheet(priceCaption);
var ratingSheet = workbook.addWorksheet(ratingCaption);
priceSheet.getRow(2).getCell(2).value = "Price";
priceSheet.getRow(2).getCell(2).font = { bold: true, size: 16, underline: "double" };
ratingSheet.getRow(2).getCell(2).value = "Rating";
ratingSheet.getRow(2).getCell(2).font = { bold: true, size: 16, underline: "double" };
function setAlternatingRowsBackground(gridCell, excelCell) {
if (gridCell.rowType === "header" || gridCell.rowType === "data") {
if (excelCell.fullAddress.row % 2 === 0) {
excelCell.fill = { type: "pattern", pattern: "solid", fgColor: { argb: "D3D3D3" }, bgColor: { argb: "D3D3D3" } };
}
}
}
DevExpress.excelExporter.exportDataGrid({
worksheet: priceSheet,
component: dataGrid1,
topLeftCell: { row: 4, column: 2 },
customizeCell: function (options) {
setAlternatingRowsBackground(options.gridCell, options.excelCell)
}
}).then(function () {
return DevExpress.excelExporter.exportDataGrid({
worksheet: ratingSheet,
component: dataGrid2,
topLeftCell: { row: 4, column: 2 },
customizeCell: function (options) {
setAlternatingRowsBackground(options.gridCell, options.excelCell)
}
});
}).then(function () {
workbook.xlsx.writeBuffer().then(function (buffer) {
saveAs(new Blob([buffer], { type: "application/octet-stream" }), "MultipleGrids.xlsx");
});
});
}
</script>
using DevExtreme.NETCore.Demos.Models;
using DevExtreme.NETCore.Demos.Models.DataGrid;
using DevExtreme.NETCore.Demos.Models.SampleData;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
namespace DevExtreme.NETCore.Demos.Controllers {
public class DataGridController : Controller {
public ActionResult ExcelJSExportMultipleGrids() {
return View();
}
}
}
#priceDataGrid, #ratingDataGrid {
padding: 10px;
}
#exportContainer {
text-align: right;
}
#tabPanel {
padding-top: 10px;
}