Class: Axlsx::MergedCells
- Inherits:
-
SimpleTypedList
- Object
- SimpleTypedList
- Axlsx::MergedCells
- Defined in:
- lib/axlsx/workbook/worksheet/merged_cells.rb
Overview
A simple list of merged cells
Instance Method Summary collapse
-
#add(cells) ⇒ Object
adds cells to the merged cells collection collection.
-
#initialize(worksheet) ⇒ MergedCells
constructor
creates a new MergedCells object.
-
#to_xml_string(str = '') ⇒ String
serialize the object.
Constructor Details
#initialize(worksheet) ⇒ MergedCells
creates a new MergedCells object
8 9 10 11 |
# File 'lib/axlsx/workbook/worksheet/merged_cells.rb', line 8 def initialize(worksheet) raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet) super String end |
Instance Method Details
#add(cells) ⇒ Object
adds cells to the merged cells collection collection. This can be an array of actual cells or a string style range like 'A1:C1'
17 18 19 20 21 22 23 |
# File 'lib/axlsx/workbook/worksheet/merged_cells.rb', line 17 def add(cells) self << if cells.is_a?(String) cells elsif cells.is_a?(Array) Axlsx::cell_range(cells, false) end end |
#to_xml_string(str = '') ⇒ String
serialize the object
28 29 30 31 32 33 |
# File 'lib/axlsx/workbook/worksheet/merged_cells.rb', line 28 def to_xml_string(str = '') return if empty? str << "<mergeCells count='#{size}'>" each { |merged_cell| str << "<mergeCell ref='#{merged_cell}'></mergeCell>" } str << '</mergeCells>' end |