大家。
我正在使用Sub ClearColumns从数据透视表中清除列区域中的所有字段。
Sub ClearColumns()
Dim PT As PivotTable, PF As PivotField
Set PT = ActiveSheet.PivotTables("Tb1")
With PT
For Each PF In .ColumnFields
PF.Orientation = xlHidden
Next PF
End With
Set PT = Nothing
End Sub
但是现在我开始使用PowerPivot,代码不起作用。我认为这些字段不再是PivotField,而是CubeFields。可以在上面制作相同的宏,但对于Cubefields?我尝试了不同的东西,但我不能让它发挥作用。
Sub ClearColumnsPP()
Dim PT As PivotTable, PF As CubeFields
Dim strSource As String
Dim strName As String
Set PT = ActiveSheet.PivotTables("Tb1")
With PT
For Each PF In .ColumnFields
strSource = PF.SourceName
strName = PF.Name
PF(strSource, strName).Orientation = xlHidden
Next PF
End With
Set PT = Nothing
End Sub
谢谢!
答案 0 :(得分:0)
您需要检查CubeField的方向,如果它是Column字段,则只设置为hidden:
println (x + y).groupBy { it.b }.collect{it.value}.collect{item -> def m = [:] ; item.collect{ m +=it}; m }