rubyXL
rubyXL copied to clipboard
It doesn't clear the formula while setting a value in a cell with 'change_contents(value)' method
I was trying to change the value in a cell which has a formula. Ideally it should clear the formula and write the value, instead in some cases it's setting the value without clearing the cell.
Here's a sample snippet I used:
workbook = RubyXL::Parser.parse(xlsx_file_path)
worksheet = workbook.worksheets[0]
worksheet[1][1].change_contents(120)
While inspecting the cell after writing, it shows like this:
> puts worksheet[1][1].inspect
#<RubyXL::Cell(1,1): 120.0 =G98*(1+$E$98), datatype=nil, style_index=54>
Is this a known issue? Do we have a method to clear the cell and write the value? I tried deleting/inserting that specific cell, but that cleared the values in other cells in the same row (which had values computed with formula).
Thanks in advance.
Got same issue. I put workaround method for my project to prevent this issue.
module RubyXL
module CellConvenienceMethods
def change_value(data)
self.change_contents(data)
self.formula = nil
self.datatype = nil
workbook.calculation_chain.cells.select! { |c|
!(c.ref.col_range.begin == self.column && c.ref.row_range.begin == self.row)
}
end
end
end