Class: RubyXL::Writer::SharedStringsWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/writer/shared_strings_writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dirpath, wb) ⇒ SharedStringsWriter

Returns a new instance of SharedStringsWriter.



13
14
15
16
17
# File 'lib/writer/shared_strings_writer.rb', line 13

def initialize(dirpath,wb)
  @dirpath = dirpath
  @workbook = wb
  @filepath = dirpath + '/xl/sharedStrings.xml'
end

Instance Attribute Details

#dirpathObject

Returns the value of attribute dirpath.



11
12
13
# File 'lib/writer/shared_strings_writer.rb', line 11

def dirpath
  @dirpath
end

#filepathObject

Returns the value of attribute filepath.



11
12
13
# File 'lib/writer/shared_strings_writer.rb', line 11

def filepath
  @filepath
end

#workbookObject

Returns the value of attribute workbook.



11
12
13
# File 'lib/writer/shared_strings_writer.rb', line 11

def workbook
  @workbook
end

Instance Method Details

#writeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/writer/shared_strings_writer.rb', line 19

def write()
  # contents = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\n"

  # builder = Nokogiri::XML::Builder.new do |xml|
  #         xml.sst('xmlns'=>"http://schemas.openxmlformats.org/spreadsheetml/2006/main",
  #         'count'=>@workbook.numStrings,
  #         'uniqueCount'=>@workbook.size) {
  #           i = 0
  #           0.upto(@workbook.size-1).each do |i|
  #             xml.si {
  #               xml.t @workbook.sharedStrings[i].to_s
  #               xml.phoneticPr('fontId'=>'1', 'type'=>'noConversion')
  #             }
  #           end
  #         }
  #       end
  #       contents = builder.to_xml
  #       contents = contents.gsub(/\n/,'')
  #       contents = contents.gsub(/>(\s)+</,'><')
  #       contents = contents.sub(/<\?xml version=\"1.0\"\?>/,'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\n")
  contents = @workbook.shared_strings_XML
  contents
end