lib/roo/excel.rb in roo-0.9.1 vs lib/roo/excel.rb in roo-0.9.2
- old
+ new
@@ -100,30 +100,43 @@
sheet = @default_sheet unless sheet
row,col = normalize(row,col)
worksheet = @workbook.worksheet(sheet_no(sheet))
skip = 0
line = 1
- worksheet.each(skip) { |row_par|
+ worksheet.each(skip) { |row_par| #TODO: nicht jedesmal durch alle Zeilen gehen, sonder aus interner Repraesentation holen?
if line == row
if row_par == nil
return nil
end
cell = row_par.at(col-1)
return nil unless cell
case cell.type
when :numeric then return cell.to_f
when :text then return cell.to_s('utf-8')
- when :date then return cell.date
+ # when :date then return cell.date
+ when :date
+ if cell.to_s.to_f < 1.0
+ f = cell.to_s.to_f*24.0*60.0*60.0
+ secs = f.round
+ h = (secs / 3600.0).floor
+ secs = secs - 3600*h
+ m = (secs / 60.0).floor
+ secs = secs - 60*m
+ s = secs
+ return h*3600+m*60+s
+ else
+ return cell.date
+ end
else
return nil # cell.to_s('utf-8')
end
end
line += 1
}
end
- # returns the type of a cell: :float, :string, :date
+ # returns the type of a cell: :float, :string, :date, :time
def celltype(row,col,sheet=nil)
sheet = @default_sheet unless sheet
row,col = normalize(row,col)
worksheet = @workbook.worksheet(sheet_no(sheet))
@@ -138,10 +151,14 @@
when :numeric
return :float
when :text
return :string
when :date
- return :date
+ if cell.to_s.to_f < 1.0
+ return :time
+ else
+ return :date
+ end
else
return cell.type.to_sym
end
end
line += 1