在VBScript中使用ADODB来查找Excel工作表中的行数? [英] Using ADODB in VBScript to find the number of rows in an Excel sheet?

查看:556
本文介绍了在VBScript中使用ADODB来查找Excel工作表中的行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VBScript中的ADODB来访问Excel文件,以查找给定表格中输入数据的行数。我的代码到目前为止显示工作表上的所有内容,但我不知道如何计数行或使用查询直接查找行数。我想使用ADODB,因为它不直接打开Excel文件,但如果这不是最好的方法,那么我该怎么办呢?谢谢。

I'm trying to use ADODB in VBScript to access an Excel file to find the number of rows in a given sheet that have data entered into them. My code so far displays everything on the sheet, but I'm not sure how I could count the rows or directly find the number of rows using a query. I want to use ADODB as it doesn't open the Excel file directly, but if this isn't the best way then how could I do it otherwise? Thanks.

Set adodb = CreateObject("ADODB.Connection")
adodb.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
              "test.xls" & ";Extended Properties=""Excel 8.0;IMEX=1;" & _
              "HDR=NO;" & """"

Set result = adodb.Execute("Select * from [Sheet1$]")

MsgBox result.GetString 

result.Close
adodb.Close
Set adodb = Nothing
Set result = Nothing


推荐答案

为您的Connection对象添加 CursorLocation 属性。

Add a CursorLocation property for your Connection object.

更新:

'result.CursorLocation = 3 'adUseClient
adodb.CursorLocation = 3 'adUseClient

然后你可以得到行数。

MsgBox result.RecordCount

这篇关于在VBScript中使用ADODB来查找Excel工作表中的行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