Class: Axlsx::Dimension

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

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worksheet) ⇒ Dimension

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

Raises:

  • (ArgumentError)


23
24
25
26
27
# 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

Instance Attribute Details

#worksheetObject (readonly)

Returns the value of attribute worksheet.



29
30
31
# File 'lib/axlsx/workbook/worksheet/dimension.rb', line 29

def worksheet
  @worksheet
end

Class Method Details

.default_firstString

the default value for the first cell in the dimension

Returns:

  • (String)


10
11
12
# File 'lib/axlsx/workbook/worksheet/dimension.rb', line 10

def self.default_first
  @@default_first ||= 'A1'
end

.default_lastString

the default value for the last cell in the dimension

Returns:

  • (String)


16
17
18
# File 'lib/axlsx/workbook/worksheet/dimension.rb', line 16

def self.default_last
  @@default_last ||= 'AA200'
end

Instance Method Details

#first_cell_referenceString

The first cell in the dimension

Returns:

  • (String)


47
48
49
# File 'lib/axlsx/workbook/worksheet/dimension.rb', line 47

def first_cell_reference
  dimension_reference(worksheet.rows.first.first, Dimension.default_first)
end

#last_cell_referenceString

the last cell in the dimension

Returns:

  • (String)


53
54
55
# File 'lib/axlsx/workbook/worksheet/dimension.rb', line 53

def last_cell_reference
  dimension_reference(worksheet.rows.last.last, Dimension.default_last)
end

#sqrefString

the full refernece for this dimension

Returns:

  • (String)


33
34
35
# File 'lib/axlsx/workbook/worksheet/dimension.rb', line 33

def sqref
  "#{first_cell_reference}:#{last_cell_reference}"
end

#to_xml_string(str = +'')) ⇒ String

serialize the object

Returns:

  • (String)


39
40
41
42
43
# File 'lib/axlsx/workbook/worksheet/dimension.rb', line 39

def to_xml_string(str = +'')
  return if worksheet.rows.empty?

  str << '<dimension ref="' << sqref << '"></dimension>'
end