summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/shared_strings_table.rb
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-03-27 09:08:06 +0900
committerRandy Morgan <[email protected]>2012-03-27 09:08:06 +0900
commit1bbcba13c7f65e725a79cc4b42f258ebe21ca8fa (patch)
tree76d8d94c4e6a6b22c1d8c82f5b698e3e1360d6ea /lib/axlsx/workbook/shared_strings_table.rb
parente64772f7552a4548b5ebb4f42b3fcaa5f4fd1e17 (diff)
downloadcaxlsx-1bbcba13c7f65e725a79cc4b42f258ebe21ca8fa.tar.gz
caxlsx-1bbcba13c7f65e725a79cc4b42f258ebe21ca8fa.zip
Some small improvements
total real axlsx_noautowidth 1.650000 ( 1.684738) axlsx 4.470000 ( 4.580439) axlsx_shared 7.990000 ( 8.151813) axlsx_stream 4.420000 ( 4.435809) csv 0.250000 ( 0.259114)
Diffstat (limited to 'lib/axlsx/workbook/shared_strings_table.rb')
-rw-r--r--lib/axlsx/workbook/shared_strings_table.rb18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/axlsx/workbook/shared_strings_table.rb b/lib/axlsx/workbook/shared_strings_table.rb
index 91892c38..2fffdd6b 100644
--- a/lib/axlsx/workbook/shared_strings_table.rb
+++ b/lib/axlsx/workbook/shared_strings_table.rb
@@ -3,7 +3,7 @@ module Axlsx
# The Shared String Table class is responsible for managing and serializing common strings in a workbook.
# While the ECMA-376 spec allows for both inline and shared strings it seems that at least some applications like iWorks Numbers
- # and Google Docs require that the shared string table is populated in order to interoperate properly.
+ # and Google Docs require that the shared string table is populated in order to interoperate properly.
# As a developer, you should never need to directly work against this class. Simply set 'use_shared_strings'
# on the package or workbook to generate a package that uses the shared strings table instead of inline strings.
# @note Serialization performance is affected by using this serialization method so if you do not need interoperability
@@ -15,14 +15,14 @@ module Axlsx
# @return [Integer]
attr_reader :count
- # The total number of unique strings in the workbook.
+ # The total number of unique strings in the workbook.
# @return [Integer]
def unique_count
@unique_cells.size
end
# An array of unique cells. Multiple attributes of the cell are used in comparison
- # each of these unique cells is parsed into the shared string table.
+ # each of these unique cells is parsed into the shared string table.
# @see Cell#sharable
attr_reader :unique_cells
@@ -35,10 +35,14 @@ module Axlsx
resolve(cells)
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]
+ end
# Generate the xml document for the Shared Strings Table
# @return [String]
def to_xml
+
builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
xml.sst(:xmlns => Axlsx::XML_NS, :count => count, :uniqueCount => unique_count) {
@unique_cells.each do |cell|
@@ -50,9 +54,9 @@ module Axlsx
end
private
-
- # Interate over all of the cells in the array.
- # if our unique cells array does not contain a sharable cell,
+
+ # Interate over all of the cells in the array.
+ # if our unique cells array does not contain a sharable cell,
# add the cell to our unique cells array and set the ssti attribute on the index of this cell in the shared strings table
# if a sharable cell already exists in our unique_cells array, set the ssti attribute of the cell and move on.
# @return [Array] unique cells
@@ -66,6 +70,6 @@ module Axlsx
cell.send :ssti=, index
end
end
- end
+ end
end
end