lib/roo/excelx.rb in roo-1.2.1 vs lib/roo/excelx.rb in roo-1.2.2

- old
+ new

@@ -43,10 +43,11 @@ '@' => :float, #-- zusaetzliche Formate, die nicht standardmaessig definiert sind: "yyyy\\-mm\\-dd" => :date, 'dd/mm/yy' => :date, 'hh:mm:ss' => :time, + "dd/mm/yy\\ hh:mm" => :datetime, } STANDARD_FORMATS = { 0 => 'General', 1 => '0', 2 => '0.00', @@ -155,10 +156,16 @@ read_cells(sheet) unless @cells_read[sheet] row,col = normalize(row,col) if celltype(row,col,sheet) == :date yyyy,mm,dd = @cell[sheet][[row,col]].split('-') return Date.new(yyyy.to_i,mm.to_i,dd.to_i) + elsif celltype(row,col,sheet) == :datetime + date_part,time_part = @cell[sheet][[row,col]].split(' ') + yyyy,mm,dd = date_part.split('-') + hh,mi,ss = time_part.split(':') + return DateTime.civil(yyyy.to_i,mm.to_i,dd.to_i,hh.to_i,mi.to_i,ss.to_i) + end @cell[sheet][[row,col]] end # Returns the formula at (row,col). @@ -207,11 +214,11 @@ # * :date # * :percentage # * :formula # * :time # * :datetime -def celltype(row,col,sheet=nil) + def celltype(row,col,sheet=nil) sheet = @default_sheet unless sheet read_cells(sheet) unless @cells_read[sheet] row,col = normalize(row,col) if @formula[sheet][[row,col]] return :formula @@ -307,11 +314,13 @@ when :float @cell[sheet][key] = v.to_f when :string @cell[sheet][key] = str_v when :date - @cell[sheet][key] = (Date.new(1899,12,30)+v.to_i).strftime("%Y-%m-%d") # tr.attributes['date-value'] + @cell[sheet][key] = (Date.new(1899,12,30)+v.to_i).strftime("%Y-%m-%d") + when :datetime + @cell[sheet][key] = (DateTime.new(1899,12,30)+v.to_f).strftime("%Y-%m-%d %H:%M:%S") when :percentage @cell[sheet][key] = v.to_f when :time @cell[sheet][key] = v.to_f*(24*60*60) else @@ -381,17 +390,36 @@ format = attribute2format(s_attribute) tmp_type = format2type(format) end formula = nil row.each_element do |cell| +# puts "cell.name: #{cell.name}" if cell.text.include? "22606.5120" +# puts "cell.text: #{cell.text}" if cell.text.include? "22606.5120" if cell.name == 'f' formula = cell.text end if cell.name == 'v' - if tmp_type == :time #2008-07-26 + #puts "tmp_type: #{tmp_type}" if cell.text.include? "22606.5120" + #puts cell.name + if tmp_type == :time or tmp_type == :datetime #2008-07-26 + #p cell.text + # p cell.text.to_f if cell.text.include? "22606.5120" if cell.text.to_f >= 1.0 # 2008-07-26 - tmp_type = :date # 2008-07-26 + # puts ">= 1.0" if cell.text.include? "22606.5120" + # puts "cell.text.to_f: #{cell.text.to_f}" if cell.text.include? "22606.5120" + #puts "cell.text.to_f.floor: #{cell.text.to_f.floor}" if cell.text.include? "22606.5120" + if (cell.text.to_f - cell.text.to_f.floor).abs > 0.000001 #TODO: + # puts "abs ist groesser" if cell.text.include? "22606.5120" + # @cell[sheet][key] = DateTime.parse(tr.attributes['date-value']) + tmp_type = :datetime + + else + #puts ":date" + tmp_type = :date # 2008-07-26 + end + else + #puts "<1.0" end # 2008-07-26 end # 2008-07-26 excelx_type = [:numeric_or_formula,format] excelx_value = cell.text if tmp_type == :shared @@ -402,16 +430,20 @@ vt = :date v = cell.text elsif tmp_type == :time vt = :time v = cell.text + elsif tmp_type == :datetime + vt = :datetime + v = cell.text elsif tmp_type == :formula vt = :formula v = cell.text.to_f #TODO: !!!! else vt = :float v = cell.text end + #puts "vt: #{vt}" if cell.text.include? "22606.5120" x,y = split_coordinate(row.attributes['r']) tr=nil #TODO: ???s set_cell_values(sheet,x,y,0,v,vt,formula,tr,str_v,excelx_type,excelx_value,s_attribute) end end