summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-03-27 16:38:27 +0900
committerRandy Morgan <[email protected]>2012-03-27 16:38:27 +0900
commita419b44526678ee1cffdcd6faddc0a6fa0473899 (patch)
tree024047b4c2e65377fe1f2c295da15b1a6120de22
parentb77c02fce0ac336d1de6c63d2d7da783f9597d76 (diff)
downloadcaxlsx-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)
-rw-r--r--lib/axlsx/workbook/shared_strings_table.rb9
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb23
-rw-r--r--test/workbook/tc_shared_strings_table.rb2
-rw-r--r--test/workbook/worksheet/tc_cell.rb9
4 files changed, 21 insertions, 22 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
diff --git a/test/workbook/tc_shared_strings_table.rb b/test/workbook/tc_shared_strings_table.rb
index 259f5970..e3c9bf7b 100644
--- a/test/workbook/tc_shared_strings_table.rb
+++ b/test/workbook/tc_shared_strings_table.rb
@@ -26,7 +26,7 @@ class TestSharedStringsTable < Test::Unit::TestCase
def test_valid_document
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
- doc = Nokogiri::XML(@p.workbook.shared_strings.to_xml)
+ doc = Nokogiri::XML(@p.workbook.shared_strings.to_xml_string)
errors = []
schema.validate(doc).each do |error|
puts error.message
diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb
index a5b0442f..991181e7 100644
--- a/test/workbook/worksheet/tc_cell.rb
+++ b/test/workbook/worksheet/tc_cell.rb
@@ -206,13 +206,14 @@ class TestCell < Test::Unit::TestCase
end
def test_equality
- c2 = @row.add_cell 1, :type=>:float, :style=>1
- assert(c2.shareable(@c))
+ c2 = @row.add_cell 1, :type=>:float, :style=>1
+
+ assert_equal(c2.shareable_hash,@c.shareable_hash)
c3 = @row.add_cell 2, :type=>:float, :style=>1
c4 = @row.add_cell 1, :type=>:float, :style=>1, :color => "#FFFFFFFF"
- assert_equal(c4.shareable(c2) ,false)
+ assert_equal(c4.shareable_hash == c2.shareable_hash,false)
c5 = @row.add_cell 1, :type=>:float, :style=>1, :color => "#FFFFFFFF"
- assert(c5.shareable(c4))
+ assert_equal(c5.shareable_hash, c4.shareable_hash)
end