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.
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
#worksheet ⇒ Object (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_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
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
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
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 |