您可以使用VBA库“Microsoft Internet控制”和“Microsoft HTML对象库”和完全自动化网页交互...
下面是一个宏做...若要进入宏代码,您可以使用Alt + F11进入Microsoft Visual Basic for Applications环境。
- 添加库引用(下Tools
>References
菜单)
- 添加代码模块
(Insert
>Module
下) - 下面的代码粘贴...修改他们的网址
代码将打开IE然后进入网页并等待你点击确定(完成任何你需要的操作后......也许登录,在某处导航,输入行数......)。然后,它将遍历您在电子表格中使用的所有列(使用Find
填充numCols
),并将单元格值放入具有相关ID的HTML元素中。它不会打到为你增加员工,以防万一出错,但图书馆确实给你的东西.Click()
的能力。
我已经使用了这个几个自动化黑客,它似乎很可靠......困难的部分可以等待页面加载/更新 - 但你不应该有这个问题。
'References needed: "Microsoft Internet Controls" and "Microsoft HTML Object Library"
' (add under menu Tools > References)
Sub populate()
Dim ws As Worksheet
Set ws = Application.ActiveSheet
Dim appIE As InternetExplorer
Set appIE = New InternetExplorer
appIE.Visible = True
appIE.Navigate "http://localhost:8080/your_form"
If vbCancel = MsgBox("Make sure the page has loaded, enter the number of ids etc. etc. Then click OK", vbOKCancel) Then
Set appIE = Nothing
Exit Sub
End If
Dim counter As Integer, index As Integer, numCols As Integer
numCols = ws.Cells.Find(What:="*", After:=[A1], LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Column
For counter = 1 To numCols
'A1 = id='firstname0'
'A2 = id='middleinitial0'
'A3 = id='lastname0'
'A6 = id='ntlogin0'
index = counter - 1
appIE.document.getElementById("firstname" & index).Value = ws.Cells(1, counter)
appIE.document.getElementById("middleinitial" & index).Value = ws.Cells(2, counter)
appIE.document.getElementById("lastname" & index).Value = ws.Cells(3, counter)
appIE.document.getElementById("ntlogin" & index).Value = ws.Cells(6, counter)
Next counter
Set appIE = Nothing
Set ws = Nothing
MsgBox "All done - hit Submit if all OK!"
End Sub
版本VALUES行
'References needed: "Microsoft Internet Controls" and "Microsoft HTML Object Library"
' (add under menu Tools > References)
Sub populate()
Dim ws As Worksheet
Set ws = Application.ActiveSheet
Dim appIE As InternetExplorer
Set appIE = New InternetExplorer
appIE.Visible = True
appIE.Navigate "http://localhost:8080/your_form"
If vbCancel = MsgBox("Make sure the page has loaded, enter the number of ids etc. etc. Then click OK", vbOKCancel) Then
Set appIE = Nothing
Exit Sub
End If
Dim counter As Integer, index As Integer, numRows As Integer
numRows = ws.Cells.Find(What:="*", After:=[A1], LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For counter = 1 To numRows
'A1 = id='firstname0'
'B1 = id='middleinitial0'
'C1 = id='lastname0'
'D1 = id='ntlogin0'
index = counter - 1
appIE.document.getElementById("firstname" & index).Value = ws.Cells(counter,1)
appIE.document.getElementById("middleinitial" & index).Value = ws.Cells(counter,2)
appIE.document.getElementById("lastname" & index).Value = ws.Cells(counter,3)
appIE.document.getElementById("ntlogin" & index).Value = ws.Cells(counter,4)
Next counter
Set appIE = Nothing
Set ws = Nothing
MsgBox "All done - hit Submit if all OK!"
End Sub
这是一个起点,但我不知道你说的:o我会尝试一下,但我从来没有使用Excel – user237025 2014-10-16 22:34:28
发挥@ user237025 - 啊哈!这对新手来说是一个很好的介绍:-)该网站是否公开,您可以分享更多您的示例数据......然后我可以给您一个更完整的示例! – Captain 2014-10-17 06:55:38
不,它是一个内部网站,但我可以给你更多的例子 http://pastebin.com/AaWCZUJe – user237025 2014-10-18 22:57:04