簡體   English   中英

如何使用Java腳本將HTML表單保存到Excel工作表?

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

我有一個HTML表單,我想將該表單數據存儲到Excel工作表中。 我正在使用linux(Fedora 15)OS。 我有一個可以在Internet Explorer,Windows OS中正常運行的VB腳本。 但是相同的腳本在linux mozilla firefox瀏覽器中不起作用。 請告訴我用於將html數據存儲到excel表中的Java腳本,該腳本可在linux OS和mozilla firefox瀏覽器中使用。 我分享我的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> 

對於此代碼,每當我單擊“提交”按鈕時,我都會在計算機中創建excel工作表,並創建一行並將數據存儲在excel工作表中。

必須更改安全權限以允許保存到本地文件夾。 如果直接在計算機上運行此文件,請考慮將其重命名為.HTA,然后查看msdn.com上的HTML Applications。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM