Class: Roo::Excelx::SheetDoc

Inherits:
Extractor show all
Extended by:
Forwardable
Defined in:
lib/roo/excelx/sheet_doc.rb

Constant Summary

Constants inherited from Extractor

Extractor::COMMON_STRINGS

Instance Method Summary collapse

Constructor Details

#initialize(path, relationships, shared, options = {}) ⇒ SheetDoc

Returns a new instance of SheetDoc.



12
13
14
15
16
17
# File 'lib/roo/excelx/sheet_doc.rb', line 12

def initialize(path, relationships, shared, options = {})
  super(path)
  @shared = shared
  @options = options
  @relationships = relationships
end

Instance Method Details

#cells(relationships) ⇒ Object



19
20
21
# File 'lib/roo/excelx/sheet_doc.rb', line 19

def cells(relationships)
  @cells ||= extract_cells(relationships)
end

#dimensionsObject

Get the dimensions for the sheet. This is the upper bound of cells that might be parsed. (the document may be sparse so cell count is only upper bound)



35
36
37
# File 'lib/roo/excelx/sheet_doc.rb', line 35

def dimensions
  @dimensions ||= extract_dimensions
end

#each_cell(row_xml) ⇒ Object

Yield each cell as Excelx::Cell to caller for given row xml



46
47
48
49
50
51
52
53
54
# File 'lib/roo/excelx/sheet_doc.rb', line 46

def each_cell(row_xml)
  return [] unless row_xml
  row_xml.children.each do |cell_element|
    coordinate = ::Roo::Utils.extract_coordinate(cell_element["r"])
    hyperlinks = hyperlinks(@relationships)[coordinate]

    yield cell_from_xml(cell_element, hyperlinks, coordinate)
  end
end

#each_row_streaming(&block) ⇒ Object

Yield each row xml element to caller



40
41
42
# File 'lib/roo/excelx/sheet_doc.rb', line 40

def each_row_streaming(&block)
  Roo::Utils.each_element(@path, 'row', &block)
end


23
24
25
26
27
28
29
30
# File 'lib/roo/excelx/sheet_doc.rb', line 23

def hyperlinks(relationships)
  # If you're sure you're not going to need this hyperlinks you can discard it
  @hyperlinks ||= if @options[:no_hyperlinks] || !relationships.include_type?("hyperlink")
    {}
  else
    extract_hyperlinks(relationships)
  end
end