用Excel读写(非常非常奇怪)

Reading and writing with Excel (very very strange)

我有一个应用程序,它应该接受输入的 URL 和文件名(以及由于要保存多个文档而需要的额外值)并将这些值写入 excel文档。 例如

| Facebook.com | Facebook | 3
| Youtube.com  | Youtube  |
| Google.com   | Google   |

第一个是URL,第二个是文件名,第三个是文档数(基本)。

目前发生的所有事情是前 2 个单元格包含不断更新的数字,第三个单元格包含“[object]”

首先是 VBS

的 HTA

sub Export

    Dim URL_1           ' URL being saved to Excel
    Dim FileName_1      ' Name for file being saved
    Dim FullPath        ' Path of file
    Dim oExcel          ' Excel
    Dim oBook           ' Workbooks
    Dim oSheet          ' Worksheets
    Dim iv              ' Interval value  
    Dim ic              ' Interval cap 
    Dim Target          ' Target  FilePath

    'sets Interval cap
    ic = IC_

    ' Declares FSO
    set FSO = CreateObject("Scripting.FileSystemObject")

    ' Declares full file path
    FullPath = FSO.GetAbsolutePathName(folderName)                  

    'Sets target
    Target = FullPath & "\list.xls"

    ' Launch Excel
    Set oExcel = CreateObject("Excel.Application")

    ' Toggles visibility
    oExcel.Application.Visible = True

    ' Open a workbook
    Set oBook = oExcel.Workbooks.Open(Cstr(target))

    iv = 0
    ic = IC_

    While iv <= ic 

         URL =Cstr (URL_1 & iv) 
         FileName = Cstr(FileName_1 & iv)

        'Writes values to excel
        oExcel.Cells(1,3).value=IC_
        oExcel.Cells(1,1).value=URL
        oExcel.Cells(1,2).value=FileName
        iv = iv + 1

    Wend        

    ' Save the workbook,
    oBook.Save

    ' Quit Excel
    oExcel.Quit

End sub

</Script>

<Body>

<input type="Button" value="Add to Que" name="Export_Run"    onclick="Export">
<input type="Button" value="Extract"    name="Extractor_Run" onclick="Extract">         

    URL         <input type="Text" value="" name=URL_1> <br>
    File Name   <input type="Text" value="" name=FileName_1> <br>
    No. Pages   <input type="Text" value="" name=IC_> <br>

</Body>

在此先感谢任何愿意帮助我解决这个问题的人。 到目前为止,我所做的所有工作都是利用现有代码和重新安排内容。自从我使用 VB 以来已经很长时间了,而且从未用于此类任务。

IC_ 如果您想将它与另一个整数进行比较,则为 HTMLInputElement object. To get the text from the input field you should use IC_.Value, and you need to convert it to an integer。此外,您应该只分配一次值,并在脚本的其余部分使用转换后的值。

...
'sets Interval cap
ic = <b>CLng(IC_.Value)</b>

set FSO = CreateObject("Scripting.FileSystemObject")
FullPath = FSO.GetAbsolutePathName(folderName)
Target = FullPath & "\list.xls"

Set oExcel = CreateObject("Excel.Application")
oExcel.Application.Visible = True

Set oBook = oExcel.Workbooks.Open(Cstr(target))

iv = 0
<strike>ic = IC_</strike>

While iv <= ic 
    URL = Cstr (URL_1 & iv) 
    FileName = Cstr(FileName_1 & iv)

    oExcel.Cells(1,3).value = <b>ic</b>
    oExcel.Cells(1,1).value = URL
    oExcel.Cells(1,2).value = FileName
    iv = iv + 1
Wend
...