- 浏览: 51946 次
- 性别:
- 来自: 广州
最近访客 更多访客>>
文章分类
最新评论
-
carlosbdw:
谢谢,去试试。
轻轻地改造activescafflod的crate 方法,加快输入数据的速度。 -
rainchen:
我记得可以直接用@user.clone,会自动去掉主键ID
轻轻地改造activescafflod的crate 方法,加快输入数据的速度。 -
gigix:
carlosbdw 写道我觉得create应该增加一种复制cr ...
轻轻地改造activescafflod的crate 方法,加快输入数据的速度。 -
carlosbdw:
我觉得create应该增加一种复制create,可以复制一条记 ...
轻轻地改造activescafflod的crate 方法,加快输入数据的速度。 -
cvu:
这样的效果的确能给用户更好的体验。我这儿也分享一个有关Acti ...
轻轻地改造activescafflod的crate 方法,加快输入数据的速度。
roo
Get Version 0.8.5
What
This gem allows you to access the content of
* Open-office spreadsheets (.ods)
* Excel spreadsheets (.xls) and
* Google (online) spreadsheets
Installing
[sudo] gem install roo
The basics
Currently only read-access is implemented. Google spreadsheets can be read and written.
Please note that the upper left cell of a table is numbered (1,1) or (1,’A’) (not 0,0).
Demonstration of usage
Supposed you have created this spreadsheet:
which includes the amount of work you have done for a customer.
You can now process this spreadsheet with the following sample code.
1 require 'rubygems'
2 require 'roo'
3
4 HOURLY_RATE = 123.45
5
6 oo = Openoffice.new("simple_spreadsheet.ods")
7 oo.default_sheet = oo.sheets.first
8 4.upto(12) do |line|
9 date = oo.cell(line,'A')
10 start_time = oo.cell(line,'B')
11 end_time = oo.cell(line,'C')
12 pause = oo.cell(line,'D')
13 sum = (end_time - start_time) - pause
14 comment = oo.cell(line,'F')
15 amount = sum * HOURLY_RATE
16 if date
17 puts "#{date}\t#{sum}\t#{amount}\t#{comment}"
18 end
19 end
which produces this output
2007-05-07 1.0 123.45 Task 1
2007-05-07 1.75 216.0375 Task 1
2007-05-07 1.0 123.45 Task 2
2007-05-08 1.0 123.45 Task 2
2007-05-08 1.0 123.45 Task 3
2007-05-08 0.5 61.725 Task 3
2007-05-14 0.5 61.725 Task 3
2007-05-14 0.5 61.725 Task 3
2007-05-15 1.0 123.45 Task 3
With the methods
first_column, last_column, first_row and last_row
you can change line 8 from
4.upto(12) do |line|
to
4.upto(oo.last_row) do |line|
Cell Types
oo.celltype(row,col) returns the type of a cell. Currently these types will be returned:
* :float
* :string
* :date
* :percentage
* :formula
Write access
Cells in a google spreadsheet can be read or written.
To write to a cell use the method call:
oo.set_value(row, col, value)
There is an example in the examples folder which illustrates write access.
Formulas
Formulas in Openoffice- and Google-Spreadsheets can be handled.
oo.celltype(row,col) returns :formula if there is a formula in this cell.
oo.formula?(row,col) returns true if there is a formula
oo.formula(row,col) returns the formula in this cell in a string variable (like ”=SUM”). You can do whatever you want with this expression. If there is no formula in this cell nil is returned.
oo.cell(row,col) returns the computed result of the formula (as it was saved in the file, no recalculation is done in this Gem).
oo.formulas returns all formulas in the selected spreadsheet in an array like this:
[[1,2,"=SUM(.A1:.B1)"],
[1,3,"=SIN(.C3)"],
[1,4,"=COS(.D4)"]]
Each entry consists of the elements row, col, formula.
Note: oo.cell(row,col) is the same for ordinary cells and formulas. So you can use the computated value of a formula. If you have to distinguish if a cell is a formula use #formula?
Please note: formulas in Excel-Spreadsheets cannot be handled (this is another gem, see: “Thanks”)
YAML-Output
You can generate YAML-Output from your spreadsheet data. The method is called:
oo.to_yaml # => produces YAML output from the entire default spreadsheet oo.to_yaml({“myattribute1” => “myvalue1”, “myattribute2” => “myvalue2”) # => YAML output with additional attributes oo.to_yaml({..}, 2,10, 300,10) # => only the rectangle from row 2, column 10 to row 300, column 10 will be returned
If you omit one or more parameters the maximum boundaries of your spreadsheet will be used.
With the YAML output you can import your data in a Ruby on Rails application in a manner that spreadsheet data can accessed in a Rails application.
This is not limited to a Rails application – you can also do further evaluations with your data.
CSV-Output
You can generate output in csv-format with
oo.to_csv
to write to the standard output or
oo.to_csv("somefile.txt")
to write to a file.
Using MS-Excel spreadsheets
You can also access MS-Excel spreadsheat.
Replace Openoffice with
oo = Excel.new("simple_spreadsheet.xls").
All methode are the same for OpenOffice-, Excel- and Google-objects. The only difference is the setting of the default-worksheet. OpenOffice uses the name of the worksheet whereas Excel needs the index of the worksheet (1,2,3,..).
Formulas can only be handled in OpenOffice- and Google-spreadsheets.
Features in OpenOffice/Excel/Google:
feature Open Office Excel Google
formulas yes no yes
celltype :percentage :float :percentage
access read-only read-only read and write
The parseexcel-gem does not support the celltype ‘percentage’ but uses ‘float’ instead. This is not a big deal as you can also use ‘float’ to do calculations with these cells.
Old .sxc OpenOffice files are currently not supported – please load these files and save it as an “OpenDocument Spreadsheet (.ods)”.
Instead of a filename the Google#new method needs the ‘key’ of a Google-Spreadsheet. This key can be copied from the URL when you display a google spreadsheet with your browser.
If you want to use Google spreadsheets you must either have set the environment variables ‘GOOGLE_MAIL’ and ‘GOOGLE_PASSWORD’ or you pass the Google-name and -password to the Google#new method.
Setting these variables can be done if you add these lines to your ~/.bashrc (or similar setup file within other shells):
export GOOGLE_MAIL="yourname@gmail.com"
export GOOGLE_PASSWORD="mysecretpassword"
This gem does not check if you are allowed to access a specific google spreadsheet. If it’s not your own spreadsheet or you are not allowed to read or wwrite to a spreadsheet the behaviour is not defined (but it will not work ;-) ).
Accessing Spreadsheet over the Web
You can even read openoffice or excel-spreadsheets from a http-address:
oo = Excel.new("http://www.somedomain.com/simple_spreadsheet.xls").
oo = Openoffice.new("http://www.somedomain.com/simple_spreadsheet.ods").
or a zipped file:
oo = Excel.new("http://www.somedomain.com/simple_spreadsheet.xls.zip",:zip).
oo = Openoffice.new("http://www.somedomain.com/simple_spreadsheet.ods.zip",:zip).
after working with a spreadsheet from the web you have to call
oo.remove_tmp
to delete the temporary local copy of the spreadsheet file. If you dont call this method you will have subdirectories names ‘oo_xxxxx’ which you can remove manually. Calling remove_tmp is not the best solution to clean temporary files – i will provide a better solution in the next releases.
Remote Access
You can even access your spreadsheet data from a remote machine via SOAP. The examples directory shows a little example how to do this. If you like, you can extend these functions or restrict the access to certain cells. Remote access with SOAP is nothing specific to roo, you can do this with every Rub object, but i thought it would nice to give an example what could be done with roo.
With Ruby on Rails
You can even use roo within your web application. On the project page there is an example named roorails.tgz, which shows a short example how you can display a spreadsheet table on a web page (see files app/controllers/spreadsheet_controller.rb and app/views/spreadsheet/index.rhtml).
To display this example:
* unpack in any directory
* cd roorails
* ruby script/server
* point your browser to http://localhost:3000/spreadsheet/
Where is it used?
How do you use roo? What are you doing with roo?
* The author of this gem uses roo for the generation of weekly reports which are (automatically) sent to his customers (Thomas Preymesser, Homepage: www.thopre.com, Blog: thopre.wordpress.com, email me: thopre@gmail.com)
If you have an interesting application where you use roo then write me a short description of your project and i will publish it here (write, if your email-address should be published or not).
Or you can write directly in the project wiki at http://roo.rubyforge.org/wiki/wiki.pl?Who’s_Using_Roo
If you don’t want to publish the details you can also write me an email and state, that it should not be published – i am just curious to hear, where it is used.
Documentation
rdoc
Only the Openoffice- and Excel-parts of this gem are currently working – the Google-Spreadheets are experimental and are currently NOT working. Don’t use this!
Google spreadsheet can now be used.
Feature Requests / Bugs
Submit Feature Requests and bugs here: http://rubyforge.org/tracker/?group_id=3729
Forum
International Group: http://groups.google.com/group/ruby-roo
Deutschsprachige Group: http://groups.google.com/group/ruby-roo-de
Wiki
http://roo.rubyforge.org/wiki/wiki.pl
How to submit patches
Read the 8 steps for fixing other people’s code and for section 8b: Submit patch to Google Groups, use the Google Group above.
<!— The trunk repository is svn://rubyforge.org/var/svn/gorank/trunk for anonymous access. —>
License
This code is free to use under the terms of Ruby
Contact
Comments are welcome. Send an email to Thomas Preymesser.
Thanks
* Dr Nic Williams for his wonderful gem ‘newgem’ which makes it very convenient to create, manage and publish Ruby gems
* for the Excel-part the spreadsheet gem is used. My functions are a convenient wrapper around the functions of this gem
* Dirk Huth fürs Testen unter Windows
Get Version 0.8.5
What
This gem allows you to access the content of
* Open-office spreadsheets (.ods)
* Excel spreadsheets (.xls) and
* Google (online) spreadsheets
Installing
[sudo] gem install roo
The basics
Currently only read-access is implemented. Google spreadsheets can be read and written.
Please note that the upper left cell of a table is numbered (1,1) or (1,’A’) (not 0,0).
Demonstration of usage
Supposed you have created this spreadsheet:
which includes the amount of work you have done for a customer.
You can now process this spreadsheet with the following sample code.
1 require 'rubygems'
2 require 'roo'
3
4 HOURLY_RATE = 123.45
5
6 oo = Openoffice.new("simple_spreadsheet.ods")
7 oo.default_sheet = oo.sheets.first
8 4.upto(12) do |line|
9 date = oo.cell(line,'A')
10 start_time = oo.cell(line,'B')
11 end_time = oo.cell(line,'C')
12 pause = oo.cell(line,'D')
13 sum = (end_time - start_time) - pause
14 comment = oo.cell(line,'F')
15 amount = sum * HOURLY_RATE
16 if date
17 puts "#{date}\t#{sum}\t#{amount}\t#{comment}"
18 end
19 end
which produces this output
2007-05-07 1.0 123.45 Task 1
2007-05-07 1.75 216.0375 Task 1
2007-05-07 1.0 123.45 Task 2
2007-05-08 1.0 123.45 Task 2
2007-05-08 1.0 123.45 Task 3
2007-05-08 0.5 61.725 Task 3
2007-05-14 0.5 61.725 Task 3
2007-05-14 0.5 61.725 Task 3
2007-05-15 1.0 123.45 Task 3
With the methods
first_column, last_column, first_row and last_row
you can change line 8 from
4.upto(12) do |line|
to
4.upto(oo.last_row) do |line|
Cell Types
oo.celltype(row,col) returns the type of a cell. Currently these types will be returned:
* :float
* :string
* :date
* :percentage
* :formula
Write access
Cells in a google spreadsheet can be read or written.
To write to a cell use the method call:
oo.set_value(row, col, value)
There is an example in the examples folder which illustrates write access.
Formulas
Formulas in Openoffice- and Google-Spreadsheets can be handled.
oo.celltype(row,col) returns :formula if there is a formula in this cell.
oo.formula?(row,col) returns true if there is a formula
oo.formula(row,col) returns the formula in this cell in a string variable (like ”=SUM”). You can do whatever you want with this expression. If there is no formula in this cell nil is returned.
oo.cell(row,col) returns the computed result of the formula (as it was saved in the file, no recalculation is done in this Gem).
oo.formulas returns all formulas in the selected spreadsheet in an array like this:
[[1,2,"=SUM(.A1:.B1)"],
[1,3,"=SIN(.C3)"],
[1,4,"=COS(.D4)"]]
Each entry consists of the elements row, col, formula.
Note: oo.cell(row,col) is the same for ordinary cells and formulas. So you can use the computated value of a formula. If you have to distinguish if a cell is a formula use #formula?
Please note: formulas in Excel-Spreadsheets cannot be handled (this is another gem, see: “Thanks”)
YAML-Output
You can generate YAML-Output from your spreadsheet data. The method is called:
oo.to_yaml # => produces YAML output from the entire default spreadsheet oo.to_yaml({“myattribute1” => “myvalue1”, “myattribute2” => “myvalue2”) # => YAML output with additional attributes oo.to_yaml({..}, 2,10, 300,10) # => only the rectangle from row 2, column 10 to row 300, column 10 will be returned
If you omit one or more parameters the maximum boundaries of your spreadsheet will be used.
With the YAML output you can import your data in a Ruby on Rails application in a manner that spreadsheet data can accessed in a Rails application.
This is not limited to a Rails application – you can also do further evaluations with your data.
CSV-Output
You can generate output in csv-format with
oo.to_csv
to write to the standard output or
oo.to_csv("somefile.txt")
to write to a file.
Using MS-Excel spreadsheets
You can also access MS-Excel spreadsheat.
Replace Openoffice with
oo = Excel.new("simple_spreadsheet.xls").
All methode are the same for OpenOffice-, Excel- and Google-objects. The only difference is the setting of the default-worksheet. OpenOffice uses the name of the worksheet whereas Excel needs the index of the worksheet (1,2,3,..).
Formulas can only be handled in OpenOffice- and Google-spreadsheets.
Features in OpenOffice/Excel/Google:
feature Open Office Excel Google
formulas yes no yes
celltype :percentage :float :percentage
access read-only read-only read and write
The parseexcel-gem does not support the celltype ‘percentage’ but uses ‘float’ instead. This is not a big deal as you can also use ‘float’ to do calculations with these cells.
Old .sxc OpenOffice files are currently not supported – please load these files and save it as an “OpenDocument Spreadsheet (.ods)”.
Instead of a filename the Google#new method needs the ‘key’ of a Google-Spreadsheet. This key can be copied from the URL when you display a google spreadsheet with your browser.
If you want to use Google spreadsheets you must either have set the environment variables ‘GOOGLE_MAIL’ and ‘GOOGLE_PASSWORD’ or you pass the Google-name and -password to the Google#new method.
Setting these variables can be done if you add these lines to your ~/.bashrc (or similar setup file within other shells):
export GOOGLE_MAIL="yourname@gmail.com"
export GOOGLE_PASSWORD="mysecretpassword"
This gem does not check if you are allowed to access a specific google spreadsheet. If it’s not your own spreadsheet or you are not allowed to read or wwrite to a spreadsheet the behaviour is not defined (but it will not work ;-) ).
Accessing Spreadsheet over the Web
You can even read openoffice or excel-spreadsheets from a http-address:
oo = Excel.new("http://www.somedomain.com/simple_spreadsheet.xls").
oo = Openoffice.new("http://www.somedomain.com/simple_spreadsheet.ods").
or a zipped file:
oo = Excel.new("http://www.somedomain.com/simple_spreadsheet.xls.zip",:zip).
oo = Openoffice.new("http://www.somedomain.com/simple_spreadsheet.ods.zip",:zip).
after working with a spreadsheet from the web you have to call
oo.remove_tmp
to delete the temporary local copy of the spreadsheet file. If you dont call this method you will have subdirectories names ‘oo_xxxxx’ which you can remove manually. Calling remove_tmp is not the best solution to clean temporary files – i will provide a better solution in the next releases.
Remote Access
You can even access your spreadsheet data from a remote machine via SOAP. The examples directory shows a little example how to do this. If you like, you can extend these functions or restrict the access to certain cells. Remote access with SOAP is nothing specific to roo, you can do this with every Rub object, but i thought it would nice to give an example what could be done with roo.
With Ruby on Rails
You can even use roo within your web application. On the project page there is an example named roorails.tgz, which shows a short example how you can display a spreadsheet table on a web page (see files app/controllers/spreadsheet_controller.rb and app/views/spreadsheet/index.rhtml).
To display this example:
* unpack in any directory
* cd roorails
* ruby script/server
* point your browser to http://localhost:3000/spreadsheet/
Where is it used?
How do you use roo? What are you doing with roo?
* The author of this gem uses roo for the generation of weekly reports which are (automatically) sent to his customers (Thomas Preymesser, Homepage: www.thopre.com, Blog: thopre.wordpress.com, email me: thopre@gmail.com)
If you have an interesting application where you use roo then write me a short description of your project and i will publish it here (write, if your email-address should be published or not).
Or you can write directly in the project wiki at http://roo.rubyforge.org/wiki/wiki.pl?Who’s_Using_Roo
If you don’t want to publish the details you can also write me an email and state, that it should not be published – i am just curious to hear, where it is used.
Documentation
rdoc
Only the Openoffice- and Excel-parts of this gem are currently working – the Google-Spreadheets are experimental and are currently NOT working. Don’t use this!
Google spreadsheet can now be used.
Feature Requests / Bugs
Submit Feature Requests and bugs here: http://rubyforge.org/tracker/?group_id=3729
Forum
International Group: http://groups.google.com/group/ruby-roo
Deutschsprachige Group: http://groups.google.com/group/ruby-roo-de
Wiki
http://roo.rubyforge.org/wiki/wiki.pl
How to submit patches
Read the 8 steps for fixing other people’s code and for section 8b: Submit patch to Google Groups, use the Google Group above.
<!— The trunk repository is svn://rubyforge.org/var/svn/gorank/trunk for anonymous access. —>
License
This code is free to use under the terms of Ruby
Contact
Comments are welcome. Send an email to Thomas Preymesser.
Thanks
* Dr Nic Williams for his wonderful gem ‘newgem’ which makes it very convenient to create, manage and publish Ruby gems
* for the Excel-part the spreadsheet gem is used. My functions are a convenient wrapper around the functions of this gem
* Dirk Huth fürs Testen unter Windows
发表评论
-
aliyun ubuntu_12.04_64bit 部署 rails
2012-12-27 13:47 1182apt-get updatesudo apt-ge ... -
ubuntu12 rvm rails thin
2012-05-15 21:09 2090# Nginx sudo apt-get instal ... -
rails on centos
2008-09-17 11:34 18871.安装gcc yum install gcc-c++ yum ... -
轻轻地改造activescafflod的crate 方法,加快输入数据的速度。
2008-04-27 14:47 1102有些时候我们得输入一批有共同属性的记录,比如同一个品牌的商品。 ... -
好用难记的linux命令(ubutun)
2008-03-06 15:50 1223以管理员身份打开文件管理器 gksu nautilus 查看硬 ... -
paginate_by_sql(原为find_by_sql)中如何避免sql 注入
2008-02-28 15:56 1644在一些不得不使用find_by_sql的场合,何如避免sql注 ... -
为 ext1.1 的 gird 添加自定义每页记录条数功能.顺便show一下我们在开发的项目.
2008-01-30 13:51 1525现在同事们要求能自定义Grid中每页记录条数功能,由于项目一开 ... -
apache2 mongrel
2008-01-29 17:32 1353sudo apt-get install apache2 su ... -
转载 ubuntu 7.04上rails deploment
2008-01-29 10:45 11971.安装Ruby 1.8.6 步骤: 下载ruby源 ... -
十四歲巨變 淬煉領袖格局
2007-12-15 09:40 34十四歲那年,經歷家道 ... -
他的兩句話:勿得罪人、勿遭人忌!
2007-12-15 09:26 49我見過許多站在最高峰 ... -
在ubuntu上安装Rails开发环境(转载)
2007-09-11 09:21 1511ubuntu上安装rails环境走了不少弯路,今天在网上搜到一 ... -
假如有一天我做了老板
2007-07-18 11:15 1281假如我有一天做了老板 ---工作后有感 1.我会为每位新员 ... -
一些我整天用又整天忘了怎么拼写的单词
2007-06-21 14:19 741@@IDENTITY T-sql中的保存最新插入记录id的全局 ... -
IE 6.0 赔偿我的时间损失~~~!
2007-06-18 17:43 1325IE浏览器有个bug,如果img元素间存在空格(指在html源 ... -
我也来记录常用正则表达式
2007-06-18 17:43 1797转载自microsoft.com ...
相关推荐
最好用的单元测试工具,除了这里你是找不到9.0版本的破解的。 ... 独立的版本破解: ... 把lic_client.jar复制到 ... c:\Program Files (x86)\Parasoft\Test\9.0\plugins\...这个是:plugins-c++Test For Visual Studio.7z
c:\Program Files (x86)\Parasoft\C++test for Visual Studio\9.0\plugins\ 这个目录中 把plugins-Test for Virsual Studio.7z 中的文件覆盖到 c:\Program Files (x86)\Parasoft\Test for Visual Studio\9.0\...
eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速...
C++test 文档库包含以下各项: • C++test 用户手册 ( 当前指南): C++test 用户手册(当前指南):解释如何使用在 Eclipse 上构 建的 C++test 功能(如果您拥有单机版的 C++test),或者如何使用添加到 Eclipse 的...
test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3
This document describes in detail available test cases for SUPL V2.0, OMA-ERP-SUPL-V2_0. URL:http://www.openmobilealliance.org/ The test cases are split in two categories, conformance and ...
内含 C++Test 两个版本的软件 、 VC++6.0(可以在Win 10 环境使用) 、 C++ Test 许可证书 、C语言编码规范(试用) 详细情况请见文章里面包含使用该软件的步骤及配置过程...
1.安装,安装时不能开vs,会安装失败 2.尽量选择独立安装一个配置cpptest_9_5 2.复制xtest.lic.client.dll...X:\Program Files\Parasoft\Test for Visual Studio\9.5\plugins\com.parasoft.xtest.libs.vstudio\Parasoft
test python programming language
Getting a high score on the GRE Math Subject Test isn’t about memorizing everything there is to know about math–it’s about targeting your test preparation. We teach you only the information you’ll...
software test automation effective use of test execution 自动化测试
LMS Test Lab是一款综合全面的振动噪声试验解决方案,其独特的工作流程设计界面,使得LMS Test Lab为系统的易用性、高效率和数据一致性确立了新的标准。为未来的振动噪声试验方式,提供了新的突破。 LMS Test Lab ...
Embark on the exciting journey of test automation, execution, and reporting in Test Studio with this practical tutorial Overview Learn to use Test Studio to design and automate tests valued with ...
C++test序列号 V1.3 C++Test是一个C/C++单元级测试工具,自动测试C/C++类、函数或部件,而不需要编写测试用例、测试驱动程序或桩调用代码。C++Test能够自动测试代码构造(白盒测试)、测试代码的功能性(黑盒测试)和...
Building a Successful Board-Test Strategy A successful test strategy is a byproduct of overall product life-cycle management. Anyone building such a strategy must consider the product's development, ...
Test Specification: 4.0.6 Self Test Tool: 5.0.0 Interoperability Test Scenario: 4.0.4 If you are going to run test from now, please use the newest version. However, in case the test specification ...
C++Test是一个C/C++单元测试工具,自动测试任何C/C++类、函数或部件,而不需要您编写一个测试用例、测试驱动程序或桩调用。C++Test能够自动测试代码构造(白盒测试)、测试代码的功能性(黑盒测试)和维护代码的完整...
从e:\mysql\test.sql中将文件中的SQL语句导入数据库中: 1.从命令行进入mysql,然后用命令CREATE DATABASE test2;创建数据库test2。 2.退出mysql 可以输入命令exit;或者quit; 3.在CMD中输入下列命令: c:\>...
最好用的单元测试工具,除了这里你是找不到9.0版本的破解的。 ... 独立的版本破解: ... 把lic_client.jar复制到 ... c:\Program Files (x86)\Parasoft\Test\9.0\plugins\...这个是:( plugins-Test for Virsual Studio.7z )
把程序目录bin下:用TestComplete替换掉原有TestComplete 然后启动替换后的程序。 首次登陆按照如下设置: User Name: Eternal Shield Company Name: HOMEZ, Inc. Registration Code: 558B8FDC-6BF62C26-F83BF6FF