roo 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,11 +6,7 @@ require 'zip/zipfilesystem'
6
6
  require 'date'
7
7
  require 'base64'
8
8
 
9
- # The class Openoffice defines the basic functionality for the access to
10
- # spreadsheet documents. Other classes like _Excel_ are defined as subclasses
11
- # of this class.
12
-
13
- class Openoffice
9
+ class Openoffice < GenericSpreadsheet
14
10
 
15
11
  @@nr = 0
16
12
 
@@ -26,7 +22,7 @@ class Openoffice
26
22
  end
27
23
  filename = open_from_uri(filename) if filename[0,7] == "http://"
28
24
  filename = unzip(filename) if packed and packed == :zip
29
- if filename[-4..-1] != ".ods"
25
+ if File.extname(filename) != ".ods"
30
26
  warn "are you sure, this is an openoffice file?"
31
27
  end
32
28
  #if create and ! File.exists?(filename)
@@ -45,7 +41,7 @@ class Openoffice
45
41
  @doc = REXML::Document.new file
46
42
  file.close
47
43
  #if ENV["roo_local"] != "thomas-p"
48
- FileUtils::rm_r(@tmpdir)
44
+ FileUtils::rm_r(@tmpdir)
49
45
  #end
50
46
  @default_sheet = nil
51
47
  # no need to set default_sheet if there is only one sheet in the document
@@ -74,14 +70,6 @@ class Openoffice
74
70
  f.close
75
71
  end
76
72
 
77
- # reopens and read a spreadsheet document
78
- def reload
79
- ds = @default_sheet
80
- initialize(@filename)
81
- self.default_sheet = ds
82
- #@first_row = @last_row = @first_column = @last_column = nil
83
- end
84
-
85
73
  # Returns the content of a spreadsheet-cell.
86
74
  # (1,1) is the upper left corner.
87
75
  # (1,1), (1,'A'), ('A',1), ('a',1) all refers to the
@@ -99,7 +87,7 @@ class Openoffice
99
87
 
100
88
  # Returns the formula at (row,col).
101
89
  # Returns nil if there is no formula.
102
- # The method Openoffice#formula? checks if there is a formula.
90
+ # The method #formula? checks if there is a formula.
103
91
  def formula(row,col,sheet=nil)
104
92
  sheet = @default_sheet unless sheet
105
93
  read_cells(sheet) unless @cells_read[sheet]
@@ -153,14 +141,6 @@ class Openoffice
153
141
  end
154
142
  end
155
143
 
156
- # recursively removes the current temporary directory
157
- # this is only needed if you work with zipped files or files via the web
158
- def remove_tmp
159
- if File.exists?(@tmpdir)
160
- FileUtils::rm_r(@tmpdir)
161
- end
162
- end
163
-
164
144
  # returns an array of sheet names in the spreadsheet
165
145
  def sheets
166
146
  return_sheets = []
@@ -252,105 +232,6 @@ class Openoffice
252
232
  result
253
233
  end
254
234
 
255
- # returns the number of the last non-empty row
256
- def last_row(sheet=nil)
257
- sheet = @default_sheet unless sheet
258
- read_cells(sheet) unless @cells_read[sheet]
259
- if @last_row[sheet]
260
- return @last_row[sheet]
261
- end
262
- impossible_value = 0
263
- result = impossible_value
264
- @cell[sheet].each_pair {|key,value|
265
- y,x = key.split(',')
266
- y = y.to_i
267
- result = [result, y].max if value
268
- }
269
- result = nil if result == impossible_value
270
- @last_row[sheet] = result
271
- result
272
- end
273
-
274
- # returns the number of the last non-empty column
275
- def last_column(sheet=nil)
276
- sheet = @default_sheet unless sheet
277
- read_cells(sheet) unless @cells_read[sheet]
278
- if @last_column[sheet]
279
- return @last_column[sheet]
280
- end
281
- impossible_value = 0
282
- result = impossible_value
283
- @cell[sheet].each_pair {|key,value|
284
- y,x = key.split(',')
285
- x = x.to_i
286
- result = [result, x].max if value
287
- }
288
- result = nil if result == impossible_value
289
- @last_column[sheet] = result
290
- result
291
- end
292
-
293
- # returns the number of the first non-empty row
294
- def first_row(sheet=nil)
295
- if sheet == nil
296
- sheet = @default_sheet
297
- end
298
- read_cells(sheet) unless @cells_read[sheet]
299
- if @first_row[sheet]
300
- return @first_row[sheet]
301
- end
302
- impossible_value = 999_999 # more than a spreadsheet can hold
303
- result = impossible_value
304
- @cell[sheet].each_pair {|key,value|
305
- y,x = key.split(',')
306
- y = y.to_i
307
- result = [result, y].min if value
308
- }
309
- result = nil if result == impossible_value
310
- @first_row[sheet] = result
311
- result
312
- end
313
-
314
- # returns the number of the first non-empty column
315
- def first_column(sheet=nil)
316
- if sheet == nil
317
- sheet = @default_sheet
318
- end
319
- read_cells(sheet) unless @cells_read[sheet]
320
- if @first_column[sheet]
321
- return @first_column[sheet]
322
- end
323
- impossible_value = 999_999 # more than a spreadsheet can hold
324
- result = impossible_value
325
- @cell[sheet].each_pair {|key,value|
326
- y,x = key.split(',')
327
- x = x.to_i
328
- result = [result, x].min if value
329
- }
330
- result = nil if result == impossible_value
331
- @first_column[sheet] = result
332
- result
333
- end
334
-
335
- # first non-empty column as a letter
336
- def first_column_as_letter(sheet=nil)
337
- Openoffice.number_to_letter(first_column(sheet))
338
- end
339
-
340
- # last non-empty column as a letter
341
- def last_column_as_letter(sheet=nil)
342
- Openoffice.number_to_letter(last_column(sheet))
343
- end
344
-
345
- # true if cell is empty
346
- def empty?(row, col, sheet=nil)
347
- sheet = @default_sheet unless sheet
348
- read_cells(sheet) unless @cells_read[sheet]
349
- return true unless cell(row, col, sheet)
350
- return true if celltype(row, col, sheet) == :string && cell(row, col, sheet).empty?
351
- false
352
- end
353
-
354
235
  # save spreadsheet
355
236
  def save #:nodoc:
356
237
  42
@@ -387,30 +268,9 @@ class Openoffice
387
268
  theformulas
388
269
  end
389
270
 
390
- # returns a rectangular area (default: all cells) as yaml-output
391
- # you can add additional attributes with the prefix parameter like:
392
- # oo.to_yaml({"file"=>"flightdata_2007-06-26", "sheet" => "1"})
393
- def to_yaml(prefix={}, from_row=nil, from_column=nil, to_row=nil, to_column=nil,sheet=nil)
394
- sheet = @default_sheet unless sheet
395
- result = "--- \n"
396
- (from_row||first_row(sheet)).upto(to_row||last_row(sheet)) do |row|
397
- (from_column||first_column(sheet)).upto(to_column||last_column(sheet)) do |col|
398
- unless empty?(row,col,sheet)
399
- result << "cell_#{row}_#{col}: \n"
400
- prefix.each {|k,v|
401
- result << " #{k}: #{v} \n"
402
- }
403
- result << " row: #{row} \n"
404
- result << " col: #{col} \n"
405
- result << " celltype: #{self.celltype(row,col,sheet)} \n"
406
- result << " value: #{self.cell(row,col,sheet)} \n"
407
- end
408
- end
409
- end
410
- result
411
- end
412
-
413
271
  # write the current spreadsheet to stdout or into a file
272
+ #TODO: refactoring --> GenericSpreadsheet
273
+
414
274
  def to_csv(filename=nil,sheet=nil)
415
275
  sheet = @default_sheet unless sheet
416
276
  if filename
@@ -456,7 +316,7 @@ class Openoffice
456
316
  tmp[x] = cell(rownum,j)
457
317
  }
458
318
  result = [ tmp ] # row(rownum)
459
- #-- :all
319
+ #-- :all
460
320
  elsif args[0] == :all
461
321
  if args[1].class == Hash
462
322
  args[1].each {|key,val|
@@ -502,58 +362,8 @@ class Openoffice
502
362
  result
503
363
  end
504
364
 
505
- # Returns information of the spreadsheet document and all sheets within
506
- # this document.
507
- def info
508
- result = "File: #{@filename}\n"+
509
- "Number of sheets: #{sheets.size}\n"+
510
- "Sheets: #{sheets.map{|sheet| sheet+", "}.to_s[0..-3]}\n"
511
- n = 1
512
- sheets.each {|sheet|
513
- self.default_sheet = sheet
514
- result << "Sheet " + n.to_s + ":\n"
515
- result << " First row: #{first_row}\n"
516
- result << " Last row: #{last_row}\n"
517
- result << " First column: #{Openoffice.number_to_letter(first_column)}\n"
518
- result << " Last column: #{Openoffice.number_to_letter(last_column)}"
519
- result << "\n" if sheet != sheets.last
520
- n += 1
521
- }
522
- result
523
- end
524
-
525
- private
526
-
527
- def process_zipfile_packed(zip, path='')
528
- ret=nil
529
- if zip.file.file? path
530
- # extract and return filename
531
- @tmpdir = "oo_"+$$.to_s
532
- unless File.exists?(@tmpdir)
533
- FileUtils::mkdir(@tmpdir)
534
- end
535
- file = File.open(File.join(@tmpdir, path),"wb")
536
- file.write(zip.read(path))
537
- file.close
538
- return File.join(@tmpdir, path)
539
- else
540
- unless path.empty?
541
- path += '/'
542
- end
543
- zip.dir.foreach(path) do |filename|
544
- ret = process_zipfile_packed(zip, path + filename)
545
- end
546
- end
547
- ret
548
- end
549
-
550
- def unzip(filename)
551
- ret = nil
552
- Zip::ZipFile.open(filename) do |zip|
553
- ret = process_zipfile_packed zip
554
- end
555
- ret
556
- end
365
+
366
+ private
557
367
 
558
368
  # read the version of the OO-Version
559
369
  def oo_version
@@ -563,6 +373,7 @@ private
563
373
  end
564
374
  end
565
375
 
376
+ # helper function to set the internal representation of cells
566
377
  def set_cell_values(sheet,x,y,i,v,vt,formula,tr,str_v)
567
378
  key = "#{y},#{x+i}"
568
379
  @cell_type[sheet] = {} unless @cell_type[sheet]
@@ -721,56 +532,12 @@ private
721
532
  end
722
533
  end
723
534
 
724
-
725
535
  def extract_content
726
536
  Zip::ZipFile.open(@filename) do |zip|
727
537
  process_zipfile(zip)
728
538
  end
729
539
  end
730
540
 
731
- # converts cell coordinate to numeric values of row,col
732
- def normalize(row,col)
733
- if row.class == String
734
- if col.class == Fixnum
735
- # ('A',1):
736
- # ('B', 5) -> (5, 2)
737
- row, col = col, row
738
- else
739
- raise ArgumentError
740
- end
741
- end
742
- if col.class == String
743
- col = Openoffice.letter_to_number(col)
744
- end
745
- return row,col
746
- end
747
-
748
- # convert a number to something like this: 'AB'
749
- def Openoffice.number_to_letter(n)
750
- letters=""
751
- while n > 0
752
- num = n%26
753
- letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[num-1,1] + letters
754
- n = n.div(26)
755
- end
756
- letters
757
- end
758
-
759
- # convert letters like 'AB' to a number
760
- def Openoffice.letter_to_number(letters)
761
- result = 0
762
- while letters && letters.length > 0
763
- character = letters[0,1].upcase
764
- num = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".index(character)
765
- raise ArgumentError, "invalid column character '#{letters[0,1]}'" if num == nil
766
- num += 1
767
- result = result * 26 + num
768
- letters = letters[1..-1]
769
- end
770
- result
771
- end
772
-
773
-
774
541
  def set_value(row,col,value,sheet=nil)
775
542
  sheet = @default_value unless sheet
776
543
  @cell[sheet]["#{row},#{col}"] = value
@@ -792,22 +559,8 @@ private
792
559
  return A_ROO_TYPE[ootype]
793
560
  end
794
561
 
795
-
796
- def open_from_uri(uri)
797
- require 'open-uri' ;
798
- tempfilename = File.join(@tmpdir, File.basename(uri))
799
- f = File.open(tempfilename,"wb")
800
- begin
801
- open(uri) do |net|
802
- f.write(net.read)
803
- end
804
- rescue
805
- raise "could not open #{uri}"
806
- end
807
- f.close
808
- File.join(@tmpdir, File.basename(uri))
809
- end
810
-
562
+
563
+ #TODO: refactoring to GenericSpreadsheet?
811
564
  def write_csv_content(file=nil,sheet=nil)
812
565
  file = STDOUT unless file
813
566
  if first_row # sheet is not empty
@@ -823,6 +576,7 @@ private
823
576
  end
824
577
  end
825
578
 
579
+ #TODO: refactor to Generic...
826
580
  def one_cell_output(onecelltype,onecell,empty)
827
581
  str = ""
828
582
  if empty
@@ -1,7 +1,7 @@
1
1
  module Roo #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 7
4
+ MINOR = 8
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
@@ -20,10 +20,13 @@ def local_only
20
20
  end
21
21
 
22
22
  DISPLAY_LOG = false
23
- DB_LOG = false
23
+ DB_LOG = true
24
24
 
25
25
  if DB_LOG
26
- require 'active_record'
26
+ # gem 'activerecord', '< 2.0.0'
27
+ # require 'activerecord'
28
+ require_gem 'activerecord', '< 2.0.0'
29
+ #require 'activerecord'
27
30
  end
28
31
 
29
32
  include FileUtils
@@ -31,10 +34,10 @@ include FileUtils
31
34
  if DB_LOG
32
35
  def activerecord_connect
33
36
  ActiveRecord::Base.establish_connection(:adapter => "mysql",
34
- :database => "test_runs",
35
- :host => "localhost",
36
- :username => "root",
37
- :socket => "/var/run/mysqld/mysqld.sock")
37
+ :database => "test_runs",
38
+ :host => "localhost",
39
+ :username => "root",
40
+ :socket => "/var/run/mysqld/mysqld.sock")
38
41
  end
