Sco*_*man 7 xml excel vba filter excel-vba
我有以下代码将XML Schema映射到Excel表(如在ListObjects中).
Sub MapXMLFieldsToExcelCells(wb As Workbook, sLOB As String)
'*******************************************************************
'** Name: xmlFieldMap
'** Purpose: Maps fields of existing xlmMap (named "xmlData") to file
'** Dependents: TieXMLToExcel (remapping of xml file)
'** Notes:
'*******************************************************************
sProcName = "MapXMLFieldsToExcelCells"
With wb
Dim xMap As XmlMap
Set xMap = .XmlMaps(sLOB)
Dim wsXMLMain As Worksheet
Set wsXMLMain = .Worksheets("xml" & IIf(Left(.Name, 2) = "SA", "SA", "") & sLOB)
Dim wsConfig As Worksheet
Set wsConfig = .Worksheets("rConfig")
With wsConfig
Dim rNode As Range
For Each rNode In .Range("xmlNodeMapping").Columns(1).Cells
Dim sNodePath As String
sNodePath = rNode & rNode.Offset(, 1)
Dim sTable As String
sTable = rNode.Offset(, 2)
'only have this here in case node does not exist
'caveat is that it will fail also if node is just written out wrong
Application.DisplayAlerts = False
'On Error Resume Next
wsXMLMain.ListObjects(sTable).ListColumns(rNode.Offset(, 3).Value2).XPath.SetValue xMap, sNodePath
'On Error GoTo ErrorReport
Application.DisplayAlerts = True
Next
End With
.XmlMaps(sLOB).DataBinding.Refresh
End With
End Sub
Run Code Online (Sandbox Code Playgroud)
(请忽略项目特定的行 - 这里没有太多)
代码效果很好.如果我通过配置表,我可以映射节点的节点和属性如下所示:
Xpath Node Table Field
/root/d/p/t/ ar tForms AR
/root/d/p/t/ @n tFormsa name
Run Code Online (Sandbox Code Playgroud)
我想做什么,如果可能的话是在节点上应用过滤器来仅映射节点的某些元素.
例如,基于正确的语法:
Xpath Node Table Field
/root/d/p/t[item='ar']/ type tForms type
Run Code Online (Sandbox Code Playgroud)
只会将节点t中的元素拉为= ar.
我无法让这个工作,也无法在网上找到任何东西,我可以接受的是,这不是一个选项,但想在放弃这个方法之前发布.