`
ali
  • 浏览: 53036 次
  • 性别: 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
分享到:
评论

相关推荐

    BURNINTEST--硬件检测工具

    PassMark BurnInTest V5.3 Copyright (C) 1999-2008 PassMark Software All Rights Reserved http://www.passmark.com Overview ======== Passmark's BurnInTest is a software tool that allows all the major sub...

    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

    eNetTest 网管内网单机测速工具

    eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速...

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

    Modeltest 使用说明

    Modeltest 使用说明 Modeltest 是一个选择核苷酸替代模型的软件,通过和 PAUP 配合使用,可以选择出合适的 MODEL,并同时计算出相关参数。下面是 Modeltest 的使用说明和相关知识点: 一、Modeltest 概述 * Model...

    Parasoft C++Test 9.5

    Parasoft C++Test 9.5是一款由Parasoft公司开发的专业自动化白盒测试工具,专注于C++编程语言的测试。它集成了多种测试策略,包括静态代码分析、动态测试、单元测试、代码覆盖率分析以及缺陷预防等功能,旨在提高...

    speedtest服务器搭建教程

    (speedtest服务器搭建教程) 本篇教程旨在指导读者搭建speedtest服务器,通过安装PHPStudy、配置WNMP和Nginx、下载并配置speedtest测速平台,实现本地测速功能。 一、 PHPStudy 安装和配置 PHPStudy 是一个集成...

    ECU-Test高级教程

    ### ECU-Test高级教程知识点解析 #### 一、ECU-Test概述 **ECU-Test**是一款专为汽车电子控制单元(ECU)开发与验证而设计的强大工具。它支持自动化测试流程,并能有效管理和控制整个测试环境,极大地提高了ECU开发...

    google test框架使用中文文档

    Google Test是Google开发的一款强大的C++测试框架,它使得C++开发者能够编写单元测试和集成测试,以确保代码的质量和稳定性。本文档将详细介绍Google Test框架的使用方法,包括基本概念、断言、测试套件、测试用例、...

    Parasoftc++ Test 9.0破解文件

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

    Test Track Client 使用说明(新)

    Test Track Client 使用说明 Test Track 是一个功能强大且实用的BUG管理软件,能够帮助测试工程师、开发工程师、开发主管和项目管理人员等角色更好地管理和跟踪项目中的BUG。该软件具有强大的管理功能和灵活的配置...

    Test Bench 经典教程.rar

    Test Bench是电子设计自动化(EDA)领域中的一个重要概念,主要用于验证数字集成电路的设计。在硬件描述语言(HDL,如Verilog或VHDL)中,Test Bench是模拟真实硬件环境来测试设计功能的一个虚拟平台。它能帮助...

    CAN Test V2.53软件使用说明

    CAN Test V2.53 软件使用说明 CAN Test V2.53 软件是一款功能强大且易用的CAN总线测试工具,旨在帮助用户快速地测试和诊断CAN总线设备。以下是CAN Test V2.53 软件使用说明的详细知识点: 软件安装 CAN Test 软件...

    ECU-TEST基本教程

    ### ECU-TEST基本教程知识点概述 #### 一、ECU-TEST简介 ECU-TEST是一款由Vector公司开发的专业汽车电子控制单元(Electronic Control Unit, ECU)测试工具,它能够实现对ECU进行全面而深入的功能性测试,并且支持...

    Parasoft C++ test 9.2官方用户手册_eclipse_中文版

    《Parasoft C++test 9.2官方用户手册_eclipse_中文版》是一本详尽的指南,专为使用C++test工具的开发者提供在Eclipse集成开发环境中的使用方法。C++test是一款强大的静态代码分析和单元测试工具,旨在提高C++软件的...

    test_batch_test_batch_cifar10_batch_

    cifar-10数据集由10个类的60000个32x32彩色图像组成,每个类有6000个图像。有50000个训练图像和10000个测试图像。数据集分为五个训练批次和一个测试...具体:test.mat文件,该训练集可以用于图片识别,非负矩阵分解等。

    PortTest串口调试工具

    **串口调试工具——PortTest详解** 在计算机通信领域,串行端口(Serial Port)是一种常见的硬件接口,用于设备间的通信。PortTest是一款专为串口调试设计的实用工具,它可以帮助用户检测和测试串口通讯功能,确保...

    C++test(VS2010插件版)简明操作手册-亲测可用.doc

    C++test简明操作手册 C++test是一款功能强大的测试工具,旨在帮助开发者编写高质量的代码。作为Parasoft公司的旗舰产品,C++test提供了全面的测试解决方案,涵盖了静态测试、动态测试、测试用例生成等多方面的测试...

Global site tag (gtag.js) - Google Analytics