分享

QTP如何获取本地Excel文件的行和列

 杨柳1234 2010-12-15
代码如下:

Set  excel=CreateObject("Excel.Application")
set openexcel=excel.Workbooks.Open("这里输入EXCEL路径")
rowcount =openexcel.ActiveSheet.UsedRange.Rows.Count
Columnscount =openexcel.ActiveSheet.UsedRange.Columns.count
print " 行数:"&rowcount&"  列数:"&Columnscount
openexcel.Close
excel.Quit
set openexcel=nothing
Set  excel=nothing
'若想要获取Excel中指定sheet的行数和列数,函数如下:
Public function getrowandcol(filepath,sheetname)
'函数作用:获取EXCEL指定sheet的行数和列数
'参数说明
'filepath:EXCEL所在路径
'sheetname:需要统计行数和列数的SHEET名称
'用法示例:getrowandcol"D:\qqq.xlsx","sheet1"
Set  excel=CreateObject("Excel.Application")
set openexcel=excel.Workbooks.Open(filepath)
openexcel.WorkSheets(sheetname).Activate
           rowcount =openexcel.ActiveSheet.UsedRange.Rows.Count
           Columnscount =openexcel.ActiveSheet.UsedRange.Columns.count
If openexcel.WorkSheets(sheetname).Cells(1,1 )="" and rowcount=1 and Columnscount=1 then
           print sheetname&"中没有数据"
else
           print sheetname&"的行数为:"&rowcount&"  列数:"&Columnscount
end if
openexcel.Close
excel.Quit
set openexcel=nothing
Set  excel=nothing
End Function
 
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/meiyuan1304/archive/2010/08/02/5783647.aspx

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多