Class: Axlsx::MergedCells

Inherits:
SimpleTypedList
  • Object
show all
Defined in:
lib/axlsx/workbook/worksheet/merged_cells.rb

Overview

A simple list of merged cells

Instance Method Summary collapse

Constructor Details

#initialize(worksheet) ⇒ MergedCells

creates a new MergedCells object

Parameters:

Raises:

  • (ArgumentError)


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'

Parameters:

  • cells (Array||String)

    The cells to add to the merged cells



17
18
19
20
21
22
23
# File 'lib/axlsx/workbook/worksheet/merged_cells.rb', line 17

def add(cells)
  @list << 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

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)


28
29
30
31
32
33
# File 'lib/axlsx/workbook/worksheet/merged_cells.rb', line 28

def to_xml_string(str = '')
  return if @list.empty?
  str << "<mergeCells count='#{size}'>"
  each { |merged_cell| str << "<mergeCell ref='#{merged_cell}'></mergeCell>" }
  str << '</mergeCells>'
end