private void InitData()
{
// Create path to xls file
string path = (this.Master as Site).GetDataDir();
// Set filename
string fileName = path + "\\Miscellaneous\\PivotTable.xls";
// Imports from an excel file.
GridWeb1.ImportExcelFile(fileName);
// Extract cells from source sheet
GridWorksheet sourceSheet = GridWeb1.WorkSheets[0];
Aspose.Cells.GridWeb.Data.GridCellArea sourceRange = new GridCellArea();
sourceRange.StartRow = 0;
sourceRange.StartColumn = 0;
sourceRange.EndRow = 29;
sourceRange.EndColumn = 5;
// Add worksheet
GridWorksheet sheet = GridWeb1.WorkSheets.Add("PivotTable Report");
GridCells cells = GridWeb1.WorkSheets[0].Cells;
// Add pivot table
int id = sheet.PivotTables.Add(sourceSheet, sourceRange, "A1", "PivotTable Report");
GridPivotTable pivotTable = sheet.PivotTables[id];
// Apply formatting
GridWeb1.DefaultFontName = "Arial";
GridWeb1.DefaultFontSize = new System.Web.UI.WebControls.FontUnit(10);
pivotTable.AddFieldToArea(GridPivotFieldType.Row, 0);
pivotTable.AddFieldToArea(GridPivotFieldType.Row, 2);
pivotTable.AddFieldToArea(GridPivotFieldType.Column, 3);
pivotTable.AddFieldToArea(GridPivotFieldType.Column, 4);
pivotTable.AddFieldToArea(GridPivotFieldType.Data, 5);
pivotTable.Fields(GridPivotFieldType.Data)[0].Function = GridPivotFieldFunction.Sum;
// Paints PivotTable report
pivotTable.CalculateData();
// Get sheet index
GridWeb1.ActiveSheetIndex = sheet.Index;
}