New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Export Header Areas
The example below demonstrates how to add the Data, Row and Column header areas in the Excel document. The solution is to add a new row at the beginning of the document and populate it with the appropriate field names. You can access the spreadsheet on PivotGridInfrastructureExporting event handler and use ShiftRowsDown to insert a row at the beginning of the document.
C#
protected void RadPivotGrid1_PivotGridInfrastructureExporting(object sender, PivotGridInfrastructureExportingEventArgs e)
{
e.ExportStructure.Tables[0].ShiftRowsDown(1, 1);
foreach (var field in RadPivotGrid1.Fields)
{
if (!field.IsHidden)
{
switch (field.FieldType)
{
case "PivotGridRowField":
e.ExportStructure.Tables[0].Cells[1, 2].Value += field.DataField + " ";
break;
case "PivotGridColumnField":
e.ExportStructure.Tables[0].Cells[2, 1].Value += field.DataField + " ";
break;
case "PivotGridAggregateField":
e.ExportStructure.Tables[0].Cells[1, 1].Value += field.DataField + " ";
break;
default:
break;
}
}
}
}