用于输出HTML表的VBScript

用于输出HTML表的VBScript,html,vbscript,Html,Vbscript,我试图读取一个包含行的文本文件,然后将它们以列的形式输出到html文件中。当使用WScript.echo在屏幕上显示它时,我没有问题完成这项工作,但是我无法将它放到HTML文件中的表中。尝试运行vbs文件时出现以下错误:类型不匹配:“OpenTextFile”。任何指导都将不胜感激 Dim fso:Set fso=CreateObject(“Scripting.FileSystemObject”) Dim OutputHTML:Set OutputHTML=fso.CreateTextFile

我试图读取一个包含行的文本文件,然后将它们以列的形式输出到html文件中。当使用WScript.echo在屏幕上显示它时,我没有问题完成这项工作,但是我无法将它放到HTML文件中的表中。尝试运行vbs文件时出现以下错误:类型不匹配:“OpenTextFile”。任何指导都将不胜感激

Dim fso:Set fso=CreateObject(“Scripting.FileSystemObject”)
Dim OutputHTML:Set OutputHTML=fso.CreateTextFile(“C:\Users\Istaley.RXDATA\Desktop\NewEmployeeTest\Part2_TableData.html”)
Dim文件:Set file=fso.OpenTextFile(“C:\Users\Istaley.RXDATA\Desktop\NewEmployeeTest\Part2\u data.txt”,1,True)
Dim fc:fc=file.ReadAll:file.close:Dim fcArray:fcArray=Split(fc,vbCrLf)
OutputHTML.WriteLine“”
OutputHTML.Writeline“”
OutputHTML.WriteLine“”
调暗opArray():调暗opArray(0)
对于fcArray中的每一行
尺寸tmp:tmp=拆分(行“|”)
对于ent=0至UBound(tmp)
如果ent>UBound(opArray),则
雷迪姆保留浑浊区(浑浊区(浑浊区)+1)
opArray(ent)=纵倾(tmp(ent))
其他的
如果Len(opArray(ent))>0,则
OutputHTML.WriteLine“”
opArray(ent)=opArray(ent)和“&修剪(tmp(ent))
OutputHTML.WriteLine“”
其他的
opArray(ent)=纵倾(tmp(ent))
如果结束
如果结束
下一个
下一个
WScript.echo连接(opArray,vbCrLf)
OutputHTML.WriteLine“”
OutputHTML.WriteLine“”
OutputHTML.WriteLine“”
OutputHTML.Write连接(opArray,vbCrLf):OutputHTML.Close

问题在于这一行。。的第一个参数接受一个字符串,但您已将其传递给一个对象。您已经使用打开了要写入的文本文件


去掉这一行,并将
WriteOutput
的所有剩余实例更改为
outputtml

问题在于这一行。。的第一个参数接受一个字符串,但您已将其传递给一个对象。您已经使用打开了要写入的文本文件


去掉这一行,并将
WriteOutput
的所有剩余实例更改为
OutputHTML

我知道这是一个老话题,但这可能对任何希望像我这样做的人都有用。这有点仓促,但我已经在线添加了评论。比特已经从许多地方取得,所以这不全是我自己的工作

