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 refernece 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.
21 22 23 24 25 |
# File 'lib/axlsx/workbook/worksheet/dimension.rb', line 21 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.
27 28 29 |
# File 'lib/axlsx/workbook/worksheet/dimension.rb', line 27 def worksheet @worksheet end |
Class Method Details
.default_first ⇒ String
the default value for the first cell in the dimension
8 9 10 |
# File 'lib/axlsx/workbook/worksheet/dimension.rb', line 8 def self.default_first @@default_first ||= 'A1' end |
.default_last ⇒ String
the default value for the last cell in the dimension
14 15 16 |
# File 'lib/axlsx/workbook/worksheet/dimension.rb', line 14 def self.default_last @@default_last ||= 'AA200' end |
Instance Method Details
#first_cell_reference ⇒ String
The first cell in the dimension
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_reference ⇒ String
the last cell in the dimension
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 |
#sqref ⇒ String
the full refernece for this dimension
31 32 33 |
# File 'lib/axlsx/workbook/worksheet/dimension.rb', line 31 def sqref "#{first_cell_reference}:#{last_cell_reference}" end |
#to_xml_string(str = '') ⇒ String
serialize the object
37 38 39 40 41 |
# File 'lib/axlsx/workbook/worksheet/dimension.rb', line 37 def to_xml_string(str = '') return if worksheet.rows.empty? str << "<dimension ref=\"%s\"></dimension>" % sqref end |