0
votes

I'm working with google-drive-ruby and trying to get a the worksheet_index when Looping through them:

# Login
@session = GoogleDrive.login("email", "password")

# Get Specific Spreadsheet
@spreadsheets = @session.spreadsheet_by_key("spreadsheet_key")

So now i have access to my Spreadsheet on Google Drive and can loop through the Worksheets:

<% @spreadsheets.worksheets.each do |c| %>
  <% c.title %>
<% end %>

All fine till now. My Problem is the actual Export of the document.

class GoogleDrive::Spreadsheet

export_as_file(local_path, format = nil, worksheet_index = nil)
# Exports the spreadsheet in format as a local file.

so to identify a specific worksheet I need that worksheet_index so i can export the right one.

And here I'm stuck, i searched for hours now but cant seem to find HOW i can get that worksheet_index. Is there another way ? What am I missing?

Edit

I need to be able to pull a specific Worksheet in my Spreadsheet. (Every Worksheet has a 'google given' index_key)

Github Repo of export_method

google-drive-ruby gem

Google Drive API Docs

1
@spreadsheets.worksheets.each_with_index do |c,worksheet_index| ?Gaurav Shah
That doesn't work actually, as Worksheets have their own index_key, so generating that based on a list doesn't work :/Mini John

1 Answers

0
votes

You need one of the gid values. Click in your google spreadsheet on one of the worsheettabs and in the url you'll see something like https://docs.google.com/spreadsheet/ccc?key=0AroM_DeBu-WAdFBEeVo2RlZ4ejhfdDetc&usp=drive_web#gid=3

Then in your script use this gid valua as your worksheet_index

@spreadsheets.export_as_file("c:\\test_sp3.xls", "xls", 3)

My experience is that it doesn't matter which gid you use als long as it is a valid one, the resulting xls (in this case) contains all the worksheets from your spreadsheet.

You can also leave the third parameter.

@spreadsheets.export_as_file("c:\\test_sp3.xls", "xls")