Function LoadFile(File)
    On Error Resume Next
    'Declaire all variables
    Dim fso,F,ReadText,strError
    Dim ReadArray
    Dim ReadHTMLOutput, ReadRowCount, ReadRowItem, ReadRowItemSplit, ReadElementCount, ReadElementItem
    'Create the object to read files
    Set fso = CreateObject("Scripting.FileSystemObject")
    'Set the file to read and the format
    Set F = fso.OpenTextFile(File,1)
    'If there's a problem, say so...
    If Err.Number <> 0  Then
        strError = "<center><b><font color=Red>The file "& File &" dosen't exists !</font></b></center>"
        OutputTable.InnerHTML = strError
        Exit Function
    End If
    'Read the contents of the file into ReadText
    ReadText = F.ReadAll

    'Split the text based on Carriage return / Line feed
    ReadArray = Split(ReadText,vbCrLf)
    'fill the output variable with the HTML of the start of the table
    ReadHTMLOutput = "<table border=" & chr(34) & "2" & chr(34) & ">" & vbcrlf
    'starting at 0 until the last line in the array, run through each line
    For ReadRowCount=0 to UBound(ReadArray)
        'Take the whole row into it's own variable
        ReadRowItem = ReadArray(ReadRowCount)
        'Split the row (separated by commas) into an array
        ReadRowItemSplit = Split(ReadRowItem,",")
        'Add the HTML for the row of the table
        ReadHTMLOutput = ReadHTMLOutput & "<tr>" & vbcrlf
        'starting at 0 until the last entry of the row array, run through each element
        For ReadElementCount=0 to UBound(ReadRowItemSplit)
            'Read the element into a variable
            ReadElementItem = ReadRowItemSplit(ReadElementCount)
            'If the element is blank, put a space in (stops the cell being formatted empty)
            If ReadElementItem = "" Then ReadElementItem = "&nbsp;"
            'Add the HTML for the cell of the row of the table
            ReadHTMLOutput = ReadHTMLOutput & "<td>" & ReadElementItem & "</td>" & vbcrlf
        'Go to the next element in the row
        Next
        'Add the HTML for the end of the row of the table
        ReadHTMLOutput = ReadHTMLOutput & "</tr>" & vbcrlf
    'Go to the next row in the file
    Next
    'Add the HTML for the end of the table
    ReadHTMLOutput = ReadHTMLOutput & "</table>" & vbcrlf
    'Fill the DIV with the contents of the variable
    OutputTable.InnerHTML = ReadHTMLOutput
End Function
函数加载文件(文件)
出错时继续下一步
“公布所有变量
尺寸fso、F、ReadText、strError
Dim读卡阵列
Dim ReadHTMLOutput、ReadRowCount、ReadRowItem、ReadRowItemSplit、ReadElementCount、ReadElementItem
'创建要读取文件的对象
设置fso=CreateObject(“Scripting.FileSystemObject”)
'将文件设置为读取,并设置格式
Set F=fso.OpenTextFile(文件,1)
“如果有问题,就说出来。。。
如果错误号为0,则
strError=“文件”&file&“不存在!”
OutputTable.InnerHTML=strError
退出功能
如果结束
'将文件内容读入ReadText
ReadText=F.ReadAll
'根据回车符/换行符拆分文本
ReadArray=Split(ReadText,vbCrLf)
'用表格开头的HTML填充输出变量
ReadHTMLOutput=“”&vbcrlf
'从0开始直到数组中的最后一行,遍历每一行
对于ReadRowCount=0,将其绑定到UBound(ReadArray)
'将整行放入它自己的变量中
ReadRowItem=ReadArray(ReadRowCount)
'将行(用逗号分隔)拆分为一个数组
ReadRowItemSplit=Split(ReadRowItem,,“”)
'为表的行添加HTML
ReadHTMLOutput=ReadHTMLOutput&“”&vbcrlf
'从0开始直到行数组的最后一个条目,遍历每个元素
对于ReadElementCount=0,为UBound(ReadRowItemSplit)
'将元素读入变量
ReadElementItem=ReadRowItemSplit(ReadElementCount)
'如果元素为空,请在中添加空格(停止将单元格格式化为空)
如果ReadElementItem=“”,则ReadElementItem=“”
'为表格行的单元格添加HTML
ReadHTMLOutput=ReadHTMLOutput&&ReadElementItem&&vbcrlf
'转到行中的下一个元素
下一个
'在表的行末尾添加HTML
ReadHTMLOutput=ReadHTMLOutput&“”&vbcrlf
'转到文件中的下一行
下一个
'将HTML添加到表的末尾
ReadHTMLOutput=ReadHTMLOutput&“”&vbcrlf
'用变量的内容填充DIV
OutputTable.InnerHTML=ReadHTMLOutput
端函数
在HTML中:

