weshatheleopard / rubyXL

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

undefined method `fill_color' for #<RubyXL::Cell(1,5): nil, datatype=nil, style_index=30> (NoMethodError) #417

Closed Souravgoswami closed 2 years ago

Souravgoswami commented 2 years ago

I used the gem version 3.3.33, where it's giving me this error:

/home/sourav/.gem/ruby/3.0.0/gems/rubyXL-3.4.10/lib/rubyXL/objects/text.rb:89:in `block in to_s': can't modify frozen String: "" (FrozenError)

It's because nil.to_s in Ruby 2.7 is returning frozen string.

So I tried updating to the latest version 3.4.22 where the problem is apparently fixed, now I'm getting this error:

xlsx_to_yaml_rubyXL.rb:80:in `block (3 levels) in <main>': undefined method `fill_color' for #<RubyXL::Cell(1,5): nil, datatype=nil, style_index=30> (NoMethodError)

I know something has changed, but I can't find the fill_color method which I used to detect the background colour of the cell.

Any ideas where did the fillcolor go? I can't find it in get* methods. No documentation either. Can only get the font colour now :(

weshatheleopard commented 2 years ago

It's in the documentation.

Souravgoswami commented 2 years ago

Well as I said, cell.fill_color doesn't work on newer versions. It worked in the older version 3.3.33 and those.

Whenever I use this I get

xlsx_to_yaml_rubyXL.rb:80:in `block (3 levels) in <main>': undefined method `fill_color' for #<RubyXL::Cell(1,5): nil, datatype=nil, style_index=30> (NoMethodError)
weshatheleopard commented 2 years ago

You are not much of a reader, are you?

> require 'rubyXL'
> require 'rubyXL/convenience_methods'
> workbook = RubyXL::Workbook.new
> cell = workbook[0].add_cell(0,0)
> cell.fill_color
 => "ffffff"
Souravgoswami commented 2 years ago

Sorry, don't want to argue. Of course, you know it better.

I was trying to say that:

image

On the above, I have 3.3.33, and on the bottom I have 3.4.22.

Not sure about add_cell(0, 0), but documentation says it's under "Modifying" category. I don't want to modify my spreadsheet, but just read the cells and read the background colour. Because in my case, the background colour determines boolean values!

I wanted to report that the documentation for cell.fill_color doesn't match the current behaviour.

In both versions, workbook.worksheets[0][0][0] returns an instance of RubyXL::Cell.

weshatheleopard commented 2 years ago

Ummm, hello? Where's your require 'rubyXL/convenience_methods'?

Please read the documentation. Slowly and carefully.

Souravgoswami commented 2 years ago

Yup, sorry, it works now. Wasn't aware of that separate file for the method RubyXL::Cell#fill_color(). Makes sense it reduces the memory footprint. Thank you very much!