Sub 提取xml文件中表格标签中7列数据()
Dim xDoc As New DOMDocument60
Set xDoc = New MSXML2.DOMDocument60
mypath = ThisWorkbook.Path & "\"
MyFile = mypath & Dir(mypath & "*.dita")
xDoc.async = True
xDoc.validateOnParse = False
[a2:b127].Clear
Do While MyFile <> mypath
xDoc.Load (MyFile)
'获取row标签节点
For Each x In xDoc.DocumentElement.getElementsByTagName("row")
If x.ChildNodes.length = 7 Then
i = i + 1
For j = 1 To x.ChildNodes.length
Cells(i, j) = x.ChildNodes.Item(j - 1).Text
Next
End If
Next
MyFile = mypath & Dir
Loop
End Sub
源数据格式样式:
提取结果如表格所示: