-
Notifications
You must be signed in to change notification settings - Fork 504
Description
If broken links are found (references to non existing sheets, DB, etc) a set of problems arise, e.g.
> worksheet.sheet(1).cell(1,1)
'assuming this works'
> worksheet.sheet(1).a1
NoMethodError (undefined method `split' for nil:NilClass)
The main culprit is:
File: ../../.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/roo-2.8.3/lib/roo/excelx/workbook.rb
31: def defined_names
32: doc.xpath('//definedName').each_with_object({}) do |defined_name, hash|
33: # "Sheet1!$C$5"
34: sheet, coordinates = defined_name.text.split('!$', 2)
35: col, row = coordinates.split('$')
36: name = defined_name['name']
37: hash[name] = Label.new(name, sheet, row, col)
38: end
39: end
defined_name.text
turns out to be "Datenblatt!#REF!"
which can't be properly split at !$
The main question is why !$
is used instead of simply !
which seems more proper. In any case a more robust solution (which I'm using now) would be:
File: ../../.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/roo-2.8.3/lib/roo/excelx/workbook.rb
31: def defined_names
32: doc.xpath('//definedName').each_with_object({}) do |defined_name, hash|
33: # "Sheet1!$C$5"
34: sheet, coordinates = defined_name.text.split('!$', 2)
35: next unless coordinates
36:
37: col, row = coordinates.split('$')
38: name = defined_name['name']
39: hash[name] = Label.new(name, sheet, row, col)
40: end
41: end
(a pull request costs me much more than writing this, and I have no Idea why !$
is important, as I don't know the format)