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
24
25
# 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)
           elsif cells.is_a?(Row)
             Axlsx::cell_range(cells, false)
           end
end

#to_xml_string(str = '') ⇒ String

serialize the object

Parameters:

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

Returns:

  • (String)


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

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