Class: Writexlsx::Package::ContentTypes

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/write_xlsx/package/content_types.rb

Constant Summary collapse

App_package =
'application/vnd.openxmlformats-package.'
App_document =
'application/vnd.openxmlformats-officedocument.'

Constants included from Utility

Utility::COL_MAX, Utility::ROW_MAX, Utility::SHEETNAME_MAX, Utility::STR_MAX

Instance Method Summary collapse

Methods included from Utility

#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #convert_date_time, #dash_types, delete_files, #fill_properties, #float_to_str, #layout_properties, #line_fill_properties, #line_properties, #palette_color, #pixels_to_points, #ptrue?, #put_deprecate_message, #r_id_attributes, #row_col_notation, #shape_style_base, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #v_shape_attributes_base, #v_shape_style_base, #value_or_raise, #write_anchor, #write_auto_fill, #write_color, #write_comment_path, #write_div, #write_fill, #write_font, #write_stroke, #write_xml_declaration, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str

Constructor Details

#initializeContentTypes

Returns a new instance of ContentTypes.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/write_xlsx/package/content_types.rb', line 14

def initialize
  @writer = Package::XMLWriterSimple.new
  @defaults  = [
    [ 'rels', "#{App_package}relationships+xml" ],
    [ 'xml', 'application/xml' ]
  ]
  @overrides = [
    [ '/docProps/app.xml',    "#{App_document}extended-properties+xml" ],
    [ '/docProps/core.xml',   "#{App_package}core-properties+xml" ],
    [ '/xl/styles.xml',       "#{App_document}spreadsheetml.styles+xml" ],
    [ '/xl/theme/theme1.xml', "#{App_document}theme+xml" ],
    [ '/xl/workbook.xml',     "#{App_document}spreadsheetml.sheet.main+xml" ]
  ]
end

Instance Method Details

#add_calc_chainObject

Add the calcChain link to the ContentTypes overrides.



117
118
119
# File 'lib/write_xlsx/package/content_types.rb', line 117

def add_calc_chain
  add_override('/xl/calcChain.xml', "#{App_document}spreadsheetml.calcChain+xml")
end

#add_chart_name(name) ⇒ Object

Add the name of a chart to the ContentTypes overrides.



76
77
78
79
80
# File 'lib/write_xlsx/package/content_types.rb', line 76

def add_chart_name(name)
  chart_name = "/xl/charts/#{name}.xml"

  add_override(chart_name, "#{App_document}drawingml.chart+xml")
end

#add_chartsheet_name(name) ⇒ Object

Add the name of a chartsheet to the ContentTypes overrides.



67
68
69
70
71
# File 'lib/write_xlsx/package/content_types.rb', line 67

def add_chartsheet_name(name)
  chartsheet_name = "/xl/chartsheets/#{name}.xml"

  add_override(chartsheet_name, "#{App_document}spreadsheetml.chartsheet+xml")
end

#add_comment_name(name) ⇒ Object

Add the name of a comment to the ContentTypes overrides.



101
102
103
104
105
# File 'lib/write_xlsx/package/content_types.rb', line 101

def add_comment_name(name)
  comment_name = "/xl/#{name}.xml"

  add_override( comment_name, "#{App_document}spreadsheetml.comments+xml")
end

#add_default(part_name, content_type) ⇒ Object

Add elements to the ContentTypes defaults.



44
45
46
# File 'lib/write_xlsx/package/content_types.rb', line 44

def add_default(part_name, content_type)
  @defaults.push([part_name, content_type])
end

#add_drawing_name(name) ⇒ Object

Add the name of a drawing to the ContentTypes overrides.



85
86
87
88
89
# File 'lib/write_xlsx/package/content_types.rb', line 85

def add_drawing_name(name)
  drawing_name = "/xl/drawings/#{name}.xml"

  add_override( drawing_name, "#{App_document}drawing+xml")
end

#add_image_types(types) ⇒ Object

Add the image default types.



124
125
126
# File 'lib/write_xlsx/package/content_types.rb', line 124

def add_image_types(types)
  types.each_key { |type| add_default(type, "image/#{type}") }
end

#add_override(part_name, content_type) ⇒ Object

Add elements to the ContentTypes overrides.



51
52
53
# File 'lib/write_xlsx/package/content_types.rb', line 51

def add_override(part_name, content_type)
  @overrides.push([part_name, content_type])
end

#add_shared_stringsObject

Add the sharedStrings link to the ContentTypes overrides.



110
111
112
# File 'lib/write_xlsx/package/content_types.rb', line 110

def add_shared_strings
  add_override('/xl/sharedStrings.xml', "#{App_document}spreadsheetml.sharedStrings+xml")
end

#add_table_name(table_name) ⇒ Object

Add the name of a table to the ContentTypes overrides.



131
132
133
134
135
136
# File 'lib/write_xlsx/package/content_types.rb', line 131

def add_table_name(table_name)
  add_override(
               "/xl/tables/#{table_name}.xml",
               "#{App_document}spreadsheetml.table+xml"
               )
end

#add_vba_projectObject

Add a vbaProject to the ContentTypes defaults.



141
142
143
144
# File 'lib/write_xlsx/package/content_types.rb', line 141

def add_vba_project
  change_the_workbook_xml_content_type_from_xlsx_to_xlsm
  add_default('bin', 'application/vnd.ms-office.vbaProject')
end

#add_vml_nameObject

Add the name of a VML drawing to the ContentTypes defaults.



94
95
96
# File 'lib/write_xlsx/package/content_types.rb', line 94

def add_vml_name
  add_default('vml', "#{App_document}vmlDrawing")
end

#add_worksheet_name(name) ⇒ Object

Add the name of a worksheet to the ContentTypes overrides.



58
59
60
61
62
# File 'lib/write_xlsx/package/content_types.rb', line 58

def add_worksheet_name(name)
  worksheet_name = "/xl/worksheets/#{name}.xml"

  add_override(worksheet_name, "#{App_document}spreadsheetml.worksheet+xml")
end

#assemble_xml_fileObject



33
34
35
36
37
38
39
40
# File 'lib/write_xlsx/package/content_types.rb', line 33

def assemble_xml_file
  write_xml_declaration do
    write_types do
      write_defaults
      write_overrides
    end
  end
end

#set_xml_writer(filename) ⇒ Object



29
30
31
# File 'lib/write_xlsx/package/content_types.rb', line 29

def set_xml_writer(filename)
  @writer.set_xml_writer(filename)
end