Reputation: 87
i want to know how to find the used rows row count and used columns column count by using win32com.client as win32
i have written code like this
excel = win32.gencache.EnsureDispatch('Excel.Application')
excel.DisplayAlerts = False
wb = excel.Workbooks.Open('path')
ws = wb.Worksheets("Global")
regards,
G Somesh
Upvotes: 2
Views: 14470
Reputation: 33
I also use win32com.client, and here is what I use to count the used columns and rows in an Excel. It should would with your current code as well:
lastCol = exclsheet.UsedRange.Columns.Count
lastRow = exclsheet.UsedRange.Rows.Count
Upvotes: 3
Reputation: 13098
This should do it when added to your code above:
used = ws.UsedRange
nrows = used.Row + used.Rows.Count - 1
ncols = used.Column + used.Columns.Count - 1
Upvotes: 8