roo 在ruby中处理和操作excel

Roo这个gem在处理excel中以及有很长时间,而且生命力很强,作者仍更新,比如支持ruby1.9

个人认为有必要在这个专辑了,给这个gem记录一笔,

[b]安装[/b]


#1.8版
gem sources -a http://gems.github.com/

sudo gem install roo -v 1.3.11


使用如下:


require 'rubygems'
require 'roo'

s = Openoffice.new("myspreadsheet.ods") # creates an Openoffice Spreadsheet instance
s = Excel.new("myspreadsheet.xls") # creates an Excel Spreadsheet instance
s = Google.new("myspreadsheetkey_at_google") # creates an Google Spreadsheet instance
s = Excelx.new("myspreadsheet.xlsx") # creates an Excel Spreadsheet instance for Excel .xlsx files

s.default_sheet = s.sheets.first # first sheet in the spreadsheet file will be used

# s.sheet is an array which holds the names of the sheets within
# a spreadsheet.
# you can also write
# s.default_sheet = s.sheets[3] or
# s.default_sheet = 'Sheet 3'

s.cell(1,1) # returns the content of the first row/first cell in the sheet
s.cell('A',1) # same cell
s.cell(1,'A') # same cell
s.cell(1,'A',s.sheets[0]) # same cell

# almost all methods have an optional argument 'sheet'.
# If this parameter is omitted, the default_sheet will be used.

s.info # prints infos about the spreadsheet file

s.first_row # the number of the first row
s.last_row # the number of the last row
s.first_column # the number of the first column
s.last_column # the number of the last column

# limited font information is available

s.font(1,1).bold?
s.font(1,1).italic?
s.font(1,1).underline?




官网tutorial如下:
[url]http://roo.rubyforge.org[/url]

话说,[url=http://hlee.iteye.com]老猪[/url]很多时候确实只知道copy官网,别人说的对,俺还必须承认。抄一点也是学习,为啥不抄,骂一骂也是关注,为啥不骂,嘿嘿
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值