ASP.NET MVC OLAP: Exporting a PivotGrid to Excel
The PivotGrid control extends the FlexGrid, so you can export its contents to XLSX files in the same way you would export regular FlexGrid controls.
We'll create a client-side JavaScript function to build the XLSX file you want. You have complete control of the output. For example, you may add sheets containing the current view, any pre-defined views, and the raw data. Here’s an example:
function exportToXlsx() {
// create book with current view
var book = wijmo.grid.xlsx.FlexGridXlsxConverter.save(thePivotGrid, {
includeColumnHeaders: true,
includeRowHeaders: true
});
book.sheets[0].name = 'Main View';
// add sheet with raw data
if (theRawGrid.rows.length <= 20000) {
var raw = wijmo.grid.xlsx.FlexGridXlsxConverter.save(theRawGrid, {
includeColumnHeaders: true,
includeRowHeaders: false
});
raw.sheets[0].name = 'Raw Data';
book.sheets.push(raw.sheets[0]);
}
// save book
book.save('olap.xlsx');
}
More from the ASP.NET MVC OLAP
Demos: ASP.NET 4.0 | ASP.NET Core
Take a look at the documentation for more details.
Download C1Studio
Full OLAP series:
- Getting Started with ASP.NET MVC OLAP: Create Basic Pivot Tables
- Answer Recurring Questions with Pre-Defined Views
- Filtering Data in a PivotGrid
- Exporting a PivotGrid to Excel
- Customizing the UI and PivotGrid (coming soon)