39
42
 
40
43
  class Testrun < ActiveRecord::Base
@@ -42,6 +45,39 @@ if DB_LOG
42
45
  end
43
46
 
44
47
  class Test::Unit::TestCase
48
+ def key_of(spreadsheetname)
49
+ begin
50
+ return {
51
+ 'numbers1' => "o10837434939102457526.4784396906364855777",
52
+ 'borders' => "o10837434939102457526.664868920231926255",
53
+ 'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
54
+ 'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
55
+ "only_one_sheet" => "o10837434939102457526.762705759906130135",
56
+ "write.me" => 'ptu6bbahNZpY0N0RrxQbWdw&hl',
57
+ 'formula' => 'o10837434939102457526.3022866619437760118',
58
+ }[spreadsheetname]
59
+ rescue
60
+ raise "unknown spreadsheetname: #{spreadsheetname}"
61
+ end
62
+
63
+ if false
64
+ case spreadsheetname
65
+ when 'numbers1'
66
+ return "o10837434939102457526.4784396906364855777"
67
+ when 'borders'
68
+ return "o10837434939102457526.664868920231926255"
69
+ when 'simple_spreadsheet'
70
+ return "o1087434939102457526.1774445811568867358"
71
+ when 'testnichtvorhandenBibelbund.ods'
72
+ return "invalidkeyforanyspreadsheet" # !!! intentionally false key
73
+ when "only_one_sheet"
74
+ return "o10837434939102457526.762705759906130135"
75
+ else
76
+ raise "unknown spreadsheetname: #{spreadsheetname}"
77
+ end
78
+ end # false
79
+ end
80
+
45
81
  if DB_LOG
46
82
  if ! (defined?(@connected) and @connected)
47
83
  activerecord_connect
@@ -68,10 +104,15 @@ class Test::Unit::TestCase
68
104
  # open('test_runs.yml','a') { |f| YAML.dump(record, f) }
69
105
  # #--
70
106
  if DB_LOG
