简体   繁体   中英

How to send html form data to excel file

how to send form data like username and email field data by using java script then it has to be stored in excel file by clicking a button and also that code should run on all browsers?? Before I was running this vb code under script tag executed in IE even there also I can't see any data filled in that excel file.

Sub sample()  
          Dim iRow  
          Set objExcel = CreateObject ("Excel.Application")  
          Set objWorkbook = objExcel.Workbooks.Open("D:\Users\users.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("lname")(0).Value  
                 .Cells (iRow, 3).value=Document.GetElementsByName("Add1")(0).Value  
                 .Cells (iRow, 4).value=Document.GetElementsByName("Add2")(0).Value  
                 MsgBox "Data Added Successfully”, 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

I'm afraid that what you're trying to do is not possible, first and foremost because you cannot edit any existing file on your computer through the browser. Not in place, anyways.

The two most simple solutions I can think of are either:

  1. Request the file from javascript ("upload" it). Edit it manually from there (you will not be able to use Excel's API from there, but maybe this library here will help you achieving what you're trying. Then have the user re-download the file.

  2. Start a simple server that changes the file for you (maybe even from VBA itself? I really have no good knowledge of its capabilities). Then you can create a simple html form that interacts with that server.

Last thing, hopefully I'm not outta line here but it seems as if you're a little bit unsure about how web technologies work. If you're interested, I suggest that you go on to read a little about html5, javascript and how basic client-server communication works over http.

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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