使用adonet读取excel的2个函数
上一篇 /
下一篇 2011-10-18 14:46:51
/ 个人分类:VBScript
'获取某单元格数据51Testing软件测试网
V1D'p\4N
Function get_excel_value(rowindex,cellindex)51Testing软件测试网0T+]%I0wn:r^N
On Error Resume NEXT
}Kf0WM0Dim myarray()
m5VqKe"e"]\4E0Set con=createobject("adodb.connection")
4D2I*GI,yC8A0 conset="DSN=test;DBQ=D:\test\test.xls;DefaultDir=D:\test;DriverId=790;FIL=excel 8.0;MaxBufferSize=2048;PageTimeout=5;"51Testing软件测试网/tQ!e(s*?5Nn0j
con.open conset
xY5wU5F#q0Set rs=createobject("adodb.recordset")51Testing软件测试网f4C?0}V`%e
sql="select count(*) from [Sheet1$]"51Testing软件测试网 t
q,^'R'G*?'Y
rs.open sql,con
I2f a8K+@\*zZ&\0rows=rs.Fields(0)51Testing软件测试网 K#IQF1?f,aj
rs.Close
%[.J*c6gd'sg1BBe0 sql="select * from [Sheet1$]"
`%p0M_ z#?0 rs.open sql,con
jn.uae!p3}Q0 If rowindex >rows or cellindex>rs.Fields.Count Then
Ry)AA![0
:lz6w0P(fG0 ‘MsgBox "该单元格无数据"51Testing软件测试网&rm?Q/rw/|7R\(To-y
get_excel_value =-151Testing软件测试网&r:F9M1W/Fh:o4p~
Exit function51Testing软件测试网1JU:Dc$|
Z{
Else
k&~wO;f/x
bdx$@0 rs.Move rowindex-1
tA3LL6B,h]0 get_excel_value =rs.Fields(cellindex-1).Value51Testing软件测试网/d
@$jC!u8Cw
51Testing软件测试网N_/_~1r:D?
End If
oJ|+[})j1u}A+B;Z0 con.Close51Testing软件测试网bv?^.i'On0Z
Set con=Nothing
Hd)F0I'wn0On Error Goto 051Testing软件测试网m9X)m4Q-q
4d~;sE[\0]gF0End Function
0{1O
R4mm0 51Testing软件测试网 m:A@`F&oD
C0Q
'get_excel_cell:获取excel某列的数据,返回数组
4yc/r-};}0n0'cellindex:获取列的序号或列名
NZ })f$ka3i8J4K0c0Function get_excel_cell(cellindex)51Testing软件测试网\&K