Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue where the contents of hidden sheet was returned when parsing visible sheets only. #536

Merged
merged 3 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/roo/excelx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,18 @@ def initialize(filename_or_stream, options = {})
@filename = local_filename(filename_or_stream, @tmpdir, packed)
process_zipfile(@filename || filename_or_stream)

@sheet_names = workbook.sheets.map do |sheet|
sheet_indicies = []
@sheet_names = workbook.sheets.each_with_index.map do |sheet, index|
simonoff marked this conversation as resolved.
Show resolved Hide resolved
unless options[:only_visible_sheets] && sheet['state'] == 'hidden'
sheet_indicies << index
sheet['name']
end
end.compact
@sheets = []
@sheets_by_name = {}
@sheet_names.each_with_index do |sheet_name, n|
@sheets_by_name[sheet_name] = @sheets[n] = Sheet.new(sheet_name, @shared, n, sheet_options)
sheet_index = sheet_indicies[n]
@sheets_by_name[sheet_name] = @sheets[sheet_index] = Sheet.new(sheet_name, @shared, sheet_index, sheet_options)
end

if cell_max
Expand Down
10 changes: 9 additions & 1 deletion spec/lib/roo/excelx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@
end
end

describe 'for a workbook with hidden sheets' do
let(:path) { 'test/files/hidden_sheets.xlsx' }

it 'returns the cell contents from the visible sheet' do
expect(Roo::Excelx.new(path, only_visible_sheets: true).cell('A', 1)).to eq "visible sheet 1"
end
end

describe '#parse' do
let(:path) { 'test/files/numeric-link.xlsx' }

Expand Down Expand Up @@ -653,4 +661,4 @@
end
end
end
end
end
Binary file added test/.DS_Store
Binary file not shown.
Binary file modified test/files/hidden_sheets.xlsx
Binary file not shown.