为了账号安全,请及时绑定邮箱和手机立即绑定

Vbscript如何读入Excel数据?

Vbscript如何读入Excel数据?

智慧大石 2019-08-03 13:03:39
刚刚接触vb的菜鸟,求教,谢谢!例如下面代码:Sub Test1Dim ngDim loginFormDim editDim mainFormDim driverTestedApps.TestedApp.Run'输入密码Set driver = DDT.ExcelDriver("c:\TB.xls","sheet1")Set ngcrm = Aliases.ngSet loginForm = ng.LoginFormSet edit = Aliases.ng.LoginForm.Panel1.EdtPasswdCall edit.Click(44, 7)edit.wText = "zzw456!@#"如果我想在edit.wText = "zzw456!@#"处读取excel的数据,代码要如何编写?
查看完整描述

3 回答

?
慕少森

TA贡献2019条经验 获得超9个赞

vbs读取excel脚本倒是好说,但你的程序明显在vb与vba之间,恕我看不懂。 给你个例子参考下:
' Read an Excel Spreadsheet

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open _
("C:\Scripts\New_users.xls")

intRow = 2

Do Until objExcel.Cells(intRow,1).Value = ""
Wscript.Echo "CN: " & objExcel.Cells(intRow, 1).Value
Wscript.Echo "sAMAccountName: " & objExcel.Cells(intRow, 2).Value
Wscript.Echo "GivenName: " & objExcel.Cells(intRow, 3).Value
Wscript.Echo "LastName: " & objExcel.Cells(intRow, 4).Value
intRow = intRow + 1
Loop

objExcel.Quit


查看完整回答
反对 回复 2019-08-05
?
交互式爱情

TA贡献1712条经验 获得超3个赞

<%
set conn=Server.CreateObject("Adodb.Connection")
Driver = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};"
DBPath = "DBQ=" & Server.MapPath("zhenhe.xls") 'zhenhe.xls改为你的文件名
conn.open Driver&DBPath
sql="select * from [Sheet1$]" '[Sheet1$]表单名
set rs=conn.execute(sql)
for i=0 to Rs.Fields.Count-1
response.write rs(i).name&""
abcde=rs(0).name&""
next
response.write "<br>"
response.write "<br>"
do while not rs.eof
for i=0 to Rs.Fields.Count-1
response.write rs(i).value&""
next
response.write "<br>"
rs.movenext
loop
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
<%=abcde%>


 


查看完整回答
反对 回复 2019-08-05
  • 3 回答
  • 0 关注
  • 433 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信