Dinesh
Dinesh

Reputation: 16428

openpyxl read excel with filtered data

With openpyxl, I am reading an excel file which has some filters applied already.

from openpyxl import load_workbook
wb = load_workbook('C:\Users\dsivaji\Downloads\testcases.xlsx')
ws = wb['TestCaseList']
print ws['B3'].value

My goal to loop through the content of the column 'B'. With this I will be able to read the content of the cell 'B3'. If filters applied and in that case, I don't want to start from the initial cell.

i.e. whichever visible in the excel (after applying the filters) , those alone I want to fetch.

After searching in web for sometime, found that ws.row_dimensions can help with the visible property, but still no luck.

>>> ws.row_dimensions[1]
<openpyxl.worksheet.dimensions.RowDimension object at 0x03EF5B48>
>>> ws.row_dimensions[2]
<openpyxl.worksheet.dimensions.RowDimension object at 0x03EF5B70>
>>> ws.row_dimensions[3].visible
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'RowDimension' object has no attribute 'visible'

How to achieve this ?

Upvotes: 0

Views: 1988

Answers (2)

Bjorkegeek
Bjorkegeek

Reputation: 128

You are almost there. The name of the attribute is hidden. If you replace visible in your code with hidden, it should work.

Upvotes: 2

Charlie Clark
Charlie Clark

Reputation: 19507

openpyxl is a library for the OOXML file format (.xlsx) and not a replacement for an application like Microsoft Excel. As such support for filters is limited to reading and writing their definitions but not applying them.

Upvotes: 0

Related Questions