71
- domain = Testrun.create(:class => self.class.to_s,
72
- :test => @method_name,
73
- :start => t1,
74
- :duration => t2-t1
107
+ # p self.class.to_s
108
+ #p @method_name
109
+ #p t1
110
+ #p t2-t1
111
+ domain = Testrun.create(
112
+ :class => self.class.to_s,
113
+ :test => @method_name,
114
+ :start => t1,
115
+ :duration => t2-t1
75
116
  )
76
117
  end
77
118
  end
@@ -79,14 +120,14 @@ end
79
120
 
80
121
  class TestRoo < Test::Unit::TestCase
81
122
 
82
- OPENOFFICE = true # do Openoffice-Spreadsheet Tests?
83
- EXCEL = true # do Excel Tests?
84
- GOOGLE = false # do Google-Spreadsheet Tests?
123
+ OPENOFFICE = true # do Openoffice-Spreadsheet Tests?
124
+ EXCEL = true # do Excel Tests?
125
+ GOOGLE = true # do Google-Spreadsheet Tests?
85
126
 
86
127
  OPENOFFICEWRITE = false # experimental: write access with OO-Documents
87
128
  ONLINE = false
88
129
  LONG_RUN = false
89
- GLOBAL_TIMEOUT = 10*60 # seconds
130
+ GLOBAL_TIMEOUT = 2*12*60 # seconds
90
131
 
91
132
 
92
133
  # helper method
@@ -104,30 +145,59 @@ class TestRoo < Test::Unit::TestCase
104
145
  end
105
146
 
106
147
  def setup
107
- if GOOGLE
108
- after Date.new(2007,8,15) do
109
- @goo = Google.new(ENV['GOOGLE_MAIL'],
110
- ENV['GOOGLE_PASSWORD'],
111
- ENV['GOOGLE_KEY'],"Roo Testspreadheet")
112
- end
113
- end
114
148
  if DISPLAY_LOG
115
149
  puts "GLOBAL_TIMEOUT = #{GLOBAL_TIMEOUT}"
116
150
  end
117
151
  end
118
152
 
153
+ def test_date
154
+ assert Google.date?("21/11/1962")
155
+ assert_equal Date.new(1962,11,21), Google.to_date("21/11/1962")
156
+
157
+ assert !Google.date?("21")
158
+ assert_nil Google.to_date("21")
159
+
160
+ assert !Google.date?("21/11")
161
+ assert_nil Google.to_date("21/11")
162
+
163
+ assert !Google.date?("Mittwoch/21/1961")
164
+ assert_nil Google.to_date("Mittwoch/21/1961")
165
+ end
166
+
167
+ def test_classes
168
+ if OPENOFFICE
169
+ oo = Openoffice.new(File.join("test","numbers1.ods"))
170
+ assert_kind_of Openoffice, oo
171
+ end
172
+ if EXCEL
173
+ oo = Excel.new(File.join("test","numbers1.xls"))
174
+ assert_kind_of Excel, oo
175
+ end
176
+ if GOOGLE
177
+ oo = Google.new(key_of("numbers1"))
178
+ assert_kind_of Google, oo
179
+ end
180
+ end
181
+
119
182
  def test_letters
120
- assert_equal 1, Openoffice.letter_to_number('A')
121
- assert_equal 1, Openoffice.letter_to_number('a')
122
- assert_equal 2, Openoffice.letter_to_number('B')
123
- assert_equal 26, Openoffice.letter_to_number('Z')
124
- assert_equal 27, Openoffice.letter_to_number('AA')
125
- assert_equal 27, Openoffice.letter_to_number('aA')
126
- assert_equal 27, Openoffice.letter_to_number('Aa')
127
- assert_equal 27, Openoffice.letter_to_number('aa')
183
+ assert_equal 1, GenericSpreadsheet.letter_to_number('A')
184
+ assert_equal 1, GenericSpreadsheet.letter_to_number('a')
185
+ assert_equal 2, GenericSpreadsheet.letter_to_number('B')
186
+ assert_equal 26, GenericSpreadsheet.letter_to_number('Z')
187
+ assert_equal 27, GenericSpreadsheet.letter_to_number('AA')
188
+ assert_equal 27, GenericSpreadsheet.letter_to_number('aA')
189
+ assert_equal 27, GenericSpreadsheet.letter_to_number('Aa')
190
+ assert_equal 27, GenericSpreadsheet.letter_to_number('aa')
191
+ end
192
+
193
+ def DONT_test_simple_google
194
+ if GOOGLE
195
+ go = Google.new("egal")
196
+ assert_equal "42", go.cell(1,1)
197
+ end
128
198
  end
129
199
 
130
- def test_sheets
200
+ def test_sheets_openoffice
131
201
  if OPENOFFICE
132
202
  oo = Openoffice.new(File.join("test","numbers1.ods"))
133
203
  assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets
@@ -137,7 +207,15 @@ class TestRoo < Test::Unit::TestCase
137
207
  assert_raise(TypeError) {
138
208
  oo.default_sheet = [1,2,3]
139
209
  }
210
+
211
+ oo.sheets.each { |sh|
212
+ oo.default_sheet = sh
213
+ assert_equal sh, oo.default_sheet
214
+ }
140
215
  end
216
+ end
217
+
218
+ def test_sheets_excel
141
219
  if EXCEL
142
220
  oo = Excel.new(File.join("test","numbers1.xls"))
143
221
  assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets
@@ -147,22 +225,33 @@ class TestRoo < Test::Unit::TestCase
147
225
  assert_raise(TypeError) {
148
226
  oo.default_sheet = [1,2,3]
149
227
  }
228
+ oo.sheets.each { |sh|
229
+ oo.default_sheet = sh
230
+ assert_equal sh, oo.default_sheet
231
+ }
150
232
  end
233
+ end
234
+
235
+ def test_sheets_google
151
236
  if GOOGLE
152
- after Date.new(2007,6,10) do
153
- assert_equal "Testspreadsheet Roo", @goo.title
237
+ oo = Google.new(key_of("numbers1"))
238
+ assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets
239
+ after Date.new(2007,12,15) do
240
+ assert_raise(RangeError) {
241
+ oo.default_sheet = "no_sheet"
242
+ }
243
+ assert_raise(TypeError) {
244
+ oo.default_sheet = [1,2,3]
245
+ }
154
246
  end
155
- assert_equal ["Sheet eins","Sheet zwei","Sheet drei"], @goo.sheets
156
- assert_raise(RangeError) {
157
- oo.default_sheet = "no_sheet"
158
- }
159
- assert_raise(TypeError) {
160
- oo.default_sheet = [1,2,3]
247
+ oo.sheets.each { |sh|
248
+ oo.default_sheet = sh
249
+ assert_equal sh, oo.default_sheet
161
250
  }
162
251
  end
163
252
  end
164
253
 
165
- def test_cell
254
+ def test_cell_openoffice
166
255
  if OPENOFFICE
167
256
  oo = Openoffice.new(File.join("test","numbers1.ods"))
168
257
  oo.default_sheet = oo.sheets.first
@@ -199,7 +288,9 @@ class TestRoo < Test::Unit::TestCase
199
288
  assert_equal Date.new(1961,11,21), oo.cell(5,1)
200
289
  assert_equal "1961-11-21", oo.cell(5,1).to_s
201
290
  end
291
+ end
202
292
 
293
+ def test_cell_excel
203
294
  if EXCEL
204
295
  oo = Excel.new(File.join("test","numbers1.xls"))
205
296
  oo.default_sheet = oo.sheets.first
@@ -236,50 +327,44 @@ class TestRoo < Test::Unit::TestCase
236
327
  assert_equal Date.new(1961,11,21), oo.cell(5,1)
237
328
  assert_equal "1961-11-21", oo.cell(5,1).to_s
238
329
  end
330
+ end
239
331
 
332
+ def test_cell_google
240
333
  if GOOGLE
241
- @goo.default_sheet = 1 # @goo.sheets.first
242
- assert_equal 1, @goo.cell(1,1).to_i
243
- assert_equal 2, @goo.cell(1,2).to_i
244
- assert_equal 3, @goo.cell(1,3).to_i
245
- assert_equal 4, @goo.cell(1,4).to_i
246
- assert_equal 5, @goo.cell(2,1).to_i
247
- assert_equal 6, @goo.cell(2,2).to_i
248
- assert_equal 7, @goo.cell(2,3).to_i
249
- assert_equal 8, @goo.cell(2,4).to_i
250
- assert_equal 9, @goo.cell(2,5).to_i
251
- assert_equal "test", @goo.cell(2,6)
252
- # assert_equal "string", @goo.celltype(2,6)
253
- assert_equal :string, @goo.celltype(2,6)
254
- assert_equal 11, @goo.cell(2,7).to_i
255
- after Date.new(2007,6,15) do
256
- # assert_equal "float", @goo.celltype(2,7)
257
- assert_equal :float, @goo.celltype(2,7)
258
- end
334
+ oo = Google.new(key_of("numbers1"))
335
+ oo.default_sheet = oo.sheets.first
336
+ assert_equal 1, oo.cell(1,1)
337
+ assert_equal 2, oo.cell(1,2)
338
+ assert_equal 3, oo.cell(1,3)
339
+ assert_equal 4, oo.cell(1,4)
340
+ assert_equal 5, oo.cell(2,1)
341
+ assert_equal 6, oo.cell(2,2)
342
+ assert_equal 7, oo.cell(2,3)
343
+ assert_equal 8, oo.cell(2,4)
344
+ assert_equal 9, oo.cell(2,5)
345
+ assert_equal "test", oo.cell(2,6)
346
+ # assert_equal "string", oo.celltype(2,6)
347
+ assert_equal :string, oo.celltype(2,6)
348
+ assert_equal 11, oo.cell(2,7)
349
+ # assert_equal "float", oo.celltype(2,7)
350
+ assert_equal :float, oo.celltype(2,7), "Inhalt: --#{oo.cell(2,7)}--"
259
351
 
260
- assert_equal 10, @goo.cell(4,1).to_i
261
- assert_equal 11, @goo.cell(4,2).to_i
262
- assert_equal 12, @goo.cell(4,3).to_i
263
- assert_equal 13, @goo.cell(4,4).to_i
264
- assert_equal 14, @goo.cell(4,5).to_i
265
-
266
- assert_equal 10, @goo.cell(4,'A').to_i
267
- assert_equal 11, @goo.cell(4,'B').to_i
268
- assert_equal 12, @goo.cell(4,'C').to_i
269
- assert_equal 13, @goo.cell(4,'D').to_i
270
- assert_equal 14, @goo.cell(4,'E').to_i
271
-
272
- after Date.new(2007,6,15) do
273
- # assert_equal "date", @goo.celltype(5,1)
274
- assert_equal :date, @goo.celltype(5,1)
275
- end
276
- after Date.new(2007,6,15) do
277
- assert_equal Date.new(1961,11,21), @goo.cell(5,1)
278
- assert_equal "1961-11-21", @goo.cell(5,1).to_s
279
- end
280
- before Date.new(2007,6,15) do
281
- assert_equal "21/11/1961", @goo.cell(5,1)
282
- end
352
+ assert_equal 10, oo.cell(4,1)
353
+ assert_equal 11, oo.cell(4,2)
354
+ assert_equal 12, oo.cell(4,3)
355
+ assert_equal 13, oo.cell(4,4)
356
+ assert_equal 14, oo.cell(4,5)
357
+
358
+ assert_equal 10, oo.cell(4,'A')
359
+ assert_equal 11, oo.cell(4,'B')
360
+ assert_equal 12, oo.cell(4,'C')
361
+ assert_equal 13, oo.cell(4,'D')
362
+ assert_equal 14, oo.cell(4,'E')
363
+
364
+ # assert_equal "date", oo.celltype(5,1)
365
+ assert_equal :date, oo.celltype(5,1)
366
+ assert_equal Date.new(1961,11,21), oo.cell(5,1)
367
+ assert_equal "1961-11-21", oo.cell(5,1).to_s
283
368
  end # GOOGLE
284
369
  end
285
370
 
@@ -296,7 +381,7 @@ class TestRoo < Test::Unit::TestCase
296
381
  assert_equal :string, oo.celltype(2,6)
297
382
  end
298
383
  if GOOGLE
299
- oo = Google.new(File.join("test","nxxxxxxxxxxxxxumbers1.xls"))
384
+ oo = Google.new(key_of("numbers1"))
300
385
  oo.default_sheet = oo.sheets.first
301
386
  assert_equal :string, oo.celltype(2,6)
302
387
  end
@@ -356,21 +441,28 @@ class TestRoo < Test::Unit::TestCase
356
441
  end
357
442
 
358
443
  if GOOGLE
359
- @goo.default_sheet = 1 # @goo.sheets.first
360
- assert_equal "tata", @goo.cell(6,1)
361
- assert_equal "tata", @goo.cell(6,'A')
362
- assert_equal "tata", @goo.cell('A',6)
363
- assert_equal "tata", @goo.cell(6,'a')
364
- assert_equal "tata", @goo.cell('a',6)
444
+ oo = Google.new(key_of("numbers1"))
445
+ oo.default_sheet = oo.sheets.first
446
+ assert_equal "tata", oo.cell(6,1)
447
+ assert_equal "tata", oo.cell(6,'A')
448
+ assert_equal "tata", oo.cell('A',6)
449
+ assert_equal "tata", oo.cell(6,'a')
450
+ assert_equal "tata", oo.cell('a',6)
365
451
 
366
- assert_equal "thisisc8", @goo.cell(8,3)
367
- assert_equal "thisisc8", @goo.cell(8,'C')
368
- assert_equal "thisisc8", @goo.cell('C',8)
369
- assert_equal "thisisc8", @goo.cell(8,'c')
370
- assert_equal "thisisc8", @goo.cell('c',8)
452
+ assert_raise(ArgumentError) {
453
+ assert_equal "tata", oo.cell('a','f')
454
+ }
455
+ assert_raise(ArgumentError) {
456
+ assert_equal "tata", oo.cell('f','a')
457
+ }
458
+ assert_equal "thisisc8", oo.cell(8,3)
459
+ assert_equal "thisisc8", oo.cell(8,'C')
460
+ assert_equal "thisisc8", oo.cell('C',8)
461
+ assert_equal "thisisc8", oo.cell(8,'c')
462
+ assert_equal "thisisc8", oo.cell('c',8)
371
463
 
372
- assert_equal "thisisd9", @goo.cell('d',9)
373
- assert_equal "thisisa11", @goo.cell('a',11)
464
+ assert_equal "thisisd9", oo.cell('d',9)
465
+ assert_equal "thisisa11", oo.cell('a',11)
374
466
  end
375
467
  end
376
468
 
@@ -383,17 +475,14 @@ class TestRoo < Test::Unit::TestCase
383
475
  if EXCEL
384
476
  # excel does not have a officeversion
385
477
  end
386
- #-- Google
387
478
  if GOOGLE
388
- after Date.new(2007,6,15) do
389
- assert_equal "1.0", @goo.officeversion
390
- end
479
+ # google does not have a officeversion
391
480
  end
392
481
  end
393
482
 
483
+ #TODO: inkonsequente Lieferung Fixnum/Float
394
484
  def test_rows
395
485
  if OPENOFFICE
396
- #-- OpenOffice
397
486
  oo = Openoffice.new(File.join("test","numbers1.ods"))
398
487
  oo.default_sheet = oo.sheets.first
399
488
  assert_equal 41, oo.cell('a',12)
@@ -425,34 +514,30 @@ class TestRoo < Test::Unit::TestCase
425
514
  assert_equal "vierundvierzig", oo.cell('d',16)
426
515
  assert_equal "fuenfundvierzig", oo.cell('e',16)
427
516
  assert_equal ["einundvierzig",
428
- "zweiundvierzig",
429
- "dreiundvierzig",
430
- "vierundvierzig",
431
- "fuenfundvierzig"], oo.row(16)
517
+ "zweiundvierzig",
518
+ "dreiundvierzig",
519
+ "vierundvierzig",
520
+ "fuenfundvierzig"], oo.row(16)
432
521
  end
433
- after Date.new(2007,6,17) do
434
- #-- GOOGLE
435
- if GOOGLE
436
- oo = Google.new(File.join("test","numbers1.xls"))
437
- oo.default_sheet = 1 # oo.sheets.first
438
- assert_equal 41, oo.cell('a',12)
439
- assert_equal 42, oo.cell('b',12)
440
- assert_equal 43, oo.cell('c',12)
441
- assert_equal 44, oo.cell('d',12)
442
- assert_equal 45, oo.cell('e',12)
443
- assert_equal [41.0,42.0,43.0,44.0,45.0], oo.row(12)
444
- assert_equal "einundvierzig", oo.cell('a',16)
445
- assert_equal "zweiundvierzig", oo.cell('b',16)
446
- assert_equal "dreiundvierzig", oo.cell('c',16)
447
- assert_equal "vierundvierzig", oo.cell('d',16)
448
- assert_equal "fuenfundvierzig", oo.cell('e',16)
449
- assert_equal "xxxfuenfundvierzig", oo.cell('e',16)
450
- assert_equal ["einundvierzig",
522
+ if GOOGLE
523
+ oo = Google.new(key_of("numbers1"))
524
+ oo.default_sheet = oo.sheets.first
525
+ assert_equal 41, oo.cell('a',12)
526
+ assert_equal 42, oo.cell('b',12)
527
+ assert_equal 43, oo.cell('c',12)
528
+ assert_equal 44, oo.cell('d',12)
529
+ assert_equal 45, oo.cell('e',12)
530
+ assert_equal [41,42,43,44,45], oo.row(12)
531
+ assert_equal "einundvierzig", oo.cell('a',16)
532
+ assert_equal "zweiundvierzig", oo.cell('b',16)
533
+ assert_equal "dreiundvierzig", oo.cell('c',16)
534
+ assert_equal "vierundvierzig", oo.cell('d',16)
535
+ assert_equal "fuenfundvierzig", oo.cell('e',16)
536
+ assert_equal ["einundvierzig",
451
537
  "zweiundvierzig",
452
538
  "dreiundvierzig",
453
539
  "vierundvierzig",
454
540
  "fuenfundvierzig"], oo.row(16)
455
- end
456
541
  end
457
542
  end
458
543
 
@@ -468,9 +553,9 @@ class TestRoo < Test::Unit::TestCase
468
553
  assert_equal 18, oo.last_row
469
554
  end
470
555
  if GOOGLE
471
- @goo.default_sheet = @goo.sheets.first
472
- assert_equal 18, @goo.last_row
473
- assert_equal "xxx", @goo.to_s, @goo.to_s
556
+ oo = Google.new(key_of("numbers1"))
557
+ oo.default_sheet = oo.sheets.first
558
+ assert_equal 18, oo.last_row
474
559
  end
475
560
  end
476
561
 
@@ -487,17 +572,18 @@ class TestRoo < Test::Unit::TestCase
487
572
  assert_equal 7, oo.last_column
488
573
  end
489
574
  if GOOGLE
490
- #-- Google
491
- @goo.default_sheet = @goo.sheets.first
492
- assert_equal 7, @goo.last_column
575
+ oo = Google.new(key_of("numbers1"))
576
+ oo.default_sheet = oo.sheets.first
577
+ assert_equal 7, oo.last_column
493
578
  end
494
579
  end
495
580
 
496
581
  def test_last_column_as_letter
497
- #-- OpenOffice
498
- oo = Openoffice.new(File.join("test","numbers1.ods"))
499
- oo.default_sheet = oo.sheets.first
500
- assert_equal 'G', oo.last_column_as_letter
582
+ if OPENOFFICE
583
+ oo = Openoffice.new(File.join("test","numbers1.ods"))
584
+ oo.default_sheet = oo.sheets.first
585
+ assert_equal 'G', oo.last_column_as_letter
586
+ end
501
587
  if EXCEL
502
588
  #-- Excel
503
589
  oo = Excel.new(File.join("test","numbers1.xls"))
@@ -505,17 +591,18 @@ class TestRoo < Test::Unit::TestCase
505
591
  assert_equal 'G', oo.last_column_as_letter
506
592
  end
507
593
  if GOOGLE
508
- #-- Google
509
- @goo.default_sheet = @goo.sheets.first
510
- assert_equal 'G', @goo.last_column_as_letter
594
+ oo = Google.new(key_of("numbers1"))
595
+ oo.default_sheet = oo.sheets.first
596
+ assert_equal 'G', oo.last_column_as_letter
511
597
  end
512
598
  end
513
599
 
514
600
  def test_first_row
515
- #-- OpenOffice
516
- oo = Openoffice.new(File.join("test","numbers1.ods"))
517
- oo.default_sheet = oo.sheets.first
518
- assert_equal 1, oo.first_row
601
+ if OPENOFFICE
602
+ oo = Openoffice.new(File.join("test","numbers1.ods"))
603
+ oo.default_sheet = oo.sheets.first
604
+ assert_equal 1, oo.first_row
605
+ end
519
606
  if EXCEL
520
607
  #-- Excel
521
608
  oo = Excel.new(File.join("test","numbers1.xls"))
@@ -523,17 +610,18 @@ class TestRoo < Test::Unit::TestCase
523
610
  assert_equal 1, oo.first_row
524
611
  end
525
612
  if GOOGLE
526
- #-- Google
527
- @goo.default_sheet = @goo.sheets.first
528
- assert_equal 1, @goo.first_row
613
+ oo = Google.new(key_of("numbers1"))
614
+ oo.default_sheet = oo.sheets.first
615
+ assert_equal 1, oo.first_row
529
616
  end
530
617
  end
531
618
 
532
619
  def test_first_column
533
- #-- OpenOffice
534
- oo = Openoffice.new(File.join("test","numbers1.ods"))
535
- oo.default_sheet = oo.sheets.first
536
- assert_equal 1, oo.first_column
620
+ if OPENOFFICE
621
+ oo = Openoffice.new(File.join("test","numbers1.ods"))
622
+ oo.default_sheet = oo.sheets.first
623
+ assert_equal 1, oo.first_column
624
+ end
537
625
  if EXCEL
538
626
  #-- Excel
539
627
  oo = Excel.new(File.join("test","numbers1.xls"))
@@ -541,37 +629,43 @@ class TestRoo < Test::Unit::TestCase
541
629
  assert_equal 1, oo.first_column
542
630
  end
543
631
  if GOOGLE
544
- #-- Google
545
- @goo.default_sheet = 1 # @goo.sheets.first
546
- assert_equal 1, @goo.first_column
632
+ assert_nothing_raised(Timeout::Error) {
633
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
634
+ oo = Google.new(key_of("numbers1"))
635
+ oo.default_sheet = oo.sheets.first
636
+ assert_equal 1, oo.first_column
637
+ end
638
+ }
547
639
  end
548
640
  end
549
641
 
550
642
  def test_first_column_as_letter_openoffice
551
- if OPENOFFICE #-- OpenOffice
643
+ if OPENOFFICE
552
644
  oo = Openoffice.new(File.join("test","numbers1.ods"))
553
645
  oo.default_sheet = oo.sheets.first
554
646
  assert_equal 'A', oo.first_column_as_letter
555
647
  end
556
648
  end
557
649
 
558
- def test_first_column_as_letter
650
+ def test_first_column_as_letter_excel
559
651
  if EXCEL
560
652
  #-- Excel
561
653
  oo = Excel.new(File.join("test","numbers1.xls"))
562
654
  oo.default_sheet = 1 # oo.sheets.first
563
655
  assert_equal 'A', oo.first_column_as_letter
564
656
  end
657
+ end
658
+
659
+ def test_first_column_as_letter_google
565
660
  if GOOGLE
566
- #-- Google
567
- @goo.default_sheet = @goo.sheets.first
568
- assert_equal 'A', @goo.first_column_as_letter
661
+ oo = Google.new(key_of("numbers1"))
662
+ oo.default_sheet = oo.sheets.first
663
+ assert_equal 'A', oo.first_column_as_letter
569
664
  end
570
665
  end
571
666
 
572
667
  def test_sheetname
573
668
  if OPENOFFICE
574
- #-- OpenOffice
575
669
  oo = Openoffice.new(File.join("test","numbers1.ods"))
576
670
  oo.default_sheet = "Name of Sheet 2"
577
671
  assert_equal 'I am sheet 2', oo.cell('C',5)
@@ -581,6 +675,11 @@ class TestRoo < Test::Unit::TestCase
581
675
  oo.default_sheet = "Name of Sheet 2"
582
676
  assert_equal 'I am sheet 2', oo.cell('C',5)
583
677
  end
678
+ if GOOGLE
679
+ oo = Google.new(key_of("numbers1"))
680
+ oo.default_sheet = "Name of Sheet 2"
681
+ assert_equal 'I am sheet 2', oo.cell('C',5)
682
+ end
584
683
  end
585
684
 
586
685
  def test_boundaries
@@ -640,13 +739,11 @@ class TestRoo < Test::Unit::TestCase
640
739
  oo.default_sheet = "Tabelle1"
641
740
  }
642
741
  end
643
- after Date.new(2007,7,20) do
644
742
  assert_nothing_raised(ArgumentError) {
645
743
  # oo.default_sheet = 1
646
744
  #oo.default_sheet = "first sheet"
647
745
  oo.default_sheet = "Tabelle1"
648
746
  }
649
- end
650
747
  end
651
748
  end
652
749
 
@@ -671,9 +768,9 @@ class TestRoo < Test::Unit::TestCase
671
768
  def test_writeopenoffice
672
769
  if OPENOFFICEWRITE
673
770
  File.cp(File.join("test","numbers1.ods"),
674
- File.join("test","numbers2.ods"))
771
+ File.join("test","numbers2.ods"))
675
772
  File.cp(File.join("test","numbers2.ods"),
676
- File.join("test","bak_numbers2.ods"))
773
+ File.join("test","bak_numbers2.ods"))
677
774
  oo = Openoffice.new(File.join("test","numbers2.ods"))
