lib/roo/google.rb in roo-0.9.0 vs lib/roo/google.rb in roo-0.9.1
- old
+ new
@@ -25,12 +25,13 @@
}
result
end
#-- new
- def save_entry_roo(entry)
- path = "/feeds/cells/#{@spreadsheet_id}/1/#{@headers ? 'private' : 'public'}/full"
+ #@@ added sheet_no to definition
+ def save_entry_roo(entry, sheet_no)
+ path = "/feeds/cells/#{@spreadsheet_id}/#{sheet_no}/#{@headers ? 'private' : 'public'}/full"
post(path, entry)
end
#-- new
def entry_roo(formula, row=1, col=1)
@@ -40,12 +41,13 @@
</entry>
XML
end
#-- new
- def add_to_cell_roo(row,col,value)
- save_entry_roo(entry_roo(value,row,col))
+ #@@ added sheet_no to definition
+ def add_to_cell_roo(row,col,value, sheet_no=1)
+ save_entry_roo(entry_roo(value,row,col), sheet_no)
end
#-- new
def get_one_sheet
path = "/feeds/cells/#{@spreadsheet_id}/1/private/full"
@@ -259,21 +261,29 @@
result
end
# sets the cell to the content of 'value'
# a formula can be set in the form of '=SUM(...)'
- def set_value(row,col,value)
- @gs.add_to_cell_roo(row,col,value)
+ def set_value(row,col,value,sheet=nil)
+ sheet = @default_sheet unless sheet
+ raise RangeError, "sheet not set" unless sheet
+ #@@ Set and pass sheet_no
+ begin
+ sheet_no = sheets.index(sheet)+1
+ rescue
+ raise RangeError, "invalid sheet '"+sheet.to_s+"'"
+ end
+ @gs.add_to_cell_roo(row,col,value,sheet_no)
end
# returns the first non-empty row in a sheet
def first_row(sheet=nil)
sheet = @default_sheet unless sheet
unless @first_row[sheet]
sheet_no = sheets.index(sheet) + 1
@first_row[sheet], @last_row[sheet], @first_column[sheet], @last_column[sheet] = @gs.oben_unten_links_rechts(sheet_no)
- end
+ end
return @first_row[sheet]
end
# returns the last non-empty row in a sheet
def last_row(sheet=nil)
@@ -312,84 +322,84 @@
# -----------------------------------------------------
# !!!TODO: should be factored out to GenericSpreadsheet
# also in Openofiffe
# -----------------------------------------------------
#++
- def find(*args)
- result_array = false
- args.each {|arg,val|
- if arg.class == Hash
- arg.each { |hkey,hval|
- if hkey == :array and hval == true
- result_array = true
- end
- }
- end
- }
- column_with = {}
- 1.upto(last_column) do |col|
- column_with[cell(@header_line,col)] = col
- end
- result = Array.new
- #-- id
- if args[0].class == Fixnum
- rownum = args[0]
- tmp = {}
- 1.upto(self.row(rownum).size) {|j|
- x = ''
- column_with.each { |key,val|
- if val == j
- x = key
- end
- }
- tmp[x] = cell(rownum,j)
- }
- result = [ tmp ] # row(rownum)
- #-- :all
- elsif args[0] == :all
- if args[1].class == Hash
- args[1].each {|key,val|
- if key == :conditions
- column_with = {}
- 1.upto(last_column) do |col|
- column_with[cell(@header_line,col)] = col
- end
- conditions = val
- first_row.upto(last_row) do |i|
- # are all conditions met?
- found = 1
- conditions.each { |key,val|
- if cell(i,column_with[key]) == val
- 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|
- if val == j
- x = key
- end
- }
- tmp[x] = cell(i,j)
- }
- if result_array
- result << self.row(i)
- else
- result << tmp
- end
- end
- end
- end # :conditions
- }
- end
- end
- result
- end
+ #def find(*args)
+ # result_array = false
+ # args.each {|arg,val|
+ # if arg.class == Hash
+ # arg.each { |hkey,hval|
+ # if hkey == :array and hval == true
+ # result_array = true
+ # end
+ # }
+ # end
+ # }
+ # column_with = {}
+ # 1.upto(last_column) do |col|
+ # column_with[cell(@header_line,col)] = col
+ # end
+ # result = Array.new
+ # #-- id
+ # if args[0].class == Fixnum
+ # rownum = args[0]
+ # tmp = {}
+ # 1.upto(self.row(rownum).size) {|j|
+ # x = ''
+ # column_with.each { |key,val|
+ # if val == j
+ # x = key
+ # end
+ # }
+ # tmp[x] = cell(rownum,j)
+ # }
+ # result = [ tmp ] # row(rownum)
+ # #-- :all
+ # elsif args[0] == :all
+ # if args[1].class == Hash
+ # args[1].each {|key,val|
+ # if key == :conditions
+ # column_with = {}
+ # 1.upto(last_column) do |col|
+ # column_with[cell(@header_line,col)] = col
+ # end
+ # conditions = val
+ # first_row.upto(last_row) do |i|
+ # # are all conditions met?
+ # found = 1
+ # conditions.each { |key,val|
+ # if cell(i,column_with[key]) == val
+ # 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|
+ # if val == j
+ # x = key
+ # end
+ # }
+ # tmp[x] = cell(i,j)
+ # }
+ # if result_array
+ # result << self.row(i)
+ # else
+ # result << tmp
+ # end
+ # end
+ # end
+ # end # :conditions
+ # }
+ # end
+ # end
+ # result
+ #end
private
# read all cells in a sheet
def read_cells(sheet=nil)
sheet = @default_sheet unless sheet