<div id="OutputTable"></div>


这样,DIV中就充满了来自
ReadHTMLOutput

的HTML,我知道这是一个老话题,但这对任何想做同样事情的人都可能有用,就像我做的那样。这有点仓促,但我已经在线添加了评论。比特已经从许多地方取得,所以这不全是我自己的工作

Function LoadFile(File)
    On Error Resume Next
    'Declaire all variables
    Dim fso,F,ReadText,strError
    Dim ReadArray
    Dim ReadHTMLOutput, ReadRowCount, ReadRowItem, ReadRowItemSplit, ReadElementCount, ReadElementItem
    'Create the object to read files
    Set fso = CreateObject("Scripting.FileSystemObject")
    'Set the file to read and the format
    Set F = fso.OpenTextFile(File,1)
    'If there's a problem, say so...
    If Err.Number <> 0  Then
        strError = "<center><b><font color=Red>The file "& File &" dosen't exists !</font></b></center>"
        OutputTable.InnerHTML = strError
        Exit Function
    End If
    'Read the contents of the file into ReadText
    ReadText = F.ReadAll

    'Split the text based on Carriage return / Line feed
    ReadArray = Split(ReadText,vbCrLf)
    'fill the output variable with the HTML of the start of the table
    ReadHTMLOutput = "<table border=" & chr(34) & "2" & chr(34) & ">" & vbcrlf
    'starting at 0 until the last line in the array, run through each line
    For ReadRowCount=0 to UBound(ReadArray)
        'Take the whole row into it's own variable
        ReadRowItem = ReadArray(ReadRowCount)
        'Split the row (separated by commas) into an array
        ReadRowItemSplit = Split(ReadRowItem,",")
        'Add the HTML for the row of the table
        ReadHTMLOutput = ReadHTMLOutput & "<tr>" & vbcrlf
        'starting at 0 until the last entry of the row array, run through each element
        For ReadElementCount=0 to UBound(ReadRowItemSplit)
            'Read the element into a variable
            ReadElementItem = ReadRowItemSplit(ReadElementCount)
            'If the element is blank, put a space in (stops the cell being formatted empty)
            If ReadElementItem = "" Then ReadElementItem = "&nbsp;"
            'Add the HTML for the cell of the row of the table
            ReadHTMLOutput = ReadHTMLOutput & "<td>" & ReadElementItem & "</td>" & vbcrlf
        'Go to the next element in the row
        Next
        'Add the HTML for the end of the row of the table
        ReadHTMLOutput = ReadHTMLOutput & "</tr>" & vbcrlf
    'Go to the next row in the file
    Next
    'Add the HTML for the end of the table
    ReadHTMLOutput = ReadHTMLOutput & "</table>" & vbcrlf
    'Fill the DIV with the contents of the variable
    OutputTable.InnerHTML = ReadHTMLOutput
End Function
函数加载文件(文件)
出错时继续下一步
“公布所有变量
尺寸fso、F、ReadText、strError
Dim读卡阵列
Dim ReadHTMLOutput、ReadRowCount、ReadRowItem、ReadRowItemSplit、ReadElementCount、ReadElementItem
'创建要读取文件的对象
设置fso=CreateObject(“Scripting.FileSystemObject”)
'将文件设置为读取,并设置格式
Set F=fso.OpenTextFile(文件,1)
“如果有问题,就说出来。。。
如果错误号为0,则
strError=“文件”&file&“不存在!”
OutputTable.InnerHTML=strError
退出功能
如果结束
'将文件内容读入ReadText
ReadText=F.ReadAll
'根据回车符/换行符拆分文本
ReadArray=Split(ReadText,vbCrLf)
'用表格开头的HTML填充输出变量
ReadHTMLOutput=“”&vbcrlf
'从0开始
<div id="OutputTable"></div>