您好我已经在网上搜索试图找到解决这个问题的方法。
码
Sub GetAllTables(doc As Object)
' get all the tables from a webpage document, doc, and put them in a new worksheet
Dim IE As Object
Dim ws As Worksheet
Dim rng As Range
Dim tbl As Object
Dim rw As Object
Dim cl As Object
Dim tabno As Long
Dim nextrow As Long
Dim I As Long
Dim oXL As Excel.Application
Set ws = Sheet1
For Each tbl In doc.getElementsByTagName("TABLE")
tabno = tabno + 1
nextrow = nextrow + 1
Set rng = ws.Range("C" & nextrow)
rng.Offset(, -1) = "Table " & tabno
For Each rw In tbl.Rows
For Each cl In rw.Cells
rng.Value = cl.outerText
Set rng = rng.Offset(, 1)
I = I + 1
Next cl
nextrow = nextrow + 1
Set rng = rng.Offset(1, -I)
I = 0
Next rw
Next tbl
ws.Range("C:N").ClearFormats
答案 0 :(得分:0)
当然有。你需要拉哪个表?您可以通过索引位置识别它:
Dim t as Integer 'represents the index position of the table you want to obtain.
t = 0
Set tbl = doc.getElementsByTagName("TABLE")(t)
或者,如果索引位置未知,则需要在For/Each
循环内开发一些其他逻辑测试。注意:这是一个非常简单的伪代码示例。您可能需要更复杂的逻辑/条件来确定哪个表是集合中的正确表:
For each tbl in doc.getElementsByTagName("TABLE")
If tbl.__some_property__ = "something" Then
Exit For
End If
Next