Class: RubyXL::Writer::AppWriter
- Inherits:
-
Object
- Object
- RubyXL::Writer::AppWriter
- Defined in:
- lib/rubyXL/writer/app_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) ⇒ AppWriter
constructor
A new instance of AppWriter.
- #write ⇒ Object
Constructor Details
#initialize(dirpath, wb) ⇒ AppWriter
Returns a new instance of AppWriter.
13 14 15 16 17 |
# File 'lib/rubyXL/writer/app_writer.rb', line 13 def initialize(dirpath, wb) @dirpath = dirpath @filepath = dirpath+'/docProps/app.xml' @workbook = wb end |
Instance Attribute Details
#dirpath ⇒ Object
Returns the value of attribute dirpath.
11 12 13 |
# File 'lib/rubyXL/writer/app_writer.rb', line 11 def dirpath @dirpath end |
#filepath ⇒ Object
Returns the value of attribute filepath.
11 12 13 |
# File 'lib/rubyXL/writer/app_writer.rb', line 11 def filepath @filepath end |
#workbook ⇒ Object
Returns the value of attribute workbook.
11 12 13 |
# File 'lib/rubyXL/writer/app_writer.rb', line 11 def workbook @workbook end |
Instance Method Details
#write ⇒ Object
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 57 58 59 |
# File 'lib/rubyXL/writer/app_writer.rb', line 19 def write() builder = Nokogiri::XML::Builder.new do |xml| xml.Properties('xmlns' => 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties', 'xmlns:vt'=>'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes') { xml.Application @workbook.application xml.DocSecurity '0' xml.ScaleCrop 'false' xml.HeadingPairs { xml['vt'].vector(:size => '2', :baseType => 'variant') { xml['vt'].variant { xml['vt'].lpstr 'Worksheets' } xml['vt'].variant { xml['vt'].i4 @workbook.worksheets.size.to_s() } } } xml.TitlesOfParts { xml['vt'].vector(:size=>@workbook.worksheets.size.to_s(), :baseType=>"lpstr") { @workbook.worksheets.each do |sheet| xml['vt'].lpstr sheet.sheet_name end } } xml.Company @workbook.company xml.LinksUpToDate 'false' xml.SharedDoc 'false' xml.HyperlinksChanged 'false' xml.AppVersion @workbook.appversion } end contents = builder.to_xml if(contents =~ /xmlns:vt=\"(.*)\" xmlns=\"(.*)\"/) contents.sub(/xmlns:vt=\"(.*)\" xmlns=\"(.*)\"<A/,'xmlns="'+$2+'" xmlns:vt="'+$1+'"<A') end 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 |