//Mycode
IWorksheet pivotSheet = workbook.Worksheets[0];
//Create Pivot cache with the given data range
IPivotCache cache = workbook.PivotCaches.Add(worksheet["A1:H50"]);
//Create "PivotTable1" with the cache at the specified range
IPivotTable pivotTable = pivotSheet.PivotTables.Add("PivotTable1", pivotSheet["A1"],cache);
//Add Pivot table fields (Row and Column fields)
pivotTable.Fields[2].Axis = PivotAxisTypes.Row;
pivotTable.Fields[6].Axis = PivotAxisTypes.Row;
pivotTable.Fields[3].Axis = PivotAxisTypes.Column;
//Add data field
IPivotField field = pivotTable.Fields[2];
pivotTable.DataFields.Add(field, "Sum", PivotSubtotalTypes.Sum);
//Output Error
Message:
System.ArgumentException : strName - string cannot be empty
Stack Trace:
PivotCacheFieldsCollection.AddNewField(String strName)
PivotCacheImpl.CreateField(IWorksheet sheet, Int32 row, Int32 lastRow, Int32 column)
PivotCacheImpl.ctor(IApplication application, Object parent, IRange dataRange)
PivotCacheCollection.Add(IRange range)
I have simply copied and pasted the code from documentation and it is showing me this error
Please tell me any solution