代码如下:
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
|
|