从 PowerPivot PivotItem 解析值的好方法?
Good method to parse value from PowerPivot PivotItem?
我有一个具有以下 .name
和 .value
属性的 PivotItem:
[dimCalendar].[MonthName].&[April 2013]
我只对 April 2013
的部分感兴趣。
从 PivotItem 解析或获取此值的好方法是什么?
如果你只需要最后一个,这会很好用:
Sub test_user1283776()
MsgBox get_PivotItem_From_PowerPivot("[dimCalendar].[MonthName].&[April 2013]")
End Sub
Function get_PivotItem_From_PowerPivot(PowerString As String) As String
Dim A() As String
A = Split(PowerString, ".&[")
get_PivotItem_From_PowerPivot = Trim(Replace(A(UBound(A)), "]", ""))
End Function
解决方法一:拆分替换
Split
最好用 [
作为分隔符。获取 Split
数组的上限并将尾部 ]
替换为 ""
.
方案二:正则表达式
添加 Microsoft VBregularexpression 5.5
作为参考。
Private Function Method(str As String) As String
Dim regexp As New regexp
regexp.Pattern = "\[.*\]\[.*\]\[(.*)\]"
Method = regexp.Replace(str, "")
End Function
我有一个具有以下 .name
和 .value
属性的 PivotItem:
[dimCalendar].[MonthName].&[April 2013]
我只对 April 2013
的部分感兴趣。
从 PivotItem 解析或获取此值的好方法是什么?
如果你只需要最后一个,这会很好用:
Sub test_user1283776()
MsgBox get_PivotItem_From_PowerPivot("[dimCalendar].[MonthName].&[April 2013]")
End Sub
Function get_PivotItem_From_PowerPivot(PowerString As String) As String
Dim A() As String
A = Split(PowerString, ".&[")
get_PivotItem_From_PowerPivot = Trim(Replace(A(UBound(A)), "]", ""))
End Function
解决方法一:拆分替换
Split
最好用 [
作为分隔符。获取 Split
数组的上限并将尾部 ]
替换为 ""
.
方案二:正则表达式
添加 Microsoft VBregularexpression 5.5
作为参考。
Private Function Method(str As String) As String
Dim regexp As New regexp
regexp.Pattern = "\[.*\]\[.*\]\[(.*)\]"
Method = regexp.Replace(str, "")
End Function