Johnathon22
Johnathon22

Reputation: 341

Ruby, spreadsheet by key

I am using ruby to call spreadsheet_by_key from a google document. The first page that I call works great, however when i try to duplicate it and use the second tab on the page it does not work. Let me better explain with some examples.

I am using:

data = session.spreadsheet_by_key("spreadsheetkeygoeshere").worksheets[0]

# Get Graph-Data
(2..data.num_rows).each do |column|
    key = data[column, 10]
    title = data[column, 2]
    current = data[column, 3]
    goal = data[column, 4]

    send_event(key, title: title, min: 0, max: goal, value: current)

end

This works great and returns all of the expected values. Here is the problem I am having.. this is on the page 1 the first page that loads when you open google docs. Now lets say I wan't to make a new spreadsheet on the same doc just under a new tab with a different name and display that data as well

Here is how i change the code: data1 = session.spreadsheet_by_key("spreadsheetkeygoeshere").worksheets[1]

# Get Graph-Data
(2..data1.num_rows).each do |column|
    key = data[column, 10]
    puts key
    title = data[column, 1]
    current = data[column, 5]
    goal = data[column, 6]

    send_event(key, title: title, min: 0, max: goal, value: current)
end

SO i changed the .worksheets[0] to .worksheets[1] also i changed (2..data.num_rows) to (2..data1.num_rows)

Also i changed the data = to data1 =

Any ideas on what i am doing wrong that causes the second spreadsheet to not get pulled ? Any help is greatly appreciated.

Upvotes: 1

Views: 408

Answers (1)

Johnathon22
Johnathon22

Reputation: 341

What worked was Cameron suggestion. I went in and changed everything to just data = instead of data1= and that fixed the problem.

Upvotes: 2

Related Questions