class Axlsx::MergedCells

A simple list of merged cells

Public Class Methods

new(worksheet) click to toggle source

creates a new MergedCells object @param [Worksheet] worksheet

Calls superclass method Axlsx::SimpleTypedList::new
# 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

Public Instance Methods

add(cells) click to toggle source

adds cells to the merged cells collection @param [Array||String] cells The cells to add to the merged cells collection. This can be an array of actual cells or a string style range like ‘A1:C1’

# 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 = '') click to toggle source

serialize the object @param [String] str @return [String]

# 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