六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 58|回复: 0

roo 在ruby中处理和操作excel

[复制链接]

升级  40.8%

220

主题

220

主题

220

主题

进士

Rank: 4

积分
704
 楼主| 发表于 2013-1-29 22:39:08 | 显示全部楼层 |阅读模式
Roo这个gem在处理excel中以及有很长时间,而且生命力很强,作者仍更新,比如支持ruby1.9

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

安装

#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 instances = Excel.new("myspreadsheet.xls")           # creates an Excel Spreadsheet instances = Google.new("myspreadsheetkey_at_google") # creates an Google Spreadsheet instances = Excelx.new("myspreadsheet.xlsx")         # creates an Excel Spreadsheet instance for Excel .xlsx filess.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 sheets.cell('A',1)                               # same cells.cell(1,'A')                               # same cells.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 files.first_row                                 # the number of the first rows.last_row                                  # the number of the last rows.first_column                              # the number of the first columns.last_column                               # the number of the last column# limited font information is availables.font(1,1).bold?s.font(1,1).italic?s.font(1,1).underline?


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

话说,老猪很多时候确实只知道copy官网,别人说的对,俺还必须承认。抄一点也是学习,为啥不抄,骂一骂也是关注,为啥不骂,嘿嘿
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表