Finding hidden cells with openpyxl
I'm trying to write a script to copy formatting from one book to another, and as anyone who owns openpyxl knows, it's a big script. I got it to work pretty well, but one thing I can't figure out is how to read from the original if the columns are hidden.
Can anyone tell me where to look in a workbook, worksheet, column or cell object to see where the hidden columns are?
source to share
The attributes you are looking for are inside attributes column_dimensions
and row_dimensions
object Worksheet
.
These are related dictionaries whose values ββare ColumnDimension
/ RowDimension
objects. The specific attribute you are looking for is ColumnDimension.hidden
.
The following will print the column letter of all hidden columns on the sheet ws
:
for colLetter,colDimension in ws.column_dimensions.items():
if colDimension.hidden == True:
print(colLetter)
And for the lines:
for rowNum,rowDimension in ws.row_dimensions.items():
if rowDimension.hidden == True:
print(rowNum)
As I understand it, uploading your book as quality read_only
might mess with ws.row_dimensions
, so be careful in this case.
source to share