Class: OOXML::Excel::Sheet
- Inherits:
-
Object
- Object
- OOXML::Excel::Sheet
- Includes:
- Helper::List, Util
- Defined in:
- lib/ooxml_excel/sheet.rb,
lib/ooxml_excel/sheet.rb,
lib/ooxml_excel/sheet.rb,
lib/ooxml_excel/sheet.rb,
lib/ooxml_excel/sheet.rb
Defined Under Namespace
Classes: Column, DataValidation, Row
Constant Summary
Constants included from Util
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#data_validations ⇒ Object
readonly
Returns the value of attribute data_validations.
-
#defined_names ⇒ Object
Returns the value of attribute defined_names.
-
#name ⇒ Object
Returns the value of attribute name.
-
#shared_strings ⇒ Object
readonly
Returns the value of attribute shared_strings.
-
#styles ⇒ Object
Returns the value of attribute styles.
Class Method Summary collapse
Instance Method Summary collapse
- #[](id) ⇒ Object
- #code_name ⇒ Object
- #column(id) ⇒ Object
- #data_validation(cell_ref) ⇒ Object
- #each_row ⇒ Object
- #each_row_as_object ⇒ Object
- #fill(cell_reference) ⇒ Object
-
#font(cell_reference) ⇒ Object
def styles(cell_reference) style_id = fetch_style_style_id(cell_reference) style = @styles.by_id(style_id.to_i) if style_id.present? end.
-
#initialize(xml, shared_strings) ⇒ Sheet
constructor
A new instance of Sheet.
- #row(index) ⇒ Object
- #rows ⇒ Object
Methods included from Util
#letter_equivalent, #letter_index, #uniform_reference
Methods included from Helper::List
#list_value_formula, #list_values, #list_values_from_formula
Constructor Details
#initialize(xml, shared_strings) ⇒ Sheet
Returns a new instance of Sheet.
9 10 11 12 13 14 15 |
# File 'lib/ooxml_excel/sheet.rb', line 9 def initialize(xml, shared_strings) @xml = xml @shared_strings = shared_strings @comments = {} @defined_names = {} @styles = [] end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
6 7 8 |
# File 'lib/ooxml_excel/sheet.rb', line 6 def columns @columns end |
#comments ⇒ Object
Returns the value of attribute comments.
7 8 9 |
# File 'lib/ooxml_excel/sheet.rb', line 7 def comments @comments end |
#data_validations ⇒ Object (readonly)
Returns the value of attribute data_validations.
6 7 8 |
# File 'lib/ooxml_excel/sheet.rb', line 6 def data_validations @data_validations end |
#defined_names ⇒ Object
Returns the value of attribute defined_names.
7 8 9 |
# File 'lib/ooxml_excel/sheet.rb', line 7 def defined_names @defined_names end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/ooxml_excel/sheet.rb', line 7 def name @name end |
#shared_strings ⇒ Object (readonly)
Returns the value of attribute shared_strings.
6 7 8 |
# File 'lib/ooxml_excel/sheet.rb', line 6 def shared_strings @shared_strings end |
#styles ⇒ Object
Returns the value of attribute styles.
7 8 9 |
# File 'lib/ooxml_excel/sheet.rb', line 7 def styles @styles end |
Class Method Details
.load_from_stream(xml_stream, shared_strings) ⇒ Object
103 104 105 |
# File 'lib/ooxml_excel/sheet.rb', line 103 def self.load_from_stream(xml_stream, shared_strings) self.new(Nokogiri.XML(xml_stream).remove_namespaces!, shared_strings) end |
Instance Method Details
#[](id) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/ooxml_excel/sheet.rb', line 38 def [](id) if id.is_a?(String) rows.find { |row| row.id == id} else rows[id] end end |
#code_name ⇒ Object
17 18 19 |
# File 'lib/ooxml_excel/sheet.rb', line 17 def code_name @code_name ||= @xml.xpath('//sheetPr').attribute('codeName').try(:value) end |
#column(id) ⇒ Object
25 26 27 28 |
# File 'lib/ooxml_excel/sheet.rb', line 25 def column(id) uniformed_reference = uniform_reference(id) columns.find { |column| column.id_range.include?(uniformed_reference)} end |
#data_validation(cell_ref) ⇒ Object
21 22 23 |
# File 'lib/ooxml_excel/sheet.rb', line 21 def data_validation(cell_ref) data_validations.find { |data_validation| data_validation.in_sqref_range?(cell_ref)} end |
#each_row ⇒ Object
60 61 62 63 64 |
# File 'lib/ooxml_excel/sheet.rb', line 60 def each_row rows.each_with_index do |row, row_index| yield row.cells.map(&:value), row_index end end |
#each_row_as_object ⇒ Object
66 67 68 69 70 |
# File 'lib/ooxml_excel/sheet.rb', line 66 def each_row_as_object 0.upto(rows.size).each do |row_index| yield rows[row_index] end end |
#fill(cell_reference) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/ooxml_excel/sheet.rb', line 86 def fill(cell_reference) style_id = fetch_style_style_id(cell_reference) if style_id.present? style = @styles.by_id(style_id.to_i) (style.present?) ? style[:fill] : nil end end |
#font(cell_reference) ⇒ Object
def styles(cell_reference)
style_id = fetch_style_style_id(cell_reference)
style = @styles.by_id(style_id.to_i) if style_id.present?
end
77 78 79 80 81 82 83 84 |
# File 'lib/ooxml_excel/sheet.rb', line 77 def font(cell_reference) style_id = fetch_style_style_id(cell_reference) if style_id.present? style = @styles.by_id(style_id.to_i) (style.present?) ? style[:font] : nil end end |
#row(index) ⇒ Object
46 47 48 |
# File 'lib/ooxml_excel/sheet.rb', line 46 def row(index) rows.find { |row| row.id == index.to_s} end |
#rows ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/ooxml_excel/sheet.rb', line 50 def rows @rows ||= begin # TODO: get the value of merged cells # merged_cells = @xml.xpath('//mergeCells/mergeCell').map { |merged_cell| merged_cell.attributes["ref"].try(:value) } @xml.xpath('//sheetData/row').map do |row_node| Excel::Sheet::Row.load_from_node(row_node, shared_strings, styles) end end end |