Dear All,
Hi Winanjaya,
Thanks for your posting and considering Aspose.Cells.
You can surely create pivot table using Aspose.Cells API and save your workbook in XLS format.
Please see the example in this article for your needs.
( Pivot Table and Source Data|Documentation )
Hi Winanjaya,
Hello,
Hi Winanjaya,
var workbook = new Workbook(myDir + “Daily+Report2014-04-04.xls”);
Worksheet sheet2 = workbook.Worksheets[workbook.Worksheets.Add()];
Aspose.Cells.Pivot.PivotTableCollection pivotTables = sheet2.PivotTables;
//Adding a PivotTable to the worksheet
int index = pivotTables.Add("=" + workbook.Worksheets[0].Name + “!A1:E” + workbook.Worksheets[0].Cells.MaxDataRow + 1, “B3”, “PivotTable1”);
//Accessing the instance of the newly added PivotTable
Aspose.Cells.Pivot.PivotTable pivotTable = pivotTables[index];
//Showing the grand totals
pivotTable.RowGrand = true;
pivotTable.ColumnGrand = true;
//Setting the PivotTable report is automatically formatted
pivotTable.IsAutoFormat = true;
//Setting the PivotTable Auto Format type
pivotTable.AutoFormatType = Aspose.Cells.Pivot.PivotTableAutoFormatType.Classic;
//Dragging Fields to Row Labels
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Row, “Branch”);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Row, “LOB”);
//Dragging Fields to Data Area
PivotField GPW = pivotTable.BaseFields[“GPW”];
GPW.Function = ConsolidationFunction.Sum;
GPW.NumberFormat = “#,##0.00”;
pivotTable.AddFieldToArea(PivotFieldType.Data, GPW);
PivotField CLM = pivotTable.BaseFields[“CLM”];
CLM.Function = ConsolidationFunction.Sum;
CLM.NumberFormat = “#,##0.00”;
pivotTable.AddFieldToArea(PivotFieldType.Data, CLM);
PivotField COLL = pivotTable.BaseFields[“COLL”];
COLL.Function = ConsolidationFunction.Sum;
COLL.NumberFormat = “#,##0.00”;
pivotTable.AddFieldToArea(PivotFieldType.Data, COLL);
if (pivotTable.DataField != null)
{
//DataField attribute of PivotTable exists only if DataFields contains two or more PivotField
pivotTable.AddFieldToArea(PivotFieldType.Column, pivotTable.DataField);
}
workbook.Save(myDir + “output.xlsx”, SaveFormat.Xlsx);
Hello,
Hello,

Hello,

Hi Winanjaya,
Hello.
Hi Winanjaya,
index = workbook.Styles.Add();
Style style = workbook.Styles[index];
style.HorizontalAlignment = TextAlignmentType.Right;
CellArea area = pivotTable.ColumnRange;
int start = area.StartRow;
for (int i = start; i <= area.EndRow; i++)
{
//Format the third column field.
pivotTable.Format(i, 3, style);
}
Hi Winanjaya,
Hello,
Hi Winanjaya,
//Accessing the column fields.
PivotFieldCollection pivotFields = pivotTable.ColumnFields;
//Accessing the first column field from the collection.
PivotField pivotField = pivotFields[0];
//Setting the field auto sort.
pivotField.IsAutoSort = true;
//Setting the field sorting in ascending order.
pivotField.IsAscendSort = true;
//Setting the field auto sort using the field itself.
pivotField.AutoSortField = -1;
//Setting the field auto show.
Hello Babar Raza,


Hi Winanjaya,
Hello,