-
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
-
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
Pivot Grid - Header and Footer
The PivotGrid allows you to customize a header and a footer in the exported Excel file. The ExcelJS library allows you to customize worksheets outside of exported cell regions. This, in turns, allows you to add a header (a title before exported data) and a footer (a note after exported data).
If you have technical questions, please create a support ticket in the DevExpress Support Center.
@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 class="long-title"><h3>Sales Amount by Region</h3></div>
@(Html.DevExtreme().PivotGrid()
.ID("sales")
.Height(440)
.ShowBorders(true)
.AllowSorting(true)
.AllowFiltering(true)
.Height(440)
.ShowBorders(true)
.FieldPanel(p => p.ShowColumnFields(true)
.ShowDataFields(true)
.ShowFilterFields(true)
.ShowRowFields(true)
.AllowFieldDragging(true)
.Visible(true))
.FieldChooser(c => c.Enabled(false))
.Export(e => e.Enabled(true))
.OnExporting("onExporting")
.DataSource(d => d
.Store(s => s.WebApi().Controller("PivotGridData"))
.Fields(fields => {
fields.Add()
.Caption("Region")
.Width(120)
.DataField("Region")
.Area(PivotGridArea.Row)
.Expanded(true);
fields.Add()
.Caption("City")
.Width(150)
.DataField("City")
.Area(PivotGridArea.Row);
fields.Add()
.DataField("Date")
.DataType(PivotGridDataType.Date)
.Area(PivotGridArea.Column)
.FilterValues(new[] { new[] { 2013 }, new[] { 2014 }, new[] { 2015 } })
.Expanded(false);
fields.Add()
.Caption("Sales")
.DataField("Amount")
.DataType(PivotGridDataType.Number)
.SummaryType(SummaryType.Sum)
.Format(Format.Currency)
.Area(PivotGridArea.Data);
fields.Add()
.Caption("Country")
.DataField("country")
.Area(PivotGridArea.Filter);
})
)
)
<div class="export-options">
<div class="caption">Export Options</div>
<div class="options">
@(Html.DevExtreme().CheckBox()
.Text("Export Data Field Headers")
.Value(false)
.OnValueChanged("onExportDataFieldHeadersChanged")
)
@(Html.DevExtreme().CheckBox()
.Text("Export Row Field Headers")
.Value(false)
.OnValueChanged("onExportRowFieldHeadersChanged")
)
@(Html.DevExtreme().CheckBox()
.Text("Export Column Field Headers")
.Value(false)
.OnValueChanged("onExportColumnFieldHeadersChanged")
)
@(Html.DevExtreme().CheckBox()
.Text("Export Filter Field Headers")
.Value(false)
.OnValueChanged("onExportFilterFieldHeadersChanged")
)
</div>
</div>
<script>
var exportHeaderOptions = {
exportRowFieldHeaders: false,
exportColumnFieldHeaders: false,
exportDataFieldHeaders: false,
exportFilterFieldHeaders: false,
};
function onExporting(e) {
var workbook = new ExcelJS.Workbook();
var worksheet = workbook.addWorksheet('Sales');
worksheet.columns = [
{ width: 30 }, { width: 20 }, { width: 30 }, { width: 30 }, { width: 30 }, { width: 30 }
];
DevExpress.excelExporter.exportPivotGrid({
component: e.component,
worksheet: worksheet,
topLeftCell: { row: 4, column: 1 },
keepColumnWidths: false,
...exportHeaderOptions
}).then(function (cellRange) {
// Header
var headerRow = worksheet.getRow(2);
headerRow.height = 30;
var columnFromIndex = worksheet.views[0].xSplit + 1;
var columnToIndex = columnFromIndex + 3;
worksheet.mergeCells(2, columnFromIndex, 2, columnToIndex);
var headerCell = headerRow.getCell(columnFromIndex);
headerCell.value = 'Sales Amount by Region';
headerCell.font = { name: 'Segoe UI Light', size: 22, bold: true };
headerCell.alignment = { horizontal: 'left', vertical: 'middle', wrapText: true };
// Footer
var footerRowIndex = cellRange.to.row + 2;
var footerCell = worksheet.getRow(footerRowIndex).getCell(cellRange.to.column);
footerCell.value = 'www.wikipedia.org';
footerCell.font = { color: { argb: 'BFBFBF' }, italic: true };
footerCell.alignment = { horizontal: 'right' };
}).then(function () {
workbook.xlsx.writeBuffer().then(function (buffer) {
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'Sales.xlsx');
});
});
}
function onExportDataFieldHeadersChanged(e) {
exportHeaderOptions.exportDataFieldHeaders = e.value;
}
function onExportRowFieldHeadersChanged(e) {
exportHeaderOptions.exportRowFieldHeaders = e.value;
}
function onExportColumnFieldHeadersChanged(e) {
exportHeaderOptions.exportColumnFieldHeaders = e.value;
}
function onExportFilterFieldHeadersChanged(e) {
exportHeaderOptions.exportFilterFieldHeaders = e.value;
}
</script>
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
Follow the steps below to configure a header/footer:
-
In the onExporting event handler, call the exportPivotGrid(options) method.
-
Enable one or multiple options to export headers of the fields in the field panel:
-
Execute a promise after the exportPivotGrid(options) method. In this promise, specify the position, appearance, and content of the header/footer. The functions used to generate header and footer sections utilize the following PivotGrid customization features:
-
Cell values formatting
-
Text alignment