Class: Writexlsx::Package::ContentTypes
- Inherits:
-
Object
- Object
- Writexlsx::Package::ContentTypes
- 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
-
#add_calc_chain ⇒ Object
Add the calcChain link to the ContentTypes overrides.
-
#add_chart_name(name) ⇒ Object
Add the name of a chart to the ContentTypes overrides.
-
#add_chartsheet_name(name) ⇒ Object
Add the name of a chartsheet to the ContentTypes overrides.
-
#add_comment_name(name) ⇒ Object
Add the name of a comment to the ContentTypes overrides.
-
#add_default(part_name, content_type) ⇒ Object
Add elements to the ContentTypes defaults.
-
#add_drawing_name(name) ⇒ Object
Add the name of a drawing to the ContentTypes overrides.
-
#add_image_types(types) ⇒ Object
Add the image default types.
-
#add_override(part_name, content_type) ⇒ Object
Add elements to the ContentTypes overrides.
-
#add_shared_strings ⇒ Object
Add the sharedStrings link to the ContentTypes overrides.
-
#add_table_name(table_name) ⇒ Object
Add the name of a table to the ContentTypes overrides.
-
#add_vba_project ⇒ Object
Add a vbaProject to the ContentTypes defaults.
-
#add_vml_name ⇒ Object
Add the name of a VML drawing to the ContentTypes defaults.
-
#add_worksheet_name(name) ⇒ Object
Add the name of a worksheet to the ContentTypes overrides.
- #assemble_xml_file ⇒ Object
-
#initialize ⇒ ContentTypes
constructor
A new instance of ContentTypes.
- #set_xml_writer(filename) ⇒ Object
Methods included from Utility
#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #convert_date_time, delete_files, #ptrue?, #put_deprecate_message, #row_col_notation, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #write_color, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str
Constructor Details
#initialize ⇒ ContentTypes
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_chain ⇒ Object
Add the calcChain link to the ContentTypes overrides.
119 120 121 |
# File 'lib/write_xlsx/package/content_types.rb', line 119 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.
78 79 80 81 82 |
# File 'lib/write_xlsx/package/content_types.rb', line 78 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.
69 70 71 72 73 |
# File 'lib/write_xlsx/package/content_types.rb', line 69 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.
103 104 105 106 107 |
# File 'lib/write_xlsx/package/content_types.rb', line 103 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.
46 47 48 |
# File 'lib/write_xlsx/package/content_types.rb', line 46 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.
87 88 89 90 91 |
# File 'lib/write_xlsx/package/content_types.rb', line 87 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.
126 127 128 |
# File 'lib/write_xlsx/package/content_types.rb', line 126 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.
53 54 55 |
# File 'lib/write_xlsx/package/content_types.rb', line 53 def add_override(part_name, content_type) @overrides.push([part_name, content_type]) end |
#add_shared_strings ⇒ Object
Add the sharedStrings link to the ContentTypes overrides.
112 113 114 |
# File 'lib/write_xlsx/package/content_types.rb', line 112 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.
133 134 135 136 137 138 |
# File 'lib/write_xlsx/package/content_types.rb', line 133 def add_table_name(table_name) add_override( "/xl/tables/#{table_name}.xml", "#{App_document}spreadsheetml.table+xml" ) end |
#add_vba_project ⇒ Object
Add a vbaProject to the ContentTypes defaults.
143 144 145 146 |
# File 'lib/write_xlsx/package/content_types.rb', line 143 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_name ⇒ Object
Add the name of a VML drawing to the ContentTypes defaults.
96 97 98 |
# File 'lib/write_xlsx/package/content_types.rb', line 96 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.
60 61 62 63 64 |
# File 'lib/write_xlsx/package/content_types.rb', line 60 def add_worksheet_name(name) worksheet_name = "/xl/worksheets/#{name}.xml" add_override(worksheet_name, "#{App_document}spreadsheetml.worksheet+xml") end |
#assemble_xml_file ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/write_xlsx/package/content_types.rb', line 33 def assemble_xml_file write_xml_declaration write_types write_defaults write_overrides @writer.end_tag('Types') @writer.crlf @writer.close 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 |