excel vba xml文件操作

来源:互联网 发布:饥荒联机版网络较差 编辑:程序博客网 时间:2024/06/16 10:22

<mainnote>

     <subnote>

    </subnote>

    <subnote>

    <subnote>


</mainnote>



Dim wsXml As Worksheet


Dim xmlDoc As Object
Dim objDOM, n, nodes, subNodes As Object, ns, i, j
Set objDOM = CreateObject("MSXML.DOMDocument")
objDOM.Load (ThisWorkbook.Path & "\xxxxxx.xml")
objDOM.async = False

strPath = Left(strPath, Len(strPath) - Len(strCbf) - 12)


Set ns =objDOM.SelectNodes("//mainnote//subnote") 
  'ns就得到了所有subnote的一个集合

 Debug.Print ns.Length
Dim k

For i = 1 Tons.Length        '可以用Length遍历所有subnote


       If ns.Item(i - 1).ChildNodes(0).Text <> "xxx" Then 'name    '用Item() 去取单独subnote
           
          '用SelectSingleNode 根据字符串筛选要得到的某个node
          '用GetEleentsByTagname 得到node下的复合tagname条件的所有标签
        Set subNodes = ns.Item(i-1).SelectSingleNode("id").getElementsByTagName_r("name")
           Debug.Print subNodes.Length
           For k = 0 To subNodes.Length - 1
               
               Debug.Print subNodes.Item(k).Text
               
               If (subNodes.Item(k).Text = "ID") Then
                   wsXml.Cells(index, "E") = "Yes"
               End If
                   
            
               
           Next
0 0
原创粉丝点击