2017-03-17 43 views
1

如何通过使用java脚本发送表单数据,如用户名和电子邮件字段数据,然后通过单击按钮将其存储在excel文件中,并且该代码应该可以在所有浏览器上运行? ? 在我在IE中执行脚本标签下运行这个vb代码之前,我也看不到在该excel文件中填充的任何数据。如何将html格式的数据发送到excel文件

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 

回答

0

我怕你想做什么是不可能的,首先是因为你不能编辑通过浏览器在您的计算机上已经存在的文件。反正没有到位。

两个最简单的解决方案,我能想到的要么是:

  1. 请求从JavaScript文件(“上传”的话)。从那里手动编辑(您将无法使用Excel的API从那里,但也许this library here将帮助你实现你想要什么,然后让用户重新下载该文件。

  2. 启动一个简单的服务器是(甚至从VBA本身可能?我真的有它的功能没有良好的知识)更改文件你。然后你就可以创建一个与服务器交互的简单的HTML表单。

最后一件事,希望我不会在这里排队,但似乎对Web技术的工作方式有点不确定。如果您有兴趣,我建议您继续读一点关于html5,javascript以及基本的客户端 - 服务器通信如何在http上工作。

祝你好运!

相关问题