Module: Spreadsheet

Defined in:
lib/compatibility.rb

Class Method Summary collapse

Class Method Details

.date_cell(row, idx) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/compatibility.rb', line 24

def Spreadsheet.date_cell(row, idx)
  if row.kind_of?(Spreadsheet::Excel::Row)
    row.at(idx) && row.date(idx)
  else
    data = row[idx]
    if data.is_a?(RubyXL::Cell)
      return data.value.respond_to?(:to_i) ? data.value.to_i : data.value
      return data.value if data.value.is_a?(DateTime)
      if data.value.class.to_s == 'DateTime'
        puts "data is_a RubyXL::Cell and value #{data.value.class} is_a? Date #{data.value.is_a?(Date)} DateTime #{data.value.is_a?(DateTime)}"
        return Date.new(1899,12,30)+data.to_date.value.to_i
      else
        return Date.new(1899,12,30)+data.value.to_i if data.is_a?(RubyXL::Cell)
      end
    end
  end
end

.open(io_or_path, mode = "rb+") ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/compatibility.rb', line 8

def open io_or_path, mode="rb+"
  if File.extname(io_or_path).downcase == '.xlsx'
    RubyXL::Parser.parse(io_or_path)
  else
    if io_or_path.respond_to? :seek
      Excel::Workbook.open(io_or_path)
    elsif block_given?
      File.open(io_or_path, mode) do |fh|
        yield open(fh)
      end
    else
      open File.open(io_or_path, mode)
    end
  end
end