从Html表单写入Excel文档

时间:2016-06-20 09:00:46

标签: html excel vbscript

在内部网络上,我想将同事在内部网络表单上填写的内容写入Excel数据库。

经过一番研究后,我想出了下面的代码,但我似乎无法让它为我工作。

任何帮助都将不胜感激。

<script language="vbscript" type="text/vbscript">
Sub Divert ()
    Dim iRow
    Set objExcel = CreateObject ("Excel. Application")
    Set objWorkbook = objExcel.Workbooks.Open ("G:\Bournemouth\CorporateShared\General Insurance\GI complaint Team\Baxter Diverted\diverted.xlsx")
    objExcel.Application.Visible = True
    ObjWorkbook.Windows (1).Visible = True
    Set XlSheet =objWorkbook.Sheets (1)
    XlSheet.Activate

    iRow = 1
    With objExcel
    Do while .Cells (iRow, 1).value <> ""
    .Cells (iRow, 1).activate
    iRow = iRow + 1
    Loop

    .Cells (iRow, 1).value=Document.GetElementsByName ("date") (0).Value
    .Cells (iRow, 2).value=Document.GetElementsByName ("date1") (0).Value
    .Cells (iRow, 3).value=Document.GetElementsByName ("name") (0).Value
    .Cells (iRow, 4).value=Document.GetElementsByName ("acti") (0).Value
    .Cells (iRow, 5).value=Document.GetElementsByName ("supwho") (0).Value
    .Cells (iRow, 6).value=Document.GetElementsByName ("prowhi") (0).Value
    .Cells (iRow, 7).value=Document.GetElementsByName ("trawha") (0).Value
    .Cells (iRow, 8).value=Document.GetElementsByName ("hanwho") (0).Value
    .Cells (iRow, 9).value=Document.GetElementsByName ("prowha") (0).Value
    .Cells (iRow, 10).value=Document.GetElementsByName ("surwho") (0).Value
    .Cells (iRow, 11).value=Document.GetElementsByName ("letwho") (0).Value
    .Cells (iRow, 12).value=Document.GetElementsByName ("miwha") (0).Value
    .Cells (iRow, 13).value=Document.GetElementsByName ("miwho") (0).Value
    .Cells (iRow, 14).value=Document.GetElementsByName ("time") (0).Value
    .Cells (iRow, 15).value=Document.GetElementsByName ("desc") (0).Value

    MsgBox "Diverted time updated”, vbinformation

    Document.GetElementsByName ("date") (0).Value=""
    Document.GetElementsByName ("date1") (0).Value=""
    Document.GetElementsByName ("name") (0).Value=""
    Document.GetElementsByName ("acti") (0).Value=""
    Document.GetElementsByName ("supwho") (0).Value=""
    Document.GetElementsByName ("prowhi") (0).Value=""
    Document.GetElementsByName ("trawha") (0).Value=""
    Document.GetElementsByName ("hanwho") (0).Value=""
    Document.GetElementsByName ("prowha") (0).Value=""
    Document.GetElementsByName ("surwho") (0).Value=""
    Document.GetElementsByName ("letwho") (0).Value=""
    Document.GetElementsByName ("miwha") (0).Value=""
    Document.GetElementsByName ("miwho") (0).Value=""
    Document.GetElementsByName ("time") (0).Value=""
    Document.GetElementsByName ("desc") (0).Value=""

    End With
    ObjWorkbook.Save
    ObjWorkbook.Close
    Set objWorkbook = Nothing
    Set objExcel = Nothing

End Sub
</script>

我填写表格并点击我的提交按钮代码:

<input type="button" onclick="Divert()" value="Submit" /> 

并且它根本不保存到文档中,并且没有显示确认框

可能有一个设置我没有设置在excel文档或类似的地方,从我可以看到代码应该工作?

由于

0 个答案:

没有答案