After having wasted almost a whole day on this issue I come to the conclusion that
DotNet simply does not support the creation of Pivot Tables!
The crucial point is the statement:
xlPivotCache := xlApp.ActiveWorkbook.PivotCaches.Add(1,iRange);
The problem is that under DotNet, the PivotCaches Object doesn't have any methods and therefore not the .Add Method.
Under Automation, the creation of Pivot Tables was quite simple:
CreatePivotFromWS(iRange : Text[250];iPivotName : Text[250])
IF iPivotName = '' THEN
iPivotName := 'PivotTable1';
xlPivotCache := XlApp.ActiveWorkbook.PivotCaches.Add(1,iRange);
xlPivotCache.CreatePivotTable('',iPivotName);
xlPivotSourceWorksheet := XlApp.ActiveSheet;
xlPivotTable := xlPivotSourceWorksheet.PivotTables(iPivotName);
Hopefully the dotnet objects will be corrected soon.
At the moment I don't see any other possibility than using pure simple and working Automation
Comments
http://www.epimatic.com
Basically when you are tired with all this you can consider the following. Write SQL stored procedures for reports. Make PowerShell scripts for creating reports in Excel and e-mailing them to the receipients. (abstract away as much as possible into a function library). Set up a Windows task to run it daily or weekly. It takes about 20-30 hours of learning if you already know SQL to make it work flawlessly. Then you have the additional bonus of reports staying future proof as long as the database structure does not change.
Navision reports are fine when an actual user needs to print something out, but for everything you would use a pivot for, not.
BTW this is how a report I wrote in PowerShell used .NET Pivot tables, maybe it is helpful from C/AL .NET as well, maybe you can access PivotCaches:
xlPivotCaches := XlApp.ActiveWorkbook.PivotCaches;
xlPivotCache := xlPivotCaches.Add(1,iRange);