roo 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ == 0.3.0 2007-06-20
2
+ * 1 enhancement:
3
+ * Openoffice: formula support
4
+
1
5
  == 0.2.7 2007-06-20
2
6
  * 1 bugfix:
3
7
  * Excel: float-numbers were truncated to integer
@@ -30,7 +30,10 @@ class Openoffice
30
30
  file.close
31
31
  @cell = Hash.new
32
32
  @cell_type = Hash.new
33
- FileUtils::rm_r(@tmpdir)
33
+ @formula = Hash.new
34
+ if DateTime.now > Date.new(2007,6,21)
35
+ FileUtils::rm_r(@tmpdir)
36
+ end
34
37
  @default_sheet = nil
35
38
  end
36
39
 
@@ -65,6 +68,21 @@ class Openoffice
65
68
  @cell["#{row},#{col}"]
66
69
  end
67
70
 
71
+ # returns the formula at (row,col)
72
+ def formula(row,col)
73
+ read_cells unless @cells_read
74
+ row,col = normalize(row,col)
75
+ if @formula["#{row},#{col}"] == nil
76
+ return nil
77
+ else
78
+ return @formula["#{row},#{col}"]["oooc:".length..-1]
79
+ end
80
+ end
81
+
82
+ def formula?(row,col)
83
+ formula(row,col) != nil
84
+ end
85
+
68
86
  def set(row,col,value)
69
87
  puts "setze zelle(#{row},#{col})"
70
88
  @cell["#{row},#{col}"] = value
@@ -74,7 +92,13 @@ class Openoffice
74
92
  def celltype(row,col)
75
93
  read_cells unless @cells_read
76
94
  row,col = normalize(row,col)
77
- @cell_type["#{row},#{col}"]
95
+
96
+ # p @formula["#{row},#{col}"]
97
+ if @formula["#{row},#{col}"]
98
+ return :formula
99
+ else
100
+ @cell_type["#{row},#{col}"]
101
+ end
78
102
  end
79
103
 
80
104
 
@@ -285,6 +309,7 @@ private
285
309
  # p tr
286
310
  if tr.name == 'table-cell'
287
311
  skip = tr.attributes['number-columns-repeated']
312
+ formula = tr.attributes['formula']
288
313
  vt = tr.attributes['value-type']
289
314
  v = tr.attributes['value']
290
315
  if vt == 'string'
@@ -300,6 +325,7 @@ private
300
325
  else
301
326
  0.upto(skip.to_i-1) do |i|
302
327
  @cell_type["#{y},#{x+i}"] = vt
328
+ @formula["#{y},#{x+i}"] = formula if formula
303
329
  if @cell_type["#{y},#{x+i}"] == 'float'
304
330
  @cell["#{y},#{x+i}"] = v.to_f
305
331
  elsif @cell_type["#{y},#{x+i}"] == 'string'
@@ -320,7 +346,7 @@ private
320
346
  x += 1
321
347
  end
322
348
  end # if skip
323
- # puts "#{vt} #{v}"
349
+ @formula["#{y},#{x}"] = formula if formula
324
350
  @cell_type["#{y},#{x}"] = vt
325
351
  if @cell_type["#{y},#{x}"] == 'float'
326
352
  @cell["#{y},#{x}"] = v.to_f
@@ -1,8 +1,8 @@
1
1
  module Roo #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 2
5
- TINY = 7
4
+ MINOR = 3
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -619,7 +619,6 @@ end
619
619
 
620
620
  def test_italo_table
621
621
  oo = Openoffice.new(File.join("test","simple_spreadsheet_from_italo.ods"))
622
- p oo.sheets
623
622
  oo.default_sheet = oo.sheets.first
624
623
 
625
624
  assert_equal '1', oo.cell('A',1)
@@ -678,30 +677,69 @@ end
678
677
 
679
678
  end
680
679
 
681
- def test_latlondata
682
- #-- this testfile contains confident data and will not be released in the public
683
- if File.exist?(File.join("test","latlondata.xls"))
684
- oo = Excel.new(File.join("test","latlondata.xls"))
685
- #oo = Excel.new("numbers1.xls")
680
+ def test_external1
681
+ if File.exist?(File.join("test","external1.xls"))
682
+ oo = Excel.new(File.join("test","external1.xls"))
686
683
  oo.default_sheet = 2
687
- 5.upto(oo.last_row) do |line|
688
- waypoint = oo.cell(line,'V')
689
- desc = oo.cell(line,'W')
690
- color = oo.cell(line,'X')
691
- symbol = oo.cell(line,'Y')
692
- longitude = oo.cell(line,'Z')
693
- latitude = oo.cell(line,'AA')
694
- alt = oo.cell(line,'AB')
695
- if waypoint
696
- puts "#{waypoint}\t#{desc}\t#{color}\t#{symbol}\t#{longitude.to_f}\t#{latitude.to_f}\t#{alt.to_f}"
684
+ assert_equal(-105.675, oo.cell('Z',5))
685
+ assert_equal(41.31205555, oo.cell('AA',5))
686
+ assert_equal(2218.3344, oo.cell('AB',5))
687
+ end
688
+ end
689
+
690
+
691
+ def test_formula
692
+
693
+ oo = Openoffice.new(File.join("test","formula.ods"))
694
+ oo.default_sheet = oo.sheets.first
695
+ assert_equal 1, oo.cell('A',1)
696
+ assert_equal 2, oo.cell('A',2)
697
+ assert_equal 3, oo.cell('A',3)
698
+ assert_equal 4, oo.cell('A',4)
699
+ assert_equal 5, oo.cell('A',5)
700
+ assert_equal 6, oo.cell('A',6)
701
+ assert_equal 21, oo.cell('A',7)
702
+ assert_equal :formula, oo.celltype('A',7)
703
+ #assert_equal "=SUM(A1:A6)", oo.formula('A',7)
704
+ #assert_equal "=SUM(A1:A6)", oo.formula('B',7)
705
+ #assert_equal "=SUM(A1:A6)", oo.formula('B',7)
706
+ assert_equal "=[Sheet2.A1]", oo.formula('C',7)
707
+ assert_nil oo.formula('A',6)
708
+
709
+ oo = Openoffice.new(File.join("test","external1.ods"))
710
+ # each spreadsheet, each row, each column
711
+ oo.sheets.each {|sheet|
712
+ oo.default_sheet = sheet
713
+ oo.first_row.upto(oo.last_row) do |row|
714
+ oo.first_column.upto(oo.last_column) do |col|
715
+ value = oo.cell(row,col)
716
+ # is it a formula?
717
+ if oo.formula?(row,col)
718
+ # formula
719
+ puts oo.formula(row,col)
720
+ # value
721
+ puts value if value
722
+ else
723
+ puts value if value
724
+ end
697
725
  end
698
726
  end
699
- #--
700
- assert_equal "[1] KLAR (takeoff)", oo.cell('V',5)
701
- assert_equal "takeoff LAR (VFR)", oo.cell('w',5)
702
- assert_equal -105.675, oo.cell('Z',5)
703
- assert_equal 41.31205555, oo.cell('AA',5)
704
- assert_equal 2218.3344, oo.cell('AB',5)
727
+ }
728
+ if false
729
+ oo = Excel.new(File.join("test","formula.xls"))
730
+ oo.default_sheet = 1 # oo.sheets.first
731
+ assert_equal 1, oo.cell('A',1)
732
+ assert_equal 2, oo.cell('A',2)
733
+ assert_equal 3, oo.cell('A',3)
734
+ assert_equal 4, oo.cell('A',4)
735
+ assert_equal 5, oo.cell('A',5)
736
+ assert_equal 6, oo.cell('A',6)
737
+ assert_equal 21, oo.cell('A',7), oo.cell('A',7).to_yaml
738
+ assert_equal :formula, oo.celltype('A',7)
739
+ assert_equal "=SUM(A1:A6)", oo.formula('A',7)
740
+ assert_equal "=SUM(A1:A6)", oo.formula('B',7)
741
+ assert_nil oo.formula('A',6)
705
742
  end