678
775
  oo.default_sheet = oo.sheets.first
679
776
  oo.first_row.upto(oo.last_row) {|y|
@@ -701,7 +798,7 @@ class TestRoo < Test::Unit::TestCase
701
798
  assert_equal oo2.cell('e',2)+7, oo1.cell('e',2)
702
799
 
703
800
  File.cp(File.join("test","bak_numbers2.ods"),
704
- File.join("test","numbers2.ods"))
801
+ File.join("test","numbers2.ods"))
705
802
  end
706
803
  end
707
804
 
@@ -734,23 +831,29 @@ class TestRoo < Test::Unit::TestCase
734
831
  assert_equal 10, oo.cell('d',1)
735
832
  assert_equal 10, oo.cell('e',1)
736
833
  end
737
- if EXCEL
738
- oo = Excel.new(File.join("test","numbers1.xls"))
739
- oo.default_sheet = 4
740
- assert_equal Date.new(2007,06,16), oo.cell('a',1)
741
- assert_equal 10, oo.cell('b',1)
742
- assert_equal 10, oo.cell('c',1)
743
- assert_equal 10, oo.cell('d',1)
744
- assert_equal 10, oo.cell('e',1)
745
- end
746
- if GOOGLE
747
- @goo.default_sheet = "Sheet4"
748
- assert_equal Date.new(2007,06,16), @goo.cell('a',1)
749
- assert_equal 10, @goo.cell('b',1)
750
- assert_equal 10, @goo.cell('c',1)
751
- assert_equal 10, @goo.cell('d',1)
752
- assert_equal 10, @goo.cell('e',1)
753
- end
834
+ #if EXCEL
835
+ # # dieser Test ist fuer Excel sheets eigentlich nicht noetig,
836
+ # # da der Bug nur bei OO-Dokumenten auftrat
837
+ # oo = Excel.new(File.join("test","numbers1.xls"))
838
+ # oo.default_sheet = 4
839
+ # assert_equal Date.new(2007,06,16), oo.cell('a',1)
840
+ # assert_equal 10, oo.cell('b',1)
841
+ # assert_equal 10, oo.cell('c',1)
842
+ # assert_equal 10, oo.cell('d',1)
843
+ # assert_equal 10, oo.cell('e',1)
844
+ #end
845
+ #if GOOGLE
846
+ # # dieser Test ist fuer Google sheets eigentlich nicht noetig,
847
+ # # da der Bug nur bei OO-Dokumenten auftrat
848
+ # oo = Google.new(key_of("numbers1"))
849
+ # #oo.sheetlist # TODO: refactor me!
850
+ # oo.default_sheet = "Sheet4"
851
+ # assert_equal Date.new(2007,06,16), oo.cell('a',1)
852
+ # assert_equal 10, oo.cell('b',1)
853
+ # assert_equal 10, oo.cell('c',1)
854
+ # assert_equal 10, oo.cell('d',1)
855
+ # assert_equal 10, oo.cell('e',1)
856
+ #end
754
857
  end
755
858
 
756
859
  def test_bug_italo_ve
@@ -772,26 +875,15 @@ class TestRoo < Test::Unit::TestCase
772
875
  assert_equal 2, oo.cell('a',2)
773
876
  assert_equal 3, oo.cell('a',3)
774
877
  end
775
- end
776
-
777
- def DONT_test_large_file
778
- if OPENOFFICE
779
- count = 0
780
- oo = Openoffice.new(File.join("test","Bibelbund.ods"))
781
- oo.default_sheet = oo.sheets.first
782
- oo.first_row.upto(oo.last_row) do |row|
783
- oo.first_column.upto(oo.last_column) do |col|
784
- unless oo.empty?(row,col)
785
- count += 1
786
- a = oo.cell(row,col)
787
- # puts a
788
- # b = gets
789
- end
790
- end
791
- end
792
- puts count.to_s+" cells with content"
793
- end
794
-
878
+ #if GOOGLE
879
+ # oo = Google.new(key_of("numbers1"))
880
+ # oo.default_sheet = "Sheet5"
881
+ # assert_equal 1, oo.cell('A',1)
882
+ # assert_equal 5, oo.cell('b',1)
883
+ # assert_equal 5, oo.cell('c',1)
884
+ # assert_equal 2, oo.cell('a',2)
885
+ # assert_equal 3, oo.cell('a',3)
886
+ #end
795
887
  end
796
888
 
797
889
  def test_italo_table
@@ -946,9 +1038,9 @@ class TestRoo < Test::Unit::TestCase
946
1038
  assert_equal "=[Sheet2.A1]", oo.formula('C',7)
947
1039
  assert_nil oo.formula('A',6)
948
1040
  assert_equal [[7, 1, "=SUM([.A1:.A6])"],
949
- [7, 2, "=SUM([.$A$1:.B6])"],
950
- [7, 3, "=[Sheet2.A1]"],
951
- [8, 2, "=SUM([.$A$1:.B7])"],
1041
+ [7, 2, "=SUM([.$A$1:.B6])"],
1042
+ [7, 3, "=[Sheet2.A1]"],
1043
+ [8, 2, "=SUM([.$A$1:.B7])"],
952
1044
  ], oo.formulas(oo.sheets.first)
953
1045
 
954
1046
  after Date.new(2007,6,25) do
@@ -960,9 +1052,6 @@ class TestRoo < Test::Unit::TestCase
960
1052
  oo.set('A',17, 42.5)
961
1053
  assert_equal 42.5, oo.cell('A',17)
962
1054
  end
963
- #after Date.new(2007,7,30) do
964
- # assert_equal 21, oo.solve('a',7)
965
- #end
966
1055
  end
967
1056
  if defined? excel_supports_formulas
968
1057
  if EXCEL
@@ -979,9 +1068,9 @@ class TestRoo < Test::Unit::TestCase
979
1068
  assert_equal " = [Sheet2.A1]", oo.formula('C',7)
980
1069
  assert_nil oo.formula('A',6)
981
1070
  assert_equal [[7, 1, " = SUM([.A1:.A6])"],
982
- [7, 2, " = SUM([.$A$1:.B6])"],
983
- [7, 3, " = [Sheet2.A1]"],
984
- [8, 2, " = SUM([.$A$1:.B7])"],
1071
+ [7, 2, " = SUM([.$A$1:.B6])"],
1072
+ [7, 3, " = [Sheet2.A1]"],
1073
+ [8, 2, " = SUM([.$A$1:.B7])"],
985
1074
  ], oo.formulas
986
1075
 
987
1076
  after Date.new(2007,6,25) do
@@ -993,16 +1082,41 @@ class TestRoo < Test::Unit::TestCase
993
1082
  oo.set('A',17, 42.5)
994
1083
  assert_equal 42.5, oo.cell('A',17)
995
1084
  end
996
- #after Date.new(2007,7,30) do
997
- # assert_equal 21, oo.solve('a',7)
998
- #end
999
1085
 
1000
1086
  end
1001
1087
  end
1088
+ if GOOGLE
1089
+ oo = Google.new(key_of("formula"))
1090
+ oo.default_sheet = oo.sheets.first
1091
+ assert_equal 1, oo.cell('A',1)
1092
+ assert_equal 2, oo.cell('A',2)
1093
+ assert_equal 3, oo.cell('A',3)
1094
+ assert_equal 4, oo.cell('A',4)
1095
+ assert_equal 5, oo.cell('A',5)
1096
+ assert_equal 6, oo.cell('A',6)
1097
+ # assert_equal 21, oo.cell('A',7)
1098
+ assert_equal 21.0, oo.cell('A',7) #TODO: better solution Fixnum/Float
1099
+ assert_equal :formula, oo.celltype('A',7)
1100
+ # assert_equal "=[Sheet2.A1]", oo.formula('C',7)
1101
+ # !!! different from formulas in Openoffice
1102
+ assert_equal "=sheet2!R[-6]C[-2]", oo.formula('C',7)
1103
+ assert_nil oo.formula('A',6)
1104
+ # assert_equal [[7, 1, "=SUM([.A1:.A6])"],
1105
+ # [7, 2, "=SUM([.$A$1:.B6])"],
1106
+ # [7, 3, "=[Sheet2.A1]"],
1107
+ # [8, 2, "=SUM([.$A$1:.B7])"],
1108
+ # ], oo.formulas(oo.sheets.first)
1109
+ # different format than in openoffice spreadsheets:
1110
+ assert_equal [[7, 1, "=SUM(R[-6]C[0]:R[-1]C[0])"],
1111
+ [7, 2, "=SUM(R1C1:R[-1]C[0])"],
1112
+ [7, 3, "=sheet2!R[-6]C[-2]"],
1113
+ [8, 2, "=SUM(R1C1:R[-1]C[0])"]],
1114
+ oo.formulas(oo.sheets.first)
1115
+ end # GOOGLE
1002
1116
  end
