weshatheleopard / rubyXL

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

Cannot set alignment in Gem verison 3.3.3 #321

Closed vaibhavmdhoke closed 5 years ago

vaibhavmdhoke commented 5 years ago

Error: TypeError - can't dup NilClass: This is my underlying code which tries to set alignment,

set_cell_style(worksheet.sheet_data[4][col_start + 1], { :bold => true, :alignment => "center", :border => "box" })

Code breaks at /rubyXL-3.3.33/lib/rubyXL/convenience_methods.rb +154

def modify_alignment(style_index, &block)
      xf = cell_xfs[style_index || 0].dup
     xf.alignment = xf.alignment.dup || RubyXL::Alignment.new ### this line
      yield(xf.alignment)
      xf.apply_alignment = true

      register_new_xf(xf)
    end
341bms commented 5 years ago

Some here with v3.3.3.. v3.3.1 works fine.

weshatheleopard commented 5 years ago

Can you please try 3.4.0?

341bms commented 5 years ago

With 3.4.0 I get "undefined method insert_row' for #<RubyXL::Worksheet:0x007fb7ce18d278>" and "undefined methodchange_contents' for #<RubyXL::Cell(4,2): nil, datatype=nil, style_index=41>" Looks like it breaks a lot more.

weshatheleopard commented 5 years ago

@341bms You are attempting to use convenience methods without first including them. Read the README file for 3.4.0.