lib/roo/generic_spreadsheet.rb in roo-1.2.0 vs lib/roo/generic_spreadsheet.rb in roo-1.2.1
- old
+ new
@@ -51,11 +51,11 @@
return @first_row[sheet]
end
impossible_value = 999_999 # more than a spreadsheet can hold
result = impossible_value
@cell[sheet].each_pair {|key,value|
- y,x = key.split(',')
+ y,x = key # _to_string(key).split(',')
y = y.to_i
result = [result, y].min if value
} if @cell[sheet]
result = nil if result == impossible_value
@first_row[sheet] = result
@@ -70,11 +70,11 @@
return @last_row[sheet]
end
impossible_value = 0
result = impossible_value
@cell[sheet].each_pair {|key,value|
- y,x = key.split(',')
+ y,x = key # _to_string(key).split(',')
y = y.to_i
result = [result, y].max if value
} if @cell[sheet]
result = nil if result == impossible_value
@last_row[sheet] = result
@@ -91,12 +91,12 @@
return @first_column[sheet]
end
impossible_value = 999_999 # more than a spreadsheet can hold
result = impossible_value
@cell[sheet].each_pair {|key,value|
- y,x = key.split(',')
- x = x.to_i
+ y,x = key # _to_string(key).split(',')
+ x = x # .to_i
result = [result, x].min if value
} if @cell[sheet]
result = nil if result == impossible_value
@first_column[sheet] = result
result
@@ -110,11 +110,11 @@
return @last_column[sheet]
end
impossible_value = 0
result = impossible_value
@cell[sheet].each_pair {|key,value|
- y,x = key.split(',')
+ y,x = key # _to_string(key).split(',')
x = x.to_i
result = [result, x].max if value
} if @cell[sheet]
result = nil if result == impossible_value
@last_column[sheet] = result
@@ -225,11 +225,10 @@
found *= 1
else
found *= 0
end
}
- # p self.row(i) if found > 0
if found > 0
tmp = {}
1.upto(self.row(i).size) {|j|
x = ''
column_with.each { |key,val|
@@ -259,11 +258,11 @@
sheet = @default_sheet unless sheet
read_cells(sheet) unless @cells_read[sheet]
result = []
tmp_arr = []
@cell[sheet].each_pair {|key,value|
- y,x = key.split(',')
+ y,x = key # _to_string(key).split(',')
x = x.to_i
y = y.to_i
if y == rownumber
tmp_arr[x] = value
end
@@ -398,11 +397,26 @@
raise "#{@file_warning} illegal state of file_warning"
end
end
end
+ # konvertiert einen Key in der Form "12,45" (=row,column) in
+ # ein Array mit numerischen Werten ([12,45])
+ # Diese Methode ist eine temp. Loesung, um zu erforschen, ob der
+ # Zugriff mit numerischen Keys schneller ist.
+ def key_to_num(str)
+ r,c = str.split(',')
+ r = r.to_i
+ c = c.to_i
+ [r,c]
+ end
+ # siehe: key_to_num
+ def key_to_string(arr)
+ "#{arr[0]},#{arr[1]}"
+ end
+
private
# converts cell coordinate to numeric values of row,col
def normalize(row,col)
if row.class == String
@@ -431,9 +445,17 @@
rescue
raise "could not open #{uri}"
end
f.close
File.join(@tmpdir, File.basename(uri))
+ end
+
+ def open_from_stream(stream)
+ tempfilename = File.join(@tmpdir, "spreadsheet")
+ f = File.open(tempfilename,"wb")
+ f.write(stream[7..-1])
+ f.close
+ File.join(@tmpdir, "spreadsheet")
end
# convert a number to something like 'AB' (1 => 'A', 2 => 'B', ...)
def self.number_to_letter(n)
letters=""