VB通过ADO访问Excel文件


(文章ID:252)|(编辑:isen)|(点击次数:1274)|(添加时间:2013-03-18 08:54:54)|(添加IP:182.135.189.127)

    '测试成功

    Private Sub Command1_Click()

     Dim ovdbConn As ADODB.Connection

    Dim ovRs As ADODB.Recordset

     Set ovdbConn = New ADODB.Connection

    Set ovRs = New ADODB.Recordset

     ovdbConn.CursorLocation = adUseClient

     ovdbConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=D:\123.xls;Extended Properties='Excel 8.0;HDR=Yes'"

    ovRs.Open "select * from [Sheet1$]", ovdbConn, 1,3

    Do While Not ovRs.EOF ‘修改并保存内容

     ovRs(0).Value = ovRs(0) * 15

     ovRs(1).Value = ovRs(1) * 15

     ovRs(2).Value = ovRs(2) * 15

     ovRs.Update

     ovRs.MoveNext

    Loop

    ovRs.MoveFirst

     Do While Not ovRs.EOF

     MsgBox ovRs(0) & ovRs(1) & ovRs(2) '把每一条信息显示出来

     ovRs.MoveNext

    Loop

    

     ovRs.Close

     ovdbConn.Close

     Set ovdbConn = Nothing

    Set ovRs = Nothing

    

    End Sub



·上一篇:一森中小学幼儿园教师继教登记系统上线...
·下一篇:flash常用脚本语言(ActionScript)实例

粤ICP备13075271号  | Copyright © 2024 Isen Software Studio - 一森软件工作室  |  Designed by www.isennet.com  | 站长入口