Here is the relevant HTML code.
(这是相关的HTML代码。)
<tr style="background-color: #f0f0f0">
<td> </td><td> a</td><td>a </td><td> </td><td> </td>
</tr>
Here is the VBA code.
(这是VBA代码。)
sub gethtmlspace()
Dim trObj As MSHTML.HTMLGenericElement
Dim tdObj As MSHTML.HTMLGenericElement
Dim aRes As Variant, bRes As Variant
Dim temp1 As Long, Temp2 As Long, temp3 As Long, Temp4 As Long
Dim oDom As Object: Set oDom = CreateObject("htmlFile")
Dim oRow As MSHTML.IHTMLElementCollection, oCell As MSHTML.IHTMLElementCollection
temp1 = 0
Temp2 = 0
With CreateObject("MSXML2.ServerXMLHttp")
.Open "GET", "https://docs.google.com/spreadsheets/d/1Yh6WlJTDxbOLPVaVgzn_mk2OAKYVUYgfnT5Wz-8odi4/gviz/tq?tqx=out:html&tq&gid=1", False
.send
oDom.body.innerHTML = .responseText
End With
Set oRow = oDom.getElementsByTagName("TR")
ReDim aRes(0 To oRow.Length - 1, 0 To oRow(0).getElementsByTagName("TD").Length - 1)
For Each trObj In oRow
Set oCell = trObj.getElementsByTagName("td")
For Each tdObj In oCell
aRes(temp1, Temp2) = tdObj.innerText
Temp2 = Temp2 + 1
Next tdObj
Temp2 = 0
temp1 = temp1 + 1
Next trObj
end sub
I would like aRes array to contain the exact value in the HTMLcode, ie
(我希望aRes数组在HTMLcode中包含确切的值,即)
aRes(1,0) should be equal to a space " " My results get empty ie""
(aRes(1,0)应该等于一个空格“” 我的结果为空,即“”)
aRes(1,1) should be equal to a space and character a " a" My results get a only "a"
(aRes(1,1)应该等于一个空格和一个字符“ a”, 我的结果只能是一个“ a”)
aRes(1,2) should be "a " this one is correctly retrieved.
(aRes(1,2)应该为“ a”, 这是正确检索到的。)
aRes(1,3) should be equal to two spaces " " My results get empty ie""
(aRes(1,3)应该等于两个空格“” 我的结果为空,即“”)
aRes(1,4) should be equal to empty My results get a space ie" "
(aRes(1,4)应该等于空我的结果得到一个空格,即“”)
I know I can use regex to get the tasks done.
(我知道我可以使用正则表达式来完成任务。)
However, I would like to do it in a simple way using getelementsbytagname method.(但是,我想使用getelementsbytagname方法以一种简单的方式做到这一点。)
I tried innerhtml, outertext, outerhtml, textcontent instead of innertext.
(我尝试使用innerhtml,outertext,outerhtml,textcontent而不是innertext。)
But no luck.(但是没有运气。)
I also googled for the key words, like innertext with spacing, getelementsbytagename properties.(我还用谷歌搜索关键字,例如带间隔的内部文本,getelementsbytagename属性。)
Also no luck.(也没有运气。)
Could someone help please.
(有人可以帮忙吗。)
Thank you so much.(非常感谢。)
ask by lordy888 translate from so