Class: OpenXML::SpreadsheetML::Sheet
- Inherits:
-
Struct
- Object
- Struct
- OpenXML::SpreadsheetML::Sheet
- Defined in:
- lib/xlsx/sheet.rb,
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 (also: #at_cell)
- #max_column ⇒ Object
- #max_row ⇒ Object
Instance Attribute Details
#dimension ⇒ Object
Returns the value of attribute dimension
3 4 5 |
# File 'lib/xlsx/sheet.rb', line 3 def dimension @dimension end |
#merge_cells ⇒ Object
Returns the value of attribute merge_cells
3 4 5 |
# File 'lib/xlsx/sheet.rb', line 3 def merge_cells @merge_cells end |
#name ⇒ Object
Returns the value of attribute name
3 4 5 |
# File 'lib/xlsx/sheet.rb', line 3 def name @name end |
#rid ⇒ Object
Returns the value of attribute rid
3 4 5 |
# File 'lib/xlsx/sheet.rb', line 3 def rid @rid end |
#sheet_data ⇒ Object
Returns the value of attribute sheet_data
3 4 5 |
# File 'lib/xlsx/sheet.rb', line 3 def sheet_data @sheet_data end |
#sheet_views ⇒ Object
Returns the value of attribute sheet_views
3 4 5 |
# File 'lib/xlsx/sheet.rb', line 3 def sheet_views @sheet_views end |
#sheetId ⇒ Object
Returns the value of attribute sheetId
3 4 5 |
# File 'lib/xlsx/sheet.rb', line 3 def sheetId @sheetId end |
Class Method Details
.parser(content) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/xlsx/sheet.rb', line 31 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
10 11 12 13 14 15 16 17 18 |
# File 'lib/xlsx/sheet.rb', line 10 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 Also known as: at_cell
20 21 22 23 24 25 26 27 |
# File 'lib/xlsx/sheet.rb', line 20 def [] index self.merge_cells.each do |mc| if mc.include?(index) index = mc.top_left end end self.sheet_data[index] end |
#max_column ⇒ Object
61 62 63 |
# File 'lib/xlsx/sheet.rb', line 61 def max_column /([A-Z]+)\d+$/.match(dimension)[1] end |
#max_row ⇒ Object
65 66 67 |
# File 'lib/xlsx/sheet.rb', line 65 def max_row /[A-Z]+(\d+)$/.match(dimension)[1] end |