-
Notifications
You must be signed in to change notification settings - Fork 265
Open
Description
From the RubyXL::WorksheetConvenienceMethods#insert_column source code, it looks like it should:
c = RubyXL::Cell.new(:style_index => old_cell.style_index, :worksheet => self,
:row => row_index, :column => column_index,
:datatype => RubyXL::DataType::SHARED_STRING)but AFAICT that worksheet param never gets used.
Steps to reproduce
- Create a new worksheet
- Add a cell
- Style the cell
- Insert a column at the index of the cell
- Get the first cell from the inserted column
- Call
change_contentson the cell
Expected
- Contents are changed
Actual
RuntimeError: Cell #<RubyXL::Cell:0x000000010561b808> is not in worksheet
Minimal example
#!/usr/bin/env ruby
require 'rubyXL'
require 'rubyXL/convenience_methods'
worksheet = RubyXL::Workbook.new.worksheets[0]
cell = worksheet.add_cell(0, 0, 'test 1')
cell.change_font_bold(true)
added_cell = worksheet[0][0]
added_cell_ws = added_cell.instance_variable_get(:@worksheet)
worksheet.insert_column(0)
inserted_cell = worksheet[0][0]
inserted_cell_ws = inserted_cell.instance_variable_get(:@worksheet)
# Uncomment to see the underlying problem
# puts "original worksheet: #{worksheet || '<nil>'}"
# puts "added cell @worksheet: #{added_cell_ws || '<nil>'}"
# puts "inserted cell @worksheet: #{inserted_cell_ws || '<nil>'}"
added_cell.change_contents('test 2')
inserted_cell.change_contents('test 3')Raises:
/Users/david/.rvm/gems/ruby-3.1.2/gems/rubyXL-3.4.25/lib/rubyXL/cell.rb:24:in `validate_worksheet': Cell #<RubyXL::Cell:0x0000000106c01c30> is not in worksheet (RuntimeError)
from /Users/david/.rvm/gems/ruby-3.1.2/gems/rubyXL-3.4.25/lib/rubyXL/convenience_methods/cell.rb:4:in `change_contents'
from /tmp/rubyxl.rb:23:in `<main>'
Metadata
Metadata
Assignees
Labels
No labels