Find first visible worksheet using RubyXL

222 Views Asked by At

I am parsing an Excel workbook using RubyXL and discovered that workbook[0] returns the first worksheet regardless of whether it is hidden.

I would like to isolate the first visible worksheet by coding something like workbook[0].not_hidden.

How can this be done in RubyXL?

1

There are 1 best solutions below

0
sscirrus On

It turns out visibility is held in a parameter called @state, where a visible worksheet has @state = nil and a hidden worksheet has @state = 'hidden'.

So, to isolate the first visible worksheet:

worksheet = workbook.select{ |w| w.state.blank? }[0]

Or, to isolate the first hidden worksheet:

worksheet = workbook.select{ |w| w.state == 'hidden' }[0]