Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从HTML接受数据并将其发送到excel?_Html_Excel_Vbscript - Fatal编程技术网

如何从HTML接受数据并将其发送到excel?

如何从HTML接受数据并将其发送到excel?,html,excel,vbscript,Html,Excel,Vbscript,下面是我的代码。问题是它没有将字段添加到Excel工作表中 <! DOCTYPE html> <Html> <Head> <script language="vbscript" type="text/vbscript"> Sub Sample () Dim iRow Set objExcel = CreateObject ("Excel.Application") Se

下面是我的代码。问题是它没有将字段添加到Excel工作表中

<! DOCTYPE html>  
<Html>  
 <Head>  
  <script language="vbscript" type="text/vbscript">  
     Sub Sample ()  
      Dim iRow  
      Set objExcel = CreateObject ("Excel.Application")  
      Set objWorkbook = objExcel.Workbooks.Open ("C:\Users\ARPIT SHAJU\Desktop\Church\Member.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 ("fname") (0).Value  
             .Cells (iRow, 2).value=Document.GetElementsByName ("surname") (0).Value  
             .Cells (iRow, 3).value=Document.GetElementsByName ("gender") (0).Value 
             .Cells (iRow, 4).value=Document.GetElementsByName ("mstatus") (0).Value
             .Cells (iRow, 5).value=Document.GetElementsByName ("dob") (0).Value
             .Cells (iRow, 6).value=Document.GetElementsByName ("doa") (0).Value
             .Cells (iRow, 7).value=Document.GetElementsByName ("baptised") (0).Value
             .Cells (iRow, 8).value=Document.GetElementsByName ("residence") (0).Value
             .Cells (iRow, 9).value=Document.GetElementsByName ("mnumber") (0).Value
             MsgBox "Data Added Successfully”, vbinformation  
             Document.GetElementsByName ("fname") (0).Value=""  
             Document.GetElementsByName ("surname") (0).Value=""  
             Document.GetElementsByName ("gender") (0).Value=""  
             Document.GetElementsByName ("mstatus") (0).Value=""  
             Document.GetElementsByName ("dob") (0).Value=""
             Document.GetElementsByName ("doa") (0).Value=""
             Document.GetElementsByName ("baptised") (0).Value=""
             Document.GetElementsByName ("residence") (0).Value=""
             Document.GetElementsByName ("mnumber") (0).Value=""


         End With  
         ObjWorkbook. Save  
         ObjWorkbook. Close  
         Set objWorkbook = Nothing  
         Set objExcel = Nothing  
         End Sub  
      </script>  
      <style type="text/css">  
         fieldset {  
            border: #00cc00 2px solid;  
        padding: 10px;  
        color: green;  
  </style>  
<body  
<form>  
<fieldset>  
  <legend>Csharpcorner</legend>  
  <center>  

     First name:<br>   
     <input type="text" name="fname" Value=""><br>  
     Surname:<br>  
     <input type="text" name="surname" Value=""><br>  
     Gender :<br>  
     <input type="text" name="gender" Value=""><br>  
     Marital Status :<br>  
     <input type="text" name="mstatus" Value=""><br> 
     Date of Birth :<br>  
     <input type="text" name="dob" Value=""><br>
     <br>  
     Marriage Date :<br>  
     <input type="text" name="doa" Value=""><br>
     Baptised :<br>  
     <input type="text" name="baptised" Value=""><br>
     Residence :<br>  
     <input type="text" name="residence" Value=""><br>
     Mobile Number :<br>  
     <input type="text" name="mnumber" Value=""><br>
     <input type="button" onclick="Sample()" value="Submit"><br>  
  </center>  
 </fieldset>  
 <form>  
 </body>  
 </html>  

子样本()
黯淡
设置objExcel=CreateObject(“Excel.Application”)
设置obj工作簿=objExcel.Workbooks.Open(“C:\Users\ARPIT SHAJU\Desktop\Church\Member.xlsx”)
objExcel.Application.Visible=True
ObjWorkbook.Windows(1).Visible=True
Set XlSheet=objWorkbook.Sheets(1)
激活
iRow=1
用objExcel
执行while.Cells(iRow,1).value“”
.单元格(iRow,1)。激活
iRow=iRow+1
环
.Cells(iRow,1).value=Document.GetElementsByName(“fname”)(0).value
.Cells(iRow,2).value=Document.GetElementsByName(“姓氏”)(0).value
.Cells(iRow,3).value=Document.GetElementsByName(“性别”)(0).value
.Cells(iRow,4).value=Document.GetElementsByName(“mstatus”)(0).value
.Cells(iRow,5).value=Document.GetElementsByName(“dob”)(0).value
.Cells(iRow,6).value=Document.GetElementsByName(“doa”)(0).value
.Cells(iRow,7).value=Document.GetElementsByName(“baptised”)(0).value
.Cells(iRow,8).value=Document.GetElementsByName(“住宅”)(0).value
.Cells(iRow,9).value=Document.GetElementsByName(“mnumber”)(0).value
MsgBox“数据添加成功”,vbinformation
Document.GetElementsByName(“fname”)(0)。Value=“”
Document.GetElementsByName(“姓氏”)(0)。Value=“”
Document.GetElementsByName(“性别”)(0)。Value=“”
Document.GetElementsByName(“mstatus”)(0.Value=“”
Document.GetElementsByName(“dob”)(0)。Value=“”
Document.GetElementsByName(“doa”)(0.Value=“”
Document.GetElementsByName(“baptised”)(0.Value=“”
Document.GetElementsByName(“住所”)(0)。Value=“”
Document.GetElementsByName(“mnumber”)(0)。Value=“”
以
ObjWorkbook.Save
关闭
设置objWorkbook=Nothing
设置objExcel=Nothing
端接头
字段集{
边框:#00cc00 2px实心;
填充:10px;
颜色:绿色;

从网站复制代码时需要小心。您需要用双引号替换所有块引号



您应该将代码另存为.hta文件,而不是“记事本”。你用什么软件打开HTML?控制台上的开发者工具报告了哪些错误?我用扩展名.htm保存了记事本,并在internet Explorer中打开了它。我将它改为双引号,但它仍然不工作。你必须允许内容,并可能更改浏览器的安全设置以允许活动我不认为Chrome已经支持它们了。IE是你的最佳选择。你可能想考虑创建一个HTA文件。用一个非常好的HTA IDE来。好的,谢谢,我会试试的。