Find range of filled contents in Excel worksheet

拟墨画扇 提交于 2019-12-11 16:40:09

问题


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:


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

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



来源:https://stackoverflow.com/questions/47204701/find-range-of-filled-contents-in-excel-worksheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!