如何读取嵌套表< td>值使用VBA? [英] How to read the nested table <td> values using VBA?

查看:58
本文介绍了如何读取嵌套表< td>值使用VBA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以通过使用Excel VBA从第三方应用程序读取嵌套的html表值的方式为我提供帮助?作为下面的示例,我将HTML源代码的一部分粘贴到其中,我想读取所有值并将其存储到excel中.但是在这里,它们都是它们使用的嵌套表,并且这些表也没有任何名称在我见过的html源代码中.

Anyone help me here by saying that how to read the nested html table values from a third party application using Excel VBA? as an example below i pasted a part of the HTML source where i want to read the all the value and want to store it into the excel.But in here all are nested tables they used,and the tables don't have any name also in the html source i have seen.

<td>
<table cellspacing="1" cellpadding="0" class="data">
<tr class="colhead">
<th colspan="3">Expression</th>
 </tr>
<tr class="colhead">
<th>Field</th>
<th>Operator</th>
<th>Answer</th>
</tr>
<tr class="rowLight">
<td width="40%">        
Location Attributes:  LOC - Sub Commodity
</td>
<td width="20%">
= 
</td>
<td width="40%">
Abrasives
</td>
</tr>
<tr class="rowDark">
<td width="40%">
Location Attributes:  LOC - Commodity Tier1
</td>
<td width="20%">
= 
</td>
<td width="40%">
Advertising, Sales &amp; Promotion
</td>
</tr>

谢谢,奥雅纳(Arup)

Thanks, Arup

推荐答案

这是我读取HTML表的方式:

This is how I read an HTML table:

Sub ReadHTMLtable()
Dim htmldb As New ADODB.Connection
Dim htmlcmd As New ADODB.Command
Dim rs As New ADODB.Recordset

With htmldb
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .ConnectionString = "Data Source=Z:\filename.html;Extended Properties=""HTML Import;HDR=YES;IMEX=1"""
    .Open
End With

Set htmlcmd.ActiveConnection = htmldb
htmlcmd.CommandType = adCmdText
htmlcmd.CommandText = "Select * from [table]"
rs.CursorLocation = adUseClient
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.Open htmlcmd

'process rs here

End Sub

这使用ADO,但对于DAO应该相同

this uses ADO, but it should be the same for DAO

这篇关于如何读取嵌套表&lt; td&gt;值使用VBA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