How to: Export the Pivot Grid's Data to a File
- 2 minutes to read
This example shows how to export the pivot grid’s data using the Data-Aware or WYSIWYG types and set the export options.
- Click the Export to XLSX button to export data using the Data-Aware type. In the exported XLSX file, fixed row headers are disabled and a sheet name is set to “Pivot Grid Export”.
- Click the Export to PDF button to export data using the WYSIWYG type. The Print dialog is displayed when the exported PDF file is opened.
<dx:ASPxButton ID="DataAwareExportButton" runat="server"
Text="Export to XLSX" onclick="DataAwareExportButton_Click" ToolTip="Export using the Data-Aware type."/>
<dx:ASPxButton ID="WysiwygExportButton" runat="server" Text="Export to PDF"
onclick="WysiwygExportButton_Click" ToolTip="Export using the WYSIWYG type." />
<dx:ASPxPivotGrid ID="ASPxPivotGrid1" runat="server" ClientIDMode="AutoID"
DataSourceID="SqlDataSource1">
<Fields>
<dx:PivotGridField ID="fieldCountry" Area="ColumnArea" AreaIndex="0"
FieldName="Country">
</dx:PivotGridField>
<dx:PivotGridField ID="fieldCategoryName" Area="RowArea" AreaIndex="0"
Caption="Category" FieldName="CategoryName">
</dx:PivotGridField>
<dx:PivotGridField ID="fieldProductName" Area="RowArea" AreaIndex="1"
Caption="Product" FieldName="ProductName">
</dx:PivotGridField>
<dx:PivotGridField ID="fieldExtendedPrice" Area="DataArea" AreaIndex="0"
Caption="Extended Price" FieldName="Extended_Price">
</dx:PivotGridField>
<dx:PivotGridField ID="fieldSalesPerson" Area="ColumnArea" AreaIndex="1"
Caption="Sales Person" FieldName="Sales_Person">
</dx:PivotGridField>
<dx:PivotGridField ID="fieldQuantity" Area="DataArea" AreaIndex="1"
FieldName="Quantity">
</dx:PivotGridField>
</Fields>
</dx:ASPxPivotGrid>
<dx:ASPxPivotGridExporter ID="ASPxPivotGridExporter1" runat="server">
</dx:ASPxPivotGridExporter>
using System;
using DevExpress.XtraPrinting;
using DevExpress.Utils;
namespace ASPPivotGridExport {
public partial class WebForm1 : System.Web.UI.Page {
protected void DataAwareExportButton_Click(object sender, EventArgs e) {
// Exports using the Data-Aware type.
ASPxPivotGridExporter1.ExportXlsxToResponse("ASPxPivotGrid", new XlsxExportOptionsEx {
AllowFixedColumns = DefaultBoolean.False,
SheetName = "Pivot Grid Export"
},
true);
}
protected void WysiwygExportButton_Click(object sender, EventArgs e) {
// Exports using the WYSIWYG type.
ASPxPivotGridExporter1.ExportPdfToResponse("ASPxPivotGrid", new PdfExportOptions() {
ShowPrintDialogOnOpen = true,
}, true);
}
}
}