简体   繁体   English

如何通过使用“ win32com.client as win32”来知道excel使用的行数和列数

[英]how to know used row count and column count of excel by using “win32com.client as win32”

i want to know how to find the used rows row count and used columns column count by using win32com.client as win32 我想知道如何通过使用win32com.client作为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 G·萨默斯

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

I also use win32com.client, and here is what I use to count the used columns and rows in an Excel. 我也使用win32com.client,这是我用来计算Excel中已使用的列和行的内容。 It should would with your current code as well: 它也应该与您当前的代码:

lastCol = exclsheet.UsedRange.Columns.Count
lastRow = exclsheet.UsedRange.Rows.Count

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM