1

I am using roo to parse out an excel sheet like this

worksheet.parse(
        :partNo => "PM_PartNo",
        :salePartNo => "PM_SalesPartNo",
        :appSearchInclude => "PM_AppSearchInclude",
        :desc => "PM_WebApp_Description",
        :brand => "PM_Brand",
        :appSegment => "PM_ApplicationSegment",
        :group => "PM_ProductGroup",
        :design => "PM_ProductDesign",
        :material => "PM_Material",
        :line => "PM_ProdLine",
        :baseSeries => "PM_BaseSeries",
        :colorCode => "PM_ColorCode",
        :series => "PM_Series",
        :weightType => "PM_oz_gram",
        :appRim => "PM_ApplicationRim",
        :coating => "PM_Coating",
        :pcs => "PM_PCSconversion",
        :clean => true
    )  do |hash|

However, Roo keeps giving me a number 200275577.0 for the PM_PartNo column. In the excel sheet, this column has all cells formatted as text. What is should return in the parse is "200275577" as text, not 200275577.0 as a number. Is there a way to ensure it adheres to the excel formatting?

skaffman
  • 398,947
  • 96
  • 818
  • 769
steventnorris
  • 5,656
  • 23
  • 93
  • 174

1 Answers1

0

This is an open issue with roo. There is a general workaround contributed by a user in the issue, or you can just convert the value yourself with .to_i.to_s.

infused
  • 24,000
  • 13
  • 68
  • 78
  • 1
    I imagine there will be issues with leading 0s. 0000505 would be 505.0 which .to_i.to_s would convert to 505. Untested, but worth a caution. – steventnorris Oct 21 '14 at 19:33
  • https://github.com/Empact/roo/issues/86 For reference. The issue seems to be with the Spreedsheet GEM as well, a requirement of Roo. – steventnorris Oct 21 '14 at 19:34
  • Very true, you may need to use `rjust` to preserve leading zeros – infused Oct 21 '14 at 19:34
  • searching on the docs, there doesn't seem to be an option to specify that you want to get the values in `text`, as they appear in the cells. Is there an `option` to do this with [`Roo::Excelx#parse`](https://www.rubydoc.info/gems/roo/2.8.3/Roo/Base#parse-instance_method)? or you still need `to_s` the values of each row? – rellampec Jul 08 '21 at 00:20