<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>
      roo
  </title>
  <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
<style>

</style>
  <script type="text/javascript">
    window.onload = function() {
      settings = {
          tl: { radius: 10 },
          tr: { radius: 10 },
          bl: { radius: 10 },
          br: { radius: 10 },
          antiAlias: true,
          autoPad: true,
          validTags: ["div"]
      }
      var versionBox = new curvyCorners(settings, document.getElementById("version"));
      versionBox.applyCornersToAll();
    }
  </script>
</head>
<body>
<div id="main">

    <h1>roo</h1>
    <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/roo"; return false'>
      Get Version
      <a href="http://rubyforge.org/projects/roo" class="numbers">0.6.0</a>
    </div>
    <h2>What</h2>


	<p>This gem allows you to access the content of open-office and Excel spreadsheets (.ods/.xls).</p>


	<h2>Installing</h2>


<pre syntax="ruby">sudo gem install roo</pre>

	<h2>The basics</h2>


	<p>Currently only read-access is implemented.</p>


	<p>Please note that the upper left cell of a table is numbered (1,1) or (1,&#8217;A&#8217;) (not 0,0).</p>


	<h2>Demonstration of usage</h2>


	<p>Supposed you have created this spreadsheet:</p>


	<p><img src="Screenshot-spreadsheet3.png"></p>


	<p>which includes the amount of work you have done for a customer.</p>


	<p>You can now process this spreadsheet with the following sample code.</p>


<pre>
<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
</code>
</pre>

	<p>which produces this output</p>


<pre>
<code>
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
</code>
</pre>

	<p>With the newly written methods</p>


<code>first_column</code>,
<code>last_column</code>,
<code>first_row</code> and
<code>last_row</code>

	<p>you can change line 8 from</p>


<pre>
<code>
  4.upto(12) do |line|
</code>
</pre>

	<p>to</p>


<pre>
<code>
  4.upto(oo.last_row) do |line|
</code>
</pre>

	<h3>Cell Types</h3>


	<p>oo.<strong>celltype</strong>(row,col) returns the type of a cell. Currently these types will be
returned:</p>


	<ul>
	<li>:float</li>
		<li>:string</li>
		<li>:date</li>
		<li>:percentage</li>
		<li>:formula</li>
	</ul>


	<h3>Formulas</h3>


	<p>Formulas in Openoffice-Spreadsheets can be handled.</p>


	<p>oo.<strong>celltype</strong>(row,col) returns :formula if there is a formula in this cell.</p>


	<p>oo.<strong>formula?</strong>(row,col) returns true if there is a formula</p>


	<p>oo.<strong>formula</strong>(row,col) returns the formula in this cell in a string variable (like &#8221;=<acronym title="[.A1:.M13]">SUM</acronym>&#8221;). You can do whatever you want with this expression.
If there is no formula in this cell nil is returned.</p>


	<p>oo.<strong>cell</strong>(row,col) returns the computed result of the formula (as it was saved in the file, no recalculation is done in this Gem).</p>


	<p>oo.<strong>formulas</strong> returns all formulas in the selected spreadsheet in an array like this:</p>


<pre>
<code>
  [[1,2,"=SUM(.A1:.B1)"],
   [1,3,"=SIN(.C3)"],
   [1,4,"=COS(.D4)"]]
</code>
</pre>

	<p>Each entry consists of the elements row, col, formula.</p>


	<p>Note: oo.<strong>cell</strong>(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 #<strong>formula</strong>?</p>


	<p>Please note: formulas in Excel-Spreadsheets cannot be handled (this is another gem, see: &#8220;Thanks&#8221;)</p>


	<h3><span class="caps">YAML</span>-Output</h3>


	<p>You can generate <span class="caps">YAML</span>-Output from your spreadsheet data. The method is called:</p>


	<p>oo.to_yaml # =&gt; produces <span class="caps">YAML</span> output from the entire default spreadsheet
oo.to_yaml({&#8220;myattribute1&#8221; =&gt; &#8220;myvalue1&#8221;, &#8220;myattribute2&#8221; =&gt; &#8220;myvalue2&#8221;)
           # =&gt; <span class="caps">YAML</span> output with additional attributes
oo.to_yaml({..}, 2,10, 300,10) # =&gt; only the rectangle from row 2, column 10 to row 300, column 10 will be returned</p>


	<p>If you omit one or more parameters the maximum boundaries of your spreadsheet will be used.</p>


	<p>With the <span class="caps">YAML</span> output you can import your data in a Ruby on Rails application in a manner that spreadsheet data can accessed in a Rails application.</p>


	<p>This is not limited to a Rails application &#8211; you can also do further evaluations with your data.</p>


	<h3><span class="caps">CSV</span>-Output</h3>


	<p>You can generate output in csv-format with</p>


<pre>
<code>
oo.to_csv
</code>
</pre>

to write to the standard output or
<pre>
<code>
oo.to_csv("somefile.txt")
</code>
</pre>

	<p>to write to a file.</p>


	<h3>Using MS-Excel spreadsheets</h3>


	<p>You can also access MS-Excel spreadsheat.</p>


Replace Openoffice with 
<pre>
<code>oo = Excel.new("simple_spreadsheet.xls").

</code>
</pre>

	<p>All methode are the same for OpenOffice and Excel-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,..).</p>


	<p>Formulas can only be handled in OpenOffice-spreadsheets.</p>


	<p>Features in OpenOffice and Excel:</p>


	<table class="border:1px solid black">
		<tr>
			<td>feature</td>
			<td>Open Office</td>
			<td>Excel</td>
		</tr>
		<tr>
			<td>formulas</td>
			<td>yes</td>
			<td>no</td>
		</tr>
		<tr>
			<td>to_yaml</td>
			<td>yes</td>
			<td>yes</td>
		</tr>
	</table>




	<p>Old .sxc OpenOffice files are currently not supported &#8211; please load these files and save it as an &#8220;OpenDocument Spreadsheet (.ods)&#8221;.</p>


	<h3>Accessing Spreadsheet over the Web</h3>


You can even read openoffice or excel-spreadsheets from a http-address:
<pre>
<code>oo = Excel.new("http://www.somedomain.com/simple_spreadsheet.xls").
oo = Openoffice.new("http://www.somedomain.com/simple_spreadsheet.ods").
</code>
</pre>

or a zipped file:
<pre>
<code>oo = Excel.new("http://www.somedomain.com/simple_spreadsheet.xls.zip",:zip).
oo = Openoffice.new("http://www.somedomain.com/simple_spreadsheet.ods.zip",:zip).
</code>
</pre>

after working with a spreadsheet from the web you have to call 
<pre>
<code>oo.remove_tmp 
</code>
</pre>

	<p>to delete the temporary local copy of the spreadsheet file. If you dont call
this method you will have subdirectories names &#8216;oo_xxxxx&#8217; which you can remove manually.
Calling remove_tmp is not the best solution to clean temporary files &#8211; i will 
provide a better solution in the next releases.</p>


	<h3>Remote Access</h3>


	<p>You can even access your spreadsheet data from a remote machine via <span class="caps">SOAP</span>. 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 <span class="caps">SOAP</span> 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.</p>


	<h3>With Ruby on Rails</h3>


	<p>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).</p>


	<p>To display this example:</p>


	<ul>
	<li>unpack in any directory</li>
		<li>cd roorails</li>
		<li>ruby script/server</li>
		<li>point your browser to http://localhost:3000/spreadsheet/</li>
	</ul>


	<h2>Where is it used?</h2>


	<p>How do you use roo? What are you doing with roo?</p>


	<ul>
	<li>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)</li>
	</ul>


	<p>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).</p>


	<p>Or you can write directly in the project wiki at <a href="http://roo.rubyforge.org/wiki/wiki.pl?Who's_Using_Roo">http://roo.rubyforge.org/wiki/wiki.pl?Who&#8217;s_Using_Roo</a></p>


	<p>If you don&#8217;t want to publish the details you can also write me an email and state, that it should not be published &#8211; i am just curious to hear, where it is used.</p>


	<h2>Documentation</h2>


	<p><a href="rdoc/index.html">rdoc</a></p>


	<p>Only the Openoffice- and Excel-parts of this gem are currently working &#8211; the Google-Spreadheets are experimental and are currently <span class="caps">NOT</span> working. Don&#8217;t use this!</p>


	<h2>Feature Requests / Bugs</h2>


	<p>Submit Feature Requests and bugs here: <a href="http://rubyforge.org/tracker/?group_id=3729">http://rubyforge.org/tracker/?group_id=3729</a></p>


	<h2>Forum</h2>


	<p><a href="http://groups.google.com/group/ruby-roo">http://groups.google.com/group/ruby-roo</a></p>


	<h2>Wiki</h2>


	<p><a href="http://roo.rubyforge.org/wiki/wiki.pl">http://roo.rubyforge.org/wiki/wiki.pl</a></p>


	<h2>How to submit patches</h2>


	<p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>


	<p>The trunk repository is <code>svn://rubyforge.org/var/svn/gorank/trunk</code> for anonymous access.</p>


	<h2>License</h2>


	<p>This code is free to use under the terms of Ruby</p>


	<h2>Contact</h2>


	<p>Comments are welcome. Send an email to <a href="mailto:thopre@gmail.com">Thomas Preymesser</a>.</p>


	<h2>Thanks</h2>


	<ul>
	<li><a href="http://rubyforge.org/users/nicwilliams/">Dr Nic Williams</a> for his wonderful gem &#8216;<a href="http://rubyforge.org/projects/newgem/">newgem</a>&#8217; which makes it very convenient to create, manage and publish Ruby gems</li>
		<li>for the Excel-part the <a href="http://rubyforge.org/projects/spreadsheet/">spreadsheet</a> gem is used. My functions are a convenient wrapper around the functions of this gem</li>
		<li>Dirk Huth f&uuml;rs Testen unter Windows</li>
	</ul>
    <p class="coda">
      <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 3rd October 2007<br>
      Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
    </p>
</div>

<!-- insert site tracking codes here, like Google Urchin -->

</body>
</html>