用ruby编辑google docs里面spreadsheet

已经有日本人写好的库供我们使用,所以是很方便的!

 

$ sudo gem install google-spreadsheet-ruby

 

使用方法

Example:

  require "rubygems"
  require "google_spreadsheet"

  # Logs in.
  # You can also use OAuth. See document of GoogleSpreadsheet.login_with_oauth for details.
  session = GoogleSpreadsheet.login("username@gmail.com", "mypassword")

  # 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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值