lib/rspreadsheet/cell.rb in rspreadsheet-0.2.11 vs lib/rspreadsheet/cell.rb in rspreadsheet-0.2.12

- old
+ new

@@ -3,13 +3,13 @@ # @title rspreadsheet Cell require 'andand' require 'rspreadsheet/xml_tied' require 'date' +require 'bigdecimal' +require 'bigdecimal/util' # for to_d method - - module Rspreadsheet ### # Represents a cell in spreadsheet which has coordinates, contains value, formula and can be formated. # You can get this object like this (suppose that @worksheet contains {Rspreadsheet::Worksheet} object) @@ -58,10 +58,11 @@ when gt == nil then nil when gt == Float then xmlnode.attributes['value'].to_f when gt == String then xmlnode.elements.first.andand.content.to_s when gt == Date then Date.strptime(xmlnode.attributes['date-value'].to_s, '%Y-%m-%d') when gt == :percentage then xmlnode.attributes['value'].to_f + when gt == :currency then xmlnode.attributes['value'].to_d end elsif self.mode == :outbound nil else raise "Unknown cell mode #{self.mode}" @@ -119,10 +120,11 @@ when gct == Float then :float when gct == String then :string when gct == Date then :date when gct == :percentage then :percentage when gct == :unassigned then :unassigned + when gct == :currency then :currency when gct == NilClass then :empty when gct == nil then :unknown else :unknown end end @@ -144,10 +146,11 @@ when 'float' then Float when 'string' then String when 'date' then Date when 'percentage' then :percentage when 'N/A' then :unassigned + when 'currency' then :currency else if xmlnode.children.size == 0 nil else raise "Unknown type at #{coordinates.to_s} from #{xmlnode.to_s} / children size=#{xmlnode.children.size.to_s} / type=#{xmlnode.attributes['value-type'].to_s}" @@ -291,9 +294,12 @@ def text_style_node; style_node_with_partial_xpath("/style:style[@style:name=\"#{style_name}\"]/style:text-properties") end def cell_style_node; style_node_with_partial_xpath("/style:style[@style:name=\"#{style_name}\"]/style:table-cell-properties") end def style_node_with_partial_xpath(xpath) return nil if cellnode.nil? cellnode.doc.root.find("./office:automatic-styles#{xpath}").first + end + def currency + Tools.get_ns_attribute_value(cellnode,'office','currency',nil) end end end