ruby-on-railsexcelroo

How to ignore hidden sheets when importing xlsx files with rails and roo


I am using Roo to import xlsx files into my rails app. The imports work fine, however, while trying to make a 'workbook' importer instead of just a 'worksheet' importer, I noticed that there are tons of hidden sheets on some of the files. For example:

In some of the files the SUB_LABOR sheet has important data that should be imported. These are not hidden. In other files, the SUB_LABOR was used as a scratch pad and then hidden so that people using the sheet will not use it.

I would like my importer to read in the workbook and parse the sheets that are not hidden and ignore the ones that are. I see that the 'hidden' value is stored in the excelx object under <Nokogiri::XML::Attr:[a hex value] name="state" value="hidden">

Is there a way to dig this information out of the object and act on it?

The whole object is way to big to post here.


Solution

  • You can pass in

    only_visible_sheets: true
    

    to the initializer, e.g.:

    Roo::Excelx.new("my.xlsx", only_visible_sheets: true)