Skip to content

All numbers are read as Float #100

Description

@amhofny

When reading an excel file that is exported from other libraries, for example caxlsx https://github.com/caxlsx/caxlsx
The library generates Excel with floats and integers represented with t="n", for example from the "sheet1.xml"

<c r="Z2" s="0" t="n"><v>1.0</v></c>
<c r="G2" s="0" t="n"><v>114</v></c>

Both of these numbers are read by Creek as: 1.0 , 114.0, which is causing problems when the system expects to see an integer value instead of float, for example when using that number to load Models from the Database

I have found in this line https://github.com/pythonicrubyist/creek/blob/master/lib/creek/styles/converter.rb#L47
That Creek always read the value as float.

My suggestion is to replace

value.to_f

with

if value.to_i.to_s == value.to_s
     value.to_i
 else
     value.to_f
 end

I don't know if this is the right solution or not, but by applying this as a patch in the system solved our problem.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions