Class: RubyXL::Writer::ContentTypesWriter
- Inherits:
-
GenericWriter
- Object
- GenericWriter
- RubyXL::Writer::ContentTypesWriter
- Defined in:
- lib/rubyXL/writer/content_types_writer.rb
Instance Method Summary collapse
Methods inherited from GenericWriter
#add_to_zip, #initialize, #ooxml_object, #render_xml
Constructor Details
This class inherits a constructor from RubyXL::Writer::GenericWriter
Instance Method Details
#filepath ⇒ Object
5 6 7 |
# File 'lib/rubyXL/writer/content_types_writer.rb', line 5 def filepath '[Content_Types].xml' end |
#write ⇒ Object
9 10 11 12 13 14 15 16 17 18 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rubyXL/writer/content_types_writer.rb', line 9 def write() render_xml do |xml| xml << (xml.create_element('Types', :xmlns => 'http://schemas.openxmlformats.org/package/2006/content-types') { |root| unless @workbook.printer_settings.empty? root << xml.create_element('Default', { :Extension => 'bin', :ContentType => 'application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings' }) end root << xml.create_element('Default', { :Extension => 'rels', :ContentType => 'application/vnd.openxmlformats-package.relationships+xml' }) root << xml.create_element('Default', { :Extension => 'xml', :ContentType => 'application/xml' }) root << xml.create_element('Default', { :Extension => 'jpeg', :ContentType => 'image/jpeg' }) # if @workbook.macros.nil? && @workbook.drawings.empty? root << xml.create_element('Override', { :PartName => '/xl/workbook.xml', :ContentType => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml' }) # else # xml.Override('PartName'=>'/xl/workbook.xml', # 'ContentType'=>"application/vnd.ms-excel.sheet.macroEnabled.main+xml") # end @workbook.worksheets.each_with_index { |sheet,i| root << xml.create_element('Override', { :PartName => "/xl/worksheets/sheet#{i+1}.xml", :ContentType => 'application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml' }) } root << xml.create_element('Override', { :PartName => '/xl/theme/theme1.xml', :ContentType => 'application/vnd.openxmlformats-officedocument.theme+xml' }) root << xml.create_element('Override', { :PartName => '/xl/styles.xml', :ContentType => 'application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml' }) unless @workbook.shared_strings_container.empty? root << xml.create_element('Override', { :PartName => '/xl/sharedStrings.xml', :ContentType => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml' }) end @workbook.drawings.each_pair { |k, v| root << xml.create_element('Override', { :PartName => "/#{@workbook.drawings.local_dir_path}/#{k}", :ContentType => 'application/vnd.openxmlformats-officedocument.drawing+xml' }) # xml.Default('Extension'=>'vml', # 'ContentType'=>'application/vnd.openxmlformats-officedocument.vmlDrawing') } @workbook.charts.each_pair { |k, v| case k when /^chart\d*.xml$/ then root << xml.create_element('Override', { :PartName => "/#{@workbook.charts.local_dir_path}/#{k}", :ContentType => 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml' }) when /^style\d*.xml$/ then root << xml.create_element('Override', { :PartName => "/#{@workbook.charts.local_dir_path}/#{k}", :ContentType => 'application/vnd.ms-office.chartstyle+xml' }) when /^colors\d*.xml$/ then root << xml.create_element('Override', { :PartName => "/#{@workbook.charts.local_dir_path}/#{k}", :ContentType => 'application/vnd.ms-office.chartcolorstyle+xml' }) end } root << xml.create_element('Override', { :PartName => '/docProps/core.xml', :ContentType => 'application/vnd.openxmlformats-package.core-properties+xml' }) root << xml.create_element('Override', { :PartName => '/docProps/app.xml', :ContentType => 'application/vnd.openxmlformats-officedocument.extended-properties+xml' }) unless @workbook.external_links.nil? 1.upto(@workbook.external_links.size-1) do |i| root << xml.create_element('Override', { :PartName => "/xl/externalLinks/externalLink#{i}.xml", :ContentType => 'application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml' }) end end unless @workbook.macros.nil? root << xml.create_element('Override', { :PartName => '/xl/vbaProject.bin', :ContentType => 'application/vnd.ms-office.vbaProject' }) end }) end end |