Sha256: 79a4c303a50e294a9dab9fc717818e528a7680995aac9cfdae75008e7ba78917

Contents?: true

Size: 1.09 KB

Versions: 14

Compression:

Stored size: 1.09 KB

Contents

module Axlsx

  # A simple list of merged cells
  class MergedCells < SimpleTypedList

    # creates a new MergedCells object
    # @param [Worksheet] worksheet
    def initialize(worksheet)
      raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet)
      super String
    end

    # 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'
    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

    # serialize the object
    # @param [String] str
    # @return [String]
    def to_xml_string(str = '')
      return if empty?
      str << "<mergeCells count='#{size}'>"
      each { |merged_cell| str << "<mergeCell ref='#{merged_cell}'></mergeCell>" }
      str << '</mergeCells>'
    end
  end
end

Version data entries

14 entries across 14 versions & 4 rubygems

Version Path
caxlsx-3.3.0 lib/axlsx/workbook/worksheet/merged_cells.rb
caxlsx-3.1.1 lib/axlsx/workbook/worksheet/merged_cells.rb
caxlsx-3.1.0 lib/axlsx/workbook/worksheet/merged_cells.rb
bonio-axlsx-2.2.3 lib/axlsx/workbook/worksheet/merged_cells.rb
caxlsx-3.0.4 lib/axlsx/workbook/worksheet/merged_cells.rb
caxlsx-3.0.3 lib/axlsx/workbook/worksheet/merged_cells.rb
caxlsx-3.0.2 lib/axlsx/workbook/worksheet/merged_cells.rb
caxlsx-3.0.1 lib/axlsx/workbook/worksheet/merged_cells.rb
caxlsx-3.0.0 lib/axlsx/workbook/worksheet/merged_cells.rb
axlsx-alt-3.0.1 lib/axlsx/workbook/worksheet/merged_cells.rb
axlsx-alt-3.0.0 lib/axlsx/workbook/worksheet/merged_cells.rb
axlsx-3.0.0.pre lib/axlsx/workbook/worksheet/merged_cells.rb
bonio-axlsx-2.2.2 lib/axlsx/workbook/worksheet/merged_cells.rb
bonio-axlsx-2.2.1 lib/axlsx/workbook/worksheet/merged_cells.rb