All notes2026-05-05

openpyxl Has a Third Sheet State

I was filtering sheets by `visible` and `hidden`. Turns out Excel has a third state — `veryHidden` — and openpyxl exposes it as-is.

Most of what you'll find about openpyxl sheet visibility talks about two states: visible and hidden. That's what I assumed. My filter handled both, and it worked on the files I tested against.

Then a workbook came through where sheet.sheet_state returned a value I didn't recognise: veryHidden.

Three states, not two

Excel has three sheet visibility states:

  • visible — shows in the tab bar
  • hidden — hidden, but the right-click menu can unhide it
  • veryHidden — hidden with no way to unhide from the UI; you need VBA or code to flip it back

veryHidden is what people use to bury internal or helper sheets where they don't want users poking around. It's invisible enough in normal Excel workflows that it's easy to forget exists when you're scripting against arbitrary workbooks from the wild.

The fix

Matching against "hidden" only catches one of the two non-visible states:

if sheet.sheet_state == "hidden":
    continue

Match against the state you actually want instead:

if sheet.sheet_state != "visible":
    continue

Lesson

When a string field looks like a boolean (visible/hidden), check the actual enum before assuming. "Hidden" sounds like "the opposite of visible" — but in Excel there are two flavours of hidden, and one of them won't show up in any UI you'd think to test against.