Class: Axlsx::Dimension
- Inherits:
-
Object
- Object
- Axlsx::Dimension
- 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
-
#worksheet ⇒ Object
readonly
Returns the value of attribute worksheet.
Class Method Summary collapse
-
.default_first ⇒ String
the default value for the first cell in the dimension.
-
.default_last ⇒ String
the default value for the last cell in the dimension.
Instance Method Summary collapse
-
#first_cell_reference ⇒ String
The first cell in the dimension.
-
#initialize(worksheet) ⇒ Dimension
constructor
Creates a new dimension object @param[Worksheet] worksheet - the worksheet this dimension applies to.
-
#last_cell_reference ⇒ String
the last cell in the dimension.
-
#sqref ⇒ String
the full reference for this dimension.
-
#to_xml_string(str = +'')) ⇒ String
serialize the object.
Constructor Details
#initialize(worksheet) ⇒ Dimension
Creates a new dimension object @param[Worksheet] worksheet - the worksheet this dimension applies to.
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
#worksheet ⇒ Object (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_first ⇒ String
the default value for the first cell in the dimension
10 11 12 |
# File 'lib/axlsx/workbook/worksheet/dimension.rb', line 10 def self.default_first @@default_first ||= 'A1' end |
.default_last ⇒ String
the default value for the last cell in the dimension
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_reference ⇒ String
The first cell in the dimension
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_reference ⇒ String
the last cell in the dimension
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 |
#sqref ⇒ String
the full reference for this dimension
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
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 |