Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Please use PivotTableCollection.Add() method to create a pivot table inside the worksheet. Once, the pivot table is created, you can work with it using the PivotTable class.
The following sample code shows how to create a pivot table and work with it. Please check the output excel file generated with this code and the following screenshot showing the output excel file in Microsoft Excel.

Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.