class Axlsx::Dimension

This class manages the dimensions for a worksheet. While this node is optional in the specification some readers like LibraOffice require this node to render the sheet

Attributes

worksheet[R]

Public Class Methods

default_first() click to toggle source

the default value for the first cell in the dimension @return [String]

# File lib/axlsx/workbook/worksheet/dimension.rb, line 10
def self.default_first
  @@default_first ||= 'A1'
end
default_last() click to toggle source

the default value for the last cell in the dimension @return [String]

# File lib/axlsx/workbook/worksheet/dimension.rb, line 16
def self.default_last
  @@default_last ||= 'AA200'
end
new(worksheet) click to toggle source

Creates a new dimension object @param worksheet - the worksheet this dimension applies to.

# File lib/axlsx/workbook/worksheet/dimension.rb, line 23
def initialize(worksheet)
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
  @worksheet = worksheet
end

Public Instance Methods

first_cell_reference() click to toggle source

The first cell in the dimension @return [String]

# File lib/axlsx/workbook/worksheet/dimension.rb, line 45
def first_cell_reference
  dimension_reference(worksheet.rows.first.cells.first, Dimension.default_first)
end
last_cell_reference() click to toggle source

the last cell in the dimension @return [String]

# File lib/axlsx/workbook/worksheet/dimension.rb, line 51
def last_cell_reference
  dimension_reference(worksheet.rows.last.cells.last, Dimension.default_last)
end
sqref() click to toggle source

the full refernece for this dimension @return [String]

# File lib/axlsx/workbook/worksheet/dimension.rb, line 32
def sqref
  "#{first_cell_reference}:#{last_cell_reference}"
end
to_xml_string(str = '') click to toggle source

serialize the object @return [String]

# File lib/axlsx/workbook/worksheet/dimension.rb, line 38
def to_xml_string(str = '')
  return if worksheet.rows.empty?
  str << "<dimension ref=\"%s\"></dimension>" % sqref
end

Private Instance Methods

dimension_reference(cell, default) click to toggle source

Returns the reference of a cell or the default specified @return [String]

# File lib/axlsx/workbook/worksheet/dimension.rb, line 59
def dimension_reference(cell, default)
  return default unless cell.respond_to?(:r)
  cell.r
end