From 40ddfac7c8243a6eba18be2ddff9dfd34b1a460c Mon Sep 17 00:00:00 2001 From: Chris Gunther Date: Wed, 22 Sep 2021 15:50:03 -0400 Subject: [PATCH] Fix internal use of deprecated `Excelx::Cell.new` Calling `Excelx#set` internally called `Excelx::Cell.new`, which is deprecated in favor of `Excelx::Cell.create_cell`. I tried using the recommended `Excelx::Cell.create_cell`, however it expects a `type` as the first argument. `#set` tries to infer the type via [`cell_type_by_value`](https://github.com/roo-rb/roo/blob/709464c77623be2bc09b2103405d90ded7604a75/lib/roo/base.rb#L175-L182), however it only returns `:float` or `:string`, but `Excelx::Cell.cell_class` doesn't support `:float`. Even if I add `:float` to map to `Cell::Number`, then there's a dilemma because `Excelx::Cell.create_cell` passes all the arguments except the first onto the specific cell class, but the arity of `Cell::String` is 5 whereas the arity of `Cell::Number` is 6, meaning `Excelx#set` would need to initialize each cell class individually to pass the appropriate arguments. Therefore I landed on simply using `Cell::Base`. It's probably not the most accurate, but given persisting the spreadsheet isn't an option, the uses for `Excelx#set` should be minimal. In my case, I simply use it in testing to avoid creating new files for every possible scenario, opting to manually set various cells to triggered assorted scenarios. Fixes #529. --- lib/roo/excelx.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/roo/excelx.rb b/lib/roo/excelx.rb index 91ebc1e0..8ea89c9a 100755 --- a/lib/roo/excelx.rb +++ b/lib/roo/excelx.rb @@ -154,7 +154,7 @@ def last_column(sheet = nil) def set(row, col, value, sheet = nil) #:nodoc: key = normalize(row, col) cell_type = cell_type_by_value(value) - sheet_for(sheet).cells[key] = Cell.new(value, cell_type, nil, cell_type, value, nil, nil, nil, Coordinate.new(row, col)) + sheet_for(sheet).cells[key] = Cell::Base.new(value, nil, nil, nil, nil, Coordinate.new(row, col)) end # Returns the formula at (row,col).