This is a Ruby 1.8/1.9 library to read/write Google Spreadsheet.

How to install

$ gem sources -a http://gems.github.com
$ sudo gem install gimite-google-spreadsheet-ruby

How to use

Example:

 require "rubygems"
 require "google_spreadsheet"

# METHOD #1: With usual google username and password 
				# Logs in.
 				session = GoogleSpreadsheet.("[email protected]", "mypassword")

 # METHOD #2: Getting rid of usual google username and password,using google OAuth protocol
  			   	# 1) First generate OAuth consumer object with key and secret for your site by registering site with google  
  				 @consumer = OAuth::Consumer.new( "key","secret", {:site=>"https://agree2"})

  				# 2) Request token with OAuth
  				 @request_token=@consumer.get_request_token
				 session[:request_token] = @request_token
				 redirect_to @request_token.authorize_url

# 3) Create an oauth access token @oauth_access_token = @request_token.get_access_token @access_token = OAuth::AccessToken.new(@consumer, @oauth_access_token.token, @oauth_access_token.secret) # See these documents for details: # oauth.rubyforge.org/ # code.google.com/apis/accounts/docs/OAuth.html

# Creates GoogleSpreadsheet object with access_token session = GoogleSpreadsheet.authorized(@access_token)

# First worksheet of http://spreadsheets.google.com/ccc?key=pz7XtlQC-PYx-jrVMJErTcg&hl=en
ws = session.spreadsheet_by_key("pz7XtlQC-PYx-jrVMJErTcg").worksheets[0]
# Gets content of A2 cell.
p ws[2, 1] #==> "hoge"
# Changes content of cells. Changes are not sent to the server until you call ws.save().
ws[2, 1] = "foo"
ws[2, 2] = "bar"
ws.save()
# Dumps all cells.
for row in 1..ws.num_rows
  for col in 1..ws.num_cols
    p ws[row, col]
  end
end
# Yet another way to do so.
p ws.rows #==> [["fuga", ""], ["foo", "bar]]
# Reloads the worksheet to get changes by other clients.
ws.reload()

API document: gimite.net/gimite/rubymess/google-spreadsheet-ruby/

Source code

github.com/gimite/google-spreadsheet-ruby/tree/master

The license of this source is “New BSD Licence”

Supported environments

Ruby 1.8.x and Ruby 1.9.x. Checked with Ruby 1.8.7 and Ruby 1.9.1.

Author

Sprout Technology Services - sprout-technology.com