Thursday 13 September 2012

C# - Excel - Error Microsoft.Office.Interop.Excel.PivotCache' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'Microsoft.Office.Interop.Excel.PivotCache' could be found (are you missing a using directive or an assembly reference?)

Microsoft.Office.Interop.Excel.PivotCache' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'Microsoft.Office.Interop.Excel.PivotCache' could be found (are you missing a using directive or an assembly reference?)

The name 'XlPivotTableSourceType' does not exist in the current context  

when trying to execute the following code:

oPivotCache.Add(XlPivotTableSourceType.xlDatabase, oRange);

Ensure the following reference was added to the project, from .NET tab called Microsoft.Office.Interop.Excel



Replace the following 2 lines
Excel.PivotCache oPivotCache = (Excel.PivotCache)oBook.PivotCaches();
oPivotCache.Add(XlPivotTableSourceType.xlDatabase, oRange);
with
Excel.PivotCache oPivotCache = (Excel.PivotCache)oBook.PivotCaches().Add(Excel.XlPivotTableSourceType.xlDatabase,oRange);



No comments:

Post a Comment