1003
1117
 
1004
1118
 
1005
- def test_borders_sheets
1119
+ def test_borders_sheets_openoffice
1006
1120
  if OPENOFFICE
1007
1121
  oo = Openoffice.new(File.join("test","borders.ods"))
1008
1122
  oo.default_sheet = oo.sheets[1]
@@ -1023,6 +1137,8 @@ class TestRoo < Test::Unit::TestCase
1023
1137
  assert_equal 5, oo.first_column
1024
1138
  assert_equal 9, oo.last_column
1025
1139
  end
1140
+ end
1141
+ def test_borders_sheets_excel
1026
1142
  if EXCEL
1027
1143
  oo = Excel.new(File.join("test","borders.xls"))
1028
1144
  oo.default_sheet = oo.sheets[1]
@@ -1043,7 +1159,37 @@ class TestRoo < Test::Unit::TestCase
1043
1159
  assert_equal 5, oo.first_column
1044
1160
  assert_equal 9, oo.last_column
1045
1161
  end
1162
+ end
1046
1163
 
1164
+ def test_borders_sheets_google
1165
+ if GOOGLE
1166
+ assert_nothing_raised(Timeout::Error) {
1167
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1168
+ oo = Google.new(key_of("borders"))
1169
+ oo.default_sheet = oo.sheets[0]
1170
+ assert_equal oo.sheets.first, oo.default_sheet
1171
+ assert_equal 5, oo.first_row
1172
+ oo.default_sheet = oo.sheets[1]
1173
+ assert_equal 'Sheet2', oo.default_sheet
1174
+ assert_equal 6, oo.first_row
1175
+ assert_equal 11, oo.last_row
1176
+ assert_equal 4, oo.first_column
1177
+ assert_equal 8, oo.last_column
1178
+
1179
+ oo.default_sheet = oo.sheets.first
1180
+ assert_equal 5, oo.first_row
1181
+ assert_equal 10, oo.last_row
1182
+ assert_equal 3, oo.first_column
1183
+ assert_equal 7, oo.last_column
1184
+
1185
+ oo.default_sheet = oo.sheets[2]
1186
+ assert_equal 7, oo.first_row
1187
+ assert_equal 12, oo.last_row
1188
+ assert_equal 5, oo.first_column
1189
+ assert_equal 9, oo.last_column
1190
+ end
1191
+ }
1192
+ end
1047
1193
  end
1048
1194
 
1049
1195
  def yaml_entry(row,col,type,value)
@@ -1058,19 +1204,19 @@ class TestRoo < Test::Unit::TestCase
1058
1204
  assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3)
1059
1205
  assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3)
1060
1206
  assert_equal \
1061
- "--- \n"+yaml_entry(12,3,"float",43.0) +
1062
- yaml_entry(12,4,"float",44.0) +
1063
- yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12)
1207
+ "--- \n"+yaml_entry(12,3,"float",43.0) +
1208
+ yaml_entry(12,4,"float",44.0) +
1209
+ yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12)
1064
1210
  assert_equal \
1065
- "--- \n"+yaml_entry(12,3,"float",43.0)+
1066
- yaml_entry(12,4,"float",44.0)+
1067
- yaml_entry(12,5,"float",45.0)+
1068
- yaml_entry(15,3,"float",43.0)+
1069
- yaml_entry(15,4,"float",44.0)+
1070
- yaml_entry(15,5,"float",45.0)+
1071
- yaml_entry(16,3,"string","dreiundvierzig")+
1072
- yaml_entry(16,4,"string","vierundvierzig")+
1073
- yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3)
1211
+ "--- \n"+yaml_entry(12,3,"float",43.0)+
1212
+ yaml_entry(12,4,"float",44.0)+
1213
+ yaml_entry(12,5,"float",45.0)+
1214
+ yaml_entry(15,3,"float",43.0)+
1215
+ yaml_entry(15,4,"float",44.0)+
1216
+ yaml_entry(15,5,"float",45.0)+
1217
+ yaml_entry(16,3,"string","dreiundvierzig")+
1218
+ yaml_entry(16,4,"string","vierundvierzig")+
1219
+ yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3)
1074
1220
  #example: puts oo.to_yaml({}, 12,3)
1075
1221
  #example: puts oo.to_yaml({"probe" => "bodenproben_2007-06-30"}, 12,3)
1076
1222
  end
@@ -1081,19 +1227,42 @@ class TestRoo < Test::Unit::TestCase
1081
1227
  assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3)
1082
1228
  assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3)
1083
1229
  assert_equal \
1084
- "--- \n"+yaml_entry(12,3,"float",43.0) +
1085
- yaml_entry(12,4,"float",44.0) +
1086
- yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12)
1230
+ "--- \n"+yaml_entry(12,3,"float",43.0) +
1231
+ yaml_entry(12,4,"float",44.0) +
1232
+ yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12)
1233
+ assert_equal \
1234
+ "--- \n"+yaml_entry(12,3,"float",43.0)+
1235
+ yaml_entry(12,4,"float",44.0)+
1236
+ yaml_entry(12,5,"float",45.0)+
1237
+ yaml_entry(15,3,"float",43.0)+
1238
+ yaml_entry(15,4,"float",44.0)+
1239
+ yaml_entry(15,5,"float",45.0)+
1240
+ yaml_entry(16,3,"string","dreiundvierzig")+
1241
+ yaml_entry(16,4,"string","vierundvierzig")+
1242
+ yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3)
1243
+ end
1244
+ if GOOGLE
1245
+ oo = Google.new(key_of("numbers1"))
1246
+ oo.default_sheet = oo.sheets.first
1247
+ assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), oo.to_yaml({}, 5,1,5,1)
1248
+ assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3)
1249
+ assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3)
1250
+ assert_equal \
1251
+ "--- \n"+yaml_entry(12,3,"float",43.0) +
1252
+ yaml_entry(12,4,"float",44.0) +
1253
+ yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12)
1087
1254
  assert_equal \
1088
- "--- \n"+yaml_entry(12,3,"float",43.0)+
1089
- yaml_entry(12,4,"float",44.0)+
1090
- yaml_entry(12,5,"float",45.0)+
1091
- yaml_entry(15,3,"float",43.0)+
1092
- yaml_entry(15,4,"float",44.0)+
1093
- yaml_entry(15,5,"float",45.0)+
1094
- yaml_entry(16,3,"string","dreiundvierzig")+
1095
- yaml_entry(16,4,"string","vierundvierzig")+
1096
- yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3)
1255
+ "--- \n"+yaml_entry(12,3,"float",43.0)+
1256
+ yaml_entry(12,4,"float",44.0)+
1257
+ yaml_entry(12,5,"float",45.0)+
1258
+ yaml_entry(15,3,"float",43.0)+
1259
+ yaml_entry(15,4,"float",44.0)+
1260
+ yaml_entry(15,5,"float",45.0)+
1261
+ yaml_entry(16,3,"string","dreiundvierzig")+
1262
+ yaml_entry(16,4,"string","vierundvierzig")+
1263
+ yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3)
1264
+ #example: puts oo.to_yaml({}, 12,3)
1265
+ #example: puts oo.to_yaml({"probe" => "bodenproben_2007-06-30"}, 12,3)
1097
1266
  end
1098
1267
  end
1099
1268
 
@@ -1238,111 +1407,127 @@ class TestRoo < Test::Unit::TestCase
1238
1407
  assert_equal 44, oo.cell('D',4)
1239
1408
  end
1240
1409
  if GOOGLE
1241
- after Date.new(2007,8,30) do
1242
- raise "need to write test for GOOGLE"
1243
- end
1410
+ oo = Google.new(key_of("only_one_sheet"))
1411
+ # oo.default_sheet = oo.sheets.first
1412
+ assert_equal 42, oo.cell('B',4)
1413
+ assert_equal 43, oo.cell('C',4)
1414
+ assert_equal 44, oo.cell('D',4)
1415
+ oo.default_sheet = oo.sheets.first
1416
+ assert_equal 42, oo.cell('B',4)
1417
+ assert_equal 43, oo.cell('C',4)
1418
+ assert_equal 44, oo.cell('D',4)
1244
1419
  end
1245
1420
 
1246
1421
  end
1247
1422
 
1248
1423
  def test_excel_open_from_uri_and_zipped
1249
- if ONLINE
1250
- url = 'http://stiny-leonhard.de/bode-v1.xls.zip'
1251
- excel = Excel.new(url, :zip)
1252
- assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
1253
- excel.remove_tmp # don't forget to remove the temporary files
1424
+ if EXCEL
1425
+ if ONLINE
1426
+ url = 'http://stiny-leonhard.de/bode-v1.xls.zip'
1427
+ excel = Excel.new(url, :zip)
1428
+ assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
1429
+ excel.remove_tmp # don't forget to remove the temporary files
1430
+ end
1254
1431
  end
1255
1432
  end
1256
1433
 
1257
1434
  def test_openoffice_open_from_uri_and_zipped
1258
- if ONLINE
1259
- url = 'http://spazioinwind.libero.it/s2/rata.ods.zip'
1260
- sheet = Openoffice.new(url, :zip)
1261
- #has been changed: assert_equal 'ist "e" im Nenner von H(s)', sheet.cell('b', 5)
1262
- assert_in_delta 0.001, 505.14, sheet.cell('c', 33).to_f
1263
- sheet.remove_tmp # don't forget to remove the temporary files
1435
+ if OPENOFFICE
1436
+ if ONLINE
1437
+ url = 'http://spazioinwind.libero.it/s2/rata.ods.zip'
1438
+ sheet = Openoffice.new(url, :zip)
1439
+ #has been changed: assert_equal 'ist "e" im Nenner von H(s)', sheet.cell('b', 5)
1440
+ assert_in_delta 0.001, 505.14, sheet.cell('c', 33).to_f
1441
+ sheet.remove_tmp # don't forget to remove the temporary files
1442
+ end
1264
1443
  end
1265
1444
  end
1266
1445
 
1267
1446
  def test_excel_zipped
1268
- excel = Excel.new(File.join("test","bode-v1.xls.zip"), :zip)
1269
- assert excel
1270
- assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
1271
- excel.remove_tmp # don't forget to remove the temporary files
1447
+ if EXCEL
1448
+ excel = Excel.new(File.join("test","bode-v1.xls.zip"), :zip)
1449
+ assert excel
1450
+ assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
1451
+ excel.remove_tmp # don't forget to remove the temporary files
1452
+ end
1272
1453
  end
1273
1454
 
1274
1455
  def test_openoffice_zipped
1275
- oo = Openoffice.new(File.join("test","bode-v1.ods.zip"), :zip)
1276
- assert oo
1277
- oo.default_sheet = oo.sheets.first
1278
- assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
1279
- oo.remove_tmp # don't forget to remove the temporary files
1456
+ if OPENOFFICE
1457
+ oo = Openoffice.new(File.join("test","bode-v1.ods.zip"), :zip)
1458
+ assert oo
1459
+ oo.default_sheet = oo.sheets.first
1460
+ assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
1461
+ oo.remove_tmp # don't forget to remove the temporary files
1462
+ end
1280
1463
  end
1281
1464
 
1282
1465
  def test_bug_ric
1283
- oo = Openoffice.new(File.join("test","ric.ods"))
1284
- oo.default_sheet = oo.sheets.first
1285
- assert oo.empty?('A',1)
1286
- assert oo.empty?('B',1)
1287
- assert oo.empty?('C',1)
1288
- assert oo.empty?('D',1)
1289
- expected = 1
1290
- letter = 'e'
1291
- while letter <= 'u'
1292
- assert_equal expected, oo.cell(letter,1)
1293
- letter.succ!
1294
- expected += 1
1295
- end
1296
- #assert_equal 2, oo.cell('f',1)
1297
- #assert_equal 3, oo.cell('g',1)
1298
- #assert_equal 4, oo.cell('h',1)
1299
- #assert_equal 5, oo.cell('i',1)
1300
- #assert_equal 6, oo.cell('j',1)
1301
- #assert_equal 7, oo.cell('k',1)
1302
- #assert_equal 8, oo.cell('l',1)
1303
- #assert_equal 9, oo.cell('m',1)
1304
- #assert_equal 10, oo.cell('n',1)
1305
- #assert_equal 11, oo.cell('o',1)
1306
- #assert_equal 12, oo.cell('p',1)
1307
- #assert_equal 13, oo.cell('q',1)
1308
- #assert_equal 14, oo.cell('r',1)
1309
- #assert_equal 15, oo.cell('s',1)
1310
- #assert_equal 16, oo.cell('t',1)
1311
- #assert_equal 17, oo.cell('u',1)
1312
- assert_equal 'J', oo.cell('v',1)
1313
- assert_equal 'P', oo.cell('w',1)
1314
- assert_equal 'B', oo.cell('x',1)
1315
- assert_equal 'All', oo.cell('y',1)
1316
- assert_equal 0, oo.cell('a',2)
1317
- assert oo.empty?('b',2)
1318
- assert oo.empty?('c',2)
1319
- assert oo.empty?('d',2)
1320
-
1321
- #'e'.upto('s') {|letter|
1322
- # assert_equal 'B', oo.cell(letter,2)
1323
- #}
1324
- assert_equal 'B', oo.cell('e',2)
1325
- assert_equal 'B', oo.cell('f',2)
1326
- assert_equal 'B', oo.cell('g',2)
1327
- assert_equal 'B', oo.cell('h',2)
1328
- assert_equal 'B', oo.cell('i',2)
1329
- assert_equal 'B', oo.cell('j',2)
1330
- assert_equal 'B', oo.cell('k',2)
1331
- assert_equal 'B', oo.cell('l',2)
1332
- assert_equal 'B', oo.cell('m',2)
1333
- assert_equal 'B', oo.cell('n',2)
1334
- assert_equal 'B', oo.cell('o',2)
1335
- assert_equal 'B', oo.cell('p',2)
1336
- assert_equal 'B', oo.cell('q',2)
1337
- assert_equal 'B', oo.cell('r',2)
1338
- assert_equal 'B', oo.cell('s',2)
1339
-
1340
- assert oo.empty?('t',2)
1341
- assert oo.empty?('u',2)
1342
- assert_equal 0 , oo.cell('v',2)
1343
- assert_equal 0 , oo.cell('w',2)
1344
- assert_equal 15 , oo.cell('x',2)
1345
- assert_equal 15 , oo.cell('y',2)
1466
+ if OPENOFFICE
1467
+ oo = Openoffice.new(File.join("test","ric.ods"))
1468
+ oo.default_sheet = oo.sheets.first
1469
+ assert oo.empty?('A',1)
1470
+ assert oo.empty?('B',1)
1471
+ assert oo.empty?('C',1)
1472
+ assert oo.empty?('D',1)
1473
+ expected = 1
1474
+ letter = 'e'
1475
+ while letter <= 'u'
1476
+ assert_equal expected, oo.cell(letter,1)
1477
+ letter.succ!
1478
+ expected += 1
1479
+ end
1480
+ #assert_equal 2, oo.cell('f',1)
1481
+ #assert_equal 3, oo.cell('g',1)
1482
+ #assert_equal 4, oo.cell('h',1)
1483
+ #assert_equal 5, oo.cell('i',1)
1484
+ #assert_equal 6, oo.cell('j',1)
1485
+ #assert_equal 7, oo.cell('k',1)
1486
+ #assert_equal 8, oo.cell('l',1)
1487
+ #assert_equal 9, oo.cell('m',1)
1488
+ #assert_equal 10, oo.cell('n',1)
1489
+ #assert_equal 11, oo.cell('o',1)
1490
+ #assert_equal 12, oo.cell('p',1)
1491
+ #assert_equal 13, oo.cell('q',1)
1492
+ #assert_equal 14, oo.cell('r',1)
1493
+ #assert_equal 15, oo.cell('s',1)
1494
+ #assert_equal 16, oo.cell('t',1)
1495
+ #assert_equal 17, oo.cell('u',1)
1496
+ assert_equal 'J', oo.cell('v',1)
1497
+ assert_equal 'P', oo.cell('w',1)
1498
+ assert_equal 'B', oo.cell('x',1)
1499
+ assert_equal 'All', oo.cell('y',1)
1500
+ assert_equal 0, oo.cell('a',2)
1501
+ assert oo.empty?('b',2)
1502
+ assert oo.empty?('c',2)
1503
+ assert oo.empty?('d',2)
1504
+
1505
+ #'e'.upto('s') {|letter|
1506
+ # assert_equal 'B', oo.cell(letter,2)
1507
+ #}
1508
+ assert_equal 'B', oo.cell('e',2)
1509
+ assert_equal 'B', oo.cell('f',2)
1510
+ assert_equal 'B', oo.cell('g',2)
1511
+ assert_equal 'B', oo.cell('h',2)
1512
+ assert_equal 'B', oo.cell('i',2)
1513
+ assert_equal 'B', oo.cell('j',2)
1514
+ assert_equal 'B', oo.cell('k',2)
1515
+ assert_equal 'B', oo.cell('l',2)
1516
+ assert_equal 'B', oo.cell('m',2)
1517
+ assert_equal 'B', oo.cell('n',2)
1518
+ assert_equal 'B', oo.cell('o',2)
1519
+ assert_equal 'B', oo.cell('p',2)
1520
+ assert_equal 'B', oo.cell('q',2)
1521
+ assert_equal 'B', oo.cell('r',2)
1522
+ assert_equal 'B', oo.cell('s',2)
1523
+
1524
+ assert oo.empty?('t',2)
1525
+ assert oo.empty?('u',2)
1526
+ assert_equal 0 , oo.cell('v',2)
1527
+ assert_equal 0 , oo.cell('w',2)
1528
+ assert_equal 15 , oo.cell('x',2)
1529
+ assert_equal 15 , oo.cell('y',2)
1530
+ end
1346
1531
  end
1347
1532
 
1348
1533
  def test_mehrteilig
@@ -1358,7 +1543,8 @@ class TestRoo < Test::Unit::TestCase
1358
1543
  if OPENOFFICE
1359
1544
  assert_nothing_raised(Timeout::Error) {
1360
1545
  Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1361
- oo = Openoffice.new(File.join("test","Bibelbund500.ods"))
1546
+ File.delete("/tmp/Bibelbund.csv")
1547
+ oo = Openoffice.new(File.join("test","Bibelbund.ods"))
1362
1548
  oo.default_sheet = oo.sheets.first
1363
1549
  assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
1364
1550
  assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", oo.cell(46,'A')
@@ -1377,7 +1563,8 @@ class TestRoo < Test::Unit::TestCase
1377
1563
  if EXCEL
1378
1564
  assert_nothing_raised(Timeout::Error) {
1379
1565
  Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1380
- oo = Excel.new(File.join("test","Bibelbund500.xls"))
1566
+ File.delete("/tmp/Bibelbund.csv")
1567
+ oo = Excel.new(File.join("test","Bibelbund.xls"))
1381
1568
  oo.default_sheet = oo.sheets.first
1382
1569
  assert oo.to_csv("/tmp/Bibelbund.csv")
1383
1570
  assert File.exists?("/tmp/Bibelbund.csv")
@@ -1388,6 +1575,27 @@ class TestRoo < Test::Unit::TestCase
1388
1575
  end # LONG_RUN
1389
1576
  end # def to_csv
1390
1577
 
1578
+ def test_to_csv_google
1579
+ # maybe a better example... TODO:
1580
+ after Date.new(2008,1,30) do
1581
+ if GOOGLE
1582
+ assert_nothing_raised(Timeout::Error) {
1583
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1584
+ File.delete("/tmp/numbers1.csv") if File.exists?("/tmp/numbers1.csv")
1585
+ oo = Google.new(key_of('numbers1'))
1586
+ oo.default_sheet = oo.sheets.first
1587
+ #?? assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
1588
+ #?? assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", oo.cell(46,'A')
1589
+ #?? assert_equal "Tagebuch aus Chile Juli 1977", oo.cell(55,'A')
1590
+ assert oo.to_csv("/tmp/numbers1.csv")
1591
+ assert File.exists?("/tmp/numbers1.csv")
1592
+ assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
1593
+ end # Timeout
1594
+ } # nothing_raised
1595
+ end # GOOGLE
1596
+ end # after
1597
+ end
1598
+
1391
1599
  def test_bug_mehrere_datum
1392
1600
  if OPENOFFICE
1393
1601
  oo = Openoffice.new(File.join("test","numbers1.ods"))
@@ -1543,6 +1751,47 @@ class TestRoo < Test::Unit::TestCase
1543
1751
  oo.reload
1544
1752
  end
1545
1753
  end
1754
+ if GOOGLE
1755
+ oo = Google.new(key_of("numbers1"))
1756
+ 2.times do
1757
+ oo.default_sheet = "Tabelle1"
1758
+ assert_equal 1, oo.cell(1,1)
1759
+ assert_equal 1, oo.cell(1,1,"Tabelle1")
1760
+ assert_equal "I am sheet 2", oo.cell('C',5,"Name of Sheet 2")
1761
+ sheetname = 'Sheet5'
1762
+ assert_equal :date, oo.celltype('A',4,sheetname)
1763
+ assert_equal :date, oo.celltype('B',4,sheetname)
1764
+ assert_equal :date, oo.celltype('C',4,sheetname)
1765
+ assert_equal :date, oo.celltype('D',4,sheetname)
1766
+ assert_equal :date, oo.celltype('E',4,sheetname)
1767
+ assert_equal Date.new(2007,11,21), oo.cell('A',4,sheetname)
1768
+ assert_equal Date.new(2007,11,21), oo.cell('B',4,sheetname)
1769
+ assert_equal Date.new(2007,11,21), oo.cell('C',4,sheetname)
1770
+ assert_equal Date.new(2007,11,21), oo.cell('D',4,sheetname)
1771
+ assert_equal Date.new(2007,11,21), oo.cell('E',4,sheetname)
1772
+ assert_equal :float, oo.celltype('A',5,sheetname)
1773
+ assert_equal :float, oo.celltype('B',5,sheetname)
1774
+ assert_equal :float, oo.celltype('C',5,sheetname)
1775
+ assert_equal :float, oo.celltype('D',5,sheetname)
1776
+ assert_equal :float, oo.celltype('E',5,sheetname)
1777
+ assert_equal 42, oo.cell('A',5,sheetname)
1778
+ assert_equal 42, oo.cell('B',5,sheetname)
1779
+ assert_equal 42, oo.cell('C',5,sheetname)
1780
+ assert_equal 42, oo.cell('D',5,sheetname)
1781
+ assert_equal 42, oo.cell('E',5,sheetname)
1782
+ assert_equal :string, oo.celltype('A',6,sheetname)
1783
+ assert_equal :string, oo.celltype('B',6,sheetname)
1784
+ assert_equal :string, oo.celltype('C',6,sheetname)
1785
+ assert_equal :string, oo.celltype('D',6,sheetname)
1786
+ assert_equal :string, oo.celltype('E',6,sheetname)
1787
+ assert_equal "ABC", oo.cell('A',6,sheetname)
1788
+ assert_equal "ABC", oo.cell('B',6,sheetname)
1789
+ assert_equal "ABC", oo.cell('C',6,sheetname)
1790
+ assert_equal "ABC", oo.cell('D',6,sheetname)
1791
+ assert_equal "ABC", oo.cell('E',6,sheetname)
1792
+ oo.reload
1793
+ end
1794
+ end
1546
1795
  end
1547
1796
 
1548
1797
  def test_bug_empty_sheet
@@ -1554,11 +1803,11 @@ class TestRoo < Test::Unit::TestCase
1554
1803
  assert_equal "", `cat /tmp/emptysheet.csv`
1555
1804
  end
1556
1805
 
1557
- def test_find_by_row_openoffice
1806
+ def test_find_by_row_huge_document_openoffice
1558
1807
  if LONG_RUN
1559
1808
  if OPENOFFICE
1560
1809
  Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1561
- oo = Openoffice.new(File.join("test","Bibelbund500.ods"))
1810
+ oo = Openoffice.new(File.join("test","Bibelbund.ods"))
1562
1811
  oo.default_sheet = oo.sheets.first
1563
1812
  rec = oo.find 20
1564
1813
  assert rec
@@ -1575,11 +1824,29 @@ class TestRoo < Test::Unit::TestCase
1575
1824
  end
1576
1825
  end
1577
1826
 
1578
- def test_find_by_row_excel
1827
+ def test_find_by_row_huge_document_excel
1579
1828
  if LONG_RUN
1580
1829
  if EXCEL
1581
1830
  Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1582
- oo = Excel.new(File.join("test","Bibelbund500.xls"))
1831
+ oo = Excel.new(File.join("test","Bibelbund.xls"))
1832
+ oo.default_sheet = oo.sheets.first
1833
+ rec = oo.find 20
1834
+ assert rec
1835
+ assert_equal "Brief aus dem Sekretariat", rec[0]
1836
+
1837
+ rec = oo.find 22
1838
+ assert rec
1839
+ assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]
1840
+ end
1841
+ end
1842
+ end
1843
+ end
1844
+
1845
+ def test_find_by_row_huge_document_google
1846
+ if LONG_RUN
1847
+ if GOOGLE
1848
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1849
+ oo = Google.new(key_of("Bibelbund"))
1583
1850
  oo.default_sheet = oo.sheets.first
1584
1851
  rec = oo.find 20
1585
1852
  assert rec
@@ -1598,88 +1865,88 @@ class TestRoo < Test::Unit::TestCase
1598
1865
  if OPENOFFICE
1599
1866
  assert_nothing_raised(Timeout::Error) {
1600
1867
  Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1601
- oo = Openoffice.new(File.join("test","Bibelbund500.ods"))
1868
+ oo = Openoffice.new(File.join("test","Bibelbund.ods"))
1602
1869
  oo.default_sheet = oo.sheets.first
1603
1870
  #-----------------------------------------------------------------
1604
1871
  zeilen = oo.find(:all, :conditions => {
1605
- 'TITEL' => 'Brief aus dem Sekretariat'
1606
- }
1872
+ 'TITEL' => 'Brief aus dem Sekretariat'
1873
+ }
1607
1874
  )
1608
1875
  assert_equal 2, zeilen.size
1609
1876
  assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
1610
- "INTERNET"=>nil,
1611
- "SEITE"=>316.0,
1612
- "KENNUNG"=>"Aus dem Bibelbund",
1613
- "OBJEKT"=>"Bibel+Gem",
1614
- "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1615
- "NUMMER"=>"1982-3",
1616
- "TITEL"=>"Brief aus dem Sekretariat"},
1617
- {"VERFASSER"=>"Almassy, Annelene von",
1618
- "INTERNET"=>nil,
1619
- "SEITE"=>222.0,
1620
- "KENNUNG"=>"Aus dem Bibelbund",
1621
- "OBJEKT"=>"Bibel+Gem",
1622
- "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1623
- "NUMMER"=>"1983-2",
1624
- "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
1877
+ "INTERNET"=>nil,
1878
+ "SEITE"=>316.0,
1879
+ "KENNUNG"=>"Aus dem Bibelbund",
1880
+ "OBJEKT"=>"Bibel+Gem",
1881
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1882
+ "NUMMER"=>"1982-3",
1883
+ "TITEL"=>"Brief aus dem Sekretariat"},
1884
+ {"VERFASSER"=>"Almassy, Annelene von",
1885
+ "INTERNET"=>nil,
1886
+ "SEITE"=>222.0,
1887
+ "KENNUNG"=>"Aus dem Bibelbund",
1888
+ "OBJEKT"=>"Bibel+Gem",
1889
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1890
+ "NUMMER"=>"1983-2",
1891
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
1625
1892
 
1626
1893
  #----------------------------------------------------------
1627
1894
  zeilen = oo.find(:all,
1628
- :conditions => { 'VERFASSER' => 'Almassy, Annelene von' }
1895
+ :conditions => { 'VERFASSER' => 'Almassy, Annelene von' }
1629
1896
  )
1630
1897
  assert_equal 13, zeilen.size
1631
1898
  #----------------------------------------------------------
1632
1899
  zeilen = oo.find(:all, :conditions => {
1633
- 'TITEL' => 'Brief aus dem Sekretariat',
1634
- 'VERFASSER' => 'Almassy, Annelene von',
1635
- }
1900
+ 'TITEL' => 'Brief aus dem Sekretariat',
1901
+ 'VERFASSER' => 'Almassy, Annelene von',
1902
+ }
1636
1903
  )
