Insert Pivot Table
Contents
[
Hide
]
Create Pivot Table
It is possible to use Aspose.Cells for Node.js via C++ to add pivot tables to spreadsheets programmatically.
Pivot Table Object Model
Aspose.Cells for Node.js via C++ provides a special set of classes that are used to create and control pivot tables. These classes are used to create and set PivotTable objects, the building blocks of a pivot table. The objects are:
- PivotField represents a field in a PivotTable.
- PivotFieldCollection represents a collection of all the PivotField objects in the PivotTable.
- PivotTable represents a PivotTable on a worksheet.
- PivotTableCollection represents a collection of all the PivotTable objects on a worksheet.
Creating a Simple Pivot Table Using Aspose.Cells
- Add data to a worksheet using the Cell object’s putValue method. This data will be used as the pivot table’s data source.
- Add a pivot table to the worksheet by calling the PivotTables collection’s add method, which is encapsulated in the Worksheet object.
- Access the new PivotTable object from the PivotTables collection by passing the PivotTable index.
- Use any of the PivotTable objects (explained above) to manage the pivot table.
After executing the example code, a pivot table is added to the worksheet.
When assigning a range of cells as the data source, the range must go from top left to bottom right. For example, “A1:C3” is valid but “C3:A1” is not.