roo-rb / roo

Roo provides an interface to spreadsheets of several sorts.
MIT License
2.8k stars 501 forks source link

Reading of xlsx fails if any datetime-cell is also linked #597

Open BartekOchab opened 1 year ago

BartekOchab commented 1 year ago

Issue

Following the full stack trace of one of my tests (sorry not suitable for here :( )

Failures:

  1) Interpreter::ConvertedPdf I variation with date times with links returns a hash with the required table entries
     Failure/Error: @start_row = sheet.first_row

     TypeError:
       no implicit conversion of Float into String
     Shared Example Group: "parser sanity check" called from ./spec/models/interpreter/converted_pdf_spec.rb:857
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/link.rb:26:in `initialize'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/link.rb:26:in `initialize'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx/cell/datetime.rb:18:in `new'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx/cell/datetime.rb:18:in `initialize'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx/cell/time.rb:13:in `initialize'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx/sheet_doc.rb:168:in `new'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx/sheet_doc.rb:168:in `create_cell_from_value'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx/sheet_doc.rb:114:in `block in cell_from_xml'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/nokogiri-1.15.4-arm64-darwin/lib/nokogiri/xml/node_set.rb:235:in `block in each'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/nokogiri-1.15.4-arm64-darwin/lib/nokogiri/xml/node_set.rb:234:in `upto'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/nokogiri-1.15.4-arm64-darwin/lib/nokogiri/xml/node_set.rb:234:in `each'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx/sheet_doc.rb:101:in `cell_from_xml'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx/sheet_doc.rb:224:in `block (2 levels) in extract_cells'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/nokogiri-1.15.4-arm64-darwin/lib/nokogiri/xml/node_set.rb:235:in `block in each'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/nokogiri-1.15.4-arm64-darwin/lib/nokogiri/xml/node_set.rb:234:in `upto'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/nokogiri-1.15.4-arm64-darwin/lib/nokogiri/xml/node_set.rb:234:in `each'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx/sheet_doc.rb:215:in `with_index'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx/sheet_doc.rb:215:in `block in extract_cells'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/nokogiri-1.15.4-arm64-darwin/lib/nokogiri/xml/node_set.rb:235:in `block in each'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/nokogiri-1.15.4-arm64-darwin/lib/nokogiri/xml/node_set.rb:234:in `upto'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/nokogiri-1.15.4-arm64-darwin/lib/nokogiri/xml/node_set.rb:234:in `each'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx/sheet_doc.rb:214:in `with_index'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx/sheet_doc.rb:214:in `extract_cells'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx/sheet_doc.rb:20:in `cells'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx/sheet.rb:22:in `cells'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx/sheet.rb:126:in `first_last_row_col'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx/sheet.rb:65:in `first_row'
     # /Users/bartek/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/roo-2.10.0/lib/roo/excelx.rb:134:in `first_row'
     # ./app/models/interpreter/converted_pdf.rb:176:in `block in parse'
     # ./app/models/interpreter/converted_pdf.rb:174:in `each'
     # ./app/models/interpreter/converted_pdf.rb:174:in `parse'

offending(cause?) code from lib/roo/excelx/cell/datetime.rb

@value = link ? Roo::Link.new(link, value) : create_datetime(base_timestamp, value)

from here

The value here is a Float and not String. Either fixing it there or converting the text of Links always to string before forwarding it to the super constructor would help.

    def initialize(href = '', text = href)
      super(text)
      @href = href
    end

from here

System configuration

Roo version: 2.8.7; 2.10. Ruby version: 3.1.0