Class: OOXML::Excel::Workbook

Inherits:
Object
  • Object
show all
Defined in:
lib/ooxml_excel/workbook.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Workbook

Returns a new instance of Workbook.



4
5
6
# File 'lib/ooxml_excel/workbook.rb', line 4

def initialize(xml)
  @xml = xml
end

Class Method Details

.load_from_stream(xml_stream) ⇒ Object



30
31
32
# File 'lib/ooxml_excel/workbook.rb', line 30

def self.load_from_stream(xml_stream)
  self.new (Nokogiri.XML(xml_stream).remove_namespaces!)
end

Instance Method Details

#defined_namesObject



19
20
21
22
23
24
25
26
27
# File 'lib/ooxml_excel/workbook.rb', line 19

def defined_names
  @defined_names ||= begin
    @xml.xpath('//definedNames/definedName').map do |defined_names_node|
      name = defined_names_node.attribute('name').value
      reference = defined_names_node.text
      [name, reference]
    end.to_h
  end
end

#sheetsObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/ooxml_excel/workbook.rb', line 8

def sheets
  @sheets ||= begin
    @xml.xpath('//sheets/sheet').map do |sheet_node|
      name = sheet_node.attribute('name').value
      rel_id = sheet_node.attribute('id').value.gsub(/[^\d+]/, '')
      sheet_id = sheet_node.attribute('sheetId').value
      { name: name, sheet_id: sheet_id, relationship_id: rel_id}
    end
  end
end