3

I have a large number of excel files and I only want to work with sheets which are not hidden and I want to ignore all hidden sheets.

Currently my python script loops through every sheet regardless of whether or not it's hidden. Is there a simple way to check if a worksheet is hidden?

I've looked online but the only thing I can find is ways to hide/unhide worksheets which I don't want to do here.

Anonymous
  • 440
  • 3
  • 14

1 Answers1

6

You can use ws.sheet_state to find out whether the worksheet is hidden or visible.

from openpyxl import load_workbook

path = r"your_excel.xlsx"

wb = load_workbook(filename=path)

for i in wb.worksheets:
    if i.sheet_state == "visible":
        #do what you need to...
Henry Yik
  • 22,275
  • 4
  • 18
  • 40