Skip to content

Commit

Permalink
[Excel Analyzer] fix hidden column count
Browse files Browse the repository at this point in the history
Hidden columns that intersect a blank row would raise an exception:
> NoMethodError: undefined method `[]' for nil:NilClass
  • Loading branch information
gbp committed Jan 25, 2024
1 parent f87ec29 commit 1c52fbb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gems/excel_analyzer/lib/excel_analyzer/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def hidden_columns
end

hidden_columns.count do |c|
cells = sheet.sheet_data.rows.map { _1[c - 1] }
cells = sheet.sheet_data.rows.compact.map { _1[c - 1] }
cells.compact.any? { !_1.value.to_s.empty? }
end
end
Expand Down
11 changes: 10 additions & 1 deletion gems/excel_analyzer/spec/excel_analyzer/probe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@
RSpec.describe ExcelAnalyzer::Probe do
include ExcelAnalyzer::Probe

def fixture(filename)
File.open(File.join(__dir__, "../fixtures/#{filename}"))
end

it "does not error if workbook has chartsheets" do
xlsx = File.open(File.join(__dir__, "../fixtures/chartsheet.xlsx"))
xlsx = fixture("chartsheet.xlsx")
expect(probe(xlsx)).to be_a(Hash)
end

it "does not error if workbook has hidden cols that intersect a blank row" do
xlsx = fixture("hidden-cols-blank-row.xlsx")
expect(probe(xlsx)).to be_a(Hash)
end
end
Expand Down
Binary file not shown.

0 comments on commit 1c52fbb

Please sign in to comment.