weshatheleopard / rubyXL

Ruby lib for reading/writing/modifying .xlsx and .xlsm files
MIT License
1.28k stars 255 forks source link

undefined method cell_xfs for #<RubyXL::Workbook:0x...> (NoMethodError) #325

Closed fruwe closed 5 years ago

fruwe commented 5 years ago

After updating the gem to 3.4.0 today, I got this error upon running RubyXL::Parser.parse('test.xlsx').worksheets[0][0][0].value

         3: from /home/chris/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubyXL-3.4.0/lib/rubyXL/objects/sheet_data.rb:85:in `value'
         2: from /home/chris/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubyXL-3.4.0/lib/rubyXL/objects/sheet_data.rb:71:in `is_date?'
         1: from /home/chris/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubyXL-3.4.0/lib/rubyXL/objects/sheet_data.rb:66:in `number_format'
/home/chris/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rubyXL-3.4.0/lib/rubyXL/cell.rb:42:in `get_cell_xf': undefined method `cell_xfs' for #<RubyXL::Workbook:0x000055ddf179ba88> (NoMethodError)

I also attach the excel file

test.xlsx

After downgrading to v3.3.0 it works as expected:

irb(main):002:0> RubyXL::Parser.parse('test.xlsx').worksheets[0][0][0].value
=> 10
ngiger commented 5 years ago

Found the same error when running oddb2xml gem.

ngiger commented 5 years ago

Resolved the problem via:

require 'rubyXL/convenience_methods/workbook'

Is is possible add a hint to this solution when this error occurs?

weshatheleopard commented 5 years ago

@ngiger it's in the README. And major version number has changed, so if you want to keep the old version with old behavior, you can use ~> when including the gem.

However, in this particular case, cell_xfs is indeed important for number_format, so I fixed this particular issue.