Class: Sheets::Parsers::NokogiriXlsxParser

Inherits:
Base
  • Object
show all
Defined in:
lib/sheets/parsers/nokogiri_xlsx_parser.rb

Instance Method Summary (collapse)

Methods inherited from Base

formats, formats=, #initialize, #io, parses

Constructor Details

This class inherits a constructor from Sheets::Parsers::Base

Instance Method Details

- (Object) to_array



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sheets/parsers/nokogiri_xlsx_parser.rb', line 7

def to_array
  # Create Matrices
  matrices = worksheets.collect do |worksheet|
    worksheet.css('sheetData>row').collect do |row|
      row.css('c').collect do |cell|
        cell_value = cell.css('v').text

        if cell.attribute('t')
          celltype = cell.attribute('t').value
          if celltype == 's'
            # Load Shared String Value
            cell_value = shared_strings[cell_value.to_i]
          elsif celltype == 'b'
            cell_value = (cell_value == "1") ? "TRUE" : "FALSE"
          end
        end
        
        if cell.attribute('s') && cell.attribute('s').value == "1"
          cell_value = (base_date + cell_value.to_f).strftime('%Y-%m-%d') # Date conversion
        end

        if cell_value.match(/\A[0-9]+\.?[0-9]*\Z/)
          cell_value = cell_value.to_f.to_s
        end

        cell_value
      end
    end
  end

  matrices.first
end