Pivot not supported under DotNet

mfabian
Member Posts: 187
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:
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:
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
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

With best regards from Switzerland
Marcus Fabian
Marcus Fabian
0
Comments
-
I haven't used this myself, but it sounds good. You may want to consider using the ClosedXML .net component: https://closedxml.codeplex.com/Rob Hansen
http://www.epimatic.com0 -
Hi Marcus
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:#constants $xlDatabase=1 $xlRowField=1 $xlColField=2 $xlDataField=4 $xlPivotTableVersion12=3 $WS2=$WB.Worksheets.Add() $WS2.name = "SUMMARY" $Range = 'DETAILS!R3C1:R' + $cnter + 'C11' $PivotCache = $WB.PivotCaches().Add($xlDatabase, $Range) $PivotCache.CreatePivotTable('SUMMARY!R1C1','Pivot1') $PivotTable = $WS2.PivotTables('Pivot1') $PivotFields = $PivotTable.PivotFields("Item No.") $PivotFields.Orientation=$xlRowField $PivotFields = $PivotTable.PivotFields("Week") $PivotFields.Orientation=$xlColField $PivotFields = $PivotTable.PivotFields("Qty. on Sales Order") $PivotFields.Orientation=$xlDataField $PivotFields.Function = -4157 # sum, not count, dammit! #make the current week stand out in color $Cells2 = $WS2.Cells $Week = get-date -UFormat %V $w = [int]$Week $Cells2.item(1, $w +1).EntireColumn.Interior.ColorIndex = 22
0 -
Try declare variable xlPivotCaches of type PivotCaches, instead of reaching so deep into the properties:
xlPivotCaches := XlApp.ActiveWorkbook.PivotCaches;
xlPivotCache := xlPivotCaches.Add(1,iRange);0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions