Class: OpenXML::SpreadsheetML::Sheet
- Inherits:
-
Object
- Object
- OpenXML::SpreadsheetML::Sheet
- Defined in:
- lib/xlsx/sheet.rb
Instance Attribute Summary collapse
-
#dimension ⇒ Object
Returns the value of attribute dimension.
-
#merge_cells ⇒ Object
Returns the value of attribute merge_cells.
-
#name ⇒ Object
Returns the value of attribute name.
-
#rid ⇒ Object
Returns the value of attribute rid.
-
#sheet_data ⇒ Object
Returns the value of attribute sheet_data.
-
#sheet_views ⇒ Object
Returns the value of attribute sheet_views.
-
#sheetId ⇒ Object
Returns the value of attribute sheetId.
Class Method Summary collapse
Instance Method Summary collapse
- #+(sheet) ⇒ Object
- #[](index) ⇒ Object
- #at_cell(index) ⇒ Object
-
#initialize(dimension = nil, sheet_data = nil, merge_cells = nil) ⇒ Sheet
constructor
A new instance of Sheet.
- #max_column ⇒ Object
- #max_row ⇒ Object
- #merge_shared_strings(shared_strings_reference) ⇒ Object
Constructor Details
#initialize(dimension = nil, sheet_data = nil, merge_cells = nil) ⇒ Sheet
Returns a new instance of Sheet.
8 9 10 11 12 |
# File 'lib/xlsx/sheet.rb', line 8 def initialize dimension = nil, sheet_data = nil, merge_cells = nil @dimension = dimension @sheet_data = sheet_data || {} @merge_cells = merge_cells || {} end |
Instance Attribute Details
#dimension ⇒ Object
Returns the value of attribute dimension.
6 7 8 |
# File 'lib/xlsx/sheet.rb', line 6 def dimension @dimension end |
#merge_cells ⇒ Object
Returns the value of attribute merge_cells.
6 7 8 |
# File 'lib/xlsx/sheet.rb', line 6 def merge_cells @merge_cells end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/xlsx/sheet.rb', line 6 def name @name end |
#rid ⇒ Object
Returns the value of attribute rid.
6 7 8 |
# File 'lib/xlsx/sheet.rb', line 6 def rid @rid end |
#sheet_data ⇒ Object
Returns the value of attribute sheet_data.
6 7 8 |
# File 'lib/xlsx/sheet.rb', line 6 def sheet_data @sheet_data end |
#sheet_views ⇒ Object
Returns the value of attribute sheet_views.
6 7 8 |
# File 'lib/xlsx/sheet.rb', line 6 def sheet_views @sheet_views end |
#sheetId ⇒ Object
Returns the value of attribute sheetId.
6 7 8 |
# File 'lib/xlsx/sheet.rb', line 6 def sheetId @sheetId end |
Class Method Details
.parser(content) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/xlsx/sheet.rb', line 47 def self.parser content doc = Nokogiri::XML content # sheetData sheet_data = {} = doc.css('sheetData') = .css('c') .each do |cell| t = cell[:t] v = cell.at_css('v') v = v.text if v f = cell.at_css('f') f = f.text if f sheet_data[cell[:r]] = Cell.new(t, v, f) end # mergeCells merge_cells = [] = doc.css('mergeCell') .each do |mc| merge_cells << MergeCell.new(mc[:ref]) end # dimension dimension_tag = doc.at_css('dimension') dimension = dimension_tag[:ref] Sheet.new(dimension, sheet_data, merge_cells) end |
Instance Method Details
#+(sheet) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/xlsx/sheet.rb', line 14 def + sheet self.dimension = self.dimension || sheet.dimension self.sheet_data = self.sheet_data || sheet.sheet_data self.merge_cells = self.merge_cells || sheet.merge_cells self.name = self.name || sheet.name self.sheetId = self.sheetId || sheet.sheetId self.rid = self.rid || sheet.rid self end |
#[](index) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/xlsx/sheet.rb', line 24 def [] index case index when /^[A-Z]+\d+$/ retrieve_one_cell index when /^\d+$/ retrieve_one_row index when /^[A-Z]+$/ retrieve_one_column index when /^(\d+)[\-:](\d+)$/ retrieve_rows($1, $2) when /^([A-Z]+)[\-:]([A-Z]+)$/ retrieve_columns($1, $2) when /^([A-Z]+)(\d+)[\-:]([A-Z]+)(\d+)$/ retrieve_one_matrix($1, $2, $3, $4) else raise IndexError, 'Invalid index' end end |
#at_cell(index) ⇒ Object
43 44 45 |
# File 'lib/xlsx/sheet.rb', line 43 def at_cell index retrieve_one_cell index end |
#max_column ⇒ Object
77 78 79 |
# File 'lib/xlsx/sheet.rb', line 77 def max_column /([A-Z]+)\d+$/.match(dimension)[1] end |
#max_row ⇒ Object
81 82 83 |
# File 'lib/xlsx/sheet.rb', line 81 def max_row /[A-Z]+(\d+)$/.match(dimension)[1] end |
#merge_shared_strings(shared_strings_reference) ⇒ Object
85 86 87 88 89 |
# File 'lib/xlsx/sheet.rb', line 85 def merge_shared_strings shared_strings_reference self.sheet_data.each do |index, cell| cell.shared_strings_pointer = shared_strings_reference end end |