title: Create several Pivot tables on the same sheet c#
body: <p>I'm trying to create several pivot tables in the same sheet ,
  it works great when I try to create one pivot table , but when I try to create many ones , I'm getting only one (witch is the combination of all pivots and having the name of the last PivotTable ) , here is my code : </p>
  
  <p>assuming that we will populate all pivot tables from the same datasource (same sheet)</p>
  
  <pre><code>pivotData is : the range of the source table
  
  name is the name of the sheet where we will create the pivots
  
    public void CreatePivotTable(Range pivotData, List&lt;string&gt; pivotFields, List&lt;string&gt; aggFields, string pivotPosition, string name)
      {
  
          var pivotTableName = name;
  
          var pivotDestination = _worksheet.Range[pivotPosition, UseDefault];
  
          _workbook.PivotTableWizard(
              XlPivotTableSourceType.xlDatabase,
              pivotData,
              pivotDestination,
              pivotTableName,
              true,
              true,
              true,
              true,
              UseDefault,
              UseDefault,
              false,
              false,
              XlOrder.xlDownThenOver,
              0,
              UseDefault,
              UseDefault
              );
  
          var pivotTable = (PivotTable)_worksheet.PivotTables(pivotTableName);
  
  
          foreach (var label in pivotFields.Select(field =&gt; ((PivotField)pivotTable.PivotFields(field))))
          {
              label.Orientation = XlPivotFieldOrientation.xlRowField;
          }
  
          foreach (var sumValues in aggFields.Select(field =&gt; ((PivotField)pivotTable.PivotFields(field))))
          {
              sumValues.Orientation =
                  XlPivotFieldOrientation.xlDataField;
              sumValues.Function = XlConsolidationFunction.xlSum;
          }
  
          pivotTable.Format(XlPivotFormatType.xlTable2);
          pivotTable.InGridDropZones = false;
  
      }
  </code></pre>
  
  <p>can any one tell me what i'm messing , how can I get every pivot separately?
  I think there some function called pivotCache that allow us to add more than one Pivot table , but how to use it</p>