Find range of filled contents in Excel worksheet

2019-08-22 08:59发布

I have an Excel 2016 Book.xlsm. In the worksheet testsheet, the cells in the range A1:Y150 are filled with text or number contents. The upper-left cell is always A1.

I am using python v3 xlwings to open the Excel file.

import xlwings as xw
Book_name = 'C:/Users/name/Book.xlsm'
sheet_name = 'testsheet'
wb = xw.Book(Book_name)
sht = wb.sheets[sheet_name]

How do I find out the range of cells that are filled with contents using python, which in this case is A1:Y150?

1条回答
太酷不给撩
2楼-- · 2019-08-22 09:11

If wb is defined as Excel Workbook, then this is a good way:

print (wb.sheets[sheet_name].api.UsedRange.Address)

查看更多
登录 后发表回答