Class: RubyXL::Writer::WorkbookRelsWriter
- Inherits:
-
Object
- Object
- RubyXL::Writer::WorkbookRelsWriter
- Defined in:
- lib/rubyXL/writer/workbook_rels_writer.rb
Instance Attribute Summary collapse
-
#dirpath ⇒ Object
Returns the value of attribute dirpath.
-
#filepath ⇒ Object
Returns the value of attribute filepath.
-
#workbook ⇒ Object
Returns the value of attribute workbook.
Instance Method Summary collapse
-
#initialize(dirpath, wb) ⇒ WorkbookRelsWriter
constructor
A new instance of WorkbookRelsWriter.
-
#write ⇒ Object
all attributes out of order.
Constructor Details
#initialize(dirpath, wb) ⇒ WorkbookRelsWriter
Returns a new instance of WorkbookRelsWriter.
13 14 15 16 |
# File 'lib/rubyXL/writer/workbook_rels_writer.rb', line 13 def initialize(dirpath, wb) @dirpath = dirpath @workbook = wb end |
Instance Attribute Details
#dirpath ⇒ Object
Returns the value of attribute dirpath.
11 12 13 |
# File 'lib/rubyXL/writer/workbook_rels_writer.rb', line 11 def dirpath @dirpath end |
#filepath ⇒ Object
Returns the value of attribute filepath.
11 12 13 |
# File 'lib/rubyXL/writer/workbook_rels_writer.rb', line 11 def filepath @filepath end |
#workbook ⇒ Object
Returns the value of attribute workbook.
11 12 13 |
# File 'lib/rubyXL/writer/workbook_rels_writer.rb', line 11 def workbook @workbook end |
Instance Method Details
#write ⇒ Object
all attributes out of order
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rubyXL/writer/workbook_rels_writer.rb', line 19 def write() builder = Nokogiri::XML::Builder.new do |xml| xml.Relationships('xmlns'=>'http://schemas.openxmlformats.org/package/2006/relationships') { i = 1 @workbook.worksheets.each do |sheet| xml.Relationship('Id'=>'rId'+i.to_s, 'Type'=>"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet", 'Target'=>'worksheets/sheet'+i.to_s+'.xml') i += 1 end unless @workbook.external_links.nil? 1.upto(@workbook.external_links.size-1) do |link| xml.Relationship('Id'=>'rId'+i.to_s, 'Type'=>"http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLink", 'Target'=>"externalLinks/externalLink#{link}.xml" ) i+=1 end end xml.Relationship('Id'=>'rId'+i.to_s, 'Type'=>"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme", 'Target'=>'theme/theme1.xml') i += 1 xml.Relationship('Id'=>'rId'+i.to_s, 'Type'=>"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", 'Target'=>'styles.xml') i+=1 xml.Relationship('Id'=>'rId'+i.to_s, 'Type'=>"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings", 'Target'=>'sharedStrings.xml') } 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 end |