Class: OpenXml::Xlsx::Parts::SharedStrings

Inherits:
Part
  • Object
show all
Defined in:
lib/openxml/xlsx/parts/shared_strings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSharedStrings

Returns a new instance of SharedStrings.



7
8
9
# File 'lib/openxml/xlsx/parts/shared_strings.rb', line 7

def initialize
  @strings = Hash.new { |hash, key| hash[key] = hash.length }
end

Instance Attribute Details

#stringsObject (readonly)

Returns the value of attribute strings.



5
6
7
# File 'lib/openxml/xlsx/parts/shared_strings.rb', line 5

def strings
  @strings
end

Instance Method Details

#reference_of(string) ⇒ Object



11
12
13
# File 'lib/openxml/xlsx/parts/shared_strings.rb', line 11

def reference_of(string)
  strings[string]
end

#to_xmlObject



15
16
17
18
19
20
21
22
23
# File 'lib/openxml/xlsx/parts/shared_strings.rb', line 15

def to_xml
  build_standalone_xml do |xml|
    xml.sst(xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main", uniqueCount: strings.length) do
      strings.each do |string, i|
        xml.si { xml.t(string) }
      end
    end
  end
end