Class: Axlsx::SharedStringsTable
- Inherits:
-
Object
- Object
- Axlsx::SharedStringsTable
- Defined in:
- lib/axlsx/workbook/shared_strings_table.rb
Overview
Serialization performance is affected by using this serialization method so if you do not need interoperability
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. 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. it is recommended that you use the default inline string method of serialization.
Instance Attribute Summary collapse
-
#count ⇒ Integer
readonly
The total number of strings in the workbook including duplicates Empty cells are treated as blank strings.
-
#unique_cells ⇒ Object
readonly
An array of unique cells.
-
#xml_space ⇒ Object
readonly
The xml:space attribute.
Instance Method Summary collapse
-
#initialize(cells, xml_space = :preserve) ⇒ SharedStringsTable
constructor
Creates a new Shared Strings Table against an array of cells.
-
#to_xml_string(str = +'')) ⇒ String
Serializes the object.
-
#unique_count ⇒ Integer
The total number of unique strings in the workbook.
Constructor Details
#initialize(cells, xml_space = :preserve) ⇒ SharedStringsTable
Creates a new Shared Strings Table against an array of cells
35 36 37 38 39 40 41 42 43 |
# File 'lib/axlsx/workbook/shared_strings_table.rb', line 35 def initialize(cells, xml_space = :preserve) @index = 0 @xml_space = xml_space @unique_cells = {} @shared_xml_string = +'' shareable_cells = cells.flatten.select { |cell| cell.plain_string? || cell.contains_rich_text? } @count = shareable_cells.size resolve(shareable_cells) end |
Instance Attribute Details
#count ⇒ Integer (readonly)
The total number of strings in the workbook including duplicates Empty cells are treated as blank strings
15 16 17 |
# File 'lib/axlsx/workbook/shared_strings_table.rb', line 15 def count @count end |
#unique_cells ⇒ Object (readonly)
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.
26 27 28 |
# File 'lib/axlsx/workbook/shared_strings_table.rb', line 26 def unique_cells @unique_cells end |
#xml_space ⇒ Object (readonly)
The xml:space attribute
30 31 32 |
# File 'lib/axlsx/workbook/shared_strings_table.rb', line 30 def xml_space @xml_space end |
Instance Method Details
#to_xml_string(str = +'')) ⇒ String
Serializes the object
48 49 50 51 52 53 |
# File 'lib/axlsx/workbook/shared_strings_table.rb', line 48 def to_xml_string(str = +'') Axlsx.sanitize(@shared_xml_string) str << '<?xml version="1.0" encoding="UTF-8"?><sst xmlns="' << XML_NS << '"' str << ' count="' << @count.to_s << '" uniqueCount="' << unique_count.to_s << '"' str << ' xml:space="' << xml_space.to_s << '">' << @shared_xml_string << '</sst>' end |
#unique_count ⇒ Integer
The total number of unique strings in the workbook.
19 20 21 |
# File 'lib/axlsx/workbook/shared_strings_table.rb', line 19 def unique_count @unique_cells.size end |