简体   繁体   English

如何使用Java脚本将HTML表单保存到Excel工作表?

[英]How to save your html form to excel sheet using java script?

I have one html form, I want to store that form data into excel sheet. 我有一个HTML表单,我想将该表单数据存储到Excel工作表中。 I am using linux(Fedora 15) OS. 我正在使用linux(Fedora 15)OS。 I have one VB Script that works for me fine in Internet Explorer, Windows OS. 我有一个可以在Internet Explorer,Windows OS中正常运行的VB脚本。 But Same script not working in linux mozilla firefox browser. 但是相同的脚本在linux mozilla firefox浏览器中不起作用。 Please tell me java script for store my html data into excel sheet, that works in linux OS and mozilla firefox browser. 请告诉我用于将html数据存储到excel表中的Java脚本,该脚本可在linux OS和mozilla firefox浏览器中使用。 I share my VB script please tell me correction in that so i can use it as java script. 我分享我的VB脚本,请告诉我更正,以便可以将其用作Java脚本。

 <!DOCTYPE html> <html> <head> <script language="vbscript" type="text/vbscript"> Sub Sample() Dim iRow Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open("home/Book1.xlsx") 'Document.GetElementsByName("fname")(0).Value="C#" 'Document.GetElementsByName("lname")(0).Value="Corner" 'Document.GetElementsByName("Add1")(0).Value="Tamilnadu" 'Document.GetElementsByName("Add2")(0).Value="Coimbatore" 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("lname")(0).Value .Cells(iRow, 3).value=Document.GetElementsByName("Add1")(0).Value .Cells(iRow, 4).value=Document.GetElementsByName("Add2")(0).Value MsgBox "Data Added Sucessfully",vbinformation Document.GetElementsByName("fname")(0).Value="" Document.GetElementsByName("lname")(0).Value="" Document.GetElementsByName("Add1")(0).Value="" Document.GetElementsByName("Add2")(0).Value="" End With objWorkbook.save objWorkbook.close Set objWorkbook = Nothing Set objExcel = Nothing End Sub </script> <body> <form> <fieldset> <center> First name:<br> <input type="text" name="fname" Value=""><br> Last name:<br> <input type="text" name="lname" Value=""><br> Address1:<br> <input type="text" name="Add1" Value=""><br> Address2 :<br> <input type="text" name="Add2" Value=""><br> <br> <input type="button" onclick="Sample()" value="Submit" /><br> </center> </fieldset> </form> </body> </html> 

For this code i have created excel sheet in my computer every time i click on Submit button one row is created and store data in my excel sheet. 对于此代码,每当我单击“提交”按钮时,我都会在计算机中创建excel工作表,并创建一行并将数据存储在excel工作表中。

Security permissions must be altered to allow saving to a local folder. 必须更改安全权限以允许保存到本地文件夹。 If you are running this file directly from your machine consider renaming it to .HTA and look at HTML Applications on msdn.com. 如果直接在计算机上运行此文件,请考虑将其重命名为.HTA,然后查看msdn.com上的HTML Applications。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM