roo 1.2.3 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,385 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
- <head>
5
- <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
- <title>
8
- roo
9
- </title>
10
- <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
- <style>
12
-
13
- </style>
14
- <script type="text/javascript">
15
- window.onload = function() {
16
- settings = {
17
- tl: { radius: 10 },
18
- tr: { radius: 10 },
19
- bl: { radius: 10 },
20
- br: { radius: 10 },
21
- antiAlias: true,
22
- autoPad: true,
23
- validTags: ["div"]
24
- }
25
- var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
- versionBox.applyCornersToAll();
27
- }
28
- </script>
29
- </head>
30
- <body>
31
- <div id="main">
32
-
33
- <h1>roo</h1>
34
- <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/roo"; return false'>
35
- Get Version
36
- <a href="http://rubyforge.org/projects/roo" class="numbers">1.2.2</a>
37
- </div>
38
- <h2>What</h2>
39
- <p>This gem allows you to access the content of</p>
40
- <ul>
41
- <li>Open-office spreadsheets (.ods)</li>
42
- <li>Excel spreadsheets (.xls)</li>
43
- <li>Google (online) spreadsheets</li>
44
- <li>Excel&#8217;s new file format .xlsx</li>
45
- </ul>
46
- <h2>Supporting this project</h2>
47
- <p>Die Programme dieses Projekts sind kostenlos erhältlich und verwendbar. <br />
48
- Du kannst jedoch die weitere Entwicklung dieses Projekts mit einer finanziellen <br />
49
- Zuwendung unterstützen (ansonsten müßte ich mich verstärkt anderen Projekten<br />
50
- widmen, die mehr finanziellen Ertrag einbringen, damit ich auch morgen noch<br />
51
- für meine Katzen das Futter kaufen kann :-)).</p>
52
- <p>Am bequemsten kannst du per Paypal an die Email-Adresse thopre@gmail.com <br />
53
- bezahlen. <br />
54
- Falls du per Überweisung zahlen willst, frage bitte nach meiner Kontoverbindung!</p>
55
- <p>Ich werde, aufteilt pro Quartal, eine Liste der Spender mit Namen und Betrag, <br />
56
- sortiert nach Spendenhöhe hier veröffenlichen. Wenn von dir nichts anderes<br />
57
- mitgeteilt, werde ich dich nach deinem Namen, soweit aus der Email-Adresse<br />
58
- ersichtlich, in der Liste veröffenlichen. Falls etwas anderes gewünscht wird,<br />
59
- z. B. &#8220;Firma <span class="caps">ABC</span> GmbH&#8221; oder anonym, dann teile mir dies bitte mit!</p>
60
- <h3>Spender</h3>
61
- <h4>Juli-September 2008</h4>
62
- <table>
63
- <tr>
64
- <td>Betrag</td>
65
- <td>Name</td>
66
- </tr>
67
- <tr>
68
- <td>-</td>
69
- <td>-</td>
70
- </tr>
71
- </table>
72
- <h4>April-Juni 2008</h4>
73
- <table>
74
- <tr>
75
- <td>Betrag</td>
76
- <td>Name</td>
77
- </tr>
78
- <tr>
79
- <td>-</td>
80
- <td>-</td>
81
- </tr>
82
- </table>
83
- <h2>Installing</h2>
84
- <pre syntax="ruby">[sudo] gem install roo</pre>
85
- <h2>The basics</h2>
86
- <p>Currently only read-access is implemented.<br />
87
- Google spreadsheets can be read and written.</p>
88
- <p>Please note that the upper left cell of a table is numbered (1,1) or (1,&#8216;A&#8217;) (not 0,0).</p>
89
- <h2>Demonstration of usage</h2>
90
- <p>Supposed you have created this spreadsheet:</p>
91
- <p><img src="Screenshot-spreadsheet3.png"></p>
92
- <p>which includes the amount of work you have done for a customer.</p>
93
- <p>You can now process this spreadsheet with the following sample code.</p>
94
- <pre>
95
- <code>
96
- 1 require 'rubygems'
97
- 2 require 'roo'
98
- 3
99
- 4 HOURLY_RATE = 123.45
100
- 5
101
- 6 oo = Openoffice.new("simple_spreadsheet.ods")
102
- 7 oo.default_sheet = oo.sheets.first
103
- 8 4.upto(12) do |line|
104
- 9 date = oo.cell(line,'A')
105
- 10 start_time = oo.cell(line,'B')
106
- 11 end_time = oo.cell(line,'C')
107
- 12 pause = oo.cell(line,'D')
108
- 13 sum = (end_time - start_time) - pause
109
- 14 comment = oo.cell(line,'F')
110
- 15 amount = sum * HOURLY_RATE
111
- 16 if date
112
- 17 puts "#{date}\t#{sum}\t#{amount}\t#{comment}"
113
- 18 end
114
- 19 end
115
- </code>
116
- </pre>
117
- <p>which produces this output</p>
118
- <pre>
119
- <code>
120
- 2007-05-07 1.0 123.45 Task 1
121
- 2007-05-07 1.75 216.0375 Task 1
122
- 2007-05-07 1.0 123.45 Task 2
123
- 2007-05-08 1.0 123.45 Task 2
124
- 2007-05-08 1.0 123.45 Task 3
125
- 2007-05-08 0.5 61.725 Task 3
126
- 2007-05-14 0.5 61.725 Task 3
127
- 2007-05-14 0.5 61.725 Task 3
128
- 2007-05-15 1.0 123.45 Task 3
129
- </code>
130
- </pre>
131
- <p>With the methods</p>
132
- <p><code>first_column</code>,<br />
133
- <code>last_column</code>,<br />
134
- <code>first_row</code> and<br />
135
- <code>last_row</code></p>
136
- <p>you can change line 8 from</p>
137
- <pre>
138
- <code>
139
- 4.upto(12) do |line|
140
- </code>
141
- </pre>
142
- <p>to</p>
143
- <pre>
144
- <code>
145
- 4.upto(oo.last_row) do |line|
146
- </code>
147
- </pre>
148
- <h3>Cell Types</h3>
149
- <p>oo.<strong>celltype</strong>(row,col) returns the type of a cell. Currently these types will be<br />
150
- returned:</p>
151
- <ul>
152
- <li>:float</li>
153
- <li>:string</li>
154
- <li>:date</li>
155
- <li>:percentage</li>
156
- <li>:formula</li>
157
- <li>:time</li>
158
- <li>:datetime</li>
159
- </ul>
160
- <p>Numeric values are returned as type :float, the return value is a Ruby Float object (note: integer values like 42 are returned as 42.0 &#8211; not as a Fixnum 42 object).</p>
161
- <p>String values are returned as type :string and Ruby String object.</p>
162
- <p>Date values are returned as type :date and as a Ruby Date object.</p>
163
- <p>Datetime values are returned as type :datetime and as a Ruby DateTime object.</p>
164
- <p>Percentage are return as type :percentage and as Ruby Float object with the <br />
165
- range from 0.0 to 1.0.</p>
166
- <p>Formulas are returned as type :formula &#8211; the value of the cell is the computed<br />
167
- value of this formula. The formula itself can be retrieved with the #formula<br />
168
- method.</p>
169
- <p>Time values are returned as type :time &#8211; the value of the cell are the seconds<br />
170
- from midnight as a Fixnum object</p>
171
- <h3>Write access</h3>
172
- <p>Cells in a google spreadsheet can be read or written.</p>
173
- <p>To write to a cell use the method call:</p>
174
- <pre>
175
- <code>
176
- oo.set_value(row, col, value)
177
- </code>
178
- </pre>
179
- <p>There is an example in the examples folder which illustrates write access.</p>
180
- <h3>Formulas</h3>
181
- <p>Formulas in Openoffice- and Google-Spreadsheets can be handled.</p>
182
- <p>oo.<strong>celltype</strong>(row,col) returns :formula if there is a formula in this cell.</p>
183
- <p>oo.<strong>formula?</strong>(row,col) returns true if there is a formula</p>
184
- <p>oo.<strong>formula</strong>(row,col) returns the formula in this cell in a string variable (like &#8220;=<acronym title="[.A1:.M13]"><span class="caps">SUM</span></acronym>&#8221;).<br />
185
- You can do whatever you want with this expression. Please note that the syntax of<br />
186
- formulas might vary between different sort of spreadsheets. There is no conversion<br />
187
- of the formula syntax.<br />
188
- <br />
189
- If there is no formula in this cell nil is returned.</p>
190
- <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>
191
- <p>oo.<strong>formulas</strong> returns all formulas in the selected spreadsheet in an array like this:</p>
192
- <pre>
193
- <code>
194
- [[1,2,"=SUM(.A1:.B1)"],
195
- [1,3,"=SIN(.C3)"],
196
- [1,4,"=COS(.D4)"]]
197
- </code>
198
- </pre>
199
- <p>Each entry consists of the elements row, col, formula.</p>
200
- <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>
201
- <p>Please note: formulas in Excel-Spreadsheets cannot be handled (this is another gem, see: &#8220;Thanks&#8221;)</p>
202
- <h3><span class="caps">YAML</span>-Output</h3>
203
- <p>You can generate <span class="caps">YAML</span>-Output from your spreadsheet data. The method is called:</p>
204
- <p>oo.to_yaml # =&gt; produces <span class="caps">YAML</span> output from the entire default spreadsheet<br />
205
- oo.to_yaml({&quot;myattribute1&quot; =&gt; &#8220;myvalue1&#8221;, &#8220;myattribute2&#8221; =&gt; &#8220;myvalue2&#8221;)<br />
206
- # =&gt; <span class="caps">YAML</span> output with additional attributes<br />
207
- 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>
208
- <p>If you omit one or more parameters the maximum boundaries of your spreadsheet will be used.</p>
209
- <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>
210
- <p>This is not limited to a Rails application &#8211; you can also do further evaluations with your data.</p>
211
- <h3><span class="caps">CSV</span>-Output</h3>
212
- <p>You can generate output in csv-format with</p>
213
- <pre>
214
- <code>
215
- oo.to_csv
216
- </code>
217
- </pre>
218
- <p>to write to the standard output or</p>
219
- <pre>
220
- <code>
221
- oo.to_csv("somefile.txt")
222
- </code>
223
- </pre>
224
- <p>to write to a file.</p>
225
- <h3>Using MS-Excel spreadsheets</h3>
226
- <p>You can also access MS-Excel spreadsheat.</p>
227
- <p>Replace Openoffice with <br />
228
- <pre><br />
229
- <code>oo = Excel.new("simple_spreadsheet.xls").</p>
230
- <p></code><br />
231
- </pre></p>
232
- <p>or Google.new() or Excelx.new().</p>
233
- <p>All methode are the same for OpenOffice-, Excel- and Google-objects.<br />
234
- <strike> The only difference<br />
235
- 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,..).<br />
236
- </strike></p>
237
- <p>Formulas can only be handled in OpenOffice-, Excel .<span class="caps">XLSX</span> files and Google-spreadsheets.</p>
238
- <p>Features in OpenOffice/Excel/Google:</p>
239
- <table class="border:1px solid black">
240
- <tr>
241
- <td>feature</td>
242
- <td>Open Office</td>
243
- <td>Excel</td>
244
- <td>Google</td>
245
- <td>Excel .xlsx</td>
246
- </tr>
247
- <tr>
248
- <td>formulas</td>
249
- <td>yes</td>
250
- <td>no</td>
251
- <td>yes</td>
252
- <td>yes</td>
253
- </tr>
254
- <tr>
255
- <td>celltype</td>
256
- <td>:percentage</td>
257
- <td>:float</td>
258
- <td>:percentage</td>
259
- <td>:percentage</td>
260
- </tr>
261
- <tr>
262
- <td>access</td>
263
- <td>read-only</td>
264
- <td>read-only</td>
265
- <td>read and write</td>
266
- <td>read-only</td>
267
- </tr>
268
- </table>
269
- <p>The parseexcel-gem does not support the celltype &#8216;percentage&#8217; but uses &#8216;float&#8217; instead. This is not a big deal as you can also use &#8216;float&#8217; to do calculations with these cells.</p>
270
- <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>
271
- <p>Instead of a filename the Google#new method needs the &#8216;key&#8217; of a Google-Spreadsheet. This key can be copied from the <span class="caps">URL</span> when you display a google spreadsheet with your browser.</p>
272
- <p>If you want to use Google spreadsheets you must either have set the<br />
273
- environment variables &#8216;GOOGLE_MAIL&#8217; and &#8216;GOOGLE_PASSWORD&#8217; or you pass<br />
274
- the Google-name and -password to the Google#new method.</p>
275
- <p>Setting these variables can be done if you add these lines to your<br />
276
- ~/.bashrc (or similar setup file within other shells):</p>
277
- export GOOGLE_MAIL=&#8220;yourname@gmail.com&#8221;
278
- export GOOGLE_PASSWORD=&#8220;mysecretpassword&#8221;
279
-
280
- <p>This gem does not check if you are allowed to access a specific google spreadsheet. If it&#8217;s not your own spreadsheet or you are not allowed to read or write to a spreadsheet the behaviour is not defined (but it will not work ;-) ).</p>
281
- <p>The default behavior at opening a spreadsheet with a certain extension has been <br />
282
- changed.<br />
283
- Say you&#8217;re trying to open a spreadsheet file with the extension .xls, which is normally<br />
284
- an Excel file <br />
285
- with the Openoffice.new() call. This cannot work, if the file is really an excel file &#8211; instead <br />
286
- you have to open it with the Excel.new() call.</p>
287
- <p>Now you&#8217;re getting an exception raised. Before it was was only a warning and the<br />
288
- access to this file failed.</p>
289
- <p>Theorectically you can have a file with the extension .xls which is in fact an Openoffice spreadsheet file.</p>
290
- <p>It&#8217;s possible to open such a file with the Openoffice class, but you have have to<br />
291
- override the parameter &#8216;file_warning&#8217; in the new method: <br />
292
- &#8216;Openoffice.new(&#8217;myfile.xls&#8217;, false, :warning)&#8217; or<br />
293
- &#8216;Openoffice.new(&#8217;myfile.xls&#8217;, false, :ignore)&#8217;.</p>
294
- <p>If you set it to :warning you get a warning if you try to use a spreadsheet file with <br />
295
- the &#8216;false&#8217; extension, but the <br />
296
- program will try to handle the file with this class (of course this will fail, if the file<br />
297
- is really of the false type).</p>
298
- <p>If you completely know what you are doing you can also disable the warning with the<br />
299
- parameter :ignore.</p>
300
- <p>Temporary files of this gem are stored in directories which are named with &#8216;oo_&#8217; and<br />
301
- a number (the <span class="caps">PID</span> of the current process).<br />
302
- These directories are created within the current working directory. If you want to<br />
303
- use a different directory for temporary files set the environment variable ROO_TMP! (for<br />
304
- example &#8220;export ROO_TMP=/tmp&#8221; in your .bashrc file). <br />
305
- ROO_TMP was introduced in releases &gt;1.1.0.</p>
306
- <h3>Accessing Spreadsheet over the Web</h3>
307
- <p>You can even read openoffice or excel-spreadsheets from a http-address:<br />
308
- <pre><br />
309
- <code>oo = Excel.new("http://www.somedomain.com/simple_spreadsheet.xls").
310
- oo = Openoffice.new("http://www.somedomain.com/simple_spreadsheet.ods").
311
- </code><br />
312
- </pre></p>
313
- <p>or a zipped file:<br />
314
- <pre><br />
315
- <code>oo = Excel.new("http://www.somedomain.com/simple_spreadsheet.xls.zip",:zip).
316
- oo = Openoffice.new("http://www.somedomain.com/simple_spreadsheet.ods.zip",:zip).
317
- </code><br />
318
- </pre></p>
319
- <p>after working with a spreadsheet from the web you have to call <br />
320
- <pre><br />
321
- <code>oo.remove_tmp
322
- </code><br />
323
- </pre></p>
324
- <p>to delete the temporary local copy of the spreadsheet file. If you don&#8217;t call<br />
325
- this method you will have subdirectories names &#8216;oo_xxxxx&#8217; which you can remove manually.<br />
326
- Calling remove_tmp is not the best solution to clean temporary files &#8211; i will <br />
327
- provide a better solution in the next releases.</p>
328
- <h3>Remote Access</h3>
329
- <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. <br />
330
- 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>
331
- <h3>Excel spreadsheets / Openoffice spreadsheets / Google spreadsheets with Ruby on Rails</h3>
332
- <p>There is a simple helper method to display a spreadsheet at your application page:</p>
333
- <ul>
334
- <li>in your controller, add &#8220;require &#8216;roo&#8217;&#8221; and &#8220;@rspreadsheet = Openoffice.new(&#8221;numbers1.ods&quot;)&quot; or<br />
335
- &#8220;@rspreadsheet = Openoffice.new(&#8221;http://www.somehost.com/data/numbers1.od s&quot;)&quot; to get access to your spreadsheet file</li>
336
- <li>use it in any view of your application with &#8220;&lt;%= spreadsheet @rspreadsheet, [&#8221;Tabelle&quot;] %&gt;<br/>&quot; or one of the following formats</li>
337
- </ul>
338
- <p><img src="Roo_Spreadsheets_Rails.png"></p>
339
- <h2>Where is it used?</h2>
340
- <p>How do you use roo? What are you doing with roo?</p>
341
- <ul>
342
- <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>
343
- </ul>
344
- <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>
345
- <p>Or you can write directly in the project wiki at <a href="http://roo.rubyforge.org/wiki/wiki.pl?Who&#39;s_Using_Roo">http://roo.rubyforge.org/wiki/wiki.pl?Who&#8217;s_Using_Roo</a></p>
346
- <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>
347
- <h2>Documentation</h2>
348
- <p><a href="rdoc/index.html">rdoc</a></p>
349
- <h2>Tests and test data</h2>
350
- <p>There are many test files within the test directory. If you don&#8217;t want to run unit tests and don&#8217;t want the test data you can completely delete the &#8216;test&#8217; directory within the hierarchy of this gem.<br />
351
- <br />
352
- h2. Feature Requests / Bugs</p>
353
- <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>
354
- <h2>Forum</h2>
355
- <p>International Group:<br />
356
- <a href="http://groups.google.com/group/ruby-roo">http://groups.google.com/group/ruby-roo</a></p>
357
- <p>Deutschsprachige Group:<br />
358
- <a href="http://groups.google.com/group/ruby-roo-de">http://groups.google.com/group/ruby-roo-de</a></p>
359
- <h2>Wiki</h2>
360
- <p><a href="http://roo.rubyforge.org/wiki/wiki.pl">http://roo.rubyforge.org/wiki/wiki.pl</a></p>
361
- <h2>How to submit patches</h2>
362
- <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>
363
- <p><strike>The trunk repository is <code>svn://rubyforge.org/var/svn/roo/trunk</code> for anonymous access.</strike></p>
364
- <h2>License</h2>
365
- <p>This code is free to use under the terms of Ruby</p>
366
- <h2>Contact</h2>
367
- <p>Comments are welcome. Send an email to <a href="mailto:thopre@gmail.com">Thomas Preymesser</a>.</p>
368
- <h2>Thanks</h2>
369
- <ul>
370
- <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>
371
- <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>
372
- <li>Dirk Huth f&uuml;rs Testen unter Windows</li>
373
- <li>Thanks to davecahill for a bug-fix patch within the google part</li>
374
- <li>Thanks to Ryan Waldron for a bug-fix patch in Google set_value</li>
375
- </ul>
376
- <p class="coda">
377
- <a href="mailto:thopre@gmail.com">Thomas Preymesser</a>, 8th December 2008<br>
378
- Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
379
- </p>
380
- </div>
381
-
382
- <!-- insert site tracking codes here, like Google Urchin -->
383
-
384
- </body>
385
- </html>
@@ -1,423 +0,0 @@
1
- h1. roo
2
-
3
- h2. What
4
-
5
- This gem allows you to access the content of
6
-
7
- * Open-office spreadsheets (.ods)
8
- * Excel spreadsheets (.xls)
9
- * Google (online) spreadsheets
10
- * Excel's new file format .xlsx
11
-
12
- h2. Supporting this project
13
-
14
- Die Programme dieses Projekts sind kostenlos erhältlich und verwendbar.
15
- Du kannst jedoch die weitere Entwicklung dieses Projekts mit einer finanziellen
16
- Zuwendung unterstützen (ansonsten müßte ich mich verstärkt anderen Projekten
17
- widmen, die mehr finanziellen Ertrag einbringen, damit ich auch morgen noch
18
- für meine Katzen das Futter kaufen kann :-)).
19
-
20
- Am bequemsten kannst du per Paypal an die Email-Adresse thopre@gmail.com
21
- bezahlen.
22
- Falls du per Überweisung zahlen willst, frage bitte nach meiner Kontoverbindung!
23
-
24
- Ich werde, aufteilt pro Quartal, eine Liste der Spender mit Namen und Betrag,
25
- sortiert nach Spendenhöhe hier veröffenlichen. Wenn von dir nichts anderes
26
- mitgeteilt, werde ich dich nach deinem Namen, soweit aus der Email-Adresse
27
- ersichtlich, in der Liste veröffenlichen. Falls etwas anderes gewünscht wird,
28
- z. B. "Firma ABC GmbH" oder anonym, dann teile mir dies bitte mit!
29
-
30
- h3. Spender
31
-
32
- h4. Juli-September 2008
33
-
34
- table.
35
- |Betrag|Name|
36
- |-|-|
37
-
38
- h4. April-Juni 2008
39
-
40
- table.
41
- |Betrag|Name|
42
- |-|-|
43
-
44
-
45
-
46
- h2. Installing
47
-
48
- <pre syntax="ruby">[sudo] gem install roo</pre>
49
-
50
- h2. The basics
51
-
52
- Currently only read-access is implemented.
53
- Google spreadsheets can be read and written.
54
-
55
- Please note that the upper left cell of a table is numbered (1,1) or (1,'A') (not 0,0).
56
-
57
- h2. Demonstration of usage
58
-
59
- Supposed you have created this spreadsheet:
60
-
61
- <img src="Screenshot-spreadsheet3.png">
62
-
63
- which includes the amount of work you have done for a customer.
64
-
65
- You can now process this spreadsheet with the following sample code.
66
-
67
- <pre>
68
- <code>
69
- 1 require 'rubygems'
70
- 2 require 'roo'
71
- 3
72
- 4 HOURLY_RATE = 123.45
73
- 5
74
- 6 oo = Openoffice.new("simple_spreadsheet.ods")
75
- 7 oo.default_sheet = oo.sheets.first
76
- 8 4.upto(12) do |line|
77
- 9 date = oo.cell(line,'A')
78
- 10 start_time = oo.cell(line,'B')
79
- 11 end_time = oo.cell(line,'C')
80
- 12 pause = oo.cell(line,'D')
81
- 13 sum = (end_time - start_time) - pause
82
- 14 comment = oo.cell(line,'F')
83
- 15 amount = sum * HOURLY_RATE
84
- 16 if date
85
- 17 puts "#{date}\t#{sum}\t#{amount}\t#{comment}"
86
- 18 end
87
- 19 end
88
- </code>
89
- </pre>
90
-
91
- which produces this output
92
-
93
- <pre>
94
- <code>
95
- 2007-05-07 1.0 123.45 Task 1
96
- 2007-05-07 1.75 216.0375 Task 1
97
- 2007-05-07 1.0 123.45 Task 2
98
- 2007-05-08 1.0 123.45 Task 2
99
- 2007-05-08 1.0 123.45 Task 3
100
- 2007-05-08 0.5 61.725 Task 3
101
- 2007-05-14 0.5 61.725 Task 3
102
- 2007-05-14 0.5 61.725 Task 3
103
- 2007-05-15 1.0 123.45 Task 3
104
- </code>
105
- </pre>
106
-
107
- With the methods
108
-
109
- <code>first_column</code>,
110
- <code>last_column</code>,
111
- <code>first_row</code> and
112
- <code>last_row</code>
113
-
114
- you can change line 8 from
115
-
116
- <pre>
117
- <code>
118
- 4.upto(12) do |line|
119
- </code>
120
- </pre>
121
-
122
- to
123
-
124
- <pre>
125
- <code>
126
- 4.upto(oo.last_row) do |line|
127
- </code>
128
- </pre>
129
-
130
- h3. Cell Types
131
-
132
- oo.*celltype*(row,col) returns the type of a cell. Currently these types will be
133
- returned:
134
-
135
- * :float
136
- * :string
137
- * :date
138
- * :percentage
139
- * :formula
140
- * :time
141
- * :datetime
142
-
143
- Numeric values are returned as type :float, the return value is a Ruby Float object (note: integer values like 42 are returned as 42.0 - not as a Fixnum 42 object).
144
-
145
- String values are returned as type :string and Ruby String object.
146
-
147
- Date values are returned as type :date and as a Ruby Date object.
148
-
149
- Datetime values are returned as type :datetime and as a Ruby DateTime object.
150
-
151
- Percentage are return as type :percentage and as Ruby Float object with the
152
- range from 0.0 to 1.0.
153
-
154
- Formulas are returned as type :formula - the value of the cell is the computed
155
- value of this formula. The formula itself can be retrieved with the #formula
156
- method.
157
-
158
- Time values are returned as type :time - the value of the cell are the seconds
159
- from midnight as a Fixnum object
160
-
161
- h3. Write access
162
-
163
- Cells in a google spreadsheet can be read or written.
164
-
165
- To write to a cell use the method call:
166
-
167
- <pre>
168
- <code>
169
- oo.set_value(row, col, value)
170
- </code>
171
- </pre>
172
-
173
- There is an example in the examples folder which illustrates write access.
174
-
175
- h3. Formulas
176
-
177
- Formulas in Openoffice- and Google-Spreadsheets can be handled.
178
-
179
- oo.*celltype*(row,col) returns :formula if there is a formula in this cell.
180
-
181
- oo.*formula?*(row,col) returns true if there is a formula
182
-
183
- oo.*formula*(row,col) returns the formula in this cell in a string variable (like "=SUM([.A1:.M13])").
184
- You can do whatever you want with this expression. Please note that the syntax of
185
- formulas might vary between different sort of spreadsheets. There is no conversion
186
- of the formula syntax.
187
-
188
- If there is no formula in this cell nil is returned.
189
-
190
- 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).
191
-
192
- oo.*formulas* returns all formulas in the selected spreadsheet in an array like this:
193
-
194
- <pre>
195
- <code>
196
- [[1,2,"=SUM(.A1:.B1)"],
197
- [1,3,"=SIN(.C3)"],
198
- [1,4,"=COS(.D4)"]]
199
- </code>
200
- </pre>
201
-
202
- Each entry consists of the elements row, col, formula.
203
-
204
- 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*?
205
-
206
- Please note: formulas in Excel-Spreadsheets cannot be handled (this is another gem, see: "Thanks")
207
-
208
- h3. YAML-Output
209
-
210
- You can generate YAML-Output from your spreadsheet data. The method is called:
211
-
212
- oo.to_yaml # => produces YAML output from the entire default spreadsheet
213
- oo.to_yaml({"myattribute1" => "myvalue1", "myattribute2" => "myvalue2")
214
- # => YAML output with additional attributes
215
- oo.to_yaml({..}, 2,10, 300,10) # => only the rectangle from row 2, column 10 to row 300, column 10 will be returned
216
-
217
- If you omit one or more parameters the maximum boundaries of your spreadsheet will be used.
218
-
219
- 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.
220
-
221
- This is not limited to a Rails application - you can also do further evaluations with your data.
222
-
223
- h3. CSV-Output
224
-
225
- You can generate output in csv-format with
226
-
227
- <pre>
228
- <code>
229
- oo.to_csv
230
- </code>
231
- </pre>
232
-
233
- to write to the standard output or
234
-
235
- <pre>
236
- <code>
237
- oo.to_csv("somefile.txt")
238
- </code>
239
- </pre>
240
-
241
- to write to a file.
242
-
243
- h3. Using MS-Excel spreadsheets
244
-
245
- You can also access MS-Excel spreadsheat.
246
-
247
- Replace Openoffice with
248
- <pre>
249
- <code>oo = Excel.new("simple_spreadsheet.xls").
250
-
251
- </code>
252
- </pre>
253
-
254
- or Google.new() or Excelx.new().
255
-
256
- All methode are the same for OpenOffice-, Excel- and Google-objects.
257
- <strike> The only difference
258
- 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,..).
259
- </strike>
260
-
261
- Formulas can only be handled in OpenOffice-, Excel .XLSX files and Google-spreadsheets.
262
-
263
- Features in OpenOffice/Excel/Google:
264
-
265
- table(border:1px solid black).
266
- |feature|Open Office|Excel|Google|Excel .xlsx|
267
- |formulas|yes|no|yes|yes|
268
- |celltype|:percentage|:float|:percentage|:percentage|
269
- |access|read-only|read-only|read and write|read-only|
270
-
271
- 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.
272
-
273
- Old .sxc OpenOffice files are currently not supported - please load these files and save it as an "OpenDocument Spreadsheet (.ods)".
274
-
275
- 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.
276
-
277
- If you want to use Google spreadsheets you must either have set the
278
- environment variables 'GOOGLE_MAIL' and 'GOOGLE_PASSWORD' or you pass
279
- the Google-name and -password to the Google#new method.
280
-
281
- Setting these variables can be done if you add these lines to your
282
- ~/.bashrc (or similar setup file within other shells):
283
-
284
- export GOOGLE_MAIL="yourname@gmail.com"
285
- export GOOGLE_PASSWORD="mysecretpassword"
286
-
287
- 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 write to a spreadsheet the behaviour is not defined (but it will not work ;-) ).
288
-
289
- The default behavior at opening a spreadsheet with a certain extension has been
290
- changed.
291
- Say you're trying to open a spreadsheet file with the extension .xls, which is normally
292
- an Excel file
293
- with the Openoffice.new() call. This cannot work, if the file is really an excel file - instead
294
- you have to open it with the Excel.new() call.
295
-
296
- Now you're getting an exception raised. Before it was was only a warning and the
297
- access to this file failed.
298
-
299
- Theorectically you can have a file with the extension .xls which is in fact an Openoffice spreadsheet file.
300
-
301
- It's possible to open such a file with the Openoffice class, but you have have to
302
- override the parameter 'file_warning' in the new method:
303
- 'Openoffice.new('myfile.xls', false, :warning)' or
304
- 'Openoffice.new('myfile.xls', false, :ignore)'.
305
-
306
- If you set it to :warning you get a warning if you try to use a spreadsheet file with
307
- the 'false' extension, but the
308
- program will try to handle the file with this class (of course this will fail, if the file
309
- is really of the false type).
310
-
311
- If you completely know what you are doing you can also disable the warning with the
312
- parameter :ignore.
313
-
314
- Temporary files of this gem are stored in directories which are named with 'oo_' and
315
- a number (the PID of the current process).
316
- These directories are created within the current working directory. If you want to
317
- use a different directory for temporary files set the environment variable ROO_TMP! (for
318
- example "export ROO_TMP=/tmp" in your .bashrc file).
319
- ROO_TMP was introduced in releases >1.1.0.
320
-
321
- h3. Accessing Spreadsheet over the Web
322
-
323
- You can even read openoffice or excel-spreadsheets from a http-address:
324
- <pre>
325
- <code>oo = Excel.new("http://www.somedomain.com/simple_spreadsheet.xls").
326
- oo = Openoffice.new("http://www.somedomain.com/simple_spreadsheet.ods").
327
- </code>
328
- </pre>
329
-
330
- or a zipped file:
331
- <pre>
332
- <code>oo = Excel.new("http://www.somedomain.com/simple_spreadsheet.xls.zip",:zip).
333
- oo = Openoffice.new("http://www.somedomain.com/simple_spreadsheet.ods.zip",:zip).
334
- </code>
335
- </pre>
336
-
337
- after working with a spreadsheet from the web you have to call
338
- <pre>
339
- <code>oo.remove_tmp
340
- </code>
341
- </pre>
342
-
343
- to delete the temporary local copy of the spreadsheet file. If you don't call
344
- this method you will have subdirectories names 'oo_xxxxx' which you can remove manually.
345
- Calling remove_tmp is not the best solution to clean temporary files - i will
346
- provide a better solution in the next releases.
347
-
348
-
349
- h3. Remote Access
350
-
351
- 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.
352
- 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.
353
-
354
- h3. Excel spreadsheets / Openoffice spreadsheets / Google spreadsheets with Ruby on Rails
355
-
356
- There is a simple helper method to display a spreadsheet at your application page:
357
-
358
- * in your controller, add "require 'roo'" and "@rspreadsheet = Openoffice.new("numbers1.ods")" or
359
- "@rspreadsheet = Openoffice.new("http://www.somehost.com/data/numbers1.od s")" to get access to your spreadsheet file
360
- * use it in any view of your application with "&lt;%= spreadsheet @rspreadsheet, ["Tabelle"] %&gt;<br/>" or one of the following formats
361
-
362
- <img src="Roo_Spreadsheets_Rails.png">
363
-
364
- h2. Where is it used?
365
-
366
- How do you use roo? What are you doing with roo?
367
-
368
- * 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)
369
-
370
-
371
- 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).
372
-
373
- Or you can write directly in the project wiki at "http://roo.rubyforge.org/wiki/wiki.pl?Who's_Using_Roo":http://roo.rubyforge.org/wiki/wiki.pl?Who's_Using_Roo
374
-
375
-
376
- 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.
377
-
378
- h2. Documentation
379
-
380
- "rdoc":rdoc/index.html
381
-
382
- h2. Tests and test data
383
-
384
- There are many test files within the test directory. If you don't want to run unit tests and don't want the test data you can completely delete the 'test' directory within the hierarchy of this gem.
385
-
386
- h2. Feature Requests / Bugs
387
-
388
- Submit Feature Requests and bugs here: "http://rubyforge.org/tracker/?group_id=3729":http://rubyforge.org/tracker/?group_id=3729
389
-
390
- h2. Forum
391
-
392
- International Group:
393
- "http://groups.google.com/group/ruby-roo":http://groups.google.com/group/ruby-roo
394
-
395
- Deutschsprachige Group:
396
- "http://groups.google.com/group/ruby-roo-de":http://groups.google.com/group/ruby-roo-de
397
-
398
- h2. Wiki
399
-
400
- "http://roo.rubyforge.org/wiki/wiki.pl":http://roo.rubyforge.org/wiki/wiki.pl
401
-
402
- h2. How to submit patches
403
-
404
- Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
405
-
406
- <strike>The trunk repository is <code>svn://rubyforge.org/var/svn/roo/trunk</code> for anonymous access.</strike>
407
-
408
- h2. License
409
-
410
- This code is free to use under the terms of Ruby
411
-
412
- h2. Contact
413
-
414
- Comments are welcome. Send an email to "Thomas Preymesser":mailto:thopre@gmail.com.
415
-
416
- h2. Thanks
417
-
418
- * "Dr Nic Williams":http://rubyforge.org/users/nicwilliams/ for his wonderful gem '"newgem":http://rubyforge.org/projects/newgem/' which makes it very convenient to create, manage and publish Ruby gems
419
- * for the Excel-part the "spreadsheet":http://rubyforge.org/projects/spreadsheet/ gem is used. My functions are a convenient wrapper around the functions of this gem
420
- * Dirk Huth f&uuml;rs Testen unter Windows
421
- * Thanks to davecahill for a bug-fix patch within the google part
422
- * Thanks to Ryan Waldron for a bug-fix patch in Google set_value
423
-