Build 4.5.0.27 of xlsgen adds automatic source code generation support for pivot tables. In other words, the automatic source code generation tool automatically creates the source code for existing pivot tables from XLS, XLSX and XLSB files, in the programming language of your choice. It makes it much simpler to use in practice : just create the pivot table in Excel, and ask the automatic source code generation tool for it.
Here is an example :
A pivot table in ExcelAnd here is the corresponding source code for it (VB) :
Dim pivotTable002s0 As IXlsPivotTable
Set pivotTable002s0 = wksht002.NewPivotTable
pivotTable002s0.DataSource.Range = "Sheet2!B2:F7"
pivotTable002s0.Options.Layout = enumPivotTableLayout.pivottablelayout_tabular
pivotTable002s0.Options.BuiltInPivotTableStyle = enumPivotTableStyle.pivottablestyle_light16
pivotTable002s0.Options.ShowRowHeaders = True
pivotTable002s0.Options.ShowColumnHeaders = True
pivotTable002s0.Options.ShowRowStripes = False
pivotTable002s0.Options.ShowColumnStripes = False
pivotTable002s0.Options.ShowGrandTotalsForRows = True
pivotTable002s0.Options.ShowGrandTotalsForColumns = True
Dim pf002s0r1 As IXlsPivotTableField
Set pf002s0r1 = pivotTable002s0.Rows.AddByName("s0")
pf002s0r1.AggregateFunction = enumPivotAggregateFunction.aggrpivotfunction_none
pf002s0r1.UnselectItemByName("aƩ")
Dim pf002s0r2 As IXlsPivotTableField
Set pf002s0r2 = pivotTable002s0.Rows.AddByName("s1")
Dim pf002s0d1 As IXlsPivotTableField
Set pf002s0d1 = pivotTable002s0.Data.AddByName("s2")
pivotTable002s0.InsertAt(13, 4)
It covers many of the pivot table features, i.e. data source, style, pivot fields (page/row/col/data), pivot field details (sorting, filtering, show values as, number format, ...)