16-09-20 02:38 PM
'PART ONE'
--------------
Dim rng as Object
Dim wb as Object = GetWorkbook(handle,workbookname)
Dim ws as Object = GetWorksheet(handle,workbookname,worksheetname,createifmissing)
sheetexists = ws IsNot Nothing
If sheetexists then ws.Activate()
rng = range
Dim PCache as object = wb.PivotCaches.Create(SourceType:=1, SourceData:= rng).CreatePivotTable(TableDestination:=ws.Range("B2"), TableName:="PivotTable1")
'PART TWO'
--------------
With ws.PivotTables("PivotTable1").PivotFields("Column1")
.Orientation = 1
.Position = 1
End With
with ws.PivotTables("PivotTable1").PivotFields("Column2")
.Orientation = 4
.Position = 1
.Function = -4112
.Caption = "Count of Column2"
End With
16-09-20 04:59 PM
17-09-20 12:23 PM
17-09-20 02:30 PM
17-09-20 02:46 PM
rng = range
Dim PCache as object = wb.PivotCaches.Create(SourceType:=1, SourceData:= rng).CreatePivotTable _
(TableDestination:=ws.Range("B2"), TableName:="PivotTable1")
Dim wb as Object = GetWorkbook(handle,workbookname)
Dim ws as Object = GetWorksheet(handle,workbookname,worksheetname)
If Len(ToString(orientation))=0 Then Throw New Exception("Orientation is mandatory parameter")
If Len(ToString(position))=0 Then Throw New Exception("Position is mandatory parameter")
With ws.PivotTables(tablename).PivotFields(pivotfield)
.Orientation = orientation
.Position = position
If fnctn<>0 Then .Function = fnctn
If calculation<>0 Then .Calculation = calculation
If caption<>"" Then .Caption = caption
End With