Html和VBscript代码将结果保存到本地文件

时间:2017-09-28 10:42:14

标签: html vbscript

我正在尝试创建一个简单的Html页面,它需要7个输入并在每次单击提交按钮时将其保存到excel文件(已在本地保存并设置了所有7个标题)。我在互联网上找到了一个VBscript代码没关系,但没有点击提交。 请帮忙!提前致谢。 VBscript的:

    <script language="vbscript" type="text/vbscript">  
      Sub Saveit()  
      Dim iRow 
      Set objExcel = CreateObject("Excel. Application")  
      Set objWorkbook = objExcel.Workbooks.Open ("D:\Users\mylaptop\Desktop\test.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 ("var1") (0).Value  
             .Cells (iRow, 2).value=Document.GetElementsByName ("op1") (0).Value  
             .Cells (iRow, 3).value=Document.GetElementsByName ("var2") (0).Value  
             .Cells (iRow, 4).value=Document.GetElementsByName ("logic") (0).Value  
             .Cells (iRow, 5).value=Document.GetElementsByName ("var3") (0).Value
             .Cells (iRow, 6).value=Document.GetElementsByName ("op2") (0).Value
             .Cells (iRow, 7).value=Document.GetElementsByName ("var4") (0).Value  
             MsgBox "Data Added Successfully”, vbinformation  
             Document.GetElementsByName ("var1") (0).Value=""  
             Document.GetElementsByName ("op1") (0).Value=""  
             Document.GetElementsByName ("var2") (0).Value=""  
             Document.GetElementsByName ("logic") (0).Value=""  
             Document.GetElementsByName ("var3") (0).Value=""  
             Document.GetElementsByName ("op2") (0).Value=""  
             Document.GetElementsByName ("var4") (0).Value=""  
         End With  
         ObjWorkbook. Save  
         ObjWorkbook. Close  
         Set objWorkbook = Nothing  
         Set objExcel = Nothing  
     End Sub  
  </script>

Html代码:

    Variable 1:   <br>
     <input type="text" name="var1" Value=""><br>  
     Operator 1:    <br>
     <input type="text" name="op1" Value=""><br>  
     Var 2/Value :      <br>
     <input type="text" name="var2" Value=""><br>  
     Logic gate :       <br>
     <input type="text" name="logic" Value=""><br>  
     Variable 3:   <br>
     <input type="text" name="var3" Value=""><br>  
     Operator 2:    <br>
     <input type="text" name="op2" Value=""><br>  
     Var 4/ Value :     <br>
     <input type="text" name="var4" Value=""><br> 
     <br>  
     <input type="button" onclick="Saveit()" value="Submit" /><br>  

0 个答案:

没有答案