`
ali
  • 浏览: 51946 次
  • 性别: Icon_minigender_1
  • 来自: 广州
最近访客 更多访客>>
社区版块
存档分类
最新评论

test

阅读更多
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
分享到:
评论

相关推荐

    parasoft c++Test9.0破解

    最好用的单元测试工具,除了这里你是找不到9.0版本的破解的。 ... 独立的版本破解: ... 把lic_client.jar复制到 ... c:\Program Files (x86)\Parasoft\Test\9.0\plugins\...这个是:plugins-c++Test For Visual Studio.7z

    Parasoft c++Test9.0破解文件

    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 网管内网单机测速工具eNetTest 网管内网单机测速...

    C++Test学习文档

    C++test 文档库包含以下各项: • C++test 用户手册 ( 当前指南): C++test 用户手册(当前指南):解释如何使用在 Eclipse 上构 建的 C++test 功能(如果您拥有单机版的 C++test),或者如何使用添加到 Eclipse 的...

    test3test3test3test3test3test3

    test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3

    Enabler Test Specification for SUPL V2.0

    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 7.2及9.2版本(附带许可证)学习资料!!

    内含 C++Test 两个版本的软件 、 VC++6.0(可以在Win 10 环境使用) 、 C++ Test 许可证书 、C语言编码规范(试用) 详细情况请见文章里面包含使用该软件的步骤及配置过程...

    c++ test9.5破解工具

    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.py_pythontest_python_

    test python programming language

    Cracking the GRE Mathematics Subject Test 4th Edition.pdf

    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 自动化测试

    software test automation effective use of test execution 自动化测试

    LMS_Test.Lab中文操作指南.pdf

    LMS Test Lab是一款综合全面的振动噪声试验解决方案,其独特的工作流程设计界面,使得LMS Test Lab为系统的易用性、高效率和数据一致性确立了新的标准。为未来的振动噪声试验方式,提供了新的突破。 LMS Test Lab ...

    [Test Studio] 软件测试入门教程 (Test Studio 实现) (英文版)

    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序列号 V1.3 C++Test是一个C/C++单元级测试工具,自动测试C/C++类、函数或部件,而不需要编写测试用例、测试驱动程序或桩调用代码。C++Test能够自动测试代码构造(白盒测试)、测试代码的功能性(黑盒测试)和...

    Building a Successful Board-Test Strategy 2nd Edition

    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, ...

    IPv6_Ready Self_Test

    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++Test是一个C/C++单元测试工具,自动测试任何C/C++类、函数或部件,而不需要您编写一个测试用例、测试驱动程序或桩调用。C++Test能够自动测试代码构造(白盒测试)、测试代码的功能性(黑盒测试)和维护代码的完整...

    workTest.rar

    从e:\mysql\test.sql中将文件中的SQL语句导入数据库中: 1.从命令行进入mysql,然后用命令CREATE DATABASE test2;创建数据库test2。 2.退出mysql 可以输入命令exit;或者quit; 3.在CMD中输入下列命令: c:\&gt;...

    Parasoftc++ Test 9.0破解文件

    最好用的单元测试工具,除了这里你是找不到9.0版本的破解的。 ... 独立的版本破解: ... 把lic_client.jar复制到 ... c:\Program Files (x86)\Parasoft\Test\9.0\plugins\...这个是:( plugins-Test for Virsual Studio.7z )

    TestComplete 7 破解

    把程序目录bin下:用TestComplete替换掉原有TestComplete 然后启动替换后的程序。 首次登陆按照如下设置: User Name: Eternal Shield Company Name: HOMEZ, Inc. Registration Code: 558B8FDC-6BF62C26-F83BF6FF

Global site tag (gtag.js) - Google Analytics