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


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

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)

45
46
47
# File 'lib/axlsx/workbook/worksheet/dimension.rb', line 45

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)

51
52
53
# File 'lib/axlsx/workbook/worksheet/dimension.rb', line 51

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

#sqrefString

the full refernece for this dimension

Returns:

  • (String)

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

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

#to_xml_string(str = '') ⇒ String

serialize the object

Returns:

  • (String)

38
39
40
41
# 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