simple_xlsx_reader icon indicating copy to clipboard operation
simple_xlsx_reader copied to clipboard

need skip type casting

Open seapy opened this issue 10 years ago • 2 comments

some cell is needed original string.

in my case cell data is floating number(currency style), type is nil, but style is fixnum. this case cell data is casting to integer.

optional skip type casting(not shared string) will be useful another case. how do you think about this?

seapy avatar Apr 09 '14 11:04 seapy

Conceptualizing excel formatting without examples hurts my brain, could you include an example spreadsheet or a screenshot?

Skipping type casting is interesting. Currently, type casting is a static method since it's a functionally pure problem (same inputs always equal the same outputs), and I could change it to be configurable so you could supply your own typecasting method? Then you could implement yours as a no-op, or call to the default type caster and do post-processing, etc.

woahdae avatar May 22 '14 22:05 woahdae

Sorry can't regenerate problem. here is some screenshot. this screenshot case data cast to String, but sometimes cast number. i think it's depends on cell style. workbook1

Maybe skipping type cast like this

module SimpleXlsxReader
  class Document
    class Mapper
      def self.cast(value, type, style, options = {})
        return nil if value.nil? || value.empty?

        case type
        when 's' # shared string
          options[:shared_strings][value.to_i]
        else
          value
        end
      end
    end
  end
end

seapy avatar May 23 '14 05:05 seapy