pythonicrubyist / creek

Ruby library for parsing large Excel files.
http://rubygems.org/gems/creek
MIT License
386 stars 109 forks source link

Creek not able to handle custom formatted Cell. Parsing it as a datetime #94

Closed ankitsharma301093 closed 3 years ago

ankitsharma301093 commented 4 years ago

I am parsing an excel spreadsheet with a cell that is custom formatted. The value is actually 25 but the format to display it is 'JPY25'. Creek gets the number but the number is converted to a DateTime after passing through the convert function.

This is the node.attributes hash: {"r"=>"M2", "s"=>"8"}

When the convert function(Ref below) is called from inside the rows_generator function, node.value is 25 for a cell formatted as 'JPY25' but because of the node.attributes['s'], the type(which is nil - determined by node.attributes['t']) is determined by style(which is DateTime) and a DateTime value is generated after Creek::Styles::Converter.call is called.

def convert(value, type, style_idx)
      style = @book.style_types[style_idx.to_i]
      Creek::Styles::Converter.call(value, type, style, converter_options)
end

Can we have the ability to pass an optional hash in instance method simple_rows of Creek::Sheet class? This way, we can define what type (:float, :string, :date, :bignum etc) we want for a particular column. Maybe a hash like below:

type_hash = {"A" => :float, "B" => :string}

Please let me know if this approach is correct or if there is a more valid solution.

P.S. Please don't mind the explanation part. Doing it for the first time.