diff options
| author | Randy Morgan <[email protected]> | 2012-03-27 16:38:27 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-03-27 16:38:27 +0900 |
| commit | a419b44526678ee1cffdcd6faddc0a6fa0473899 (patch) | |
| tree | 024047b4c2e65377fe1f2c295da15b1a6120de22 /lib | |
| parent | b77c02fce0ac336d1de6c63d2d7da783f9597d76 (diff) | |
| download | caxlsx-a419b44526678ee1cffdcd6faddc0a6fa0473899.tar.gz caxlsx-a419b44526678ee1cffdcd6faddc0a6fa0473899.zip | |
FAST ENOUGH?
user system total real
axlsx_noautowidth 1.560000 0.030000 1.590000 ( 1.717595)
axlsx 4.360000 0.140000 4.500000 ( 5.748329)
axlsx_shared 6.880000 0.160000 7.040000 ( 9.325648)
axlsx_stream 4.320000 0.120000 4.440000 ( 5.642124)
csv 0.240000 0.010000 0.250000 ( 0.301004)
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/workbook/shared_strings_table.rb | 9 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 23 |
2 files changed, 15 insertions, 17 deletions
diff --git a/lib/axlsx/workbook/shared_strings_table.rb b/lib/axlsx/workbook/shared_strings_table.rb index 2fffdd6b..5ebfd87f 100644 --- a/lib/axlsx/workbook/shared_strings_table.rb +++ b/lib/axlsx/workbook/shared_strings_table.rb @@ -36,7 +36,7 @@ module Axlsx end def to_xml_string - str = "<sst xmlns=\"%s\" count='%s' uniqueCount='%s'>%s</sst>" % [XML_NS, count, unique_count, @unique_cells.map {|cell| cell.run_xml_string}.join] + str = "<sst xmlns=\"%s\" count='%s' uniqueCount='%s'>%s</sst>" % [XML_NS, count, unique_count, @unique_cells.map {|cell| cell[:data]}.join] end # Generate the xml document for the Shared Strings Table @@ -62,10 +62,13 @@ module Axlsx # @return [Array] unique cells def resolve(cells) cells.each do |cell| - index = @unique_cells.index { |item| item.shareable(cell) } + cell_hash = cell.shareable_hash + index = @unique_cells.index do |item| + item[:hash] == cell_hash + end if index == nil cell.send :ssti=, @unique_cells.size - @unique_cells << cell + @unique_cells << {:hash => cell_hash, :data => '<si>'<< cell.run_xml_string << '</si>'} else cell.send :ssti=, index end diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 59ce0838..a3ec046a 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -224,16 +224,10 @@ module Axlsx # equality comparison to test value, type and inline style attributes # this is how we work out if the cell needs to be added or already exists in the shared strings table - def shareable(v) - - #using reject becase 1.8.7 select returns an array... - v_hash = v.instance_values.reject { |key, val| !INLINE_STYLES.include?(key) } + def shareable_hash self_hash = self.instance_values.reject { |key, val| !INLINE_STYLES.include?(key) } - # required as color is an object, and the comparison will fail even though both use the same color. - v_hash['color'] = v_hash['color'].instance_values if v_hash['color'] self_hash['color'] = self_hash['color'].instance_values if self_hash['color'] - - v_hash == self_hash + self_hash end # @return [Integer] The index of the cell in the containing row. @@ -284,7 +278,8 @@ module Axlsx def run_xml_string str = "" if is_text_run? - keys = self.instance_values.reject{|key, value| value == nil }.keys & INLINE_STYLES + data = self.instance_values.reject{|key, value| value == nil } + keys = data.keys & INLINE_STYLES keys.delete ['value', 'type'] str << "<r><rPr>" keys.each do |key| @@ -292,9 +287,9 @@ module Axlsx when 'font_name' str << "<rFont val='"<< @font_name << "'/>" when 'color' - str << self.instance_values[key].to_xml_string + str << data[key].to_xml_string else - "<" << key << "val='" << self.instance_values[key] << "'/>" + "<" << key.to_s << " val='" << data[key].to_s << "'/>" end end str << "</rPr>" << "<t>" << value.to_s << "</t></r>" @@ -354,11 +349,11 @@ module Axlsx end when :date # TODO: See if this is subject to the same restriction as Time below - '<c r="' << r << '" s="' << @style.to_s << '"><v>' << DateTimeConverter::date_to_serial(@value) << '</v></c>' + '<c r="' << r << '" s="' << @style.to_s << '"><v>' << DateTimeConverter::date_to_serial(@value).to_s << '</v></c>' when :time - '<c r="' << r << '" s="' << @style.to_s << '"><v>' << DateTimeConverter::time_to_serial(@value) << '</v></c>' + '<c r="' << r << '" s="' << @style.to_s << '"><v>' << DateTimeConverter::time_to_serial(@value).to_s << '</v></c>' when :boolean - '<c r="' << r << '" t="b" s="' << @style.to_s << '"><v>' << ssti << '</v></c>' + '<c r="' << r << '" t="b" s="' << @style.to_s << '"><v>' << @value.to_s << '</v></c>' else '<c r="' << r << '" s="' << @style.to_s << '"><v>' << @value.to_s << '</v></c>' end |