1637
1904
  assert_equal 2, zeilen.size
1638
1905
  assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
1639
- "INTERNET"=>nil,
1640
- "SEITE"=>316.0,
1641
- "KENNUNG"=>"Aus dem Bibelbund",
1642
- "OBJEKT"=>"Bibel+Gem",
1643
- "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1644
- "NUMMER"=>"1982-3",
1645
- "TITEL"=>"Brief aus dem Sekretariat"},
1646
- {"VERFASSER"=>"Almassy, Annelene von",
1647
- "INTERNET"=>nil,
1648
- "SEITE"=>222.0,
1649
- "KENNUNG"=>"Aus dem Bibelbund",
1650
- "OBJEKT"=>"Bibel+Gem",
1651
- "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1652
- "NUMMER"=>"1983-2",
1653
- "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
1906
+ "INTERNET"=>nil,
1907
+ "SEITE"=>316.0,
1908
+ "KENNUNG"=>"Aus dem Bibelbund",
1909
+ "OBJEKT"=>"Bibel+Gem",
1910
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1911
+ "NUMMER"=>"1982-3",
1912
+ "TITEL"=>"Brief aus dem Sekretariat"},
1913
+ {"VERFASSER"=>"Almassy, Annelene von",
1914
+ "INTERNET"=>nil,
1915
+ "SEITE"=>222.0,
1916
+ "KENNUNG"=>"Aus dem Bibelbund",
1917
+ "OBJEKT"=>"Bibel+Gem",
1918
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1919
+ "NUMMER"=>"1983-2",
1920
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
1654
1921
 
1655
1922
  # Result as an array
1656
1923
  zeilen = oo.find(:all,
1657
- :conditions => {
1658
- 'TITEL' => 'Brief aus dem Sekretariat',
1659
- 'VERFASSER' => 'Almassy, Annelene von',
1660
- }, :array => true)
1924
+ :conditions => {
1925
+ 'TITEL' => 'Brief aus dem Sekretariat',
1926
+ 'VERFASSER' => 'Almassy, Annelene von',
1927
+ }, :array => true)
1661
1928
  assert_equal 2, zeilen.size
1662
1929
  assert_equal [
1663
- [
1664
- "Brief aus dem Sekretariat",
1665
- "Almassy, Annelene von",
1666
- "Bibel+Gem",
1667
- "1982-3",
1668
- 316.0,
1669
- nil,
1670
- "#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1671
- "Aus dem Bibelbund",
1672
- ],
1673
- [
1674
- "Brief aus dem Sekretariat",
1675
- "Almassy, Annelene von",
1676
- "Bibel+Gem",
1677
- "1983-2",
1678
- 222.0,
1679
- nil,
1680
- "#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1681
- "Aus dem Bibelbund",
1682
- ]] , zeilen
1930
+ [
1931
+ "Brief aus dem Sekretariat",
1932
+ "Almassy, Annelene von",
1933
+ "Bibel+Gem",
1934
+ "1982-3",
1935
+ 316.0,
1936
+ nil,
1937
+ "#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1938
+ "Aus dem Bibelbund",
1939
+ ],
1940
+ [
1941
+ "Brief aus dem Sekretariat",
1942
+ "Almassy, Annelene von",
1943
+ "Bibel+Gem",
1944
+ "1983-2",
1945
+ 222.0,
1946
+ nil,
1947
+ "#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1948
+ "Aus dem Bibelbund",
1949
+ ]] , zeilen
1683
1950
  end # Timeout
1684
1951
  } # nothing_raised
1685
1952
  end
@@ -1691,59 +1958,152 @@ class TestRoo < Test::Unit::TestCase
1691
1958
  if EXCEL
1692
1959
  assert_nothing_raised(Timeout::Error) {
1693
1960
  Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1694
- oo = Excel.new(File.join("test","Bibelbund500.xls"))
1961
+ oo = Excel.new(File.join("test","Bibelbund.xls"))
1962
+ oo.default_sheet = oo.sheets.first
1963
+ #-----------------------------------------------------------------
1964
+ zeilen = oo.find(:all, :conditions => {
1965
+ 'TITEL' => 'Brief aus dem Sekretariat'
1966
+ }
1967
+ )
1968
+ assert_equal 2, zeilen.size
1969
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
1970
+ "INTERNET"=>nil,
1971
+ "SEITE"=>316.0,
1972
+ "KENNUNG"=>"Aus dem Bibelbund",
1973
+ "OBJEKT"=>"Bibel+Gem",
1974
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1975
+ "NUMMER"=>"1982-3",
1976
+ "TITEL"=>"Brief aus dem Sekretariat"},
1977
+ {"VERFASSER"=>"Almassy, Annelene von",
1978
+ "INTERNET"=>nil,
1979
+ "SEITE"=>222.0,
1980
+ "KENNUNG"=>"Aus dem Bibelbund",
1981
+ "OBJEKT"=>"Bibel+Gem",
1982
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1983
+ "NUMMER"=>"1983-2",
1984
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
1985
+
1986
+ #----------------------------------------------------------
1987
+ zeilen = oo.find(:all,
1988
+ :conditions => { 'VERFASSER' => 'Almassy, Annelene von' }
1989
+ )
1990
+ assert_equal 13, zeilen.size
1991
+ #----------------------------------------------------------
1992
+ zeilen = oo.find(:all, :conditions => {
1993
+ 'TITEL' => 'Brief aus dem Sekretariat',
1994
+ 'VERFASSER' => 'Almassy, Annelene von',
1995
+ }
1996
+ )
1997
+ assert_equal 2, zeilen.size
1998
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
1999
+ "INTERNET"=>nil,
2000
+ "SEITE"=>316.0,
2001
+ "KENNUNG"=>"Aus dem Bibelbund",
2002
+ "OBJEKT"=>"Bibel+Gem",
2003
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
2004
+ "NUMMER"=>"1982-3",
2005
+ "TITEL"=>"Brief aus dem Sekretariat"},
2006
+ {"VERFASSER"=>"Almassy, Annelene von",
2007
+ "INTERNET"=>nil,
2008
+ "SEITE"=>222.0,
2009
+ "KENNUNG"=>"Aus dem Bibelbund",
2010
+ "OBJEKT"=>"Bibel+Gem",
2011
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
2012
+ "NUMMER"=>"1983-2",
2013
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
2014
+ end # Timeout
2015
+ } # nothing_raised
2016
+ end
2017
+ end
2018
+ end
2019
+
2020
+ def test_find_by_conditions_google
2021
+ if LONG_RUN
2022
+ if GOOGLE
2023
+ assert_nothing_raised(Timeout::Error) {
2024
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2025
+ oo = Google.new(key_of("Bibelbund"))
1695
2026
  oo.default_sheet = oo.sheets.first
1696
2027
  #-----------------------------------------------------------------
1697
2028
  zeilen = oo.find(:all, :conditions => {
1698
- 'TITEL' => 'Brief aus dem Sekretariat'
1699
- }
2029
+ 'TITEL' => 'Brief aus dem Sekretariat'
2030
+ }
1700
2031
  )
1701
2032
  assert_equal 2, zeilen.size
1702
2033
  assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
1703
- "INTERNET"=>nil,
1704
- "SEITE"=>316.0,
1705
- "KENNUNG"=>"Aus dem Bibelbund",
1706
- "OBJEKT"=>"Bibel+Gem",
1707
- "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1708
- "NUMMER"=>"1982-3",
1709
- "TITEL"=>"Brief aus dem Sekretariat"},
1710
- {"VERFASSER"=>"Almassy, Annelene von",
1711
- "INTERNET"=>nil,
1712
- "SEITE"=>222.0,
1713
- "KENNUNG"=>"Aus dem Bibelbund",
1714
- "OBJEKT"=>"Bibel+Gem",
1715
- "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1716
- "NUMMER"=>"1983-2",
1717
- "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
2034
+ "INTERNET"=>nil,
2035
+ "SEITE"=>316.0,
2036
+ "KENNUNG"=>"Aus dem Bibelbund",
2037
+ "OBJEKT"=>"Bibel+Gem",
2038
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
2039
+ "NUMMER"=>"1982-3",
2040
+ "TITEL"=>"Brief aus dem Sekretariat"},
2041
+ {"VERFASSER"=>"Almassy, Annelene von",
2042
+ "INTERNET"=>nil,
2043
+ "SEITE"=>222.0,
2044
+ "KENNUNG"=>"Aus dem Bibelbund",
2045
+ "OBJEKT"=>"Bibel+Gem",
2046
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
2047
+ "NUMMER"=>"1983-2",
2048
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
1718
2049
 
1719
2050
  #----------------------------------------------------------
1720
2051
  zeilen = oo.find(:all,
1721
- :conditions => { 'VERFASSER' => 'Almassy, Annelene von' }
2052
+ :conditions => { 'VERFASSER' => 'Almassy, Annelene von' }
1722
2053
  )
1723
2054
  assert_equal 13, zeilen.size
1724
2055
  #----------------------------------------------------------
1725
2056
  zeilen = oo.find(:all, :conditions => {
1726
- 'TITEL' => 'Brief aus dem Sekretariat',
1727
- 'VERFASSER' => 'Almassy, Annelene von',
1728
- }
2057
+ 'TITEL' => 'Brief aus dem Sekretariat',
2058
+ 'VERFASSER' => 'Almassy, Annelene von',
2059
+ }
1729
2060
  )