743
+
706
744
  end
707
745
  end # class
@@ -33,7 +33,7 @@
33
33
  <h1>roo</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/roo"; return false'>
35
35
  Get Version
36
- <a href="http://rubyforge.org/projects/roo" class="numbers">0.2.7</a>
36
+ <a href="http://rubyforge.org/projects/roo" class="numbers">0.3.0</a>
37
37
  </div>
38
38
  <h2>What</h2>
39
39
 
@@ -137,6 +137,25 @@
137
137
  </code>
138
138
  </pre>
139
139
 
140
+ <h3>Formulas</h3>
141
+
142
+
143
+ <p>Formulas in Openoffice-Spreadsheets can be handled.</p>
144
+
145
+
146
+ <p>oo.celltype(row,col) returns :formula if there is a formula in this cell.</p>
147
+
148
+
149
+ <p>oo.formula(row,col) returns the formula in this cell in a string variable.
150
+ If there is no formula in this cell nil is return</p>
151
+
152
+
153
+ <p>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).</p>
154
+
155
+
156
+ <p>Please note: formulas in Excel-Spreadsheets cannot be handled (this is another gem, see: &#8220;Thanks&#8221;)</p>
157
+
158
+
140
159
  <h3>Using MS-Excel spreadsheets</h3>
141
160
 
142
161
 
@@ -154,6 +173,21 @@ Replace Openoffice with
154
173
  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>
155
174
 
156
175
 
176
+ <p>Formulas cannot be handled in Excel-spreadsheets.</p>
177
+
178
+
179
+ <h2>Where is it used?</h2>
180
+
181
+
182
+ <p>How do you use roo? What are you doing with roo?</p>
183
+
184
+
185
+ <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>
186
+
187
+
188
+ <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>
189
+
190
+
157
191
  <h2>Documentation</h2>
158
192
 
159
193
 
@@ -199,7 +233,7 @@ is the setting of the default-worksheet. OpenOffice uses the name of the workshe
199
233
  <li>Dirk Huth f&uuml;rs Testen unter Windows</li>
200
234
  </ul>
201
235
  <p class="coda">
202
- <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 18th June 2007<br>
236
+ <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 20th June 2007<br>
203
237
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
204
238
  </p>
205
239
  </div>
@@ -87,6 +87,19 @@ to
87
87
  </code>
88
88
  </pre>
89
89
 
90
+ h3. Formulas
91
+
92
+ Formulas in Openoffice-Spreadsheets can be handled.
93
+
94
+ oo.celltype(row,col) returns :formula if there is a formula in this cell.
95
+
96
+ oo.formula(row,col) returns the formula in this cell in a string variable.
97
+ If there is no formula in this cell nil is return
98
+
99
+ 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).
100
+
101
+ Please note: formulas in Excel-Spreadsheets cannot be handled (this is another gem, see: "Thanks")
102
+
90
103
  h3. Using MS-Excel spreadsheets
91
104
 
92
105
  You can also access MS-Excel spreadsheat.
@@ -101,6 +114,16 @@ Replace Openoffice with
101
114
  all methode are the same for OpenOffice and Excel-objects. The only difference
102
115
  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,..).
103
116
 
117
+ Formulas cannot be handled in Excel-spreadsheets.
118
+
119
+
120
+ h2. Where is it used?
121
+
122
+ How do you use roo? What are you doing with roo?
123
+
124
+ 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).
125
+
126
+ 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.
104
127
 
105
128
  h2. Documentation
106
129
 
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: roo
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.7
6
+ version: 0.3.0
7
7
  date: 2007-06-20 00:00:00 +02:00
8
8
  summary: roo can access the contents of OpenOffice-Spreadsheets
9
9
  require_paths: