Class: Dullard::Workbook
- Inherits:
-
Object
- Object
- Dullard::Workbook
- Defined in:
- lib/dullard/reader.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(file) ⇒ Workbook
constructor
A new instance of Workbook.
- #read_string_table ⇒ Object
- #sheets ⇒ Object
- #string_table ⇒ Object
- #zipfs ⇒ Object
Constructor Details
#initialize(file) ⇒ Workbook
Returns a new instance of Workbook.
7 8 9 10 |
# File 'lib/dullard/reader.rb', line 7 def initialize(file) @file = file @zipfs = Zip::ZipFile.open(@file) end |
Instance Method Details
#close ⇒ Object
40 41 42 |
# File 'lib/dullard/reader.rb', line 40 def close @zipfs.close end |
#read_string_table ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dullard/reader.rb', line 21 def read_string_table @string_table = [] entry = '' Nokogiri::XML::Reader(@zipfs.file.open("xl/sharedStrings.xml")).each do |node| if node.name == "si" and node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT entry = '' elsif node.name == "si" and node.node_type == Nokogiri::XML::Reader::TYPE_END_ELEMENT @string_table << entry elsif node.value? entry << node.value end end @string_table end |
#sheets ⇒ Object
12 13 14 15 |
# File 'lib/dullard/reader.rb', line 12 def sheets workbook = Nokogiri::XML::Document.parse(@zipfs.file.open("xl/workbook.xml")) @sheets = workbook.css("sheet").each_with_index.map {|n,i| Dullard::Sheet.new(self, n.attr("name"), n.attr("sheetId"), i+1) } end |
#string_table ⇒ Object
17 18 19 |
# File 'lib/dullard/reader.rb', line 17 def string_table @string_tabe ||= read_string_table end |
#zipfs ⇒ Object
36 37 38 |
# File 'lib/dullard/reader.rb', line 36 def zipfs @zipfs end |