1730
2061
  assert_equal 2, zeilen.size
1731
2062
  assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
1732
- "INTERNET"=>nil,
1733
- "SEITE"=>316.0,
1734
- "KENNUNG"=>"Aus dem Bibelbund",
1735
- "OBJEKT"=>"Bibel+Gem",
1736
- "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1737
- "NUMMER"=>"1982-3",
1738
- "TITEL"=>"Brief aus dem Sekretariat"},
1739
- {"VERFASSER"=>"Almassy, Annelene von",
1740
- "INTERNET"=>nil,
1741
- "SEITE"=>222.0,
1742
- "KENNUNG"=>"Aus dem Bibelbund",
1743
- "OBJEKT"=>"Bibel+Gem",
1744
- "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1745
- "NUMMER"=>"1983-2",
1746
- "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
2063
+ "INTERNET"=>nil,
2064
+ "SEITE"=>316.0,
2065
+ "KENNUNG"=>"Aus dem Bibelbund",
2066
+ "OBJEKT"=>"Bibel+Gem",
2067
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
2068
+ "NUMMER"=>"1982-3",
2069
+ "TITEL"=>"Brief aus dem Sekretariat"},
2070
+ {"VERFASSER"=>"Almassy, Annelene von",
2071
+ "INTERNET"=>nil,
2072
+ "SEITE"=>222.0,
2073
+ "KENNUNG"=>"Aus dem Bibelbund",
2074
+ "OBJEKT"=>"Bibel+Gem",
2075
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
2076
+ "NUMMER"=>"1983-2",
2077
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
2078
+
2079
+ # Result as an array
2080
+ zeilen = oo.find(:all,
2081
+ :conditions => {
2082
+ 'TITEL' => 'Brief aus dem Sekretariat',
2083
+ 'VERFASSER' => 'Almassy, Annelene von',
2084
+ }, :array => true)
2085
+ assert_equal 2, zeilen.size
2086
+ assert_equal [
2087
+ [
2088
+ "Brief aus dem Sekretariat",
2089
+ "Almassy, Annelene von",
2090
+ "Bibel+Gem",
2091
+ "1982-3",
2092
+ 316.0,
2093
+ nil,
2094
+ "#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
2095
+ "Aus dem Bibelbund",
2096
+ ],
2097
+ [
2098
+ "Brief aus dem Sekretariat",
2099
+ "Almassy, Annelene von",
2100
+ "Bibel+Gem",
2101
+ "1983-2",
2102
+ 222.0,
2103
+ nil,
2104
+ "#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
2105
+ "Aus dem Bibelbund",
2106
+ ]] , zeilen
1747
2107
  end # Timeout
1748
2108
  } # nothing_raised
1749
2109
  end
@@ -1774,13 +2134,25 @@ class TestRoo < Test::Unit::TestCase
1774
2134
  end
1775
2135
  end
1776
2136
 
2137
+ def test_columns_google
2138
+ expected = [1.0,5.0,nil,10.0,Date.new(1961,11,21),'tata',nil,nil,nil,nil,'thisisa11',41.0,nil,nil,41.0,'einundvierzig',nil,Date.new(2007,5,31)]
2139
+ if GOOGLE
2140
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2141
+ oo = Google.new(key_of('numbers1'))
2142
+ oo.default_sheet = oo.sheets.first
2143
+ assert_equal expected, oo.column(1)
2144
+ assert_equal expected, oo.column('a')
2145
+ end
2146
+ end
2147
+ end
2148
+
1777
2149
  def test_column_huge_document_openoffice
1778
2150
  if LONG_RUN
1779
2151
  if OPENOFFICE
1780
2152
  assert_nothing_raised(Timeout::Error) {
1781
2153
  Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1782
2154
  #puts Time.now.to_s + "column Openoffice gestartet"
1783
- oo = Openoffice.new(File.join('test','Bibelbund500.ods'))
2155
+ oo = Openoffice.new(File.join('test','Bibelbund.ods'))
1784
2156
  oo.default_sheet = oo.sheets.first
1785
2157
  #assert_equal 3735, oo.column('a').size
1786
2158
  assert_equal 499, oo.column('a').size
@@ -1797,7 +2169,7 @@ class TestRoo < Test::Unit::TestCase
1797
2169
  assert_nothing_raised(Timeout::Error) {
1798
2170
  Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1799
2171
  #puts Time.now.to_s + "column Excel gestartet"
1800
- oo = Excel.new(File.join('test','Bibelbund500.xls'))
2172
+ oo = Excel.new(File.join('test','Bibelbund.xls'))
1801
2173
  oo.default_sheet = oo.sheets.first
1802
2174
  #assert_equal 3735, oo.column('a').size
1803
2175
  assert_equal 499, oo.column('a').size
@@ -1808,6 +2180,23 @@ class TestRoo < Test::Unit::TestCase
1808
2180
  end
1809
2181
  end
1810
2182
 
2183
+ def test_column_huge_document_google
2184
+ if LONG_RUN
2185
+ if GOOGLE_NEW
2186
+ assert_nothing_raised(Timeout::Error) {
2187
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2188
+ #puts Time.now.to_s + "column Openoffice gestartet"
2189
+ oo = Google.new(key_of('Bibelbund'))
2190
+ oo.default_sheet = oo.sheets.first
2191
+ #assert_equal 3735, oo.column('a').size
2192
+ assert_equal 499, oo.column('a').size
2193
+ #puts Time.now.to_s + "column Openoffice beendet"
2194
+ end
2195
+ }
2196
+ end
2197
+ end
2198
+ end
2199
+
1811
2200
  def test_simple_spreadsheet_find_by_condition_openoffice
1812
2201
  oo = Openoffice.new(File.join("test","simple_spreadsheet.ods"))
1813
2202
  oo.default_sheet = oo.sheets.first
@@ -1821,6 +2210,24 @@ class TestRoo < Test::Unit::TestCase
1821
2210
  assert_equal "Task 1" , erg[1]['Comment']
1822
2211
  end
1823
2212
 
2213
+ def test_simple_spreadsheet_find_by_condition_google
2214
+ if GOOGLE
2215
+ after Date.new(2007,12,15) do
2216
+ oo = Google.new(key_of("simple_spreadsheet"))
2217
+ oo.default_sheet = oo.sheets.first
2218
+ oo.header_line = 3
2219
+ erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'})
2220
+ assert_equal Date.new(2007,05,07), erg[1]['Date']
2221
+ assert_equal 10.75 , erg[1]['Start time']
2222
+ assert_equal 12.50 , erg[1]['End time']
2223
+ assert_equal 0 , erg[1]['Pause']
2224
+ assert_kind_of Float, erg[1]['Sum']
2225
+ assert_equal 1.75 , erg[1]['Sum']
2226
+ assert_equal "Task 1" , erg[1]['Comment']
2227
+ end
2228
+ end
2229
+ end
2230
+
1824
2231
  def DONT_test_false_encoding
1825
2232
  ex = Excel.new(File.join('test','false_encoding.xls'))
1826
2233
  ex.default_sheet = ex.sheets.first
@@ -1889,33 +2296,33 @@ class TestRoo < Test::Unit::TestCase
1889
2296
 
1890
2297
  def test_info
1891
2298
  expected_templ = "File: test/numbers1%s\n"+
1892
- "Number of sheets: 5\n"+
1893
- "Sheets: Tabelle1, Name of Sheet 2, Sheet3, Sheet4, Sheet5\n"+
1894
- "Sheet 1:\n"+
1895
- " First row: 1\n"+
1896
- " Last row: 18\n"+
1897
- " First column: A\n"+
1898
- " Last column: G\n"+
1899
- "Sheet 2:\n"+
1900
- " First row: 5\n"+
1901
- " Last row: 14\n"+
1902
- " First column: B\n"+
1903
- " Last column: E\n"+
1904
- "Sheet 3:\n"+
1905
- " First row: 1\n"+
1906
- " Last row: 1\n"+
1907
- " First column: A\n"+
1908
- " Last column: BA\n"+
1909
- "Sheet 4:\n"+
1910
- " First row: 1\n"+
1911
- " Last row: 1\n"+
1912
- " First column: A\n"+
1913
- " Last column: E\n"+
1914
- "Sheet 5:\n"+
1915
- " First row: 1\n"+
1916
- " Last row: 6\n"+
1917
- " First column: A\n"+
1918
- " Last column: E"
2299
+ "Number of sheets: 5\n"+
2300
+ "Sheets: Tabelle1, Name of Sheet 2, Sheet3, Sheet4, Sheet5\n"+
2301
+ "Sheet 1:\n"+
2302
+ " First row: 1\n"+
2303
+ " Last row: 18\n"+
2304
+ " First column: A\n"+
2305
+ " Last column: G\n"+
2306
+ "Sheet 2:\n"+
2307
+ " First row: 5\n"+
2308
+ " Last row: 14\n"+
2309
+ " First column: B\n"+
2310
+ " Last column: E\n"+
2311
+ "Sheet 3:\n"+
2312
+ " First row: 1\n"+
2313
+ " Last row: 1\n"+
2314
+ " First column: A\n"+
2315
+ " Last column: BA\n"+
2316
+ "Sheet 4:\n"+
2317
+ " First row: 1\n"+
2318
+ " Last row: 1\n"+
2319
+ " First column: A\n"+
2320
+ " Last column: E\n"+
2321
+ "Sheet 5:\n"+
2322
+ " First row: 1\n"+
2323
+ " Last row: 6\n"+
2324
+ " First column: A\n"+
2325
+ " Last column: E"
1919
2326
  if OPENOFFICE
1920
2327
  ext = ".ods"
1921
2328
  expected = sprintf(expected_templ,ext)
@@ -1928,6 +2335,14 @@ class TestRoo < Test::Unit::TestCase
1928
2335
  oo = Excel.new(File.join("test","numbers1.xls"))
1929
2336
  assert_equal expected, oo.info
1930
2337
  end
2338
+ if GOOGLE
2339
+ ext = ""
2340
+ expected = sprintf(expected_templ,ext)
2341
+ oo = Google.new(key_of("numbers1"))
2342
+ #$log.debug(expected)
2343
+ #$log.debug expected.gsub(/test\/numbers1/,key_of("numbers1"))
2344
+ assert_equal expected.gsub(/test\/numbers1/,key_of("numbers1")), oo.info
2345
+ end
1931
2346
  end
1932
2347
 
1933
2348
  def test_bug_excel_numbers1_sheet5_last_row
@@ -1970,5 +2385,35 @@ class TestRoo < Test::Unit::TestCase
1970
2385
  oo = Excel.new(File.join('testnichtvorhanden','Bibelbund.xls'))
1971
2386
  }
1972
2387
  end
2388
+ if GOOGLE
2389
+ after Date.new(2008,1,1) do
2390
+ assert_raise(IOError) {
2391
+ oo = Google.new(key_of('testnichtvorhanden'+'Bibelbund.ods'))
2392
+ }
2393
+ end
2394
+ end
2395
+ end
2396
+
2397
+ def test_bug_cell_no_default_sheet
2398
+ if GOOGLE
2399
+ oo = Google.new(key_of("numbers1"))
2400
+ assert_raise(ArgumentError) {
2401
+ # should complain about not set default-sheet
2402
+ #assert_equal 1.0, oo.cell('A',1)
2403
+ value = oo.cell('A',1)
2404
+ assert_equal "ganz rechts gehts noch wetier", oo.cell('A',1,"Sheet3")
2405
+ }
2406
+ end
2407
+ end
2408
+
2409
+ def test_write_google
2410
+ # write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB
2411
+ if GOOGLE
2412
+ oo = Google.new('ptu6bbahNZpY0N0RrxQbWdw')
2413
+ oo.default_sheet = oo.sheets.first
2414
+ oo.set_value(1,1,"hello from the tests")
2415
+ #oo.set_value(1,1,"sin(1)")
2416
+ assert_equal "hello from the tests", oo.cell(1,1)
2417
+ end
1973
2418
  end
1974
2419
  end # class