生成表 [英] Generating table
问题描述
我正在尝试将 VBScript 代码的输出推送到表格行和表格单元格中.
I am trying to push my output from VBScript code in table row and table cell.
我的代码是:
Set table = document.CreateElement("table")
i = 0
For Each node In objMSXML.selectNodes(sXPath)
Set tr = document.createElement("tr")
Set td = document.createElement("td")
For Each element In node
td.innerText = element.parentNode.nodeName & "->" & element.text
tr.appendChild td
Next
table.appendChild tr
ObjOutFile.WriteLine node.parentNode.nodeName & "->" & node.text
i = i + 1
Next
document.body.appendChild table
有什么问题吗?当我能够在列表中推送输出时它不起作用.
What is wrong with it? it is not working while I am able to push output in list.
编辑我正在使用此代码,它按预期打印输出,但未填充表.
Edit I am using this code it prints output as expected but table is not populated.
ObjOutFile.WriteLine thing.path
document.body.appendChild p
Set tbody = document.createElement("tbody")
For Each node In objMSXML.selectNodes(sXPath)
Set trow = document.createElement("tr")
Set tcol = document.createElement("td")
tcol.innerText = tcol.innerText & node.parentNode.nodeName & "->" & node.text
ObjOutFile.WriteLine node.parentNode.nodeName & "->" & node.text
trow.appendChild(tcol)
tbody.appendChild(trow)
'ObjOutFile.WriteLine node.parentNode.nodeName & "->" & node.text
Next
document.appendChild(tbody)
ObjOutFile.writeLine
打印如下:
C:\Users\abc\Desktop\samp.txt
hamster->AbcPos
hamster->Database Layer
hairyStyle->qskxyz
hairyGirl->qixyz
hairyGirl->abc
hairyGirl->def
推荐答案
您的代码中有两个问题:
You have two issues in your code:
node
不是集合,所以For Each element In node
失败.您的 HTA 中可能有一个On Error Resume Next
其他位置隐藏此错误,否则您将看到如下错误消息:
node
is not a collection, soFor Each element In node
fails. You probably have anOn Error Resume Next
elswhere in your HTA that is hiding this error, because otherwise you'd be seeing an error message like this:
对象不支持此属性或方法.
Object doesn't support this property or method.
您需要先将表格行附加到 将您的代码更改为类似的内容(并删除 Change your code to something like this (and remove the 这篇关于生成表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! 元素(请参阅 这个相关的问题).
On Error Resume Next
):On Error Resume Next
):Set table = document.createElement("table")
Set tbody = document.createElement("tbody")
i = 0
For Each node In objMSXML.selectNodes(sXPath)
Set tr = document.createElement("tr")
Set td = document.createElement("td")
td.innerText = node.parentNode.nodeName & "->" & node.text
tr.appendChild td
tbody.appendChild tr
i = i + 1
Next
table.appendChild tbody
document.body.appendChild table
登录
关闭