在外部数据源的情况下,Pivottable.pivotfields不会检测到任何字段 [英] Pivottable.pivotfields does not detect any fields in case of external datasource
问题描述
我正在使用连接到外部数据源的数据透视表.当我显示字段列表时,它在顶部显示数据源名称"Source".我正在尝试使用PivotTable.PivotFields遍历字段.它根本没有进入循环. 所需的行为:应进入循环并将字段名称附加到字符串后.
I am using a pivot which connects to an external datasource. When i display field list, it shows the datasource name "Source" at the top. I am trying to loop through the fields using PivotTable.PivotFields. Its not entering the loop at all. Desired behaivior: It should enter the loop and the field names should be appended to the string.
For Each pvtField As PivotField In pvttable.PivotFields
mRetVal = mRetVal & pvtField.Name & "-" & pvtField.SourceName & "-" & pvtField.SourceCaption & ","
Next
推荐答案
如果要在VBA中编写它,这里有一些帮助.
在VBA中,通常必须像这样分隔变量声明:
If you want to write it in VBA, here's some help.
In VBA you generally have to separate variable declarations like this:
Dim pvtField As PivotField
For Each pvtField In pvttable.PivotFields
mRetVal = mRetVal & pvtField.Name & "-" & pvtField.SourceName & "-" & pvtField.SourceCaption & ","
Next pvtField
如果数据透视表基于外部源(OLAP),则还可以遍历具有某些不同属性的CubeFields
:
If your pivot table is based on an external source (OLAP), then you can also loop through the CubeFields
which have some different properties:
Dim pvtCubeField as CubeField
For Each pvtCubeField In pvttable.CubeFields
mRetVal = mRetVal & pvtCubeField.Name & "-" & pvtCubeField.Value & "-" & pvtCubeField.Caption & ","
Next pvtCubeField
由于链接了OLAP源中的CubeFields
和数据透视表中的PivotFields
,因此您可以再次选择PivotFields
:
As CubeFields
from the OLAP source and PivotFields
from the pivot table are linked, you may select the PivotFields
by this again:
Dim pvtCubeField as CubeField, pvtField As PivotField
For Each pvtCubeField In pvttable.CubeFields
For Each pvtField In pvtCubeField.PivotFields
mRetVal = mRetVal & pvtField.Name & "-" & pvtField.SourceName & "-" & pvtField.SourceCaption & ","
Next pvtField
Next pvtCubeField
这篇关于在外部数据源的情况下,Pivottable.pivotfields不会检测到任何字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!