hmcgowan-roo 1.2.4

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.
Files changed (62) hide show
  1. data/History.txt +225 -0
  2. data/README.txt +43 -0
  3. data/lib/roo/excel.rb +455 -0
  4. data/lib/roo/excelx.rb +654 -0
  5. data/lib/roo/generic_spreadsheet.rb +636 -0
  6. data/lib/roo/google.rb +411 -0
  7. data/lib/roo/openoffice.rb +508 -0
  8. data/lib/roo/roo_rails_helper.rb +81 -0
  9. data/lib/roo/version.rb +9 -0
  10. data/lib/roo.rb +11 -0
  11. data/test/Bibelbund.csv +3741 -0
  12. data/test/Bibelbund.ods +0 -0
  13. data/test/Bibelbund.xls +0 -0
  14. data/test/Bibelbund.xlsx +0 -0
  15. data/test/Bibelbund1.ods +0 -0
  16. data/test/bbu.ods +0 -0
  17. data/test/bbu.xls +0 -0
  18. data/test/bbu.xlsx +0 -0
  19. data/test/bode-v1.ods.zip +0 -0
  20. data/test/bode-v1.xls.zip +0 -0
  21. data/test/boolean.ods +0 -0
  22. data/test/boolean.xls +0 -0
  23. data/test/boolean.xlsx +0 -0
  24. data/test/borders.ods +0 -0
  25. data/test/borders.xls +0 -0
  26. data/test/borders.xlsx +0 -0
  27. data/test/bug-row-column-fixnum-float.xls +0 -0
  28. data/test/datetime.ods +0 -0
  29. data/test/datetime.xls +0 -0
  30. data/test/datetime.xlsx +0 -0
  31. data/test/emptysheets.ods +0 -0
  32. data/test/emptysheets.xls +0 -0
  33. data/test/false_encoding.xls +0 -0
  34. data/test/formula.ods +0 -0
  35. data/test/formula.xls +0 -0
  36. data/test/formula.xlsx +0 -0
  37. data/test/html-escape.ods +0 -0
  38. data/test/no_spreadsheet_file.txt +1 -0
  39. data/test/numbers1.csv +18 -0
  40. data/test/numbers1.ods +0 -0
  41. data/test/numbers1.xls +0 -0
  42. data/test/numbers1.xlsx +0 -0
  43. data/test/numbers1_excel.csv +18 -0
  44. data/test/only_one_sheet.ods +0 -0
  45. data/test/only_one_sheet.xls +0 -0
  46. data/test/only_one_sheet.xlsx +0 -0
  47. data/test/ric.ods +0 -0
  48. data/test/simple_spreadsheet.ods +0 -0
  49. data/test/simple_spreadsheet.xls +0 -0
  50. data/test/simple_spreadsheet.xlsx +0 -0
  51. data/test/simple_spreadsheet_from_italo.ods +0 -0
  52. data/test/simple_spreadsheet_from_italo.xls +0 -0
  53. data/test/style.ods +0 -0
  54. data/test/style.xls +0 -0
  55. data/test/style.xlsx +0 -0
  56. data/test/test_helper.rb +19 -0
  57. data/test/test_roo.rb +4946 -0
  58. data/test/time-test.csv +2 -0
  59. data/test/time-test.ods +0 -0
  60. data/test/time-test.xls +0 -0
  61. data/test/time-test.xlsx +0 -0
  62. metadata +225 -0
data/test/test_roo.rb ADDED
@@ -0,0 +1,4946 @@
1
+ #damit keine falschen Vermutungen aufkommen: Ich habe religioes rein gar nichts
2
+ # mit diesem Bibelbund zu tun, aber die hatten eine ziemlich grosse
3
+ # Spreadsheet-Datei mit ca. 3500 Zeilen oeffentlich im Netz, die sich ganz gut
4
+ # zum Testen eignete.
5
+ #
6
+ #--
7
+ # these test cases were developed to run under Linux OS, some commands
8
+ # (like 'diff') must be changed (or commented out ;-)) if you want to run
9
+ # the tests under another OS
10
+ #
11
+
12
+ TESTDIR = File.dirname(__FILE__)
13
+ require TESTDIR + '/test_helper.rb'
14
+ #require 'soap/rpc/driver'
15
+ require 'fileutils'
16
+ require 'timeout'
17
+ require 'logger'
18
+ $log = Logger.new(File.join(ENV['HOME'],"roo.log"))
19
+ $log.level = Logger::WARN
20
+ #$log.level = Logger::DEBUG
21
+
22
+ DISPLAY_LOG = false
23
+ DB_LOG = false
24
+
25
+ if DB_LOG
26
+ require 'activerecord'
27
+ end
28
+
29
+ include FileUtils
30
+
31
+ if DB_LOG
32
+ def activerecord_connect
33
+ ActiveRecord::Base.establish_connection(:adapter => "mysql",
34
+ :database => "test_runs",
35
+ :host => "localhost",
36
+ :username => "root",
37
+ :socket => "/var/run/mysqld/mysqld.sock")
38
+ end
39
+
40
+ class Testrun < ActiveRecord::Base
41
+ end
42
+ end
43
+
44
+ class Test::Unit::TestCase
45
+ def key_of(spreadsheetname)
46
+ begin
47
+ return {
48
+ 'numbers1' => "o10837434939102457526.4784396906364855777",
49
+ 'borders' => "o10837434939102457526.664868920231926255",
50
+ 'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
51
+ 'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
52
+ "only_one_sheet" => "o10837434939102457526.762705759906130135",
53
+ "write.me" => 'ptu6bbahNZpY0N0RrxQbWdw&hl',
54
+ 'formula' => 'o10837434939102457526.3022866619437760118',
55
+ 'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
56
+ 'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
57
+ }[spreadsheetname]
58
+ rescue
59
+ raise "unknown spreadsheetname: #{spreadsheetname}"
60
+ end
61
+ end
62
+
63
+ if DB_LOG
64
+ if ! (defined?(@connected) and @connected)
65
+ activerecord_connect
66
+ else
67
+ @connected = true
68
+ end
69
+ end
70
+ alias unlogged_run run
71
+ def run(result, &block)
72
+ t1 = Time.now
73
+ #RAILS_DEFAULT_LOGGER.debug "RUNNING #{self.class} #{@method_name} \t#{Time.now.to_s}"
74
+ if DISPLAY_LOG
75
+ print "RUNNING #{self.class} #{@method_name} \t#{Time.now.to_s}"
76
+ STDOUT.flush
77
+ end
78
+ unlogged_run result, &block
79
+ t2 = Time.now
80
+ if DISPLAY_LOG
81
+ puts "\t#{t2-t1} seconds"
82
+ end
83
+ if DB_LOG
84
+ domain = Testrun.create(
85
+ :class_name => self.class.to_s,
86
+ :test_name => @method_name,
87
+ :start => t1,
88
+ :duration => t2-t1
89
+ )
90
+ end
91
+ end
92
+ end
93
+
94
+ class File
95
+ def File.delete_if_exist(filename)
96
+ if File.exist?(filename)
97
+ File.delete(filename)
98
+ end
99
+ end
100
+ end
101
+
102
+ # :nodoc
103
+ class Fixnum
104
+ def minutes
105
+ self * 60
106
+ end
107
+ end
108
+
109
+ class TestRoo < Test::Unit::TestCase
110
+
111
+ OPENOFFICE = true # do Openoffice-Spreadsheet Tests?
112
+ EXCEL = true # do Excel Tests?
113
+ GOOGLE = false # do Google-Spreadsheet Tests?
114
+ GNUMERIC_ODS = false # do gnumeric with ods files Tests?
115
+ EXCELX = true # do Excel-X Tests? (.xlsx-files)
116
+
117
+ OPENOFFICEWRITE = false # experimental: write access with OO-Documents
118
+ ONLINE = true
119
+ LONG_RUN = false
120
+ GLOBAL_TIMEOUT = 48.minutes #*60 # 2*12*60 # seconds
121
+
122
+ def setup
123
+ #if DISPLAY_LOG
124
+ # puts " GLOBAL_TIMEOUT = #{GLOBAL_TIMEOUT}"
125
+ #end
126
+ end
127
+
128
+ def test_internal_minutes
129
+ assert_equal 42*60, 42.minutes
130
+ end
131
+
132
+ def test_date
133
+ assert Google.date?("21/11/1962")
134
+ assert_equal Date.new(1962,11,21), Google.to_date("21/11/1962")
135
+
136
+ assert !Google.date?("21")
137
+ assert_nil Google.to_date("21")
138
+
139
+ assert !Google.date?("21/11")
140
+ assert_nil Google.to_date("21/11")
141
+
142
+ assert !Google.date?("Mittwoch/21/1961")
143
+ assert_nil Google.to_date("Mittwoch/21/1961")
144
+ end
145
+
146
+ def test_classes
147
+ if OPENOFFICE
148
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
149
+ assert_kind_of Openoffice, oo
150
+ end
151
+ if EXCEL
152
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
153
+ assert_kind_of Excel, oo
154
+ end
155
+ if GOOGLE
156
+ oo = Google.new(key_of("numbers1"))
157
+ assert_kind_of Google, oo
158
+ end
159
+ if EXCELX
160
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
161
+ assert_kind_of Excelx, oo
162
+ end
163
+ end
164
+
165
+ def test_letters
166
+ assert_equal 1, GenericSpreadsheet.letter_to_number('A')
167
+ assert_equal 1, GenericSpreadsheet.letter_to_number('a')
168
+ assert_equal 2, GenericSpreadsheet.letter_to_number('B')
169
+ assert_equal 26, GenericSpreadsheet.letter_to_number('Z')
170
+ assert_equal 27, GenericSpreadsheet.letter_to_number('AA')
171
+ assert_equal 27, GenericSpreadsheet.letter_to_number('aA')
172
+ assert_equal 27, GenericSpreadsheet.letter_to_number('Aa')
173
+ assert_equal 27, GenericSpreadsheet.letter_to_number('aa')
174
+ end
175
+
176
+ def DONT_test_simple_google
177
+ if GOOGLE
178
+ go = Google.new("egal")
179
+ assert_equal "42", go.cell(1,1)
180
+ end
181
+ end
182
+
183
+ def test_sheets_openoffice
184
+ if OPENOFFICE
185
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
186
+ assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets
187
+ assert_raise(RangeError) {
188
+ oo.default_sheet = "no_sheet"
189
+ }
190
+ assert_raise(TypeError) {
191
+ oo.default_sheet = [1,2,3]
192
+ }
193
+
194
+ oo.sheets.each { |sh|
195
+ oo.default_sheet = sh
196
+ assert_equal sh, oo.default_sheet
197
+ }
198
+ end
199
+ end
200
+
201
+ def test_sheets_gnumeric_ods
202
+ if GNUMERIC_ODS
203
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
204
+ assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets
205
+ assert_raise(RangeError) {
206
+ oo.default_sheet = "no_sheet"
207
+ }
208
+ assert_raise(TypeError) {
209
+ oo.default_sheet = [1,2,3]
210
+ }
211
+
212
+ oo.sheets.each { |sh|
213
+ oo.default_sheet = sh
214
+ assert_equal sh, oo.default_sheet
215
+ }
216
+ end
217
+ end
218
+
219
+ def test_sheets_excel
220
+ if EXCEL
221
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
222
+ assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets
223
+ assert_raise(RangeError) {
224
+ oo.default_sheet = "no_sheet"
225
+ }
226
+ assert_raise(TypeError) {
227
+ oo.default_sheet = [1,2,3]
228
+ }
229
+ oo.sheets.each { |sh|
230
+ oo.default_sheet = sh
231
+ assert_equal sh, oo.default_sheet
232
+ }
233
+ end
234
+ end
235
+
236
+ def test_sheets_excelx
237
+ if EXCELX
238
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
239
+ assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets
240
+ assert_raise(RangeError) {
241
+ oo.default_sheet = "no_sheet"
242
+ }
243
+ assert_raise(TypeError) {
244
+ oo.default_sheet = [1,2,3]
245
+ }
246
+ oo.sheets.each { |sh|
247
+ oo.default_sheet = sh
248
+ assert_equal sh, oo.default_sheet
249
+ }
250
+ end
251
+ end
252
+
253
+ def test_sheets_google
254
+ if GOOGLE
255
+ oo = Google.new(key_of("numbers1"))
256
+ assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets
257
+ assert_raise(RangeError) {
258
+ oo.default_sheet = "no_sheet"
259
+ }
260
+ assert_raise(TypeError) {
261
+ oo.default_sheet = [1,2,3]
262
+ }
263
+ oo.sheets.each { |sh|
264
+ oo.default_sheet = sh
265
+ assert_equal sh, oo.default_sheet
266
+ }
267
+ end
268
+ end
269
+
270
+ def test_cell_openoffice
271
+ if OPENOFFICE
272
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
273
+ oo.default_sheet = oo.sheets.first
274
+ assert_equal 1, oo.cell(1,1)
275
+ assert_equal 2, oo.cell(1,2)
276
+ assert_equal 3, oo.cell(1,3)
277
+ assert_equal 4, oo.cell(1,4)
278
+ assert_equal 5, oo.cell(2,1)
279
+ assert_equal 6, oo.cell(2,2)
280
+ assert_equal 7, oo.cell(2,3)
281
+ assert_equal 8, oo.cell(2,4)
282
+ assert_equal 9, oo.cell(2,5)
283
+ assert_equal "test", oo.cell(2,6)
284
+ # assert_equal "string", oo.celltype(2,6)
285
+ assert_equal :string, oo.celltype(2,6)
286
+ assert_equal 11, oo.cell(2,7)
287
+ # assert_equal "float", oo.celltype(2,7)
288
+ assert_equal :float, oo.celltype(2,7)
289
+
290
+ assert_equal 10, oo.cell(4,1)
291
+ assert_equal 11, oo.cell(4,2)
292
+ assert_equal 12, oo.cell(4,3)
293
+ assert_equal 13, oo.cell(4,4)
294
+ assert_equal 14, oo.cell(4,5)
295
+
296
+ assert_equal 10, oo.cell(4,'A')
297
+ assert_equal 11, oo.cell(4,'B')
298
+ assert_equal 12, oo.cell(4,'C')
299
+ assert_equal 13, oo.cell(4,'D')
300
+ assert_equal 14, oo.cell(4,'E')
301
+
302
+ # assert_equal "date", oo.celltype(5,1)
303
+ assert_equal :date, oo.celltype(5,1)
304
+ assert_equal Date.new(1961,11,21), oo.cell(5,1)
305
+ assert_equal "1961-11-21", oo.cell(5,1).to_s
306
+ end
307
+ end
308
+
309
+ def test_cell_gnumeric_ods
310
+ if GNUMERIC_ODS
311
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
312
+ oo.default_sheet = oo.sheets.first
313
+ assert_equal 1, oo.cell(1,1)
314
+ assert_equal 2, oo.cell(1,2)
315
+ assert_equal 3, oo.cell(1,3)
316
+ assert_equal 4, oo.cell(1,4)
317
+ assert_equal 5, oo.cell(2,1)
318
+ assert_equal 6, oo.cell(2,2)
319
+ assert_equal 7, oo.cell(2,3)
320
+ assert_equal 8, oo.cell(2,4)
321
+ assert_equal 9, oo.cell(2,5)
322
+ assert_equal "test", oo.cell(2,6)
323
+ # assert_equal "string", oo.celltype(2,6)
324
+ assert_equal :string, oo.celltype(2,6)
325
+ assert_equal 11, oo.cell(2,7)
326
+ # assert_equal "float", oo.celltype(2,7)
327
+ assert_equal :float, oo.celltype(2,7)
328
+
329
+ assert_equal 10, oo.cell(4,1)
330
+ assert_equal 11, oo.cell(4,2)
331
+ assert_equal 12, oo.cell(4,3)
332
+ assert_equal 13, oo.cell(4,4)
333
+ assert_equal 14, oo.cell(4,5)
334
+
335
+ assert_equal 10, oo.cell(4,'A')
336
+ assert_equal 11, oo.cell(4,'B')
337
+ assert_equal 12, oo.cell(4,'C')
338
+ assert_equal 13, oo.cell(4,'D')
339
+ assert_equal 14, oo.cell(4,'E')
340
+
341
+ # assert_equal "date", oo.celltype(5,1)
342
+ assert_equal :date, oo.celltype(5,1)
343
+ assert_equal Date.new(1961,11,21), oo.cell(5,1)
344
+ assert_equal "1961-11-21", oo.cell(5,1).to_s
345
+ end
346
+ end
347
+
348
+ def test_cell_excel
349
+ if EXCEL
350
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
351
+ oo.default_sheet = oo.sheets.first
352
+ assert_equal 1, oo.cell(1,1)
353
+ assert_equal 2, oo.cell(1,2)
354
+ assert_equal 3, oo.cell(1,3)
355
+ assert_equal 4, oo.cell(1,4)
356
+ assert_equal 5, oo.cell(2,1)
357
+ assert_equal 6, oo.cell(2,2)
358
+ assert_equal 7, oo.cell(2,3)
359
+ assert_equal 8, oo.cell(2,4)
360
+ assert_equal 9, oo.cell(2,5)
361
+ assert_equal "test", oo.cell(2,6)
362
+ # assert_equal "string", oo.celltype(2,6)
363
+ assert_equal :string, oo.celltype(2,6)
364
+ assert_equal 11, oo.cell(2,7)
365
+ # assert_equal "float", oo.celltype(2,7)
366
+ assert_equal :float, oo.celltype(2,7)
367
+
368
+ assert_equal 10, oo.cell(4,1)
369
+ assert_equal 11, oo.cell(4,2)
370
+ assert_equal 12, oo.cell(4,3)
371
+ assert_equal 13, oo.cell(4,4)
372
+ assert_equal 14, oo.cell(4,5)
373
+
374
+ assert_equal 10, oo.cell(4,'A')
375
+ assert_equal 11, oo.cell(4,'B')
376
+ assert_equal 12, oo.cell(4,'C')
377
+ assert_equal 13, oo.cell(4,'D')
378
+ assert_equal 14, oo.cell(4,'E')
379
+
380
+ # assert_equal "date", oo.celltype(5,1)
381
+ assert_equal :date, oo.celltype(5,1)
382
+ assert_equal Date.new(1961,11,21), oo.cell(5,1)
383
+ assert_equal "1961-11-21", oo.cell(5,1).to_s
384
+ end
385
+ end
386
+
387
+ def test_cell_excelx
388
+ if EXCELX
389
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
390
+ oo.default_sheet = oo.sheets.first
391
+
392
+ assert_kind_of Float, oo.cell(1,1)
393
+ assert_equal 1, oo.cell(1,1)
394
+ assert_equal 2, oo.cell(1,2)
395
+ assert_equal 3, oo.cell(1,3)
396
+ assert_equal 4, oo.cell(1,4)
397
+ assert_equal 5, oo.cell(2,1)
398
+ assert_equal 6, oo.cell(2,2)
399
+ assert_equal 7, oo.cell(2,3)
400
+ assert_equal 8, oo.cell(2,4)
401
+ assert_equal 9, oo.cell(2,5)
402
+ assert_equal "test", oo.cell(2,6)
403
+ # assert_equal "string", oo.celltype(2,6)
404
+ assert_equal :string, oo.celltype(2,6)
405
+ assert_equal 11, oo.cell(2,7)
406
+ # assert_equal "float", oo.celltype(2,7)
407
+ assert_equal :float, oo.celltype(2,7)
408
+
409
+ assert_equal 10, oo.cell(4,1)
410
+ assert_equal 11, oo.cell(4,2)
411
+ assert_equal 12, oo.cell(4,3)
412
+ assert_equal 13, oo.cell(4,4)
413
+ assert_equal 14, oo.cell(4,5)
414
+
415
+ assert_equal 10, oo.cell(4,'A')
416
+ assert_equal 11, oo.cell(4,'B')
417
+ assert_equal 12, oo.cell(4,'C')
418
+ assert_equal 13, oo.cell(4,'D')
419
+ assert_equal 14, oo.cell(4,'E')
420
+
421
+ # assert_equal "date", oo.celltype(5,1)
422
+ assert_equal :date, oo.celltype(5,1)
423
+ assert_equal Date.new(1961,11,21), oo.cell(5,1)
424
+ assert_equal "1961-11-21", oo.cell(5,1).to_s
425
+ end
426
+ end
427
+
428
+ def test_cell_google
429
+ if GOOGLE
430
+ oo = Google.new(key_of("numbers1"))
431
+ oo.default_sheet = oo.sheets.first
432
+ assert_equal 1, oo.cell(1,1)
433
+ assert_equal 2, oo.cell(1,2)
434
+ assert_equal 3, oo.cell(1,3)
435
+ assert_equal 4, oo.cell(1,4)
436
+ assert_equal 5, oo.cell(2,1)
437
+ assert_equal 6, oo.cell(2,2)
438
+ assert_equal 7, oo.cell(2,3)
439
+ assert_equal 8, oo.cell(2,4)
440
+ assert_equal 9, oo.cell(2,5)
441
+ assert_equal "test", oo.cell(2,6)
442
+ # assert_equal "string", oo.celltype(2,6)
443
+ assert_equal :string, oo.celltype(2,6)
444
+ assert_equal 11, oo.cell(2,7)
445
+ # assert_equal "float", oo.celltype(2,7)
446
+ assert_equal :float, oo.celltype(2,7), "Inhalt: --#{oo.cell(2,7)}--"
447
+
448
+ assert_equal 10, oo.cell(4,1)
449
+ assert_equal 11, oo.cell(4,2)
450
+ assert_equal 12, oo.cell(4,3)
451
+ assert_equal 13, oo.cell(4,4)
452
+ assert_equal 14, oo.cell(4,5)
453
+
454
+ assert_equal 10, oo.cell(4,'A')
455
+ assert_equal 11, oo.cell(4,'B')
456
+ assert_equal 12, oo.cell(4,'C')
457
+ assert_equal 13, oo.cell(4,'D')
458
+ assert_equal 14, oo.cell(4,'E')
459
+
460
+ # assert_equal "date", oo.celltype(5,1)
461
+ assert_equal :date, oo.celltype(5,1)
462
+ assert_equal Date.new(1961,11,21), oo.cell(5,1)
463
+ assert_equal "1961-11-21", oo.cell(5,1).to_s
464
+ end # GOOGLE
465
+ end
466
+
467
+ def test_celltype
468
+ ###
469
+ if OPENOFFICE
470
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
471
+ oo.default_sheet = oo.sheets.first
472
+ assert_equal :string, oo.celltype(2,6)
473
+ end
474
+ if GNUMERIC_ODS
475
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
476
+ oo.default_sheet = oo.sheets.first
477
+ assert_equal :string, oo.celltype(2,6)
478
+ end
479
+ if EXCEL
480
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
481
+ oo.default_sheet = oo.sheets.first
482
+ assert_equal :string, oo.celltype(2,6)
483
+ end
484
+ if GOOGLE
485
+ oo = Google.new(key_of("numbers1"))
486
+ oo.default_sheet = oo.sheets.first
487
+ assert_equal :string, oo.celltype(2,6)
488
+ end
489
+ if EXCELX
490
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
491
+ oo.default_sheet = oo.sheets.first
492
+ assert_equal :string, oo.celltype(2,6)
493
+ end
494
+ end
495
+
496
+ def test_cell_address
497
+ if OPENOFFICE
498
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
499
+ oo.default_sheet = oo.sheets.first
500
+ assert_equal "tata", oo.cell(6,1)
501
+ assert_equal "tata", oo.cell(6,'A')
502
+ assert_equal "tata", oo.cell('A',6)
503
+ assert_equal "tata", oo.cell(6,'a')
504
+ assert_equal "tata", oo.cell('a',6)
505
+
506
+ assert_raise(ArgumentError) {
507
+ assert_equal "tata", oo.cell('a','f')
508
+ }
509
+ assert_raise(ArgumentError) {
510
+ assert_equal "tata", oo.cell('f','a')
511
+ }
512
+ assert_equal "thisisc8", oo.cell(8,3)
513
+ assert_equal "thisisc8", oo.cell(8,'C')
514
+ assert_equal "thisisc8", oo.cell('C',8)
515
+ assert_equal "thisisc8", oo.cell(8,'c')
516
+ assert_equal "thisisc8", oo.cell('c',8)
517
+
518
+ assert_equal "thisisd9", oo.cell('d',9)
519
+ assert_equal "thisisa11", oo.cell('a',11)
520
+ end
521
+
522
+ if GNUMERIC_ODS
523
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
524
+ oo.default_sheet = oo.sheets.first
525
+ assert_equal "tata", oo.cell(6,1)
526
+ assert_equal "tata", oo.cell(6,'A')
527
+ assert_equal "tata", oo.cell('A',6)
528
+ assert_equal "tata", oo.cell(6,'a')
529
+ assert_equal "tata", oo.cell('a',6)
530
+
531
+ assert_raise(ArgumentError) {
532
+ assert_equal "tata", oo.cell('a','f')
533
+ }
534
+ assert_raise(ArgumentError) {
535
+ assert_equal "tata", oo.cell('f','a')
536
+ }
537
+ assert_equal "thisisc8", oo.cell(8,3)
538
+ assert_equal "thisisc8", oo.cell(8,'C')
539
+ assert_equal "thisisc8", oo.cell('C',8)
540
+ assert_equal "thisisc8", oo.cell(8,'c')
541
+ assert_equal "thisisc8", oo.cell('c',8)
542
+
543
+ assert_equal "thisisd9", oo.cell('d',9)
544
+ assert_equal "thisisa11", oo.cell('a',11)
545
+ end
546
+
547
+ if EXCEL
548
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
549
+ oo.default_sheet = oo.sheets.first
550
+ assert_equal "tata", oo.cell(6,'A')
551
+ assert_equal "tata", oo.cell(6,1)
552
+ assert_equal "tata", oo.cell('A',6)
553
+ assert_equal "tata", oo.cell(6,'a')
554
+ assert_equal "tata", oo.cell('a',6)
555
+
556
+ assert_raise(ArgumentError) {
557
+ assert_equal "tata", oo.cell('a','f')
558
+ }
559
+ assert_raise(ArgumentError) {
560
+ assert_equal "tata", oo.cell('f','a')
561
+ }
562
+
563
+ assert_equal "thisisc8", oo.cell(8,3)
564
+ assert_equal "thisisc8", oo.cell(8,'C')
565
+ assert_equal "thisisc8", oo.cell('C',8)
566
+ assert_equal "thisisc8", oo.cell(8,'c')
567
+ assert_equal "thisisc8", oo.cell('c',8)
568
+
569
+ assert_equal "thisisd9", oo.cell('d',9)
570
+ assert_equal "thisisa11", oo.cell('a',11)
571
+ #assert_equal "lulua", oo.cell('b',10)
572
+ end
573
+
574
+ if EXCELX
575
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
576
+ oo.default_sheet = oo.sheets.first
577
+ assert_equal "tata", oo.cell(6,1)
578
+ assert_equal "tata", oo.cell(6,'A')
579
+ assert_equal "tata", oo.cell('A',6)
580
+ assert_equal "tata", oo.cell(6,'a')
581
+ assert_equal "tata", oo.cell('a',6)
582
+
583
+ assert_raise(ArgumentError) {
584
+ assert_equal "tata", oo.cell('a','f')
585
+ }
586
+ assert_raise(ArgumentError) {
587
+ assert_equal "tata", oo.cell('f','a')
588
+ }
589
+
590
+ assert_equal "thisisc8", oo.cell(8,3)
591
+ assert_equal "thisisc8", oo.cell(8,'C')
592
+ assert_equal "thisisc8", oo.cell('C',8)
593
+ assert_equal "thisisc8", oo.cell(8,'c')
594
+ assert_equal "thisisc8", oo.cell('c',8)
595
+
596
+ assert_equal "thisisd9", oo.cell('d',9)
597
+ assert_equal "thisisa11", oo.cell('a',11)
598
+ #assert_equal "lulua", oo.cell('b',10)
599
+ end
600
+
601
+ if GOOGLE
602
+ oo = Google.new(key_of("numbers1"))
603
+ oo.default_sheet = oo.sheets.first
604
+ assert_equal "tata", oo.cell(6,1)
605
+ assert_equal "tata", oo.cell(6,'A')
606
+ assert_equal "tata", oo.cell('A',6)
607
+ assert_equal "tata", oo.cell(6,'a')
608
+ assert_equal "tata", oo.cell('a',6)
609
+
610
+ assert_raise(ArgumentError) {
611
+ assert_equal "tata", oo.cell('a','f')
612
+ }
613
+ assert_raise(ArgumentError) {
614
+ assert_equal "tata", oo.cell('f','a')
615
+ }
616
+ assert_equal "thisisc8", oo.cell(8,3)
617
+ assert_equal "thisisc8", oo.cell(8,'C')
618
+ assert_equal "thisisc8", oo.cell('C',8)
619
+ assert_equal "thisisc8", oo.cell(8,'c')
620
+ assert_equal "thisisc8", oo.cell('c',8)
621
+
622
+ assert_equal "thisisd9", oo.cell('d',9)
623
+ assert_equal "thisisa11", oo.cell('a',11)
624
+ end
625
+ end
626
+
627
+ # Version of the (XML) office document
628
+ # please note that "1.0" is returned even if it was created with OpenOffice V. 2.0
629
+ def test_officeversion
630
+ if OPENOFFICE
631
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
632
+ assert_equal "1.0", oo.officeversion
633
+ end
634
+ if GNUMERIC_ODS
635
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
636
+ assert_equal "1.0", oo.officeversion
637
+ end
638
+ if EXCEL
639
+ # excel does not have a officeversion
640
+ end
641
+ if EXCELX
642
+ # excelx does not have a officeversion
643
+ #TODO: gibt es hier eine Versionsnummer
644
+ end
645
+ if GOOGLE
646
+ # google does not have a officeversion
647
+ end
648
+ end
649
+
650
+ #TODO: inkonsequente Lieferung Fixnum/Float
651
+ def test_rows
652
+ if OPENOFFICE
653
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
654
+ oo.default_sheet = oo.sheets.first
655
+ assert_equal 41, oo.cell('a',12)
656
+ assert_equal 42, oo.cell('b',12)
657
+ assert_equal 43, oo.cell('c',12)
658
+ assert_equal 44, oo.cell('d',12)
659
+ assert_equal 45, oo.cell('e',12)
660
+ assert_equal [41.0,42.0,43.0,44.0,45.0], oo.row(12)
661
+ assert_equal "einundvierzig", oo.cell('a',16)
662
+ assert_equal "zweiundvierzig", oo.cell('b',16)
663
+ assert_equal "dreiundvierzig", oo.cell('c',16)
664
+ assert_equal "vierundvierzig", oo.cell('d',16)
665
+ assert_equal "fuenfundvierzig", oo.cell('e',16)
666
+ assert_equal ["einundvierzig", "zweiundvierzig", "dreiundvierzig", "vierundvierzig", "fuenfundvierzig"], oo.row(16)
667
+ end
668
+ if GNUMERIC_ODS
669
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
670
+ oo.default_sheet = oo.sheets.first
671
+ assert_equal 41, oo.cell('a',12)
672
+ assert_equal 42, oo.cell('b',12)
673
+ assert_equal 43, oo.cell('c',12)
674
+ assert_equal 44, oo.cell('d',12)
675
+ assert_equal 45, oo.cell('e',12)
676
+ assert_equal [41.0,42.0,43.0,44.0,45.0], oo.row(12)
677
+ assert_equal "einundvierzig", oo.cell('a',16)
678
+ assert_equal "zweiundvierzig", oo.cell('b',16)
679
+ assert_equal "dreiundvierzig", oo.cell('c',16)
680
+ assert_equal "vierundvierzig", oo.cell('d',16)
681
+ assert_equal "fuenfundvierzig", oo.cell('e',16)
682
+ assert_equal ["einundvierzig", "zweiundvierzig", "dreiundvierzig", "vierundvierzig", "fuenfundvierzig"], oo.row(16)
683
+ end
684
+ if EXCEL
685
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
686
+ oo.default_sheet = oo.sheets.first
687
+ assert_equal 41, oo.cell('a',12)
688
+ assert_equal 42, oo.cell('b',12)
689
+ assert_equal 43, oo.cell('c',12)
690
+ assert_equal 44, oo.cell('d',12)
691
+ assert_equal 45, oo.cell('e',12)
692
+ assert_equal [41,42,43,44,45], oo.row(12)
693
+ assert_equal "einundvierzig", oo.cell('a',16)
694
+ assert_equal "zweiundvierzig", oo.cell('b',16)
695
+ assert_equal "dreiundvierzig", oo.cell('c',16)
696
+ assert_equal "vierundvierzig", oo.cell('d',16)
697
+ assert_equal "fuenfundvierzig", oo.cell('e',16)
698
+ assert_equal ["einundvierzig",
699
+ "zweiundvierzig",
700
+ "dreiundvierzig",
701
+ "vierundvierzig",
702
+ "fuenfundvierzig"], oo.row(16)
703
+ end
704
+ if EXCELX
705
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
706
+ oo.default_sheet = oo.sheets.first
707
+ assert_equal 41, oo.cell('a',12)
708
+ assert_equal 42, oo.cell('b',12)
709
+ assert_equal 43, oo.cell('c',12)
710
+ assert_equal 44, oo.cell('d',12)
711
+ assert_equal 45, oo.cell('e',12)
712
+ assert_equal [41,42,43,44,45], oo.row(12)
713
+ assert_equal "einundvierzig", oo.cell('a',16)
714
+ assert_equal "zweiundvierzig", oo.cell('b',16)
715
+ assert_equal "dreiundvierzig", oo.cell('c',16)
716
+ assert_equal "vierundvierzig", oo.cell('d',16)
717
+ assert_equal "fuenfundvierzig", oo.cell('e',16)
718
+ assert_equal ["einundvierzig",
719
+ "zweiundvierzig",
720
+ "dreiundvierzig",
721
+ "vierundvierzig",
722
+ "fuenfundvierzig"], oo.row(16)
723
+ end
724
+ if GOOGLE
725
+ oo = Google.new(key_of("numbers1"))
726
+ oo.default_sheet = oo.sheets.first
727
+ assert_equal 41, oo.cell('a',12)
728
+ assert_equal 42, oo.cell('b',12)
729
+ assert_equal 43, oo.cell('c',12)
730
+ assert_equal 44, oo.cell('d',12)
731
+ assert_equal 45, oo.cell('e',12)
732
+ assert_equal [41,42,43,44,45], oo.row(12)
733
+ assert_equal "einundvierzig", oo.cell('a',16)
734
+ assert_equal "zweiundvierzig", oo.cell('b',16)
735
+ assert_equal "dreiundvierzig", oo.cell('c',16)
736
+ assert_equal "vierundvierzig", oo.cell('d',16)
737
+ assert_equal "fuenfundvierzig", oo.cell('e',16)
738
+ assert_equal ["einundvierzig",
739
+ "zweiundvierzig",
740
+ "dreiundvierzig",
741
+ "vierundvierzig",
742
+ "fuenfundvierzig"], oo.row(16)
743
+ end
744
+ end
745
+
746
+ def test_last_row
747
+ if OPENOFFICE
748
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
749
+ oo.default_sheet = oo.sheets.first
750
+ assert_equal 18, oo.last_row
751
+ end
752
+ if GNUMERIC_ODS
753
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
754
+ oo.default_sheet = oo.sheets.first
755
+ assert_equal 18, oo.last_row
756
+ end
757
+ if EXCEL
758
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
759
+ oo.default_sheet = oo.sheets.first
760
+ assert_equal 18, oo.last_row
761
+ end
762
+ if EXCELX
763
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
764
+ oo.default_sheet = oo.sheets.first
765
+ assert_equal 18, oo.last_row
766
+ end
767
+ if GOOGLE
768
+ oo = Google.new(key_of("numbers1"))
769
+ oo.default_sheet = oo.sheets.first
770
+ assert_equal 18, oo.last_row
771
+ end
772
+ end
773
+
774
+ def test_last_column
775
+ if OPENOFFICE
776
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
777
+ oo.default_sheet = oo.sheets.first
778
+ assert_equal 7, oo.last_column
779
+ end
780
+ if GNUMERIC_ODS
781
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
782
+ oo.default_sheet = oo.sheets.first
783
+ assert_equal 7, oo.last_column
784
+ end
785
+ if EXCEL
786
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
787
+ oo.default_sheet = oo.sheets.first
788
+ assert_equal 7, oo.last_column
789
+ end
790
+ if EXCELX
791
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
792
+ oo.default_sheet = oo.sheets.first
793
+ assert_equal 7, oo.last_column
794
+ end
795
+ if GOOGLE
796
+ oo = Google.new(key_of("numbers1"))
797
+ oo.default_sheet = oo.sheets.first
798
+ assert_equal 7, oo.last_column
799
+ end
800
+ end
801
+
802
+ def test_last_column_as_letter
803
+ if OPENOFFICE
804
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
805
+ oo.default_sheet = oo.sheets.first
806
+ assert_equal 'G', oo.last_column_as_letter
807
+ end
808
+ if GNUMERIC_ODS
809
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
810
+ oo.default_sheet = oo.sheets.first
811
+ assert_equal 'G', oo.last_column_as_letter
812
+ end
813
+ if EXCEL
814
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
815
+ oo.default_sheet = 1 # oo.sheets.first
816
+ assert_equal 'G', oo.last_column_as_letter
817
+ end
818
+ if EXCELX
819
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
820
+ oo.default_sheet = oo.sheets.first
821
+ assert_equal 'G', oo.last_column_as_letter
822
+ end
823
+ if GOOGLE
824
+ oo = Google.new(key_of("numbers1"))
825
+ oo.default_sheet = oo.sheets.first
826
+ assert_equal 'G', oo.last_column_as_letter
827
+ end
828
+ end
829
+
830
+ def test_first_row
831
+ if OPENOFFICE
832
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
833
+ oo.default_sheet = oo.sheets.first
834
+ assert_equal 1, oo.first_row
835
+ end
836
+ if GNUMERIC_ODS
837
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
838
+ oo.default_sheet = oo.sheets.first
839
+ assert_equal 1, oo.first_row
840
+ end
841
+ if EXCEL
842
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
843
+ oo.default_sheet = 1 # oo.sheets.first
844
+ assert_equal 1, oo.first_row
845
+ end
846
+ if EXCELX
847
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
848
+ oo.default_sheet = oo.sheets.first
849
+ assert_equal 1, oo.first_row
850
+ end
851
+ if GOOGLE
852
+ oo = Google.new(key_of("numbers1"))
853
+ oo.default_sheet = oo.sheets.first
854
+ assert_equal 1, oo.first_row
855
+ end
856
+ end
857
+
858
+ def test_first_column
859
+ if OPENOFFICE
860
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
861
+ oo.default_sheet = oo.sheets.first
862
+ assert_equal 1, oo.first_column
863
+ end
864
+ if GNUMERIC_ODS
865
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
866
+ oo.default_sheet = oo.sheets.first
867
+ assert_equal 1, oo.first_column
868
+ end
869
+ if EXCEL
870
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
871
+ oo.default_sheet = 1 # oo.sheets.first
872
+ assert_equal 1, oo.first_column
873
+ end
874
+ if EXCELX
875
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
876
+ oo.default_sheet = oo.sheets.first
877
+ assert_equal 1, oo.first_column
878
+ end
879
+ if GOOGLE
880
+ assert_nothing_raised(Timeout::Error) {
881
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
882
+ oo = Google.new(key_of("numbers1"))
883
+ oo.default_sheet = oo.sheets.first
884
+ assert_equal 1, oo.first_column
885
+ end
886
+ }
887
+ end
888
+ end
889
+
890
+ def test_first_column_as_letter_openoffice
891
+ if OPENOFFICE
892
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
893
+ oo.default_sheet = oo.sheets.first
894
+ assert_equal 'A', oo.first_column_as_letter
895
+ end
896
+ end
897
+
898
+ def test_first_column_as_letter_gnumeric_ods
899
+ if GNUMERIC_ODS
900
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
901
+ oo.default_sheet = oo.sheets.first
902
+ assert_equal 'A', oo.first_column_as_letter
903
+ end
904
+ end
905
+
906
+ def test_first_column_as_letter_excel
907
+ if EXCEL
908
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
909
+ oo.default_sheet = 1 # oo.sheets.first
910
+ assert_equal 'A', oo.first_column_as_letter
911
+ end
912
+ end
913
+
914
+ def test_first_column_as_letter_excelx
915
+ if EXCELX
916
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
917
+ oo.default_sheet = oo.sheets.first
918
+ assert_equal 'A', oo.first_column_as_letter
919
+ end
920
+ end
921
+
922
+ def test_first_column_as_letter_google
923
+ if GOOGLE
924
+ oo = Google.new(key_of("numbers1"))
925
+ oo.default_sheet = oo.sheets.first
926
+ assert_equal 'A', oo.first_column_as_letter
927
+ end
928
+ end
929
+
930
+ def test_sheetname
931
+ if OPENOFFICE
932
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
933
+ oo.default_sheet = "Name of Sheet 2"
934
+ assert_equal 'I am sheet 2', oo.cell('C',5)
935
+ assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
936
+ assert_raise(RangeError) { dummy = oo.cell('C',5,"non existing sheet name")}
937
+ assert_raise(RangeError) { dummy = oo.celltype('C',5,"non existing sheet name")}
938
+ assert_raise(RangeError) { dummy = oo.empty?('C',5,"non existing sheet name")}
939
+ assert_raise(RangeError) { dummy = oo.formula?('C',5,"non existing sheet name")}
940
+ assert_raise(RangeError) { dummy = oo.formula('C',5,"non existing sheet name")}
941
+ assert_raise(RangeError) { dummy = oo.set('C',5,42,"non existing sheet name")}
942
+ assert_raise(RangeError) { dummy = oo.formulas("non existing sheet name")}
943
+ assert_raise(RangeError) { dummy = oo.to_yaml({},1,1,1,1,"non existing sheet name")}
944
+ end
945
+ if GNUMERIC_ODS
946
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
947
+ oo.default_sheet = "Name of Sheet 2"
948
+ assert_equal 'I am sheet 2', oo.cell('C',5)
949
+ assert_raise(RangeError) {
950
+ oo.default_sheet = "non existing sheet name"
951
+ }
952
+ assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
953
+ assert_raise(RangeError) { dummy = oo.cell('C',5,"non existing sheet name")}
954
+ assert_raise(RangeError) { dummy = oo.celltype('C',5,"non existing sheet name")}
955
+ assert_raise(RangeError) { dummy = oo.empty?('C',5,"non existing sheet name")}
956
+ assert_raise(RangeError) { dummy = oo.formula?('C',5,"non existing sheet name")}
957
+ assert_raise(RangeError) { dummy = oo.formula('C',5,"non existing sheet name")}
958
+ assert_raise(RangeError) { dummy = oo.set('C',5,42,"non existing sheet name")}
959
+ assert_raise(RangeError) { dummy = oo.formulas("non existing sheet name")}
960
+ assert_raise(RangeError) { dummy = oo.to_yaml({},1,1,1,1,"non existing sheet name")}
961
+ end
962
+ if EXCEL
963
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
964
+ oo.default_sheet = "Name of Sheet 2"
965
+ assert_equal 'I am sheet 2', oo.cell('C',5)
966
+ assert_raise(RangeError) {
967
+ oo.default_sheet = "non existing sheet name"
968
+ }
969
+ assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
970
+ assert_raise(RangeError) { dummy = oo.cell('C',5,"non existing sheet name")}
971
+ assert_raise(RangeError) { dummy = oo.celltype('C',5,"non existing sheet name")}
972
+ assert_raise(RangeError) { dummy = oo.empty?('C',5,"non existing sheet name")}
973
+ assert_raise(RuntimeError) { dummy = oo.formula?('C',5,"non existing sheet name")}
974
+ assert_raise(RuntimeError) { dummy = oo.formula('C',5,"non existing sheet name")}
975
+ #assert_raise(RangeError) { dummy = oo.set('C',5,42,"non existing sheet name")}
976
+ #assert_raise(RangeError) { dummy = oo.formulas("non existing sheet name")}
977
+ assert_raise(RangeError) { dummy = oo.to_yaml({},1,1,1,1,"non existing sheet name")}
978
+ end
979
+ if EXCELX
980
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
981
+ oo.default_sheet = "Name of Sheet 2"
982
+ assert_equal 'I am sheet 2', oo.cell('C',5)
983
+ assert_raise(RangeError) {
984
+ oo.default_sheet = "non existing sheet name"
985
+ }
986
+ assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
987
+ assert_raise(RangeError) { dummy = oo.cell('C',5,"non existing sheet name")}
988
+ assert_raise(RangeError) { dummy = oo.celltype('C',5,"non existing sheet name")}
989
+ assert_raise(RangeError) { dummy = oo.empty?('C',5,"non existing sheet name")}
990
+ assert_raise(RangeError) { dummy = oo.formula?('C',5,"non existing sheet name")}
991
+ assert_raise(RangeError) { dummy = oo.formula('C',5,"non existing sheet name")}
992
+ assert_raise(RangeError) { dummy = oo.set('C',5,42,"non existing sheet name")}
993
+ assert_raise(RangeError) { dummy = oo.formulas("non existing sheet name")}
994
+ assert_raise(RangeError) { dummy = oo.to_yaml({},1,1,1,1,"non existing sheet name")}
995
+ end
996
+ if GOOGLE
997
+ oo = Google.new(key_of("numbers1"))
998
+ oo.default_sheet = "Name of Sheet 2"
999
+ assert_equal 'I am sheet 2', oo.cell('C',5)
1000
+ assert_raise(RangeError) {
1001
+ oo.default_sheet = "non existing sheet name"
1002
+ }
1003
+ assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
1004
+ assert_raise(RangeError) { dummy = oo.cell('C',5,"non existing sheet name")}
1005
+ assert_raise(RangeError) { dummy = oo.celltype('C',5,"non existing sheet name")}
1006
+ assert_raise(RangeError) { dummy = oo.empty?('C',5,"non existing sheet name")}
1007
+ assert_raise(RangeError) { dummy = oo.formula?('C',5,"non existing sheet name")}
1008
+ assert_raise(RangeError) { dummy = oo.formula('C',5,"non existing sheet name")}
1009
+ #2008-12-04: assert_raise(RangeError) { dummy = oo.set('C',5,42,"non existing sheet name")}
1010
+ assert_raise(RangeError) { dummy = oo.set_value('C',5,42,"non existing sheet name")}
1011
+ assert_raise(RangeError) { dummy = oo.formulas("non existing sheet name")}
1012
+ assert_raise(RangeError) { dummy = oo.to_yaml({},1,1,1,1,"non existing sheet name")}
1013
+ end
1014
+ end
1015
+
1016
+ def test_boundaries
1017
+ if OPENOFFICE
1018
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
1019
+ oo.default_sheet = "Name of Sheet 2"
1020
+ assert_equal 2, oo.first_column
1021
+ assert_equal 'B', oo.first_column_as_letter
1022
+ assert_equal 5, oo.first_row
1023
+ assert_equal 'E', oo.last_column_as_letter
1024
+ assert_equal 14, oo.last_row
1025
+ end
1026
+ if GNUMERIC_ODS
1027
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
1028
+ oo.default_sheet = "Name of Sheet 2"
1029
+ assert_equal 2, oo.first_column
1030
+ assert_equal 'B', oo.first_column_as_letter
1031
+ assert_equal 5, oo.first_row
1032
+ assert_equal 'E', oo.last_column_as_letter
1033
+ assert_equal 14, oo.last_row
1034
+ end
1035
+ if EXCEL
1036
+ #-- Excel
1037
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
1038
+ oo.default_sheet = 2 # "Name of Sheet 2"
1039
+ assert_equal 2, oo.first_column
1040
+ assert_equal 'B', oo.first_column_as_letter
1041
+ assert_equal 5, oo.first_row
1042
+ assert_equal 'E', oo.last_column_as_letter
1043
+ assert_equal 14, oo.last_row
1044
+ end
1045
+ if EXCELX
1046
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
1047
+ oo.default_sheet = "Name of Sheet 2"
1048
+ assert_equal 2, oo.first_column
1049
+ assert_equal 'B', oo.first_column_as_letter
1050
+ assert_equal 5, oo.first_row
1051
+ assert_equal 'E', oo.last_column_as_letter
1052
+ assert_equal 14, oo.last_row
1053
+ end
1054
+ end
1055
+
1056
+ def test_multiple_letters
1057
+ if OPENOFFICE
1058
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
1059
+ oo.default_sheet = "Sheet3"
1060
+ assert_equal "i am AA", oo.cell('AA',1)
1061
+ assert_equal "i am AB", oo.cell('AB',1)
1062
+ assert_equal "i am BA", oo.cell('BA',1)
1063
+ assert_equal 'BA', oo.last_column_as_letter
1064
+ assert_equal "i am BA", oo.cell(1,'BA')
1065
+ end
1066
+ if GNUMERIC_ODS
1067
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
1068
+ oo.default_sheet = "Sheet3"
1069
+ assert_equal "i am AA", oo.cell('AA',1)
1070
+ assert_equal "i am AB", oo.cell('AB',1)
1071
+ assert_equal "i am BA", oo.cell('BA',1)
1072
+ assert_equal 'BA', oo.last_column_as_letter
1073
+ assert_equal "i am BA", oo.cell(1,'BA')
1074
+ end
1075
+ if EXCEL
1076
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
1077
+ oo.default_sheet = 3 # "Sheet3"
1078
+ assert_equal "i am AA", oo.cell('AA',1)
1079
+ assert_equal "i am AB", oo.cell('AB',1)
1080
+ assert_equal "i am BA", oo.cell('BA',1)
1081
+ assert_equal 'BA', oo.last_column_as_letter
1082
+ assert_equal "i am BA", oo.cell(1,'BA')
1083
+ end
1084
+ if EXCELX
1085
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
1086
+ oo.default_sheet = "Sheet3"
1087
+ assert_equal "i am AA", oo.cell('AA',1)
1088
+ assert_equal "i am AB", oo.cell('AB',1)
1089
+ assert_equal "i am BA", oo.cell('BA',1)
1090
+ assert_equal 'BA', oo.last_column_as_letter
1091
+ assert_equal "i am BA", oo.cell(1,'BA')
1092
+ end
1093
+ end
1094
+
1095
+ def test_argument_error
1096
+ if EXCEL
1097
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
1098
+ before Date.new(2007,7,20) do
1099
+ assert_raise(ArgumentError) {
1100
+ #oo.default_sheet = "first sheet"
1101
+ oo.default_sheet = "Tabelle1"
1102
+ }
1103
+ end
1104
+ assert_nothing_raised(ArgumentError) {
1105
+ # oo.default_sheet = 1
1106
+ #oo.default_sheet = "first sheet"
1107
+ oo.default_sheet = "Tabelle1"
1108
+ }
1109
+ end
1110
+ end
1111
+
1112
+ def test_empty_eh
1113
+ if OPENOFFICE #-- OpenOffice
1114
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
1115
+ oo.default_sheet = oo.sheets.first
1116
+ assert oo.empty?('a',14)
1117
+ assert ! oo.empty?('a',15)
1118
+ assert oo.empty?('a',20)
1119
+ end
1120
+ if GNUMERIC_ODS
1121
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
1122
+ oo.default_sheet = oo.sheets.first
1123
+ assert oo.empty?('a',14)
1124
+ assert ! oo.empty?('a',15)
1125
+ assert oo.empty?('a',20)
1126
+ end
1127
+ if EXCEL
1128
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
1129
+ oo.default_sheet = 1
1130
+ assert oo.empty?('a',14)
1131
+ assert ! oo.empty?('a',15)
1132
+ assert oo.empty?('a',20)
1133
+ end
1134
+ if EXCELX
1135
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
1136
+ oo.default_sheet = oo.sheets.first
1137
+ assert oo.empty?('a',14)
1138
+ assert ! oo.empty?('a',15)
1139
+ assert oo.empty?('a',20)
1140
+ end
1141
+ end
1142
+
1143
+ def test_writeopenoffice
1144
+ if OPENOFFICEWRITE
1145
+ File.cp(File.join(TESTDIR,"numbers1.ods"),
1146
+ File.join(TESTDIR,"numbers2.ods"))
1147
+ File.cp(File.join(TESTDIR,"numbers2.ods"),
1148
+ File.join(TESTDIR,"bak_numbers2.ods"))
1149
+ oo = Openoffice.new(File.join(TESTDIR,"numbers2.ods"))
1150
+ oo.default_sheet = oo.sheets.first
1151
+ oo.first_row.upto(oo.last_row) {|y|
1152
+ oo.first_column.upto(oo.last_column) {|x|
1153
+ unless oo.empty?(y,x)
1154
+ # oo.set(y, x, oo.cell(y,x) + 7) if oo.celltype(y,x) == "float"
1155
+ oo.set(y, x, oo.cell(y,x) + 7) if oo.celltype(y,x) == :float
1156
+ end
1157
+ }
1158
+ }
1159
+ oo.save
1160
+
1161
+ oo1 = Openoffice.new(File.join(TESTDIR,"numbers2.ods"))
1162
+ oo2 = Openoffice.new(File.join(TESTDIR,"bak_numbers2.ods"))
1163
+ #p oo2.to_s
1164
+ assert_equal 999, oo2.cell('a',1), oo2.cell('a',1)
1165
+ assert_equal oo2.cell('a',1) + 7, oo1.cell('a',1)
1166
+ assert_equal oo2.cell('b',1)+7, oo1.cell('b',1)
1167
+ assert_equal oo2.cell('c',1)+7, oo1.cell('c',1)
1168
+ assert_equal oo2.cell('d',1)+7, oo1.cell('d',1)
1169
+ assert_equal oo2.cell('a',2)+7, oo1.cell('a',2)
1170
+ assert_equal oo2.cell('b',2)+7, oo1.cell('b',2)
1171
+ assert_equal oo2.cell('c',2)+7, oo1.cell('c',2)
1172
+ assert_equal oo2.cell('d',2)+7, oo1.cell('d',2)
1173
+ assert_equal oo2.cell('e',2)+7, oo1.cell('e',2)
1174
+
1175
+ File.cp(File.join(TESTDIR,"bak_numbers2.ods"),
1176
+ File.join(TESTDIR,"numbers2.ods"))
1177
+ end
1178
+ end
1179
+
1180
+ def test_reload
1181
+ if OPENOFFICE
1182
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
1183
+ oo.default_sheet = oo.sheets.first
1184
+ assert_equal 1, oo.cell(1,1)
1185
+
1186
+ oo.reload
1187
+ assert_equal 1, oo.cell(1,1)
1188
+ end
1189
+ if GNUMERIC_ODS
1190
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
1191
+ oo.default_sheet = oo.sheets.first
1192
+ assert_equal 1, oo.cell(1,1)
1193
+
1194
+ oo.reload
1195
+ assert_equal 1, oo.cell(1,1)
1196
+ end
1197
+ if EXCEL
1198
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
1199
+ oo.default_sheet = 1 # oo.sheets.first
1200
+ assert_equal 1, oo.cell(1,1)
1201
+
1202
+ oo.reload
1203
+ assert_equal 1, oo.cell(1,1)
1204
+ end
1205
+ if EXCELX
1206
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
1207
+ oo.default_sheet = oo.sheets.first
1208
+ assert_equal 1, oo.cell(1,1)
1209
+
1210
+ oo.reload
1211
+ assert_equal 1, oo.cell(1,1)
1212
+ end
1213
+ end
1214
+
1215
+ def test_bug_contiguous_cells
1216
+ if OPENOFFICE
1217
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
1218
+ oo.default_sheet = "Sheet4"
1219
+ assert_equal Date.new(2007,06,16), oo.cell('a',1)
1220
+ assert_equal 10, oo.cell('b',1)
1221
+ assert_equal 10, oo.cell('c',1)
1222
+ assert_equal 10, oo.cell('d',1)
1223
+ assert_equal 10, oo.cell('e',1)
1224
+ end
1225
+ if GNUMERIC_ODS
1226
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
1227
+ oo.default_sheet = "Sheet4"
1228
+ assert_equal Date.new(2007,06,16), oo.cell('a',1)
1229
+ assert_equal 10, oo.cell('b',1)
1230
+ assert_equal 10, oo.cell('c',1)
1231
+ assert_equal 10, oo.cell('d',1)
1232
+ assert_equal 10, oo.cell('e',1)
1233
+ end
1234
+ if EXCEL
1235
+ # dieser Test ist fuer Excel sheets nicht noetig,
1236
+ # da der Bug nur bei OO-Dokumenten auftrat
1237
+ end
1238
+ if GOOGLE
1239
+ # dieser Test ist fuer Google sheets nicht noetig,
1240
+ # da der Bug nur bei OO-Dokumenten auftrat
1241
+ end
1242
+ end
1243
+
1244
+ def test_bug_italo_ve
1245
+ if OPENOFFICE
1246
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
1247
+ oo.default_sheet = "Sheet5"
1248
+ assert_equal 1, oo.cell('A',1)
1249
+ assert_equal 5, oo.cell('b',1)
1250
+ assert_equal 5, oo.cell('c',1)
1251
+ assert_equal 2, oo.cell('a',2)
1252
+ assert_equal 3, oo.cell('a',3)
1253
+ end
1254
+ if OPENOFFICE
1255
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
1256
+ oo.default_sheet = "Sheet5"
1257
+ assert_equal 1, oo.cell('A',1)
1258
+ assert_equal 5, oo.cell('b',1)
1259
+ assert_equal 5, oo.cell('c',1)
1260
+ assert_equal 2, oo.cell('a',2)
1261
+ assert_equal 3, oo.cell('a',3)
1262
+ end
1263
+ if GNUMERIC_ODS
1264
+ oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
1265
+ oo.default_sheet = "Sheet5"
1266
+ assert_equal 1, oo.cell('A',1)
1267
+ assert_equal 5, oo.cell('b',1)
1268
+ assert_equal 5, oo.cell('c',1)
1269
+ assert_equal 2, oo.cell('a',2)
1270
+ assert_equal 3, oo.cell('a',3)
1271
+ end
1272
+ if EXCEL
1273
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
1274
+ oo.default_sheet = 5
1275
+ assert_equal 1, oo.cell('A',1)
1276
+ assert_equal 5, oo.cell('b',1)
1277
+ assert_equal 5, oo.cell('c',1)
1278
+ assert_equal 2, oo.cell('a',2)
1279
+ assert_equal 3, oo.cell('a',3)
1280
+ end
1281
+ if EXCELX
1282
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
1283
+ oo.default_sheet = "Sheet5" # oo.sheets[5-1]
1284
+ assert_equal 1, oo.cell('A',1)
1285
+ assert_equal 5, oo.cell('b',1)
1286
+ assert_equal 5, oo.cell('c',1)
1287
+ assert_equal 2, oo.cell('a',2)
1288
+ assert_equal 3, oo.cell('a',3)
1289
+ end
1290
+ #if GOOGLE
1291
+ # oo = Google.new(key_of("numbers1"))
1292
+ # oo.default_sheet = "Sheet5"
1293
+ # assert_equal 1, oo.cell('A',1)
1294
+ # assert_equal 5, oo.cell('b',1)
1295
+ # assert_equal 5, oo.cell('c',1)
1296
+ # assert_equal 2, oo.cell('a',2)
1297
+ # assert_equal 3, oo.cell('a',3)
1298
+ #end
1299
+ end
1300
+
1301
+ #2008-01-30
1302
+ def test_italo_table
1303
+ local_only do
1304
+ oo = Openoffice.new(File.join(TESTDIR,"simple_spreadsheet_from_italo.ods"))
1305
+ oo.default_sheet = oo.sheets.first
1306
+
1307
+ assert_equal '1', oo.cell('A',1)
1308
+ assert_equal '1', oo.cell('B',1)
1309
+ assert_equal '1', oo.cell('C',1)
1310
+
1311
+ # assert_equal 1, oo.cell('A',2)
1312
+ # assert_equal 2, oo.cell('B',2)
1313
+ # assert_equal 1, oo.cell('C',2)
1314
+ # are stored as strings, not numbers
1315
+
1316
+ assert_equal 1, oo.cell('A',2).to_i
1317
+ assert_equal 2, oo.cell('B',2).to_i
1318
+ assert_equal 1, oo.cell('C',2).to_i
1319
+
1320
+ assert_equal 1, oo.cell('A',3)
1321
+ assert_equal 3, oo.cell('B',3)
1322
+ assert_equal 1, oo.cell('C',3)
1323
+
1324
+ assert_equal 'A', oo.cell('A',4)
1325
+ assert_equal 'A', oo.cell('B',4)
1326
+ assert_equal 'A', oo.cell('C',4)
1327
+
1328
+ # assert_equal '0.01', oo.cell('A',5)
1329
+ # assert_equal '0.01', oo.cell('B',5)
1330
+ # assert_equal '0.01', oo.cell('C',5)
1331
+ #
1332
+ assert_equal 0.01, oo.cell('A',5)
1333
+ assert_equal 0.01, oo.cell('B',5)
1334
+ assert_equal 0.01, oo.cell('C',5)
1335
+
1336
+ assert_equal 0.03, oo.cell('a',5)+oo.cell('b',5)+oo.cell('c',5)
1337
+
1338
+
1339
+ # 1.0
1340
+
1341
+ # Cells values in row 1:
1342
+ assert_equal "1:string", oo.cell(1, 1)+":"+oo.celltype(1, 1).to_s
1343
+ assert_equal "1:string",oo.cell(1, 2)+":"+oo.celltype(1, 2).to_s
1344
+ assert_equal "1:string",oo.cell(1, 3)+":"+oo.celltype(1, 3).to_s
1345
+
1346
+ # Cells values in row 2:
1347
+ assert_equal "1:string",oo.cell(2, 1)+":"+oo.celltype(2, 1).to_s
1348
+ assert_equal "2:string",oo.cell(2, 2)+":"+oo.celltype(2, 2).to_s
1349
+ assert_equal "1:string",oo.cell(2, 3)+":"+oo.celltype(2, 3).to_s
1350
+
1351
+ # Cells values in row 3:
1352
+ assert_equal "1.0:float",oo.cell(3, 1).to_s+":"+oo.celltype(3, 1).to_s
1353
+ assert_equal "3.0:float",oo.cell(3, 2).to_s+":"+oo.celltype(3, 2).to_s
1354
+ assert_equal "1.0:float",oo.cell(3, 3).to_s+":"+oo.celltype(3, 3).to_s
1355
+
1356
+ # Cells values in row 4:
1357
+ assert_equal "A:string",oo.cell(4, 1)+":"+oo.celltype(4, 1).to_s
1358
+ assert_equal "A:string",oo.cell(4, 2)+":"+oo.celltype(4, 2).to_s
1359
+ assert_equal "A:string",oo.cell(4, 3)+":"+oo.celltype(4, 3).to_s
1360
+
1361
+ # Cells values in row 5:
1362
+ assert_equal "0.01:percentage",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
1363
+ assert_equal "0.01:percentage",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
1364
+ assert_equal "0.01:percentage",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
1365
+
1366
+ oo = Excel.new(File.join(TESTDIR,"simple_spreadsheet_from_italo.xls"))
1367
+ oo.default_sheet = oo.sheets.first
1368
+
1369
+ assert_equal '1', oo.cell('A',1)
1370
+ assert_equal '1', oo.cell('B',1)
1371
+ assert_equal '1', oo.cell('C',1)
1372
+
1373
+ # assert_equal 1, oo.cell('A',2)
1374
+ # assert_equal 2, oo.cell('B',2)
1375
+ # assert_equal 1, oo.cell('C',2)
1376
+ # are stored as strings, not numbers
1377
+
1378
+ assert_equal 1, oo.cell('A',2).to_i
1379
+ assert_equal 2, oo.cell('B',2).to_i
1380
+ assert_equal 1, oo.cell('C',2).to_i
1381
+
1382
+ assert_equal 1, oo.cell('A',3)
1383
+ assert_equal 3, oo.cell('B',3)
1384
+ assert_equal 1, oo.cell('C',3)
1385
+
1386
+ assert_equal 'A', oo.cell('A',4)
1387
+ assert_equal 'A', oo.cell('B',4)
1388
+ assert_equal 'A', oo.cell('C',4)
1389
+
1390
+ # assert_equal '0.01', oo.cell('A',5)
1391
+ # assert_equal '0.01', oo.cell('B',5)
1392
+ # assert_equal '0.01', oo.cell('C',5)
1393
+ #
1394
+ assert_equal 0.01, oo.cell('A',5)
1395
+ assert_equal 0.01, oo.cell('B',5)
1396
+ assert_equal 0.01, oo.cell('C',5)
1397
+
1398
+ assert_equal 0.03, oo.cell('a',5)+oo.cell('b',5)+oo.cell('c',5)
1399
+
1400
+
1401
+ # 1.0
1402
+
1403
+ # Cells values in row 1:
1404
+ assert_equal "1:string", oo.cell(1, 1)+":"+oo.celltype(1, 1).to_s
1405
+ assert_equal "1:string",oo.cell(1, 2)+":"+oo.celltype(1, 2).to_s
1406
+ assert_equal "1:string",oo.cell(1, 3)+":"+oo.celltype(1, 3).to_s
1407
+
1408
+ # Cells values in row 2:
1409
+ assert_equal "1:string",oo.cell(2, 1)+":"+oo.celltype(2, 1).to_s
1410
+ assert_equal "2:string",oo.cell(2, 2)+":"+oo.celltype(2, 2).to_s
1411
+ assert_equal "1:string",oo.cell(2, 3)+":"+oo.celltype(2, 3).to_s
1412
+
1413
+ # Cells values in row 3:
1414
+ assert_equal "1.0:float",oo.cell(3, 1).to_s+":"+oo.celltype(3, 1).to_s
1415
+ assert_equal "3.0:float",oo.cell(3, 2).to_s+":"+oo.celltype(3, 2).to_s
1416
+ assert_equal "1.0:float",oo.cell(3, 3).to_s+":"+oo.celltype(3, 3).to_s
1417
+
1418
+ # Cells values in row 4:
1419
+ assert_equal "A:string",oo.cell(4, 1)+":"+oo.celltype(4, 1).to_s
1420
+ assert_equal "A:string",oo.cell(4, 2)+":"+oo.celltype(4, 2).to_s
1421
+ assert_equal "A:string",oo.cell(4, 3)+":"+oo.celltype(4, 3).to_s
1422
+
1423
+ # Cells values in row 5:
1424
+ #assert_equal "0.01:percentage",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
1425
+ #assert_equal "0.01:percentage",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
1426
+ #assert_equal "0.01:percentage",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
1427
+ # why do we get floats here? in the spreadsheet the cells were defined
1428
+ # to be percentage
1429
+ # TODO: should be fixed
1430
+ # the excel gem does not support the cell type 'percentage' these
1431
+ # cells are returned to be of the type float.
1432
+ assert_equal "0.01:float",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
1433
+ assert_equal "0.01:float",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
1434
+ assert_equal "0.01:float",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
1435
+ end
1436
+ end
1437
+
1438
+ def test_formula_openoffice
1439
+ if OPENOFFICE
1440
+ oo = Openoffice.new(File.join(TESTDIR,"formula.ods"))
1441
+ oo.default_sheet = oo.sheets.first
1442
+ assert_equal 1, oo.cell('A',1)
1443
+ assert_equal 2, oo.cell('A',2)
1444
+ assert_equal 3, oo.cell('A',3)
1445
+ assert_equal 4, oo.cell('A',4)
1446
+ assert_equal 5, oo.cell('A',5)
1447
+ assert_equal 6, oo.cell('A',6)
1448
+ assert_equal 21, oo.cell('A',7)
1449
+ assert_equal :formula, oo.celltype('A',7)
1450
+ assert_equal "=[Sheet2.A1]", oo.formula('C',7)
1451
+ assert_nil oo.formula('A',6)
1452
+ assert_equal [[7, 1, "=SUM([.A1:.A6])"],
1453
+ [7, 2, "=SUM([.$A$1:.B6])"],
1454
+ [7, 3, "=[Sheet2.A1]"],
1455
+ [8, 2, "=SUM([.$A$1:.B7])"],
1456
+ ], oo.formulas(oo.sheets.first)
1457
+
1458
+ # setting a cell
1459
+ oo.set('A',15, 41)
1460
+ assert_equal 41, oo.cell('A',15)
1461
+ oo.set('A',16, "41")
1462
+ assert_equal "41", oo.cell('A',16)
1463
+ oo.set('A',17, 42.5)
1464
+ assert_equal 42.5, oo.cell('A',17)
1465
+ end
1466
+ end
1467
+
1468
+ def test_formula_excel
1469
+ if defined? excel_supports_formulas
1470
+ if EXCEL
1471
+ oo = Excel.new(File.join(TESTDIR,"formula.xls"))
1472
+ oo.default_sheet = oo.sheets.first
1473
+ assert_equal 1, oo.cell('A',1)
1474
+ assert_equal 2, oo.cell('A',2)
1475
+ assert_equal 3, oo.cell('A',3)
1476
+ assert_equal 4, oo.cell('A',4)
1477
+ assert_equal 5, oo.cell('A',5)
1478
+ assert_equal 6, oo.cell('A',6)
1479
+ assert_equal :formula, oo.celltype('A',7)
1480
+ assert_equal 21, oo.cell('A',7)
1481
+ assert_equal " = [Sheet2.A1]", oo.formula('C',7)
1482
+ assert_nil oo.formula('A',6)
1483
+ assert_equal [[7, 1, " = SUM([.A1:.A6])"],
1484
+ [7, 2, " = SUM([.$A$1:.B6])"],
1485
+ [7, 3, " = [Sheet2.A1]"],
1486
+ [8, 2, " = SUM([.$A$1:.B7])"],
1487
+ ], oo.formulas
1488
+
1489
+ # setting a cell
1490
+ oo.set('A',15, 41)
1491
+ assert_equal 41, oo.cell('A',15)
1492
+ oo.set('A',16, "41")
1493
+ assert_equal "41", oo.cell('A',16)
1494
+ oo.set('A',17, 42.5)
1495
+ assert_equal 42.5, oo.cell('A',17)
1496
+
1497
+ end
1498
+ end
1499
+ end
1500
+ def test_formula_google
1501
+ if GOOGLE
1502
+ oo = Google.new(key_of("formula"))
1503
+ oo.default_sheet = oo.sheets.first
1504
+ assert_equal 1, oo.cell('A',1)
1505
+ assert_equal 2, oo.cell('A',2)
1506
+ assert_equal 3, oo.cell('A',3)
1507
+ assert_equal 4, oo.cell('A',4)
1508
+ assert_equal 5, oo.cell('A',5)
1509
+ assert_equal 6, oo.cell('A',6)
1510
+ # assert_equal 21, oo.cell('A',7)
1511
+ assert_equal 21.0, oo.cell('A',7) #TODO: better solution Fixnum/Float
1512
+ assert_equal :formula, oo.celltype('A',7)
1513
+ # assert_equal "=[Sheet2.A1]", oo.formula('C',7)
1514
+ # !!! different from formulas in Openoffice
1515
+ #was: assert_equal "=sheet2!R[-6]C[-2]", oo.formula('C',7)
1516
+ # has Google changed their format of formulas/references to other sheets?
1517
+ assert_equal "=Sheet2!R[-6]C[-2]", oo.formula('C',7)
1518
+ assert_nil oo.formula('A',6)
1519
+ # assert_equal [[7, 1, "=SUM([.A1:.A6])"],
1520
+ # [7, 2, "=SUM([.$A$1:.B6])"],
1521
+ # [7, 3, "=[Sheet2.A1]"],
1522
+ # [8, 2, "=SUM([.$A$1:.B7])"],
1523
+ # ], oo.formulas(oo.sheets.first)
1524
+ # different format than in openoffice spreadsheets:
1525
+ #was:
1526
+ # assert_equal [[7, 1, "=SUM(R[-6]C[0]:R[-1]C[0])"],
1527
+ # [7, 2, "=SUM(R1C1:R[-1]C[0])"],
1528
+ # [7, 3, "=sheet2!R[-6]C[-2]"],
1529
+ # [8, 2, "=SUM(R1C1:R[-1]C[0])"]],
1530
+ # oo.formulas(oo.sheets.first)
1531
+ assert_equal [[7, 1, "=SUM(R[-6]C:R[-1]C)"],
1532
+ [7, 2, "=SUM(R1C1:R[-1]C)"],
1533
+ [7, 3, "=Sheet2!R[-6]C[-2]"],
1534
+ [8, 2, "=SUM(R1C1:R[-1]C)"]],
1535
+ oo.formulas(oo.sheets.first)
1536
+ end # GOOGLE
1537
+ end
1538
+
1539
+ def test_formula_excelx
1540
+ if EXCELX
1541
+ oo = Excelx.new(File.join(TESTDIR,"formula.xlsx"))
1542
+ oo.default_sheet = oo.sheets.first
1543
+ assert_equal 1, oo.cell('A',1)
1544
+ assert_equal 2, oo.cell('A',2)
1545
+ assert_equal 3, oo.cell('A',3)
1546
+ assert_equal 4, oo.cell('A',4)
1547
+ assert_equal 5, oo.cell('A',5)
1548
+ assert_equal 6, oo.cell('A',6)
1549
+ assert_equal 21, oo.cell('A',7)
1550
+ assert_equal :formula, oo.celltype('A',7)
1551
+ after Date.new(9999,12,31) do
1552
+ #steht nicht in Datei, oder?
1553
+ #nein, diesen Bezug habe ich nur in der Openoffice-Datei
1554
+ assert_equal "=[Sheet2.A1]", oo.formula('C',7)
1555
+ end
1556
+ assert_nil oo.formula('A',6)
1557
+ # assert_equal [[7, 1, "=SUM([.A1:.A6])"],
1558
+ # [7, 2, "=SUM([.$A$1:.B6])"],
1559
+ #[7, 3, "=[Sheet2.A1]"],
1560
+ #[8, 2, "=SUM([.$A$1:.B7])"],
1561
+ #], oo.formulas(oo.sheets.first)
1562
+ assert_equal [[7, 1, 'SUM(A1:A6)'],
1563
+ [7, 2, 'SUM($A$1:B6)'],
1564
+ # [7, 3, "=[Sheet2.A1]"],
1565
+ # [8, 2, "=SUM([.$A$1:.B7])"],
1566
+ ], oo.formulas(oo.sheets.first)
1567
+
1568
+ # setting a cell
1569
+ oo.set('A',15, 41)
1570
+ assert_equal 41, oo.cell('A',15)
1571
+ oo.set('A',16, "41")
1572
+ assert_equal "41", oo.cell('A',16)
1573
+ oo.set('A',17, 42.5)
1574
+ assert_equal 42.5, oo.cell('A',17)
1575
+ end
1576
+ end
1577
+
1578
+ def test_borders_sheets_openoffice
1579
+ if OPENOFFICE
1580
+ oo = Openoffice.new(File.join(TESTDIR,"borders.ods"))
1581
+ oo.default_sheet = oo.sheets[1]
1582
+ assert_equal 6, oo.first_row
1583
+ assert_equal 11, oo.last_row
1584
+ assert_equal 4, oo.first_column
1585
+ assert_equal 8, oo.last_column
1586
+
1587
+ oo.default_sheet = oo.sheets.first
1588
+ assert_equal 5, oo.first_row
1589
+ assert_equal 10, oo.last_row
1590
+ assert_equal 3, oo.first_column
1591
+ assert_equal 7, oo.last_column
1592
+
1593
+ oo.default_sheet = oo.sheets[2]
1594
+ assert_equal 7, oo.first_row
1595
+ assert_equal 12, oo.last_row
1596
+ assert_equal 5, oo.first_column
1597
+ assert_equal 9, oo.last_column
1598
+ end
1599
+ end
1600
+
1601
+ def test_borders_sheets_excel
1602
+ if EXCEL
1603
+ oo = Excel.new(File.join(TESTDIR,"borders.xls"))
1604
+ oo.default_sheet = oo.sheets[1]
1605
+ assert_equal 6, oo.first_row
1606
+ assert_equal 11, oo.last_row
1607
+ assert_equal 4, oo.first_column
1608
+ assert_equal 8, oo.last_column
1609
+
1610
+ oo.default_sheet = 1 # oo.sheets.first
1611
+ assert_equal 5, oo.first_row
1612
+ assert_equal 10, oo.last_row
1613
+ assert_equal 3, oo.first_column
1614
+ assert_equal 7, oo.last_column
1615
+
1616
+ oo.default_sheet = 3 # oo.sheets[2]
1617
+ assert_equal 7, oo.first_row
1618
+ assert_equal 12, oo.last_row
1619
+ assert_equal 5, oo.first_column
1620
+ assert_equal 9, oo.last_column
1621
+ end
1622
+ end
1623
+
1624
+ def test_borders_sheets_excelx
1625
+ if EXCELX
1626
+ oo = Excelx.new(File.join(TESTDIR,"borders.xlsx"))
1627
+ oo.default_sheet = oo.sheets[1]
1628
+ assert_equal 6, oo.first_row
1629
+ assert_equal 11, oo.last_row
1630
+ assert_equal 4, oo.first_column
1631
+ assert_equal 8, oo.last_column
1632
+
1633
+ oo.default_sheet = oo.sheets.first
1634
+ assert_equal 5, oo.first_row
1635
+ assert_equal 10, oo.last_row
1636
+ assert_equal 3, oo.first_column
1637
+ assert_equal 7, oo.last_column
1638
+
1639
+ oo.default_sheet = oo.sheets[2]
1640
+ assert_equal 7, oo.first_row
1641
+ assert_equal 12, oo.last_row
1642
+ assert_equal 5, oo.first_column
1643
+ assert_equal 9, oo.last_column
1644
+ end
1645
+ end
1646
+
1647
+ def test_borders_sheets_google
1648
+ if GOOGLE
1649
+ assert_nothing_raised(Timeout::Error) {
1650
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1651
+ oo = Google.new(key_of("borders"))
1652
+ oo.default_sheet = oo.sheets[0]
1653
+ assert_equal oo.sheets.first, oo.default_sheet
1654
+ assert_equal 5, oo.first_row
1655
+ oo.default_sheet = oo.sheets[1]
1656
+ assert_equal 'Sheet2', oo.default_sheet
1657
+ assert_equal 6, oo.first_row
1658
+ assert_equal 11, oo.last_row
1659
+ assert_equal 4, oo.first_column
1660
+ assert_equal 8, oo.last_column
1661
+
1662
+ oo.default_sheet = oo.sheets.first
1663
+ assert_equal 5, oo.first_row
1664
+ assert_equal 10, oo.last_row
1665
+ assert_equal 3, oo.first_column
1666
+ assert_equal 7, oo.last_column
1667
+
1668
+ oo.default_sheet = oo.sheets[2]
1669
+ assert_equal 7, oo.first_row
1670
+ assert_equal 12, oo.last_row
1671
+ assert_equal 5, oo.first_column
1672
+ assert_equal 9, oo.last_column
1673
+ end
1674
+ }
1675
+ end
1676
+ end
1677
+
1678
+ def yaml_entry(row,col,type,value)
1679
+ "cell_#{row}_#{col}: \n row: #{row} \n col: #{col} \n celltype: #{type} \n value: #{value} \n"
1680
+ end
1681
+
1682
+ def test_to_yaml
1683
+ if OPENOFFICE
1684
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
1685
+ oo.default_sheet = oo.sheets.first
1686
+ assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), oo.to_yaml({}, 5,1,5,1)
1687
+ assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3)
1688
+ assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3)
1689
+ assert_equal \
1690
+ "--- \n"+yaml_entry(12,3,"float",43.0) +
1691
+ yaml_entry(12,4,"float",44.0) +
1692
+ yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12)
1693
+ assert_equal \
1694
+ "--- \n"+yaml_entry(12,3,"float",43.0)+
1695
+ yaml_entry(12,4,"float",44.0)+
1696
+ yaml_entry(12,5,"float",45.0)+
1697
+ yaml_entry(15,3,"float",43.0)+
1698
+ yaml_entry(15,4,"float",44.0)+
1699
+ yaml_entry(15,5,"float",45.0)+
1700
+ yaml_entry(16,3,"string","dreiundvierzig")+
1701
+ yaml_entry(16,4,"string","vierundvierzig")+
1702
+ yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3)
1703
+ #example: puts oo.to_yaml({}, 12,3)
1704
+ #example: puts oo.to_yaml({"probe" => "bodenproben_2007-06-30"}, 12,3)
1705
+ end
1706
+ if EXCEL
1707
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
1708
+ oo.default_sheet = 1
1709
+ assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), oo.to_yaml({}, 5,1,5,1)
1710
+ assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3)
1711
+ assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3)
1712
+ assert_equal \
1713
+ "--- \n"+yaml_entry(12,3,"float",43.0) +
1714
+ yaml_entry(12,4,"float",44.0) +
1715
+ yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12)
1716
+ assert_equal \
1717
+ "--- \n"+yaml_entry(12,3,"float",43.0)+
1718
+ yaml_entry(12,4,"float",44.0)+
1719
+ yaml_entry(12,5,"float",45.0)+
1720
+ yaml_entry(15,3,"float",43.0)+
1721
+ yaml_entry(15,4,"float",44.0)+
1722
+ yaml_entry(15,5,"float",45.0)+
1723
+ yaml_entry(16,3,"string","dreiundvierzig")+
1724
+ yaml_entry(16,4,"string","vierundvierzig")+
1725
+ yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3)
1726
+ end
1727
+ if EXCELX
1728
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
1729
+ oo.default_sheet = oo.sheets.first
1730
+ assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), oo.to_yaml({}, 5,1,5,1)
1731
+ assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3)
1732
+ assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3)
1733
+ assert_equal \
1734
+ "--- \n"+yaml_entry(12,3,"float",43.0) +
1735
+ yaml_entry(12,4,"float",44.0) +
1736
+ yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12)
1737
+ assert_equal \
1738
+ "--- \n"+yaml_entry(12,3,"float",43.0)+
1739
+ yaml_entry(12,4,"float",44.0)+
1740
+ yaml_entry(12,5,"float",45.0)+
1741
+ yaml_entry(15,3,"float",43.0)+
1742
+ yaml_entry(15,4,"float",44.0)+
1743
+ yaml_entry(15,5,"float",45.0)+
1744
+ yaml_entry(16,3,"string","dreiundvierzig")+
1745
+ yaml_entry(16,4,"string","vierundvierzig")+
1746
+ yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3)
1747
+ end
1748
+ if GOOGLE
1749
+ oo = Google.new(key_of("numbers1"))
1750
+ oo.default_sheet = oo.sheets.first
1751
+ assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), oo.to_yaml({}, 5,1,5,1)
1752
+ assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3)
1753
+ assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3)
1754
+ assert_equal \
1755
+ "--- \n"+yaml_entry(12,3,"float",43.0) +
1756
+ yaml_entry(12,4,"float",44.0) +
1757
+ yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12)
1758
+ assert_equal \
1759
+ "--- \n"+yaml_entry(12,3,"float",43.0)+
1760
+ yaml_entry(12,4,"float",44.0)+
1761
+ yaml_entry(12,5,"float",45.0)+
1762
+ yaml_entry(15,3,"float",43.0)+
1763
+ yaml_entry(15,4,"float",44.0)+
1764
+ yaml_entry(15,5,"float",45.0)+
1765
+ yaml_entry(16,3,"string","dreiundvierzig")+
1766
+ yaml_entry(16,4,"string","vierundvierzig")+
1767
+ yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3)
1768
+ #example: puts oo.to_yaml({}, 12,3)
1769
+ #example: puts oo.to_yaml({"probe" => "bodenproben_2007-06-30"}, 12,3)
1770
+ end
1771
+ end
1772
+
1773
+ if false
1774
+ def test_soap_server
1775
+ #threads = []
1776
+ #threads << Thread.new("serverthread") do
1777
+ fork do
1778
+ p "serverthread started"
1779
+ puts "in child, pid = #$$"
1780
+ puts `/usr/bin/ruby rooserver.rb`
1781
+ p "serverthread finished"
1782
+ end
1783
+ #threads << Thread.new("clientthread") do
1784
+ p "clientthread started"
1785
+ sleep 10
1786
+ proxy = SOAP::RPC::Driver.new("http://localhost:12321","spreadsheetserver")
1787
+ proxy.add_method('cell','row','col')
1788
+ proxy.add_method('officeversion')
1789
+ proxy.add_method('last_row')
1790
+ proxy.add_method('last_column')
1791
+ proxy.add_method('first_row')
1792
+ proxy.add_method('first_column')
1793
+ proxy.add_method('sheets')
1794
+ proxy.add_method('set_default_sheet','s')
1795
+ proxy.add_method('ferien_fuer_region', 'region')
1796
+
1797
+ sheets = proxy.sheets
1798
+ p sheets
1799
+ proxy.set_default_sheet(sheets.first)
1800
+
1801
+ assert_equal 1, proxy.first_row
1802
+ assert_equal 1, proxy.first_column
1803
+ assert_equal 187, proxy.last_row
1804
+ assert_equal 7, proxy.last_column
1805
+ assert_equal 42, proxy.cell('C',8)
1806
+ assert_equal 43, proxy.cell('F',12)
1807
+ assert_equal "1.0", proxy.officeversion
1808
+ p "clientthread finished"
1809
+ #end
1810
+ #threads.each {|t| t.join }
1811
+ puts "fertig"
1812
+ Process.kill("INT",pid)
1813
+ pid = Process.wait
1814
+ puts "child terminated, pid= #{pid}, status= #{$?.exitstatus}"
1815
+ end
1816
+ end # false
1817
+
1818
+ def split_coord(s)
1819
+ letter = ""
1820
+ number = 0
1821
+ i = 0
1822
+ while i<s.length and "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".include?(s[i,1])
1823
+ letter += s[i,1]
1824
+ i+=1
1825
+ end
1826
+ while i<s.length and "01234567890".include?(s[i,1])
1827
+ number = number*10 + s[i,1].to_i
1828
+ i+=1
1829
+ end
1830
+ if letter=="" or number==0
1831
+ raise ArgumentError
1832
+ end
1833
+ return letter,number
1834
+ end
1835
+
1836
+ #def sum(s,expression)
1837
+ # arg = expression.split(':')
1838
+ # b,z = split_coord(arg[0])
1839
+ # first_row = z
1840
+ # first_col = Openoffice.letter_to_number(b)
1841
+ # b,z = split_coord(arg[1])
1842
+ # last_row = z
1843
+ # last_col = Openoffice.letter_to_number(b)
1844
+ # result = 0
1845
+ # first_row.upto(last_row) {|row|
1846
+ # first_col.upto(last_col) {|col|
1847
+ # result = result + s.cell(row,col)
1848
+ # }
1849
+ # }
1850
+ # result
1851
+ #end
1852
+
1853
+ #def test_dsl
1854
+ # s = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
1855
+ # s.default_sheet = s.sheets.first
1856
+ #
1857
+ # s.set 'a',1, 5
1858
+ # s.set 'b',1, 3
1859
+ # s.set 'c',1, 7
1860
+ # s.set('a',2, s.cell('a',1)+s.cell('b',1))
1861
+ # assert_equal 8, s.cell('a',2)
1862
+ #
1863
+ # assert_equal 15, sum(s,'A1:C1')
1864
+ # end
1865
+
1866
+ #def test_create_spreadsheet1
1867
+ # name = File.join(TESTDIR,'createdspreadsheet.ods')
1868
+ # rm(name) if File.exists?(File.join(TESTDIR,'createdspreadsheet.ods'))
1869
+ # # anlegen, falls noch nicht existierend
1870
+ # s = Openoffice.new(name,true)
1871
+ # assert File.exists?(name)
1872
+ #end
1873
+
1874
+ #def test_create_spreadsheet2
1875
+ # # anlegen, falls noch nicht existierend
1876
+ # s = Openoffice.new(File.join(TESTDIR,"createdspreadsheet.ods"),true)
1877
+ # s.set 'a',1,42
1878
+ # s.set 'b',1,43
1879
+ # s.set 'c',1,44
1880
+ # s.save
1881
+ #
1882
+ # #after Date.new(2007,7,3) do
1883
+ # # t = Openoffice.new(File.join(TESTDIR,"createdspreadsheet.ods"))
1884
+ # # assert_equal 42, t.cell(1,'a')
1885
+ # # assert_equal 43, t.cell('b',1)
1886
+ # # assert_equal 44, t.cell('c',3)
1887
+ # #end
1888
+ #end
1889
+
1890
+ def test_only_one_sheet
1891
+ if OPENOFFICE
1892
+ oo = Openoffice.new(File.join(TESTDIR,"only_one_sheet.ods"))
1893
+ # oo.default_sheet = oo.sheets.first
1894
+ assert_equal 42, oo.cell('B',4)
1895
+ assert_equal 43, oo.cell('C',4)
1896
+ assert_equal 44, oo.cell('D',4)
1897
+ oo.default_sheet = oo.sheets.first
1898
+ assert_equal 42, oo.cell('B',4)
1899
+ assert_equal 43, oo.cell('C',4)
1900
+ assert_equal 44, oo.cell('D',4)
1901
+ end
1902
+ if EXCEL
1903
+ oo = Excel.new(File.join(TESTDIR,"only_one_sheet.xls"))
1904
+ # oo.default_sheet = oo.sheets.first
1905
+ assert_equal 42, oo.cell('B',4)
1906
+ assert_equal 43, oo.cell('C',4)
1907
+ assert_equal 44, oo.cell('D',4)
1908
+ oo.default_sheet = oo.sheets.first
1909
+ assert_equal 42, oo.cell('B',4)
1910
+ assert_equal 43, oo.cell('C',4)
1911
+ assert_equal 44, oo.cell('D',4)
1912
+ end
1913
+ if EXCELX
1914
+ oo = Excelx.new(File.join(TESTDIR,"only_one_sheet.xlsx"))
1915
+ # oo.default_sheet = oo.sheets.first
1916
+ assert_equal 42, oo.cell('B',4)
1917
+ assert_equal 43, oo.cell('C',4)
1918
+ assert_equal 44, oo.cell('D',4)
1919
+ oo.default_sheet = oo.sheets.first
1920
+ assert_equal 42, oo.cell('B',4)
1921
+ assert_equal 43, oo.cell('C',4)
1922
+ assert_equal 44, oo.cell('D',4)
1923
+ end
1924
+ if GOOGLE
1925
+ oo = Google.new(key_of("only_one_sheet"))
1926
+ # oo.default_sheet = oo.sheets.first
1927
+ assert_equal 42, oo.cell('B',4)
1928
+ assert_equal 43, oo.cell('C',4)
1929
+ assert_equal 44, oo.cell('D',4)
1930
+ oo.default_sheet = oo.sheets.first
1931
+ assert_equal 42, oo.cell('B',4)
1932
+ assert_equal 43, oo.cell('C',4)
1933
+ assert_equal 44, oo.cell('D',4)
1934
+ end
1935
+
1936
+ end
1937
+
1938
+ def test_excel_open_from_uri_and_zipped
1939
+ if EXCEL
1940
+ if ONLINE
1941
+ url = 'http://stiny-leonhard.de/bode-v1.xls.zip'
1942
+ excel = Excel.new(url, :zip)
1943
+ excel.default_sheet = excel.sheets.first
1944
+ assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
1945
+ excel.remove_tmp # don't forget to remove the temporary files
1946
+ end
1947
+ end
1948
+ end
1949
+
1950
+ #TODO: xlsx-Datei anpassen!
1951
+ def test_excelx_open_from_uri_and_zipped
1952
+ #TODO: gezippte xlsx Datei online zum Testen suchen
1953
+ after Date.new(2999,6,30) do
1954
+ if EXCELX
1955
+ if ONLINE
1956
+ url = 'http://stiny-leonhard.de/bode-v1.xlsx.zip'
1957
+ excel = Excelx.new(url, :zip)
1958
+ assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
1959
+ excel.remove_tmp # don't forget to remove the temporary files
1960
+ end
1961
+ end
1962
+ end
1963
+ end
1964
+
1965
+ def test_openoffice_open_from_uri_and_zipped
1966
+ if OPENOFFICE
1967
+ if ONLINE
1968
+ url = 'http://spazioinwind.libero.it/s2/rata.ods.zip'
1969
+ sheet = Openoffice.new(url, :zip)
1970
+ #has been changed: assert_equal 'ist "e" im Nenner von H(s)', sheet.cell('b', 5)
1971
+ assert_in_delta 0.001, 505.14, sheet.cell('c', 33).to_f
1972
+ sheet.remove_tmp # don't forget to remove the temporary files
1973
+ end
1974
+ end
1975
+ end
1976
+
1977
+ def SKIP_test_excel_zipped
1978
+ after Date.new(2009,1,10) do
1979
+ if EXCEL
1980
+ $log.level = Logger::DEBUG
1981
+ excel = Excel.new(File.join(TESTDIR,"bode-v1.xls.zip"), :zip)
1982
+ assert excel
1983
+ # muss Fehler bringen, weil kein default_sheet gesetzt wurde
1984
+ assert_raises (ArgumentError) {
1985
+ assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
1986
+ }
1987
+ $log.level = Logger::WARN
1988
+ excel.default_sheet = excel.sheets.first
1989
+ assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
1990
+ excel.remove_tmp # don't forget to remove the temporary files
1991
+ end
1992
+ end
1993
+ end
1994
+
1995
+ def test_excelx_zipped
1996
+ # TODO: bode...xls bei Gelegenheit nach .xlsx konverieren lassen und zippen!
1997
+ if EXCELX
1998
+ after Date.new(2999,7,30) do
1999
+ # diese Datei gibt es noch nicht gezippt
2000
+ excel = Excelx.new(File.join(TESTDIR,"bode-v1.xlsx.zip"), :zip)
2001
+ assert excel
2002
+ assert_raises (ArgumentError) {
2003
+ assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
2004
+ }
2005
+ excel.default_sheet = excel.sheets.first
2006
+ assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
2007
+ excel.remove_tmp # don't forget to remove the temporary files
2008
+ end
2009
+ end
2010
+ end
2011
+
2012
+ def test_openoffice_zipped
2013
+ if OPENOFFICE
2014
+ oo = Openoffice.new(File.join(TESTDIR,"bode-v1.ods.zip"), :zip)
2015
+ assert oo
2016
+ # muss Fehler bringen, weil kein default_sheet gesetzt wurde
2017
+ assert_raises (ArgumentError) {
2018
+ assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
2019
+
2020
+ }
2021
+ oo.default_sheet = oo.sheets.first
2022
+ assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
2023
+ oo.remove_tmp # don't forget to remove the temporary files
2024
+ end
2025
+ end
2026
+
2027
+ def test_bug_ric
2028
+ if OPENOFFICE
2029
+ oo = Openoffice.new(File.join(TESTDIR,"ric.ods"))
2030
+ oo.default_sheet = oo.sheets.first
2031
+ assert oo.empty?('A',1)
2032
+ assert oo.empty?('B',1)
2033
+ assert oo.empty?('C',1)
2034
+ assert oo.empty?('D',1)
2035
+ expected = 1
2036
+ letter = 'e'
2037
+ while letter <= 'u'
2038
+ assert_equal expected, oo.cell(letter,1)
2039
+ letter.succ!
2040
+ expected += 1
2041
+ end
2042
+ #assert_equal 2, oo.cell('f',1)
2043
+ #assert_equal 3, oo.cell('g',1)
2044
+ #assert_equal 4, oo.cell('h',1)
2045
+ #assert_equal 5, oo.cell('i',1)
2046
+ #assert_equal 6, oo.cell('j',1)
2047
+ #assert_equal 7, oo.cell('k',1)
2048
+ #assert_equal 8, oo.cell('l',1)
2049
+ #assert_equal 9, oo.cell('m',1)
2050
+ #assert_equal 10, oo.cell('n',1)
2051
+ #assert_equal 11, oo.cell('o',1)
2052
+ #assert_equal 12, oo.cell('p',1)
2053
+ #assert_equal 13, oo.cell('q',1)
2054
+ #assert_equal 14, oo.cell('r',1)
2055
+ #assert_equal 15, oo.cell('s',1)
2056
+ #assert_equal 16, oo.cell('t',1)
2057
+ #assert_equal 17, oo.cell('u',1)
2058
+ assert_equal 'J', oo.cell('v',1)
2059
+ assert_equal 'P', oo.cell('w',1)
2060
+ assert_equal 'B', oo.cell('x',1)
2061
+ assert_equal 'All', oo.cell('y',1)
2062
+ assert_equal 0, oo.cell('a',2)
2063
+ assert oo.empty?('b',2)
2064
+ assert oo.empty?('c',2)
2065
+ assert oo.empty?('d',2)
2066
+
2067
+ #'e'.upto('s') {|letter|
2068
+ # assert_equal 'B', oo.cell(letter,2)
2069
+ #}
2070
+ assert_equal 'B', oo.cell('e',2)
2071
+ assert_equal 'B', oo.cell('f',2)
2072
+ assert_equal 'B', oo.cell('g',2)
2073
+ assert_equal 'B', oo.cell('h',2)
2074
+ assert_equal 'B', oo.cell('i',2)
2075
+ assert_equal 'B', oo.cell('j',2)
2076
+ assert_equal 'B', oo.cell('k',2)
2077
+ assert_equal 'B', oo.cell('l',2)
2078
+ assert_equal 'B', oo.cell('m',2)
2079
+ assert_equal 'B', oo.cell('n',2)
2080
+ assert_equal 'B', oo.cell('o',2)
2081
+ assert_equal 'B', oo.cell('p',2)
2082
+ assert_equal 'B', oo.cell('q',2)
2083
+ assert_equal 'B', oo.cell('r',2)
2084
+ assert_equal 'B', oo.cell('s',2)
2085
+
2086
+ assert oo.empty?('t',2)
2087
+ assert oo.empty?('u',2)
2088
+ assert_equal 0 , oo.cell('v',2)
2089
+ assert_equal 0 , oo.cell('w',2)
2090
+ assert_equal 15 , oo.cell('x',2)
2091
+ assert_equal 15 , oo.cell('y',2)
2092
+ end
2093
+ end
2094
+
2095
+ def test_mehrteilig
2096
+ if OPENOFFICE
2097
+ oo = Openoffice.new(File.join(TESTDIR,"Bibelbund1.ods"))
2098
+ oo.default_sheet = oo.sheets.first
2099
+ assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
2100
+ end
2101
+ #if EXCELX
2102
+ # after Date.new(2008,6,1) do
2103
+ # #Datei gibt es noch nicht
2104
+ # oo = Excelx.new(File.join(TESTDIR,"Bibelbund1.xlsx"))
2105
+ # oo.default_sheet = oo.sheets.first
2106
+ # assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
2107
+ # end
2108
+ #end
2109
+ end
2110
+
2111
+ def test_huge_document_to_csv_openoffice
2112
+ if LONG_RUN
2113
+ if OPENOFFICE
2114
+ assert_nothing_raised(Timeout::Error) {
2115
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2116
+ File.delete_if_exist("/tmp/Bibelbund.csv")
2117
+ oo = Openoffice.new(File.join(TESTDIR,"Bibelbund.ods"))
2118
+ oo.default_sheet = oo.sheets.first
2119
+ assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
2120
+ assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", oo.cell(46,'A')
2121
+ assert_equal "Tagebuch aus Chile Juli 1977", oo.cell(55,'A')
2122
+ assert oo.to_csv("/tmp/Bibelbund.csv")
2123
+ assert File.exists?("/tmp/Bibelbund.csv")
2124
+ assert_equal "", `diff test/Bibelbund.csv /tmp/Bibelbund.csv`
2125
+ end # Timeout
2126
+ } # nothing_raised
2127
+ end # OPENOFFICE
2128
+ end
2129
+ end
2130
+
2131
+ def test_huge_document_to_csv_excel
2132
+ if LONG_RUN
2133
+ if EXCEL
2134
+ assert_nothing_raised(Timeout::Error) {
2135
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2136
+ File.delete_if_exist("/tmp/Bibelbund.csv")
2137
+ oo = Excel.new(File.join(TESTDIR,"Bibelbund.xls"))
2138
+ oo.default_sheet = oo.sheets.first
2139
+ assert oo.to_csv("/tmp/Bibelbund.csv")
2140
+ assert File.exists?("/tmp/Bibelbund.csv")
2141
+ assert_equal "", `diff test/Bibelbund.csv /tmp/Bibelbund.csv`
2142
+ end
2143
+ }
2144
+ end
2145
+ end # LONG_RUN
2146
+ end # def to_csv
2147
+
2148
+ def test_huge_document_to_csv_excelx
2149
+ after Date.new(2008,8,27) do
2150
+ if LONG_RUN
2151
+ if EXCELX
2152
+ assert_nothing_raised(Timeout::Error) {
2153
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2154
+ File.delete_if_exist("/tmp/Bibelbund.csv")
2155
+ oo = Excelx.new(File.join(TESTDIR,"Bibelbund.xlsx"))
2156
+ oo.default_sheet = oo.sheets.first
2157
+ assert oo.to_csv("/tmp/Bibelbund.csv")
2158
+ assert File.exists?("/tmp/Bibelbund.csv")
2159
+ assert_equal "", `diff test/Bibelbund.csv /tmp/Bibelbund.csv`
2160
+ end
2161
+ }
2162
+ end
2163
+ end # LONG_RUN
2164
+ end
2165
+ end
2166
+
2167
+ def test_huge_document_to_csv_google
2168
+ # maybe a better example... TODO:
2169
+ if GOOGLE and LONG_RUN
2170
+ assert_nothing_raised(Timeout::Error) {
2171
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2172
+ File.delete("/tmp/numbers1.csv") if File.exists?("/tmp/numbers1.csv")
2173
+ oo = Google.new(key_of('numbers1'))
2174
+ oo.default_sheet = oo.sheets.first
2175
+ #?? assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
2176
+ #?? assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", oo.cell(46,'A')
2177
+ #?? assert_equal "Tagebuch aus Chile Juli 1977", oo.cell(55,'A')
2178
+ assert oo.to_csv("/tmp/numbers1.csv")
2179
+ assert File.exists?("/tmp/numbers1.csv")
2180
+ assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
2181
+ end # Timeout
2182
+ } # nothing_raised
2183
+ end # GOOGLE
2184
+ end
2185
+
2186
+ def test_to_csv_openoffice
2187
+ if OPENOFFICE
2188
+ #assert_nothing_raised(Timeout::Error) {
2189
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2190
+ File.delete_if_exist("/tmp/numbers1.csv")
2191
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
2192
+
2193
+
2194
+ # bug?, 2008-01-15 from Troy Davis
2195
+ assert oo.to_csv("/tmp/numbers1.csv",oo.sheets.first)
2196
+ assert File.exists?("/tmp/numbers1.csv")
2197
+ assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
2198
+
2199
+ oo.default_sheet = oo.sheets.first
2200
+ assert oo.to_csv("/tmp/numbers1.csv")
2201
+ assert File.exists?("/tmp/numbers1.csv")
2202
+ assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
2203
+
2204
+ end # Timeout
2205
+ #} # nothing_raised
2206
+ end # OPENOFFICE
2207
+ end
2208
+
2209
+ def test_to_csv_excel
2210
+ if EXCEL
2211
+ #assert_nothing_raised(Timeout::Error) {
2212
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2213
+ File.delete_if_exist("/tmp/numbers1_excel.csv")
2214
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
2215
+
2216
+ # bug?, 2008-01-15 from Troy Davis
2217
+ assert oo.to_csv("/tmp/numbers1_excel.csv",oo.sheets.first)
2218
+ assert File.exists?("/tmp/numbers1_excel.csv")
2219
+ assert_equal "", `diff test/numbers1_excel.csv /tmp/numbers1_excel.csv`
2220
+ oo.default_sheet = oo.sheets.first
2221
+ assert oo.to_csv("/tmp/numbers1_excel.csv")
2222
+ assert File.exists?("/tmp/numbers1_excel.csv")
2223
+ assert_equal "", `diff test/numbers1_excel.csv /tmp/numbers1_excel.csv`
2224
+ end
2225
+
2226
+ #}
2227
+ end
2228
+ end
2229
+
2230
+ def test_to_csv_excelx
2231
+ if EXCELX
2232
+ #assert_nothing_raised(Timeout::Error) {
2233
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2234
+ File.delete_if_exist("/tmp/numbers1.csv")
2235
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
2236
+
2237
+ # bug?, 2008-01-15 from Troy Davis
2238
+ assert oo.to_csv("/tmp/numbers1.csv",oo.sheets.first)
2239
+ assert File.exists?("/tmp/numbers1.csv")
2240
+ assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
2241
+ oo.default_sheet = oo.sheets.first
2242
+ assert oo.to_csv("/tmp/numbers1.csv")
2243
+ assert File.exists?("/tmp/numbers1.csv")
2244
+ assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
2245
+ end
2246
+
2247
+ #}
2248
+ end
2249
+ end
2250
+
2251
+ def test_to_csv_google
2252
+ # maybe a better example... TODO:
2253
+ if GOOGLE
2254
+ #assert_nothing_raised(Timeout::Error) {
2255
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2256
+ File.delete_if_exist("/tmp/numbers1.csv") if File.exists?("/tmp/numbers1.csv")
2257
+ oo = Google.new(key_of('numbers1'))
2258
+
2259
+ oo.default_sheet = oo.sheets.first
2260
+ assert oo.to_csv("/tmp/numbers1.csv")
2261
+ assert File.exists?("/tmp/numbers1.csv")
2262
+ assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
2263
+
2264
+ # bug?, 2008-01-15 from Troy Davis
2265
+ assert oo.to_csv("/tmp/numbers1.csv",oo.sheets.first)
2266
+ assert File.exists?("/tmp/numbers1.csv")
2267
+ assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
2268
+
2269
+ end # Timeout
2270
+ #} # nothing_raised
2271
+ end # GOOGLE
2272
+ end
2273
+
2274
+ def test_bug_mehrere_datum
2275
+ if OPENOFFICE
2276
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
2277
+ oo.default_sheet = 'Sheet5'
2278
+ assert_equal :date, oo.celltype('A',4)
2279
+ assert_equal :date, oo.celltype('B',4)
2280
+ assert_equal :date, oo.celltype('C',4)
2281
+ assert_equal :date, oo.celltype('D',4)
2282
+ assert_equal :date, oo.celltype('E',4)
2283
+ assert_equal Date.new(2007,11,21), oo.cell('A',4)
2284
+ assert_equal Date.new(2007,11,21), oo.cell('B',4)
2285
+ assert_equal Date.new(2007,11,21), oo.cell('C',4)
2286
+ assert_equal Date.new(2007,11,21), oo.cell('D',4)
2287
+ assert_equal Date.new(2007,11,21), oo.cell('E',4)
2288
+ assert_equal :float, oo.celltype('A',5)
2289
+ assert_equal :float, oo.celltype('B',5)
2290
+ assert_equal :float, oo.celltype('C',5)
2291
+ assert_equal :float, oo.celltype('D',5)
2292
+ assert_equal :float, oo.celltype('E',5)
2293
+ assert_equal 42, oo.cell('A',5)
2294
+ assert_equal 42, oo.cell('B',5)
2295
+ assert_equal 42, oo.cell('C',5)
2296
+ assert_equal 42, oo.cell('D',5)
2297
+ assert_equal 42, oo.cell('E',5)
2298
+ assert_equal :string, oo.celltype('A',6)
2299
+ assert_equal :string, oo.celltype('B',6)
2300
+ assert_equal :string, oo.celltype('C',6)
2301
+ assert_equal :string, oo.celltype('D',6)
2302
+ assert_equal :string, oo.celltype('E',6)
2303
+ assert_equal "ABC", oo.cell('A',6)
2304
+ assert_equal "ABC", oo.cell('B',6)
2305
+ assert_equal "ABC", oo.cell('C',6)
2306
+ assert_equal "ABC", oo.cell('D',6)
2307
+ assert_equal "ABC", oo.cell('E',6)
2308
+ end # Openoffice
2309
+
2310
+ if EXCEL
2311
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
2312
+ oo.default_sheet = 'Sheet5'
2313
+ assert_equal :date, oo.celltype('A',4)
2314
+ assert_equal :date, oo.celltype('B',4)
2315
+ assert_equal :date, oo.celltype('C',4)
2316
+ assert_equal :date, oo.celltype('D',4)
2317
+ assert_equal :date, oo.celltype('E',4)
2318
+ assert_equal Date.new(2007,11,21), oo.cell('A',4)
2319
+ assert_equal Date.new(2007,11,21), oo.cell('B',4)
2320
+ assert_equal Date.new(2007,11,21), oo.cell('C',4)
2321
+ assert_equal Date.new(2007,11,21), oo.cell('D',4)
2322
+ assert_equal Date.new(2007,11,21), oo.cell('E',4)
2323
+ assert_equal :float, oo.celltype('A',5)
2324
+ assert_equal :float, oo.celltype('B',5)
2325
+ assert_equal :float, oo.celltype('C',5)
2326
+ assert_equal :float, oo.celltype('D',5)
2327
+ assert_equal :float, oo.celltype('E',5)
2328
+ assert_equal 42, oo.cell('A',5)
2329
+ assert_equal 42, oo.cell('B',5)
2330
+ assert_equal 42, oo.cell('C',5)
2331
+ assert_equal 42, oo.cell('D',5)
2332
+ assert_equal 42, oo.cell('E',5)
2333
+ assert_equal :string, oo.celltype('A',6)
2334
+ assert_equal :string, oo.celltype('B',6)
2335
+ assert_equal :string, oo.celltype('C',6)
2336
+ assert_equal :string, oo.celltype('D',6)
2337
+ assert_equal :string, oo.celltype('E',6)
2338
+ assert_equal "ABC", oo.cell('A',6)
2339
+ assert_equal "ABC", oo.cell('B',6)
2340
+ assert_equal "ABC", oo.cell('C',6)
2341
+ assert_equal "ABC", oo.cell('D',6)
2342
+ assert_equal "ABC", oo.cell('E',6)
2343
+ end # Excel
2344
+ if EXCELX
2345
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
2346
+ oo.default_sheet = 'Sheet5'
2347
+ assert_equal :date, oo.celltype('A',4)
2348
+ assert_equal :date, oo.celltype('B',4)
2349
+ assert_equal :date, oo.celltype('C',4)
2350
+ assert_equal :date, oo.celltype('D',4)
2351
+ assert_equal :date, oo.celltype('E',4)
2352
+ assert_equal Date.new(2007,11,21), oo.cell('A',4)
2353
+ assert_equal Date.new(2007,11,21), oo.cell('B',4)
2354
+ assert_equal Date.new(2007,11,21), oo.cell('C',4)
2355
+ assert_equal Date.new(2007,11,21), oo.cell('D',4)
2356
+ assert_equal Date.new(2007,11,21), oo.cell('E',4)
2357
+ assert_equal :float, oo.celltype('A',5)
2358
+ assert_equal :float, oo.celltype('B',5)
2359
+ assert_equal :float, oo.celltype('C',5)
2360
+ assert_equal :float, oo.celltype('D',5)
2361
+ assert_equal :float, oo.celltype('E',5)
2362
+ assert_equal 42, oo.cell('A',5)
2363
+ assert_equal 42, oo.cell('B',5)
2364
+ assert_equal 42, oo.cell('C',5)
2365
+ assert_equal 42, oo.cell('D',5)
2366
+ assert_equal 42, oo.cell('E',5)
2367
+ assert_equal :string, oo.celltype('A',6)
2368
+ assert_equal :string, oo.celltype('B',6)
2369
+ assert_equal :string, oo.celltype('C',6)
2370
+ assert_equal :string, oo.celltype('D',6)
2371
+ assert_equal :string, oo.celltype('E',6)
2372
+ assert_equal "ABC", oo.cell('A',6)
2373
+ assert_equal "ABC", oo.cell('B',6)
2374
+ assert_equal "ABC", oo.cell('C',6)
2375
+ assert_equal "ABC", oo.cell('D',6)
2376
+ assert_equal "ABC", oo.cell('E',6)
2377
+ end # Excelx
2378
+ end
2379
+
2380
+ def test_multiple_sheets
2381
+ if OPENOFFICE
2382
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
2383
+ 2.times do
2384
+ oo.default_sheet = "Tabelle1"
2385
+ assert_equal 1, oo.cell(1,1)
2386
+ assert_equal 1, oo.cell(1,1,"Tabelle1")
2387
+ assert_equal "I am sheet 2", oo.cell('C',5,"Name of Sheet 2")
2388
+ sheetname = 'Sheet5'
2389
+ assert_equal :date, oo.celltype('A',4,sheetname)
2390
+ assert_equal :date, oo.celltype('B',4,sheetname)
2391
+ assert_equal :date, oo.celltype('C',4,sheetname)
2392
+ assert_equal :date, oo.celltype('D',4,sheetname)
2393
+ assert_equal :date, oo.celltype('E',4,sheetname)
2394
+ assert_equal Date.new(2007,11,21), oo.cell('A',4,sheetname)
2395
+ assert_equal Date.new(2007,11,21), oo.cell('B',4,sheetname)
2396
+ assert_equal Date.new(2007,11,21), oo.cell('C',4,sheetname)
2397
+ assert_equal Date.new(2007,11,21), oo.cell('D',4,sheetname)
2398
+ assert_equal Date.new(2007,11,21), oo.cell('E',4,sheetname)
2399
+ assert_equal :float, oo.celltype('A',5,sheetname)
2400
+ assert_equal :float, oo.celltype('B',5,sheetname)
2401
+ assert_equal :float, oo.celltype('C',5,sheetname)
2402
+ assert_equal :float, oo.celltype('D',5,sheetname)
2403
+ assert_equal :float, oo.celltype('E',5,sheetname)
2404
+ assert_equal 42, oo.cell('A',5,sheetname)
2405
+ assert_equal 42, oo.cell('B',5,sheetname)
2406
+ assert_equal 42, oo.cell('C',5,sheetname)
2407
+ assert_equal 42, oo.cell('D',5,sheetname)
2408
+ assert_equal 42, oo.cell('E',5,sheetname)
2409
+ assert_equal :string, oo.celltype('A',6,sheetname)
2410
+ assert_equal :string, oo.celltype('B',6,sheetname)
2411
+ assert_equal :string, oo.celltype('C',6,sheetname)
2412
+ assert_equal :string, oo.celltype('D',6,sheetname)
2413
+ assert_equal :string, oo.celltype('E',6,sheetname)
2414
+ assert_equal "ABC", oo.cell('A',6,sheetname)
2415
+ assert_equal "ABC", oo.cell('B',6,sheetname)
2416
+ assert_equal "ABC", oo.cell('C',6,sheetname)
2417
+ assert_equal "ABC", oo.cell('D',6,sheetname)
2418
+ assert_equal "ABC", oo.cell('E',6,sheetname)
2419
+ oo.reload
2420
+ end
2421
+ end # OPENOFFICE
2422
+
2423
+
2424
+ if EXCEL
2425
+ $debug = true
2426
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
2427
+ 2.times do
2428
+ oo.default_sheet = "Tabelle1"
2429
+ assert_equal 1, oo.cell(1,1)
2430
+ assert_equal 1, oo.cell(1,1,"Tabelle1")
2431
+ assert_equal "I am sheet 2", oo.cell('C',5,"Name of Sheet 2")
2432
+ sheetname = 'Sheet5'
2433
+ assert_equal :date, oo.celltype('A',4,sheetname)
2434
+ assert_equal :date, oo.celltype('B',4,sheetname)
2435
+ assert_equal :date, oo.celltype('C',4,sheetname)
2436
+ assert_equal :date, oo.celltype('D',4,sheetname)
2437
+ assert_equal :date, oo.celltype('E',4,sheetname)
2438
+ assert_equal Date.new(2007,11,21), oo.cell('A',4,sheetname)
2439
+ assert_equal Date.new(2007,11,21), oo.cell('B',4,sheetname)
2440
+ assert_equal Date.new(2007,11,21), oo.cell('C',4,sheetname)
2441
+ assert_equal Date.new(2007,11,21), oo.cell('D',4,sheetname)
2442
+ assert_equal Date.new(2007,11,21), oo.cell('E',4,sheetname)
2443
+ assert_equal :float, oo.celltype('A',5,sheetname)
2444
+ assert_equal :float, oo.celltype('B',5,sheetname)
2445
+ assert_equal :float, oo.celltype('C',5,sheetname)
2446
+ assert_equal :float, oo.celltype('D',5,sheetname)
2447
+ assert_equal :float, oo.celltype('E',5,sheetname)
2448
+ assert_equal 42, oo.cell('A',5,sheetname)
2449
+ assert_equal 42, oo.cell('B',5,sheetname)
2450
+ assert_equal 42, oo.cell('C',5,sheetname)
2451
+ assert_equal 42, oo.cell('D',5,sheetname)
2452
+ assert_equal 42, oo.cell('E',5,sheetname)
2453
+ assert_equal :string, oo.celltype('A',6,sheetname)
2454
+ assert_equal :string, oo.celltype('B',6,sheetname)
2455
+ assert_equal :string, oo.celltype('C',6,sheetname)
2456
+ assert_equal :string, oo.celltype('D',6,sheetname)
2457
+ assert_equal :string, oo.celltype('E',6,sheetname)
2458
+ assert_equal "ABC", oo.cell('A',6,sheetname)
2459
+ assert_equal "ABC", oo.cell('B',6,sheetname)
2460
+ assert_equal "ABC", oo.cell('C',6,sheetname)
2461
+ assert_equal "ABC", oo.cell('D',6,sheetname)
2462
+ assert_equal "ABC", oo.cell('E',6,sheetname)
2463
+ oo.reload
2464
+ end # times
2465
+ $debug = false
2466
+ end # EXCEL
2467
+ if GOOGLE
2468
+ oo = Google.new(key_of("numbers1"))
2469
+ 2.times do
2470
+ oo.default_sheet = "Tabelle1"
2471
+ assert_equal 1, oo.cell(1,1)
2472
+ assert_equal 1, oo.cell(1,1,"Tabelle1")
2473
+ assert_equal "I am sheet 2", oo.cell('C',5,"Name of Sheet 2")
2474
+ sheetname = 'Sheet5'
2475
+ assert_equal :date, oo.celltype('A',4,sheetname)
2476
+ assert_equal :date, oo.celltype('B',4,sheetname)
2477
+ assert_equal :date, oo.celltype('C',4,sheetname)
2478
+ assert_equal :date, oo.celltype('D',4,sheetname)
2479
+ assert_equal :date, oo.celltype('E',4,sheetname)
2480
+ assert_equal Date.new(2007,11,21), oo.cell('A',4,sheetname)
2481
+ assert_equal Date.new(2007,11,21), oo.cell('B',4,sheetname)
2482
+ assert_equal Date.new(2007,11,21), oo.cell('C',4,sheetname)
2483
+ assert_equal Date.new(2007,11,21), oo.cell('D',4,sheetname)
2484
+ assert_equal Date.new(2007,11,21), oo.cell('E',4,sheetname)
2485
+ assert_equal :float, oo.celltype('A',5,sheetname)
2486
+ assert_equal :float, oo.celltype('B',5,sheetname)
2487
+ assert_equal :float, oo.celltype('C',5,sheetname)
2488
+ assert_equal :float, oo.celltype('D',5,sheetname)
2489
+ assert_equal :float, oo.celltype('E',5,sheetname)
2490
+ assert_equal 42, oo.cell('A',5,sheetname)
2491
+ assert_equal 42, oo.cell('B',5,sheetname)
2492
+ assert_equal 42, oo.cell('C',5,sheetname)
2493
+ assert_equal 42, oo.cell('D',5,sheetname)
2494
+ assert_equal 42, oo.cell('E',5,sheetname)
2495
+ assert_equal :string, oo.celltype('A',6,sheetname)
2496
+ assert_equal :string, oo.celltype('B',6,sheetname)
2497
+ assert_equal :string, oo.celltype('C',6,sheetname)
2498
+ assert_equal :string, oo.celltype('D',6,sheetname)
2499
+ assert_equal :string, oo.celltype('E',6,sheetname)
2500
+ assert_equal "ABC", oo.cell('A',6,sheetname)
2501
+ assert_equal "ABC", oo.cell('B',6,sheetname)
2502
+ assert_equal "ABC", oo.cell('C',6,sheetname)
2503
+ assert_equal "ABC", oo.cell('D',6,sheetname)
2504
+ assert_equal "ABC", oo.cell('E',6,sheetname)
2505
+ oo.reload
2506
+ end
2507
+ end
2508
+ if EXCELX
2509
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
2510
+ 2.times do
2511
+ oo.default_sheet = "Tabelle1"
2512
+ assert_equal 1, oo.cell(1,1)
2513
+ assert_equal 1, oo.cell(1,1,"Tabelle1")
2514
+ assert_equal "I am sheet 2", oo.cell('C',5,"Name of Sheet 2")
2515
+ sheetname = 'Sheet5'
2516
+ assert_equal :date, oo.celltype('A',4,sheetname)
2517
+ assert_equal :date, oo.celltype('B',4,sheetname)
2518
+ assert_equal :date, oo.celltype('C',4,sheetname)
2519
+ assert_equal :date, oo.celltype('D',4,sheetname)
2520
+ assert_equal :date, oo.celltype('E',4,sheetname)
2521
+ assert_equal Date.new(2007,11,21), oo.cell('A',4,sheetname)
2522
+ assert_equal Date.new(2007,11,21), oo.cell('B',4,sheetname)
2523
+ assert_equal Date.new(2007,11,21), oo.cell('C',4,sheetname)
2524
+ assert_equal Date.new(2007,11,21), oo.cell('D',4,sheetname)
2525
+ assert_equal Date.new(2007,11,21), oo.cell('E',4,sheetname)
2526
+ assert_equal :float, oo.celltype('A',5,sheetname)
2527
+ assert_equal :float, oo.celltype('B',5,sheetname)
2528
+ assert_equal :float, oo.celltype('C',5,sheetname)
2529
+ assert_equal :float, oo.celltype('D',5,sheetname)
2530
+ assert_equal :float, oo.celltype('E',5,sheetname)
2531
+ assert_equal 42, oo.cell('A',5,sheetname)
2532
+ assert_equal 42, oo.cell('B',5,sheetname)
2533
+ assert_equal 42, oo.cell('C',5,sheetname)
2534
+ assert_equal 42, oo.cell('D',5,sheetname)
2535
+ assert_equal 42, oo.cell('E',5,sheetname)
2536
+ assert_equal :string, oo.celltype('A',6,sheetname)
2537
+ assert_equal :string, oo.celltype('B',6,sheetname)
2538
+ assert_equal :string, oo.celltype('C',6,sheetname)
2539
+ assert_equal :string, oo.celltype('D',6,sheetname)
2540
+ assert_equal :string, oo.celltype('E',6,sheetname)
2541
+ assert_equal "ABC", oo.cell('A',6,sheetname)
2542
+ assert_equal "ABC", oo.cell('B',6,sheetname)
2543
+ assert_equal "ABC", oo.cell('C',6,sheetname)
2544
+ assert_equal "ABC", oo.cell('D',6,sheetname)
2545
+ assert_equal "ABC", oo.cell('E',6,sheetname)
2546
+ oo.reload
2547
+ end
2548
+ end
2549
+ end
2550
+
2551
+
2552
+ def test_bug_empty_sheet_openoffice
2553
+ if OPENOFFICE
2554
+ oo = Openoffice.new(File.join(TESTDIR,"formula.ods"))
2555
+ oo.default_sheet = 'Sheet3' # is an empty sheet
2556
+ assert_nothing_raised(NoMethodError) {
2557
+ oo.to_csv(File.join("/","tmp","emptysheet.csv"))
2558
+ }
2559
+ assert_equal "", `cat /tmp/emptysheet.csv`
2560
+ end
2561
+ end
2562
+
2563
+ def test_bug_empty_sheet_excelx
2564
+ if EXCELX
2565
+ oo = Excelx.new(File.join(TESTDIR,"formula.xlsx"))
2566
+ oo.default_sheet = 'Sheet3' # is an empty sheet
2567
+ assert_nothing_raised(NoMethodError) {
2568
+ oo.to_csv(File.join("/","tmp","emptysheet.csv"))
2569
+ }
2570
+ assert_equal "", `cat /tmp/emptysheet.csv`
2571
+ end
2572
+ end
2573
+
2574
+ def test_find_by_row_huge_document_openoffice
2575
+ if LONG_RUN
2576
+ if OPENOFFICE
2577
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2578
+ oo = Openoffice.new(File.join(TESTDIR,"Bibelbund.ods"))
2579
+ oo.default_sheet = oo.sheets.first
2580
+ rec = oo.find 20
2581
+ assert rec
2582
+ # assert_equal "Brief aus dem Sekretariat", rec[0]
2583
+ #p rec
2584
+ assert_equal "Brief aus dem Sekretariat", rec[0]['TITEL']
2585
+
2586
+ rec = oo.find 22
2587
+ assert rec
2588
+ # assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]
2589
+ assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]['TITEL']
2590
+ end
2591
+ end
2592
+ end
2593
+ end
2594
+
2595
+ def test_find_by_row_huge_document_excel
2596
+ if LONG_RUN
2597
+ if EXCEL
2598
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2599
+ oo = Excel.new(File.join(TESTDIR,"Bibelbund.xls"))
2600
+ oo.default_sheet = oo.sheets.first
2601
+ rec = oo.find 20
2602
+ assert rec
2603
+ #jetzt als Hash assert_equal "Brief aus dem Sekretariat", rec[0]
2604
+ assert_equal "Brief aus dem Sekretariat", rec[0]['TITEL']
2605
+
2606
+ rec = oo.find 22
2607
+ assert rec
2608
+ # assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]
2609
+ assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]['TITEL']
2610
+ end
2611
+ end
2612
+ end
2613
+ end
2614
+
2615
+ def test_find_by_row_huge_document_excelx
2616
+ if LONG_RUN
2617
+ if EXCEL
2618
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2619
+ oo = Excelx.new(File.join(TESTDIR,"Bibelbund.xlsx"))
2620
+ oo.default_sheet = oo.sheets.first
2621
+ rec = oo.find 20
2622
+ assert rec
2623
+ assert_equal "Brief aus dem Sekretariat", rec[0]['TITEL']
2624
+
2625
+ rec = oo.find 22
2626
+ assert rec
2627
+ assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]['TITEL']
2628
+ end
2629
+ end
2630
+ end
2631
+ end
2632
+
2633
+ def test_find_by_row_openoffice
2634
+ if OPENOFFICE
2635
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
2636
+ oo.default_sheet = oo.sheets.first
2637
+ oo.header_line = nil
2638
+ rec = oo.find 16
2639
+ assert rec
2640
+ assert_nil oo.header_line
2641
+ # keine Headerlines in diesem Beispiel definiert
2642
+ assert_equal "einundvierzig", rec[0]
2643
+ #assert_equal false, rec
2644
+
2645
+ rec = oo.find 15
2646
+ assert rec
2647
+ assert_equal 41,rec[0]
2648
+ end
2649
+ end
2650
+
2651
+ def test_find_by_row_excel
2652
+ if EXCEL
2653
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
2654
+ oo.default_sheet = oo.sheets.first
2655
+ oo.header_line = nil
2656
+ rec = oo.find 16
2657
+ assert rec
2658
+ # keine Headerlines in diesem Beispiel definiert
2659
+ assert_equal "einundvierzig", rec[0]
2660
+
2661
+ rec = oo.find 15
2662
+ assert rec
2663
+ assert_equal 41,rec[0]
2664
+ end
2665
+ end
2666
+
2667
+ def test_find_by_row_excelx
2668
+ if EXCELX
2669
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
2670
+ oo.default_sheet = oo.sheets.first
2671
+ oo.header_line = nil
2672
+ rec = oo.find 16
2673
+ assert rec
2674
+ # keine Headerlines in diesem Beispiel definiert
2675
+ assert_equal "einundvierzig", rec[0]
2676
+
2677
+ rec = oo.find 15
2678
+ assert rec
2679
+ assert_equal 41,rec[0]
2680
+ end
2681
+ end
2682
+
2683
+ def test_find_by_row_google
2684
+ if GOOGLE
2685
+ oo = Google.new(key_of("numbers1"))
2686
+ oo.default_sheet = oo.sheets.first
2687
+ oo.header_line = nil
2688
+ rec = oo.find 16
2689
+ assert rec
2690
+ # keine Headerlines in diesem Beispiel definiert
2691
+ assert_equal "einundvierzig", rec[0]
2692
+
2693
+ rec = oo.find 15
2694
+ assert rec
2695
+ assert_equal 41,rec[0]
2696
+ end
2697
+ end
2698
+
2699
+ def test_find_by_row_huge_document_google
2700
+ if LONG_RUN
2701
+ if GOOGLE
2702
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2703
+ oo = Google.new(key_of("Bibelbund"))
2704
+ oo.default_sheet = oo.sheets.first
2705
+ rec = oo.find 20
2706
+ assert rec
2707
+ assert_equal "Brief aus dem Sekretariat", rec[0]
2708
+
2709
+ rec = oo.find 22
2710
+ assert rec
2711
+ assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]
2712
+ end
2713
+ end
2714
+ end
2715
+ end
2716
+
2717
+ def test_find_by_conditions_openoffice
2718
+ if LONG_RUN
2719
+ if OPENOFFICE
2720
+ assert_nothing_raised(Timeout::Error) {
2721
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2722
+ oo = Openoffice.new(File.join(TESTDIR,"Bibelbund.ods"))
2723
+ oo.default_sheet = oo.sheets.first
2724
+ #-----------------------------------------------------------------
2725
+ zeilen = oo.find(:all, :conditions => {
2726
+ 'TITEL' => 'Brief aus dem Sekretariat'
2727
+ }
2728
+ )
2729
+ assert_equal 2, zeilen.size
2730
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
2731
+ "INTERNET"=>nil,
2732
+ "SEITE"=>316.0,
2733
+ "KENNUNG"=>"Aus dem Bibelbund",
2734
+ "OBJEKT"=>"Bibel+Gem",
2735
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
2736
+ "NUMMER"=>"1982-3",
2737
+ "TITEL"=>"Brief aus dem Sekretariat"},
2738
+ {"VERFASSER"=>"Almassy, Annelene von",
2739
+ "INTERNET"=>nil,
2740
+ "SEITE"=>222.0,
2741
+ "KENNUNG"=>"Aus dem Bibelbund",
2742
+ "OBJEKT"=>"Bibel+Gem",
2743
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
2744
+ "NUMMER"=>"1983-2",
2745
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
2746
+
2747
+ #----------------------------------------------------------
2748
+ zeilen = oo.find(:all,
2749
+ :conditions => { 'VERFASSER' => 'Almassy, Annelene von' }
2750
+ )
2751
+ assert_equal 13, zeilen.size
2752
+ #----------------------------------------------------------
2753
+ zeilen = oo.find(:all, :conditions => {
2754
+ 'TITEL' => 'Brief aus dem Sekretariat',
2755
+ 'VERFASSER' => 'Almassy, Annelene von',
2756
+ }
2757
+ )
2758
+ assert_equal 2, zeilen.size
2759
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
2760
+ "INTERNET"=>nil,
2761
+ "SEITE"=>316.0,
2762
+ "KENNUNG"=>"Aus dem Bibelbund",
2763
+ "OBJEKT"=>"Bibel+Gem",
2764
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
2765
+ "NUMMER"=>"1982-3",
2766
+ "TITEL"=>"Brief aus dem Sekretariat"},
2767
+ {"VERFASSER"=>"Almassy, Annelene von",
2768
+ "INTERNET"=>nil,
2769
+ "SEITE"=>222.0,
2770
+ "KENNUNG"=>"Aus dem Bibelbund",
2771
+ "OBJEKT"=>"Bibel+Gem",
2772
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
2773
+ "NUMMER"=>"1983-2",
2774
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
2775
+
2776
+ # Result as an array
2777
+ zeilen = oo.find(:all,
2778
+ :conditions => {
2779
+ 'TITEL' => 'Brief aus dem Sekretariat',
2780
+ 'VERFASSER' => 'Almassy, Annelene von',
2781
+ }, :array => true)
2782
+ assert_equal 2, zeilen.size
2783
+ assert_equal [
2784
+ [
2785
+ "Brief aus dem Sekretariat",
2786
+ "Almassy, Annelene von",
2787
+ "Bibel+Gem",
2788
+ "1982-3",
2789
+ 316.0,
2790
+ nil,
2791
+ "#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
2792
+ "Aus dem Bibelbund",
2793
+ ],
2794
+ [
2795
+ "Brief aus dem Sekretariat",
2796
+ "Almassy, Annelene von",
2797
+ "Bibel+Gem",
2798
+ "1983-2",
2799
+ 222.0,
2800
+ nil,
2801
+ "#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
2802
+ "Aus dem Bibelbund",
2803
+ ]] , zeilen
2804
+ end # Timeout
2805
+ } # nothing_raised
2806
+ end
2807
+ end
2808
+ end
2809
+
2810
+ def test_find_by_conditions_excel
2811
+ if LONG_RUN
2812
+ if EXCEL
2813
+ assert_nothing_raised(Timeout::Error) {
2814
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2815
+ oo = Excel.new(File.join(TESTDIR,"Bibelbund.xls"))
2816
+ oo.default_sheet = oo.sheets.first
2817
+ #-----------------------------------------------------------------
2818
+ zeilen = oo.find(:all, :conditions => {
2819
+ 'TITEL' => 'Brief aus dem Sekretariat'
2820
+ }
2821
+ )
2822
+ assert_equal 2, zeilen.size
2823
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
2824
+ "INTERNET"=>nil,
2825
+ "SEITE"=>316.0,
2826
+ "KENNUNG"=>"Aus dem Bibelbund",
2827
+ "OBJEKT"=>"Bibel+Gem",
2828
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
2829
+ "NUMMER"=>"1982-3",
2830
+ "TITEL"=>"Brief aus dem Sekretariat"},
2831
+ {"VERFASSER"=>"Almassy, Annelene von",
2832
+ "INTERNET"=>nil,
2833
+ "SEITE"=>222.0,
2834
+ "KENNUNG"=>"Aus dem Bibelbund",
2835
+ "OBJEKT"=>"Bibel+Gem",
2836
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
2837
+ "NUMMER"=>"1983-2",
2838
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
2839
+
2840
+ #----------------------------------------------------------
2841
+ zeilen = oo.find(:all,
2842
+ :conditions => { 'VERFASSER' => 'Almassy, Annelene von' }
2843
+ )
2844
+ assert_equal 13, zeilen.size
2845
+ #----------------------------------------------------------
2846
+ zeilen = oo.find(:all, :conditions => {
2847
+ 'TITEL' => 'Brief aus dem Sekretariat',
2848
+ 'VERFASSER' => 'Almassy, Annelene von',
2849
+ }
2850
+ )
2851
+ assert_equal 2, zeilen.size
2852
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
2853
+ "INTERNET"=>nil,
2854
+ "SEITE"=>316.0,
2855
+ "KENNUNG"=>"Aus dem Bibelbund",
2856
+ "OBJEKT"=>"Bibel+Gem",
2857
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
2858
+ "NUMMER"=>"1982-3",
2859
+ "TITEL"=>"Brief aus dem Sekretariat"},
2860
+ {"VERFASSER"=>"Almassy, Annelene von",
2861
+ "INTERNET"=>nil,
2862
+ "SEITE"=>222.0,
2863
+ "KENNUNG"=>"Aus dem Bibelbund",
2864
+ "OBJEKT"=>"Bibel+Gem",
2865
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
2866
+ "NUMMER"=>"1983-2",
2867
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
2868
+ end # Timeout
2869
+ } # nothing_raised
2870
+ end
2871
+ end
2872
+ end
2873
+
2874
+ #TODO: temporaerer Test
2875
+ def test_seiten_als_date
2876
+ oo = Excelx.new(File.join(TESTDIR,"Bibelbund.xlsx"))
2877
+ oo.default_sheet = oo.sheets.first
2878
+ assert_equal 'Bericht aus dem Sekretariat', oo.cell(13,1)
2879
+ assert_equal '1981-4', oo.cell(13,'D')
2880
+ assert_equal [:numeric_or_formula,"General"], oo.excelx_type(13,'E')
2881
+ assert_equal '428', oo.excelx_value(13,'E')
2882
+ assert_equal 428.0, oo.cell(13,'E')
2883
+ end
2884
+
2885
+ def test_find_by_conditions_excelx
2886
+ if LONG_RUN
2887
+ if EXCELX
2888
+ assert_nothing_raised(Timeout::Error) {
2889
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2890
+ oo = Excelx.new(File.join(TESTDIR,"Bibelbund.xlsx"))
2891
+ oo.default_sheet = oo.sheets.first
2892
+ #-----------------------------------------------------------------
2893
+ zeilen = oo.find(:all, :conditions => {
2894
+ 'TITEL' => 'Brief aus dem Sekretariat'
2895
+ }
2896
+ )
2897
+ assert_equal 2, zeilen.size
2898
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
2899
+ "INTERNET"=>nil,
2900
+ "SEITE"=>316.0,
2901
+ "KENNUNG"=>"Aus dem Bibelbund",
2902
+ "OBJEKT"=>"Bibel+Gem",
2903
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
2904
+ "NUMMER"=>"1982-3",
2905
+ "TITEL"=>"Brief aus dem Sekretariat"},
2906
+ {"VERFASSER"=>"Almassy, Annelene von",
2907
+ "INTERNET"=>nil,
2908
+ "SEITE"=>222.0,
2909
+ "KENNUNG"=>"Aus dem Bibelbund",
2910
+ "OBJEKT"=>"Bibel+Gem",
2911
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
2912
+ "NUMMER"=>"1983-2",
2913
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
2914
+
2915
+ #----------------------------------------------------------
2916
+ zeilen = oo.find(:all,
2917
+ :conditions => { 'VERFASSER' => 'Almassy, Annelene von' }
2918
+ )
2919
+ assert_equal 13, zeilen.size
2920
+ #----------------------------------------------------------
2921
+ zeilen = oo.find(:all, :conditions => {
2922
+ 'TITEL' => 'Brief aus dem Sekretariat',
2923
+ 'VERFASSER' => 'Almassy, Annelene von',
2924
+ }
2925
+ )
2926
+ assert_equal 2, zeilen.size
2927
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
2928
+ "INTERNET"=>nil,
2929
+ "SEITE"=>316.0,
2930
+ "KENNUNG"=>"Aus dem Bibelbund",
2931
+ "OBJEKT"=>"Bibel+Gem",
2932
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
2933
+ "NUMMER"=>"1982-3",
2934
+ "TITEL"=>"Brief aus dem Sekretariat"},
2935
+ {"VERFASSER"=>"Almassy, Annelene von",
2936
+ "INTERNET"=>nil,
2937
+ "SEITE"=>222.0,
2938
+ "KENNUNG"=>"Aus dem Bibelbund",
2939
+ "OBJEKT"=>"Bibel+Gem",
2940
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
2941
+ "NUMMER"=>"1983-2",
2942
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
2943
+ end # Timeout
2944
+ } # nothing_raised
2945
+ end
2946
+ end
2947
+ end
2948
+
2949
+ def test_find_by_conditions_google
2950
+ if LONG_RUN
2951
+ if GOOGLE
2952
+ assert_nothing_raised(Timeout::Error) {
2953
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2954
+ oo = Google.new(key_of("Bibelbund"))
2955
+ oo.default_sheet = oo.sheets.first
2956
+ #-----------------------------------------------------------------
2957
+ zeilen = oo.find(:all, :conditions => {
2958
+ 'TITEL' => 'Brief aus dem Sekretariat'
2959
+ }
2960
+ )
2961
+ assert_equal 2, zeilen.size
2962
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
2963
+ "INTERNET"=>nil,
2964
+ "SEITE"=>316.0,
2965
+ "KENNUNG"=>"Aus dem Bibelbund",
2966
+ "OBJEKT"=>"Bibel+Gem",
2967
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
2968
+ "NUMMER"=>"1982-3",
2969
+ "TITEL"=>"Brief aus dem Sekretariat"},
2970
+ {"VERFASSER"=>"Almassy, Annelene von",
2971
+ "INTERNET"=>nil,
2972
+ "SEITE"=>222.0,
2973
+ "KENNUNG"=>"Aus dem Bibelbund",
2974
+ "OBJEKT"=>"Bibel+Gem",
2975
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
2976
+ "NUMMER"=>"1983-2",
2977
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
2978
+
2979
+ #----------------------------------------------------------
2980
+ zeilen = oo.find(:all,
2981
+ :conditions => { 'VERFASSER' => 'Almassy, Annelene von' }
2982
+ )
2983
+ assert_equal 13, zeilen.size
2984
+ #----------------------------------------------------------
2985
+ zeilen = oo.find(:all, :conditions => {
2986
+ 'TITEL' => 'Brief aus dem Sekretariat',
2987
+ 'VERFASSER' => 'Almassy, Annelene von',
2988
+ }
2989
+ )
2990
+ assert_equal 2, zeilen.size
2991
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
2992
+ "INTERNET"=>nil,
2993
+ "SEITE"=>316.0,
2994
+ "KENNUNG"=>"Aus dem Bibelbund",
2995
+ "OBJEKT"=>"Bibel+Gem",
2996
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
2997
+ "NUMMER"=>"1982-3",
2998
+ "TITEL"=>"Brief aus dem Sekretariat"},
2999
+ {"VERFASSER"=>"Almassy, Annelene von",
3000
+ "INTERNET"=>nil,
3001
+ "SEITE"=>222.0,
3002
+ "KENNUNG"=>"Aus dem Bibelbund",
3003
+ "OBJEKT"=>"Bibel+Gem",
3004
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
3005
+ "NUMMER"=>"1983-2",
3006
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
3007
+
3008
+ # Result as an array
3009
+ zeilen = oo.find(:all,
3010
+ :conditions => {
3011
+ 'TITEL' => 'Brief aus dem Sekretariat',
3012
+ 'VERFASSER' => 'Almassy, Annelene von',
3013
+ }, :array => true)
3014
+ assert_equal 2, zeilen.size
3015
+ assert_equal [
3016
+ [
3017
+ "Brief aus dem Sekretariat",
3018
+ "Almassy, Annelene von",
3019
+ "Bibel+Gem",
3020
+ "1982-3",
3021
+ 316.0,
3022
+ nil,
3023
+ "#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
3024
+ "Aus dem Bibelbund",
3025
+ ],
3026
+ [
3027
+ "Brief aus dem Sekretariat",
3028
+ "Almassy, Annelene von",
3029
+ "Bibel+Gem",
3030
+ "1983-2",
3031
+ 222.0,
3032
+ nil,
3033
+ "#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
3034
+ "Aus dem Bibelbund",
3035
+ ]] , zeilen
3036
+ end # Timeout
3037
+ } # nothing_raised
3038
+ end
3039
+ end
3040
+ end
3041
+
3042
+ def test_column_openoffice
3043
+ after Date.new(2008,9,30) do
3044
+
3045
+ 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)]
3046
+ if OPENOFFICE
3047
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
3048
+ oo = Openoffice.new(File.join(TESTDIR,'numbers1.ods'))
3049
+ oo.default_sheet = oo.sheets.first
3050
+ assert_equal expected, oo.column(1)
3051
+ assert_equal expected, oo.column('a')
3052
+ end
3053
+ end
3054
+ end
3055
+ end
3056
+
3057
+ def test_column_excel
3058
+ 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)]
3059
+ if EXCEL
3060
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
3061
+ oo = Excel.new(File.join(TESTDIR,'numbers1.xls'))
3062
+ oo.default_sheet = oo.sheets.first
3063
+ assert_equal expected, oo.column(1)
3064
+ assert_equal expected, oo.column('a')
3065
+ end
3066
+ end
3067
+ end
3068
+
3069
+ def test_column_excelx
3070
+ 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)]
3071
+ if EXCELX
3072
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
3073
+ oo = Excelx.new(File.join(TESTDIR,'numbers1.xlsx'))
3074
+ oo.default_sheet = oo.sheets.first
3075
+ assert_equal expected, oo.column(1)
3076
+ assert_equal expected, oo.column('a')
3077
+ end
3078
+ end
3079
+ end
3080
+
3081
+ def test_column_google
3082
+ 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)]
3083
+ if GOOGLE
3084
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
3085
+ oo = Google.new(key_of('numbers1'))
3086
+ oo.default_sheet = oo.sheets.first
3087
+ assert_equal expected, oo.column(1)
3088
+ assert_equal expected, oo.column('a')
3089
+ end
3090
+ end
3091
+ end
3092
+
3093
+ def test_column_huge_document_openoffice
3094
+ if LONG_RUN
3095
+ if OPENOFFICE
3096
+ assert_nothing_raised(Timeout::Error) {
3097
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
3098
+ oo = Openoffice.new(File.join(TESTDIR,'Bibelbund.ods'))
3099
+ oo.default_sheet = oo.sheets.first
3100
+ assert_equal 3735, oo.column('a').size
3101
+ #assert_equal 499, oo.column('a').size
3102
+ end
3103
+ }
3104
+ end
3105
+ end
3106
+ end
3107
+
3108
+ def test_column_huge_document_excel
3109
+ if LONG_RUN
3110
+ if EXCEL
3111
+ assert_nothing_raised(Timeout::Error) {
3112
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
3113
+ oo = Excel.new(File.join(TESTDIR,'Bibelbund.xls'))
3114
+ oo.default_sheet = oo.sheets.first
3115
+ assert_equal 3735, oo.column('a').size
3116
+ #assert_equal 499, oo.column('a').size
3117
+ end
3118
+ }
3119
+ end
3120
+ end
3121
+ end
3122
+
3123
+ def test_column_huge_document_excelx
3124
+ if LONG_RUN
3125
+ if EXCELX
3126
+ assert_nothing_raised(Timeout::Error) {
3127
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
3128
+ oo = Excelx.new(File.join(TESTDIR,'Bibelbund.xlsx'))
3129
+ oo.default_sheet = oo.sheets.first
3130
+ assert_equal 3735, oo.column('a').size
3131
+ #assert_equal 499, oo.column('a').size
3132
+ end
3133
+ }
3134
+ end
3135
+ end
3136
+ end
3137
+
3138
+ def test_column_huge_document_google
3139
+ if LONG_RUN
3140
+ if GOOGLE
3141
+ assert_nothing_raised(Timeout::Error) {
3142
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
3143
+ #puts Time.now.to_s + "column Openoffice gestartet"
3144
+ oo = Google.new(key_of('Bibelbund'))
3145
+ oo.default_sheet = oo.sheets.first
3146
+ #assert_equal 3735, oo.column('a').size
3147
+ assert_equal 499, oo.column('a').size
3148
+ #puts Time.now.to_s + "column Openoffice beendet"
3149
+ end
3150
+ }
3151
+ end
3152
+ end
3153
+ end
3154
+
3155
+ def test_simple_spreadsheet_find_by_condition_openoffice
3156
+ oo = Openoffice.new(File.join(TESTDIR,"simple_spreadsheet.ods"))
3157
+ oo.default_sheet = oo.sheets.first
3158
+ oo.header_line = 3
3159
+ erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'})
3160
+ assert_equal Date.new(2007,05,07), erg[1]['Date']
3161
+ assert_equal 10.75 , erg[1]['Start time']
3162
+ assert_equal 12.50 , erg[1]['End time']
3163
+ assert_equal 0 , erg[1]['Pause']
3164
+ assert_equal 1.75 , erg[1]['Sum']
3165
+ assert_equal "Task 1" , erg[1]['Comment']
3166
+ end
3167
+
3168
+ def test_simple_spreadsheet_find_by_condition_excel
3169
+ if EXCEL
3170
+ $debug = true
3171
+ oo = Excel.new(File.join(TESTDIR,"simple_spreadsheet.xls"))
3172
+ oo.default_sheet = oo.sheets.first
3173
+ oo.header_line = 3
3174
+ erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'})
3175
+ assert_equal Date.new(2007,05,07), erg[1]['Date']
3176
+ assert_equal 10.75 , erg[1]['Start time']
3177
+ assert_equal 12.50 , erg[1]['End time']
3178
+ assert_equal 0 , erg[1]['Pause']
3179
+ #cannot be tested because excel cannot return the result of formulas:
3180
+ # assert_equal 1.75 , erg[1]['Sum']
3181
+ assert_equal "Task 1" , erg[1]['Comment']
3182
+ $debug = false
3183
+ end
3184
+ end
3185
+
3186
+ def test_simple_spreadsheet_find_by_condition_excelx
3187
+ if EXCELX
3188
+ # die dezimalen Seiten bekomme ich seltsamerweise als Date
3189
+ oo = Excelx.new(File.join(TESTDIR,"simple_spreadsheet.xlsx"))
3190
+ oo.default_sheet = oo.sheets.first
3191
+ oo.header_line = 3
3192
+ erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'})
3193
+ #expected = { "Start time"=>10.75,
3194
+ # "Pause"=>0.0,
3195
+ # "Sum" => 1.75,
3196
+ # "End time" => 12.5,
3197
+ # "Pause" => 0.0,
3198
+ # "Sum"=> 1.75,
3199
+ # "Comment" => "Task 1",
3200
+ # "Date" => Date.new(2007,5,7)}
3201
+ assert_equal Date.new(2007,5,7), erg[1]['Date']
3202
+ assert_equal 10.75,erg[1]['Start time']
3203
+ assert_equal 12.5, erg[1]['End time']
3204
+ assert_equal 0.0, erg[1]['Pause']
3205
+ assert_equal 1.75, erg[1]['Sum']
3206
+ assert_equal 'Task 1', erg[1]['Comment']
3207
+
3208
+ #assert_equal expected, erg[1], erg[1]
3209
+ # hier bekomme ich den celltype :time zurueck
3210
+ # jetzt ist alles OK
3211
+ assert_equal Date.new(2007,05,07), erg[1]['Date']
3212
+ assert_equal 10.75 , erg[1]['Start time']
3213
+ assert_equal 12.50 , erg[1]['End time']
3214
+ assert_equal 0 , erg[1]['Pause']
3215
+ assert_equal 1.75 , erg[1]['Sum']
3216
+ assert_equal "Task 1" , erg[1]['Comment']
3217
+ end
3218
+ end
3219
+
3220
+ def test_simple_spreadsheet_find_by_condition_google
3221
+ if GOOGLE
3222
+ oo = Google.new(key_of("simple_spreadsheet"))
3223
+ oo.default_sheet = oo.sheets.first
3224
+ oo.header_line = 3
3225
+ erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'})
3226
+ assert_equal Date.new(2007,05,07), erg[1]['Date']
3227
+ assert_equal 10.75 , erg[1]['Start time']
3228
+ assert_equal 12.50 , erg[1]['End time']
3229
+ assert_equal 0 , erg[1]['Pause']
3230
+ assert_kind_of Float, erg[1]['Sum']
3231
+ assert_equal 1.75 , erg[1]['Sum']
3232
+ assert_equal "Task 1" , erg[1]['Comment']
3233
+ end
3234
+ end
3235
+
3236
+ def DONT_test_false_encoding
3237
+ ex = Excel.new(File.join(TESTDIR,'false_encoding.xls'))
3238
+ ex.default_sheet = ex.sheets.first
3239
+ assert_equal "Sheet1", ex.sheets.first
3240
+ ex.first_row.upto(ex.last_row) do |row|
3241
+ ex.first_column.upto(ex.last_column) do |col|
3242
+ content = ex.cell(row,col)
3243
+ puts "#{row}/#{col}"
3244
+ #puts content if ! ex.empty?(row,col) or ex.formula?(row,col)
3245
+ if ex.formula?(row,col)
3246
+ #! ex.empty?(row,col)
3247
+ puts content
3248
+ end
3249
+ end
3250
+ end
3251
+ end
3252
+
3253
+ def test_bug_false_borders_with_formulas
3254
+ if EXCEL
3255
+ after Date.new(2008,9,15) do
3256
+ ex = Excel.new(File.join(TESTDIR,'false_encoding.xls'))
3257
+ ex.default_sheet = ex.sheets.first
3258
+ #assert_equal 1, ex.first_row
3259
+ =begin
3260
+ korrigiert auf Zeile 2. Zeile 1 enthaelt nur Formeln, die in parseexcel nicht
3261
+ ausgewertet werden koennen. D. h. der Nutzer hat keinen Vorteil davon, wenn
3262
+ er von Zeile 1 ab iterieren kann, da er auf die Formeln sowieso nicht zugreifen
3263
+ kann. Ideal waere aber noch eine Loesung, die auch diese Zeilen bei Excel
3264
+ als nichtleere Zeile liefert.
3265
+ TODO:
3266
+ =end
3267
+ assert_equal 2, ex.first_row
3268
+ assert_equal 3, ex.last_row
3269
+ assert_equal 1, ex.first_column
3270
+ assert_equal 4, ex.last_column
3271
+ end
3272
+ end
3273
+ end
3274
+
3275
+ def test_fe
3276
+ ex = Excel.new(File.join(TESTDIR,'false_encoding.xls'))
3277
+ ex.default_sheet = ex.sheets.first
3278
+ #DOES NOT WORK IN EXCEL FILES: assert_equal Date.new(2007,11,1), ex.cell('a',1)
3279
+ #DOES NOT WORK IN EXCEL FILES: assert_equal true, ex.formula?('a',1)
3280
+ #DOES NOT WORK IN EXCEL FILES: assert_equal '=TODAY()', ex.formula('a',1)
3281
+
3282
+ #DOES NOT WORK IN EXCEL FILES: assert_equal Date.new(2008,2,9), ex.cell('B',1)
3283
+ #DOES NOT WORK IN EXCEL FILES: assert_equal true, ex.formula?('B',1)
3284
+ #DOES NOT WORK IN EXCEL FILES: assert_equal "=A1+100", ex.formula('B',1)
3285
+
3286
+ #DOES NOT WORK IN EXCEL FILES: assert_equal Date.new(2008,2,9), ex.cell('C',1)
3287
+ #DOES NOT WORK IN EXCEL FILES: assert_equal true, ex.formula?('C',1)
3288
+ #DOES NOT WORK IN EXCEL FILES: assert_equal "=C1", ex.formula('C',1)
3289
+
3290
+ assert_equal 'H1', ex.cell('A',2)
3291
+ assert_equal 'H2', ex.cell('B',2)
3292
+ assert_equal 'H3', ex.cell('C',2)
3293
+ assert_equal 'H4', ex.cell('D',2)
3294
+ assert_equal 'R1', ex.cell('A',3)
3295
+ assert_equal 'R2', ex.cell('B',3)
3296
+ assert_equal 'R3', ex.cell('C',3)
3297
+ assert_equal 'R4', ex.cell('D',3)
3298
+ end
3299
+
3300
+ def test_excel_does_not_support_formulas
3301
+ if EXCEL
3302
+ ex = Excel.new(File.join(TESTDIR,'false_encoding.xls'))
3303
+ ex.default_sheet = ex.sheets.first
3304
+ assert_raise(RuntimeError) {
3305
+ void = ex.formula('a',1)
3306
+ }
3307
+ assert_raise(RuntimeError) {
3308
+ void = ex.formula?('a',1)
3309
+ }
3310
+ assert_raise(RuntimeError) {
3311
+ void = ex.formulas(ex.sheets.first)
3312
+ }
3313
+ end
3314
+ end
3315
+
3316
+ def test_info
3317
+ expected_templ = "File: numbers1%s\n"+
3318
+ "Number of sheets: 5\n"+
3319
+ "Sheets: Tabelle1, Name of Sheet 2, Sheet3, Sheet4, Sheet5\n"+
3320
+ "Sheet 1:\n"+
3321
+ " First row: 1\n"+
3322
+ " Last row: 18\n"+
3323
+ " First column: A\n"+
3324
+ " Last column: G\n"+
3325
+ "Sheet 2:\n"+
3326
+ " First row: 5\n"+
3327
+ " Last row: 14\n"+
3328
+ " First column: B\n"+
3329
+ " Last column: E\n"+
3330
+ "Sheet 3:\n"+
3331
+ " First row: 1\n"+
3332
+ " Last row: 1\n"+
3333
+ " First column: A\n"+
3334
+ " Last column: BA\n"+
3335
+ "Sheet 4:\n"+
3336
+ " First row: 1\n"+
3337
+ " Last row: 1\n"+
3338
+ " First column: A\n"+
3339
+ " Last column: E\n"+
3340
+ "Sheet 5:\n"+
3341
+ " First row: 1\n"+
3342
+ " Last row: 6\n"+
3343
+ " First column: A\n"+
3344
+ " Last column: E"
3345
+ if OPENOFFICE
3346
+ ext = ".ods"
3347
+ expected = sprintf(expected_templ,ext)
3348
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
3349
+ assert_equal expected, oo.info
3350
+ end
3351
+ if EXCEL
3352
+ ext = ".xls"
3353
+ expected = sprintf(expected_templ,ext)
3354
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
3355
+ assert_equal expected, oo.info
3356
+ end
3357
+ if EXCELX
3358
+ ext = ".xlsx"
3359
+ expected = sprintf(expected_templ,ext)
3360
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
3361
+ assert_equal expected, oo.info
3362
+ end
3363
+ if GOOGLE
3364
+ ext = ""
3365
+ expected = sprintf(expected_templ,ext)
3366
+ oo = Google.new(key_of("numbers1"))
3367
+ #$log.debug(expected)
3368
+ assert_equal expected.gsub(/numbers1/,key_of("numbers1")), oo.info
3369
+ end
3370
+ end
3371
+
3372
+ def test_bug_excel_numbers1_sheet5_last_row
3373
+ if EXCEL
3374
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
3375
+ oo.default_sheet = "Tabelle1"
3376
+ assert_equal 1, oo.first_row
3377
+ assert_equal 18, oo.last_row
3378
+ assert_equal Openoffice.letter_to_number('A'), oo.first_column
3379
+ assert_equal Openoffice.letter_to_number('G'), oo.last_column
3380
+ oo.default_sheet = "Name of Sheet 2"
3381
+ assert_equal 5, oo.first_row
3382
+ assert_equal 14, oo.last_row
3383
+ assert_equal Openoffice.letter_to_number('B'), oo.first_column
3384
+ assert_equal Openoffice.letter_to_number('E'), oo.last_column
3385
+ oo.default_sheet = "Sheet3"
3386
+ assert_equal 1, oo.first_row
3387
+ assert_equal 1, oo.last_row
3388
+ assert_equal Openoffice.letter_to_number('A'), oo.first_column
3389
+ assert_equal Openoffice.letter_to_number('BA'), oo.last_column
3390
+ oo.default_sheet = "Sheet4"
3391
+ assert_equal 1, oo.first_row
3392
+ assert_equal 1, oo.last_row
3393
+ assert_equal Openoffice.letter_to_number('A'), oo.first_column
3394
+ assert_equal Openoffice.letter_to_number('E'), oo.last_column
3395
+ oo.default_sheet = "Sheet5"
3396
+ assert_equal 1, oo.first_row
3397
+ assert_equal 6, oo.last_row
3398
+ assert_equal Openoffice.letter_to_number('A'), oo.first_column
3399
+ assert_equal Openoffice.letter_to_number('E'), oo.last_column
3400
+ end
3401
+ end
3402
+
3403
+ def test_should_raise_file_not_found_error
3404
+ if OPENOFFICE
3405
+ assert_raise(IOError) {
3406
+ oo = Openoffice.new(File.join('testnichtvorhanden','Bibelbund.ods'))
3407
+ }
3408
+ end
3409
+ if EXCEL
3410
+ assert_raise(IOError) {
3411
+ oo = Excel.new(File.join('testnichtvorhanden','Bibelbund.xls'))
3412
+ }
3413
+ end
3414
+ if EXCELX
3415
+ assert_raise(IOError) {
3416
+ oo = Excelx.new(File.join('testnichtvorhanden','Bibelbund.xlsx'))
3417
+ }
3418
+ end
3419
+ if GOOGLE
3420
+ after Date.new(2009,1,15) do
3421
+ assert_raise(IOError) {
3422
+ # oo = Google.new(key_of('testnichtvorhanden'+'Bibelbund.ods'))
3423
+ oo = Google.new('testnichtvorhanden')
3424
+ }
3425
+ end
3426
+ end
3427
+ end
3428
+
3429
+ def test_bug_cell_no_default_sheet
3430
+ if GOOGLE
3431
+ oo = Google.new(key_of("numbers1"))
3432
+ assert_raise(ArgumentError) {
3433
+ # should complain about not set default-sheet
3434
+ #assert_equal 1.0, oo.cell('A',1)
3435
+ value = oo.cell('A',1)
3436
+ assert_equal "ganz rechts gehts noch wetier", oo.cell('A',1,"Sheet3")
3437
+ }
3438
+ end
3439
+ end
3440
+
3441
+ def test_write_google
3442
+ # write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB
3443
+ if GOOGLE
3444
+ oo = Google.new('ptu6bbahNZpY0N0RrxQbWdw')
3445
+ oo.default_sheet = oo.sheets.first
3446
+ oo.set_value(1,1,"hello from the tests")
3447
+ #oo.set_value(1,1,"sin(1)")
3448
+ assert_equal "hello from the tests", oo.cell(1,1)
3449
+ end
3450
+ end
3451
+
3452
+ def test_bug_set_value_with_more_than_one_sheet_google
3453
+ # write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB
3454
+ if GOOGLE
3455
+ content1 = 'AAA'
3456
+ content2 = 'BBB'
3457
+ oo = Google.new('ptu6bbahNZpY0N0RrxQbWdw')
3458
+ oo.default_sheet = oo.sheets.first
3459
+ oo.set_value(1,1,content1)
3460
+ oo.default_sheet = oo.sheets[1]
3461
+ oo.set_value(1,1,content2) # in the second sheet
3462
+ oo.default_sheet = oo.sheets.first
3463
+ assert_equal content1, oo.cell(1,1)
3464
+ oo.default_sheet = oo.sheets[1]
3465
+ assert_equal content2, oo.cell(1,1)
3466
+ end
3467
+ end
3468
+
3469
+ def test_set_value_with_sheet_argument_google
3470
+ if GOOGLE
3471
+ random_row = rand(10)+1
3472
+ random_column = rand(10)+1
3473
+ oo = Google.new('ptu6bbahNZpY0N0RrxQbWdw')
3474
+ oo.default_sheet = oo.sheets.first
3475
+ content1 = 'ABC'
3476
+ content2 = 'DEF'
3477
+ oo.set_value(random_row,random_column,content1,oo.sheets.first)
3478
+ oo.set_value(random_row,random_column,content2,oo.sheets[1])
3479
+ assert_equal content1, oo.cell(random_row,random_column,oo.sheets.first)
3480
+ assert_equal content2, oo.cell(random_row,random_column,oo.sheets[1])
3481
+ end
3482
+ end
3483
+
3484
+ def test_set_value_for_non_existing_sheet_google
3485
+ if GOOGLE
3486
+ oo = Google.new('ptu6bbahNZpY0N0RrxQbWdw')
3487
+ assert_raise(RangeError) {
3488
+ #oo.default_sheet = "no_sheet"
3489
+ oo.set_value(1,1,"dummy","no_sheet")
3490
+ }
3491
+ end # GOOGLE
3492
+ end
3493
+
3494
+ def test_bug_bbu_openoffice
3495
+ oo = Openoffice.new(File.join(TESTDIR,'bbu.ods'))
3496
+ assert_nothing_raised() {
3497
+ assert_equal "File: bbu.ods
3498
+ Number of sheets: 3
3499
+ Sheets: 2007_12, Tabelle2, Tabelle3
3500
+ Sheet 1:
3501
+ First row: 1
3502
+ Last row: 4
3503
+ First column: A
3504
+ Last column: F
3505
+ Sheet 2:
3506
+ - empty -
3507
+ Sheet 3:
3508
+ - empty -", oo.info
3509
+ }
3510
+
3511
+ oo.default_sheet = oo.sheets[1] # empty sheet
3512
+ assert_nil oo.first_row
3513
+ assert_nil oo.last_row
3514
+ assert_nil oo.first_column
3515
+ assert_nil oo.last_column
3516
+ end
3517
+
3518
+ def test_bug_bbu_excel
3519
+ if EXCEL
3520
+ oo = Excel.new(File.join(TESTDIR,'bbu.xls'))
3521
+ assert_nothing_raised() {
3522
+ assert_equal "File: bbu.xls
3523
+ Number of sheets: 3
3524
+ Sheets: 2007_12, Tabelle2, Tabelle3
3525
+ Sheet 1:
3526
+ First row: 1
3527
+ Last row: 4
3528
+ First column: A
3529
+ Last column: F
3530
+ Sheet 2:
3531
+ - empty -
3532
+ Sheet 3:
3533
+ - empty -", oo.info
3534
+ }
3535
+
3536
+ oo.default_sheet = oo.sheets[1] # empty sheet
3537
+ assert_nil oo.first_row
3538
+ assert_nil oo.last_row
3539
+ assert_nil oo.first_column
3540
+ assert_nil oo.last_column
3541
+ end
3542
+ end
3543
+
3544
+ def test_bug_bbu_excelx
3545
+ if EXCELX
3546
+ oo = Excelx.new(File.join(TESTDIR,'bbu.xlsx'))
3547
+ assert_nothing_raised() {
3548
+ assert_equal "File: bbu.xlsx
3549
+ Number of sheets: 3
3550
+ Sheets: 2007_12, Tabelle2, Tabelle3
3551
+ Sheet 1:
3552
+ First row: 1
3553
+ Last row: 4
3554
+ First column: A
3555
+ Last column: F
3556
+ Sheet 2:
3557
+ - empty -
3558
+ Sheet 3:
3559
+ - empty -", oo.info
3560
+ }
3561
+
3562
+ oo.default_sheet = oo.sheets[1] # empty sheet
3563
+ assert_nil oo.first_row
3564
+ assert_nil oo.last_row
3565
+ assert_nil oo.first_column
3566
+ assert_nil oo.last_column
3567
+ end
3568
+ end
3569
+
3570
+ if false
3571
+ # there is no google spreadsheet for this test
3572
+ def test_bug_bbu_google
3573
+ oo = Excel.new(key_of('bbu'))
3574
+ assert_nothing_raised() {
3575
+ assert_equal "File: test/bbu.xls
3576
+ Number of sheets: 3
3577
+ Sheets: 2007_12, Tabelle2, Tabelle3
3578
+ Sheet 1:
3579
+ First row: 1
3580
+ Last row: 4
3581
+ First column: A
3582
+ Last column: F
3583
+ Sheet 2:
3584
+ - empty -
3585
+ Sheet 3:
3586
+ - empty -", oo.info
3587
+ }
3588
+
3589
+ oo.default_sheet = oo.sheets[1] # empty sheet
3590
+ assert_nil oo.first_row
3591
+ assert_nil oo.last_row
3592
+ assert_nil oo.first_column
3593
+ assert_nil oo.last_column
3594
+ end
3595
+ end # false
3596
+
3597
+ def test_bug_time_nil_openoffice
3598
+ if OPENOFFICE
3599
+ oo = Openoffice.new(File.join(TESTDIR,"time-test.ods"))
3600
+ oo.default_sheet = oo.sheets.first
3601
+ assert_equal 12*3600+13*60+14, oo.cell('B',1) # 12:13:14 (secs since midnight)
3602
+ assert_equal :time, oo.celltype('B',1)
3603
+ assert_equal 15*3600+16*60, oo.cell('C',1) # 15:16 (secs since midnight)
3604
+ assert_equal :time, oo.celltype('C',1)
3605
+
3606
+ assert_equal 23*3600, oo.cell('D',1) # 23:00 (secs since midnight)
3607
+ assert_equal :time, oo.celltype('D',1)
3608
+ end
3609
+ end
3610
+
3611
+ def test_bug_time_nil_excel
3612
+ if EXCEL
3613
+ oo = Excel.new(File.join(TESTDIR,"time-test.xls"))
3614
+ oo.default_sheet = oo.sheets.first
3615
+ assert_equal 12*3600+13*60+14, oo.cell('B',1) # 12:13:14 (secs since midnight)
3616
+ assert_equal :time, oo.celltype('B',1)
3617
+ assert_equal 15*3600+16*60, oo.cell('C',1) # 15:16 (secs since midnight)
3618
+ assert_equal :time, oo.celltype('C',1)
3619
+
3620
+ assert_equal 23*3600, oo.cell('D',1) # 23:00 (secs since midnight)
3621
+ assert_equal :time, oo.celltype('D',1)
3622
+ end
3623
+ end
3624
+
3625
+ def test_bug_time_nil_excelx
3626
+ if EXCELX
3627
+ oo = Excelx.new(File.join(TESTDIR,"time-test.xlsx"))
3628
+ oo.default_sheet = oo.sheets.first
3629
+ assert_equal [:numeric_or_formula, "hh:mm:ss"],oo.excelx_type('b',1)
3630
+ assert_in_delta 0.50918981481481485, oo.excelx_value('b', 1), 0.000001
3631
+ assert_equal :time, oo.celltype('B',1)
3632
+ assert_equal 12*3600+13*60+14, oo.cell('B',1) # 12:13:14 (secs since midnight)
3633
+
3634
+ assert_equal :time, oo.celltype('C',1)
3635
+ assert_equal 15*3600+16*60, oo.cell('C',1) # 15:16 (secs since midnight)
3636
+
3637
+ assert_equal :time, oo.celltype('D',1)
3638
+ assert_equal 23*3600, oo.cell('D',1) # 23:00 (secs since midnight)
3639
+ end
3640
+ end
3641
+
3642
+ def test_bug_time_nil_google
3643
+ if GOOGLE
3644
+ oo = Google.new(key_of("time-test"))
3645
+ oo.default_sheet = oo.sheets.first
3646
+ assert_equal 12*3600+13*60+14, oo.cell('B',1) # 12:13:14 (secs since midnight)
3647
+ assert_equal :time, oo.celltype('B',1)
3648
+ assert_equal 15*3600+16*60, oo.cell('C',1) # 15:16 (secs since midnight)
3649
+ assert_equal :time, oo.celltype('C',1)
3650
+
3651
+ assert_equal 23*3600, oo.cell('D',1) # 23:00 (secs since midnight)
3652
+ assert_equal :time, oo.celltype('D',1)
3653
+ end
3654
+ end
3655
+
3656
+ def test_date_time_to_csv_openoffice
3657
+ if OPENOFFICE
3658
+ File.delete_if_exist("/tmp/time-test.csv")
3659
+ oo = Openoffice.new(File.join(TESTDIR,"time-test.ods"))
3660
+ oo.default_sheet = oo.sheets.first
3661
+ assert oo.to_csv("/tmp/time-test.csv")
3662
+ assert File.exists?("/tmp/time-test.csv")
3663
+ assert_equal "", `diff test/time-test.csv /tmp/time-test.csv`
3664
+ end # OPENOFFICE
3665
+ end
3666
+
3667
+ def test_date_time_to_csv_excel
3668
+ if EXCEL
3669
+ #ueberfluessige leere Zeilen werden am Ende noch angehaengt
3670
+ # last_row fehlerhaft?
3671
+ File.delete_if_exist("/tmp/time-test.csv")
3672
+ oo = Excel.new(File.join(TESTDIR,"time-test.xls"))
3673
+ oo.default_sheet = oo.sheets.first
3674
+ assert oo.to_csv("/tmp/time-test.csv")
3675
+ assert File.exists?("/tmp/time-test.csv")
3676
+ assert_equal "", `diff test/time-test.csv /tmp/time-test.csv`
3677
+ end # EXCEL
3678
+ end
3679
+
3680
+ def test_date_time_to_csv_excelx
3681
+ if EXCELX
3682
+ #ueberfluessige leere Zeilen werden am Ende noch angehaengt
3683
+ # last_row fehlerhaft?
3684
+ File.delete_if_exist("/tmp/time-test.csv")
3685
+ oo = Excelx.new(File.join(TESTDIR,"time-test.xlsx"))
3686
+ oo.default_sheet = oo.sheets.first
3687
+ assert oo.to_csv("/tmp/time-test.csv")
3688
+ assert File.exists?("/tmp/time-test.csv")
3689
+ assert_equal "", `diff test/time-test.csv /tmp/time-test.csv`
3690
+ end # EXCELX
3691
+ end
3692
+
3693
+ def test_date_time_to_csv_google
3694
+ if GOOGLE
3695
+ File.delete_if_exist("/tmp/time-test.csv")
3696
+ oo = Google.new(key_of("time-test"))
3697
+ oo.default_sheet = oo.sheets.first
3698
+ assert oo.to_csv("/tmp/time-test.csv")
3699
+ assert File.exists?("/tmp/time-test.csv")
3700
+ assert_equal "", `diff test/time-test.csv /tmp/time-test.csv`
3701
+ end # GOOGLE
3702
+ end
3703
+
3704
+ def test_date_time_yaml_openoffice
3705
+ if OPENOFFICE
3706
+ expected =
3707
+ "--- \ncell_1_1: \n row: 1 \n col: 1 \n celltype: string \n value: Mittags: \ncell_1_2: \n row: 1 \n col: 2 \n celltype: time \n value: 12:13:14 \ncell_1_3: \n row: 1 \n col: 3 \n celltype: time \n value: 15:16:00 \ncell_1_4: \n row: 1 \n col: 4 \n celltype: time \n value: 23:00:00 \ncell_2_1: \n row: 2 \n col: 1 \n celltype: date \n value: 2007-11-21 \n"
3708
+ oo = Openoffice.new(File.join(TESTDIR,"time-test.ods"))
3709
+ oo.default_sheet = oo.sheets.first
3710
+ assert_equal expected, oo.to_yaml
3711
+ end
3712
+ end
3713
+
3714
+ def test_date_time_yaml_excel
3715
+ if EXCEL
3716
+ expected =
3717
+ "--- \ncell_1_1: \n row: 1 \n col: 1 \n celltype: string \n value: Mittags: \ncell_1_2: \n row: 1 \n col: 2 \n celltype: time \n value: 12:13:14 \ncell_1_3: \n row: 1 \n col: 3 \n celltype: time \n value: 15:16:00 \ncell_1_4: \n row: 1 \n col: 4 \n celltype: time \n value: 23:00:00 \ncell_2_1: \n row: 2 \n col: 1 \n celltype: date \n value: 2007-11-21 \n"
3718
+ oo = Excel.new(File.join(TESTDIR,"time-test.xls"))
3719
+ oo.default_sheet = oo.sheets.first
3720
+ assert_equal expected, oo.to_yaml
3721
+ end
3722
+ end
3723
+
3724
+ def test_date_time_yaml_excelx
3725
+ if EXCELX
3726
+ expected =
3727
+ "--- \ncell_1_1: \n row: 1 \n col: 1 \n celltype: string \n value: Mittags: \ncell_1_2: \n row: 1 \n col: 2 \n celltype: time \n value: 12:13:14 \ncell_1_3: \n row: 1 \n col: 3 \n celltype: time \n value: 15:16:00 \ncell_1_4: \n row: 1 \n col: 4 \n celltype: time \n value: 23:00:00 \ncell_2_1: \n row: 2 \n col: 1 \n celltype: date \n value: 2007-11-21 \n"
3728
+ oo = Excelx.new(File.join(TESTDIR,"time-test.xlsx"))
3729
+ oo.default_sheet = oo.sheets.first
3730
+ assert_equal expected, oo.to_yaml
3731
+ end
3732
+ end
3733
+
3734
+ def test_date_time_yaml_google
3735
+ if GOOGLE
3736
+ expected =
3737
+ "--- \ncell_1_1: \n row: 1 \n col: 1 \n celltype: string \n value: Mittags: \ncell_1_2: \n row: 1 \n col: 2 \n celltype: time \n value: 12:13:14 \ncell_1_3: \n row: 1 \n col: 3 \n celltype: time \n value: 15:16:00 \ncell_1_4: \n row: 1 \n col: 4 \n celltype: time \n value: 23:00:00 \ncell_2_1: \n row: 2 \n col: 1 \n celltype: date \n value: 2007-11-21 \n"
3738
+ oo = Google.new(key_of("time-test"))
3739
+ oo.default_sheet = oo.sheets.first
3740
+ assert_equal expected, oo.to_yaml
3741
+ end
3742
+ end
3743
+
3744
+ def test_no_remaining_tmp_files_openoffice
3745
+ if OPENOFFICE
3746
+ assert_raise(Zip::ZipError) { #TODO: besseres Fehlerkriterium bei
3747
+ # oo = Openoffice.new(File.join(TESTDIR,"no_spreadsheet_file.txt"))
3748
+ # es soll absichtlich ein Abbruch provoziert werden, deshalb :ignore
3749
+ oo = Openoffice.new(File.join(TESTDIR,"no_spreadsheet_file.txt"),
3750
+ false,
3751
+ :ignore)
3752
+ }
3753
+ a=Dir.glob("oo_*")
3754
+ assert_equal [], a
3755
+ end
3756
+ end
3757
+
3758
+ def test_no_remaining_tmp_files_excel
3759
+ if EXCEL
3760
+ assert_raise(Ole::Storage::FormatError) {
3761
+ # oo = Excel.new(File.join(TESTDIR,"no_spreadsheet_file.txt"))
3762
+ # es soll absichtlich ein Abbruch provoziert werden, deshalb :ignore
3763
+ oo = Excel.new(File.join(TESTDIR,"no_spreadsheet_file.txt"),
3764
+ false,
3765
+ :ignore)
3766
+ }
3767
+ a=Dir.glob("oo_*")
3768
+ assert_equal [], a
3769
+ end
3770
+ end
3771
+
3772
+ def test_no_remaining_tmp_files_excelx
3773
+ if EXCELX
3774
+ assert_raise(Zip::ZipError) { #TODO: besseres Fehlerkriterium bei
3775
+
3776
+ # oo = Excelx.new(File.join(TESTDIR,"no_spreadsheet_file.txt"))
3777
+ # es soll absichtlich ein Abbruch provoziert werden, deshalb :ignore
3778
+ oo = Excelx.new(File.join(TESTDIR,"no_spreadsheet_file.txt"),
3779
+ false,
3780
+ :ignore)
3781
+
3782
+ }
3783
+ a=Dir.glob("oo_*")
3784
+ assert_equal [], a
3785
+ end
3786
+ end
3787
+
3788
+ def test_no_remaining_tmp_files_google
3789
+ if GOOGLE
3790
+ assert_nothing_raised() {
3791
+ oo = Google.new(key_of("no_spreadsheet_file.txt"))
3792
+ }
3793
+ a=Dir.glob("oo_*")
3794
+ assert_equal [], a
3795
+ end
3796
+ end
3797
+
3798
+ # Erstellt eine Liste aller Zellen im Spreadsheet. Dies ist nötig, weil ein einfacher
3799
+ # Textvergleich des XML-Outputs nicht funktioniert, da xml-builder die Attribute
3800
+ # nicht immer in der gleichen Reihenfolge erzeugt.
3801
+ def init_all_cells(oo,sheet)
3802
+ all = []
3803
+ oo.first_row(sheet).upto(oo.last_row(sheet)) do |row|
3804
+ oo.first_column(sheet).upto(oo.last_column(sheet)) do |col|
3805
+ unless oo.empty?(row,col,sheet)
3806
+ all << {:row => row.to_s,
3807
+ :column => col.to_s,
3808
+ :content => oo.cell(row,col,sheet).to_s,
3809
+ :type => oo.celltype(row,col,sheet).to_s,
3810
+ }
3811
+ end
3812
+ end
3813
+ end
3814
+ all
3815
+ end
3816
+
3817
+ def do_test_xml(oo)
3818
+ assert_nothing_raised {oo.to_xml}
3819
+ sheetname = oo.sheets.first
3820
+ doc = REXML::Document.new(oo.to_xml)
3821
+ doc.root.each_element {|xml_sheet|
3822
+ all_cells = init_all_cells(oo, sheetname)
3823
+ x = 0
3824
+ assert_equal sheetname, xml_sheet.attributes['name']
3825
+ xml_sheet.each_element {|cell|
3826
+ expected = [all_cells[x][:row],
3827
+ all_cells[x][:column],
3828
+ all_cells[x][:content],
3829
+ all_cells[x][:type],
3830
+ ]
3831
+ result = [
3832
+ cell.attributes['row'],
3833
+ cell.attributes['column'],
3834
+ cell.text,
3835
+ cell.attributes['type'],
3836
+ ]
3837
+ assert_equal expected, result
3838
+ x += 1
3839
+ } # end of sheet
3840
+ sheetname = oo.sheets[oo.sheets.index(sheetname)+1]
3841
+ }
3842
+ end
3843
+
3844
+ def test_to_xml_openoffice
3845
+ if OPENOFFICE
3846
+ oo = Openoffice.new(File.join(TESTDIR,'numbers1.ods'))
3847
+ do_test_xml(oo)
3848
+ end
3849
+ end
3850
+
3851
+ def test_to_xml_excel
3852
+ if EXCEL
3853
+ oo = Excel.new(File.join(TESTDIR,'numbers1.xls'))
3854
+ do_test_xml(oo)
3855
+ end
3856
+ end
3857
+
3858
+ def test_to_xml_excelx
3859
+ if EXCELX
3860
+ oo = Excelx.new(File.join(TESTDIR,'numbers1.xlsx'))
3861
+ do_test_xml(oo)
3862
+ end
3863
+ end
3864
+
3865
+ def test_to_xml_google
3866
+ if GOOGLE
3867
+ oo = Google.new(key_of(File.join(TESTDIR,'numbers1.xlsx')))
3868
+ do_test_xml(oo)
3869
+ end
3870
+ end
3871
+
3872
+ def SKIP_test_invalid_iconv_from_ms
3873
+ #TODO: does only run within a darwin-environment
3874
+ if RUBY_PLATFORM.downcase =~ /darwin/
3875
+ assert_nothing_raised() {
3876
+ oo = Excel.new(File.join(TESTDIR,"ms.xls"))
3877
+ }
3878
+ end
3879
+ end
3880
+
3881
+ def test_bug_row_column_fixnum_float
3882
+ if EXCEL
3883
+ ex = Excel.new(File.join(TESTDIR,'bug-row-column-fixnum-float.xls'))
3884
+ ex.default_sheet = ex.sheets.first
3885
+ assert_equal 42.5, ex.cell('b',2)
3886
+ assert_equal 43 , ex.cell('c',2)
3887
+ assert_equal ['hij',42.5, 43], ex.row(2)
3888
+ assert_equal ['def',42.5, 'nop'], ex.column(2)
3889
+ end
3890
+
3891
+ end
3892
+
3893
+ def test_bug_c2
3894
+ if EXCEL
3895
+ after Date.new(2009,1,6) do
3896
+ local_only do
3897
+ expected = ['Supermodel X','T6','Shaun White','Jeremy','Custom',
3898
+ 'Warhol','Twin','Malolo','Supermodel','Air','Elite',
3899
+ 'King','Dominant','Dominant Slick','Blunt','Clash',
3900
+ 'Bullet','Tadashi Fuse','Jussi','Royale','S-Series',
3901
+ 'Fish','Love','Feelgood ES','Feelgood','GTwin','Troop',
3902
+ 'Lux','Stigma','Feather','Stria','Alpha','Feelgood ICS']
3903
+ result = []
3904
+ @e = Excel.new(File.join(TESTDIR,"problem.xls"))
3905
+ @e.sheets[2..@e.sheets.length].each do |s|
3906
+ #(13..13).each do |s|
3907
+ @e.default_sheet = s
3908
+ name = @e.cell(2,'C')
3909
+ result << name
3910
+ #puts "#{name} (sheet: #{s})"
3911
+ #assert_equal "whatever (sheet: 13)", "#{name} (sheet: #{s})"
3912
+ end
3913
+ assert_equal expected, result
3914
+ end
3915
+ end
3916
+ end
3917
+ end
3918
+
3919
+ def test_bug_c2_parseexcel
3920
+ after Date.new(2009,1,10) do
3921
+ local_only do
3922
+ #-- this is OK
3923
+ @workbook = Spreadsheet::ParseExcel.parse(File.join(TESTDIR,"problem.xls"))
3924
+ worksheet = @workbook.worksheet(11)
3925
+ skip = 0
3926
+ line = 1
3927
+ row = 2
3928
+ col = 3
3929
+ worksheet.each(skip) { |row_par|
3930
+ if line == row
3931
+ if row_par == nil
3932
+ raise "nil"
3933
+ end
3934
+ cell = row_par.at(col-1)
3935
+ assert cell, "cell should not be nil"
3936
+ assert_equal "Air", cell.to_s('utf-8')
3937
+ end
3938
+ line += 1
3939
+ }
3940
+ #-- worksheet 12 does not work
3941
+ @workbook = Spreadsheet::ParseExcel.parse(File.join(TESTDIR,"problem.xls"))
3942
+ worksheet = @workbook.worksheet(12)
3943
+ skip = 0
3944
+ line = 1
3945
+ row = 2
3946
+ col = 3
3947
+ worksheet.each(skip) { |row_par|
3948
+ if line == row
3949
+ if row_par == nil
3950
+ raise "nil"
3951
+ end
3952
+ cell = row_par.at(col-1)
3953
+ assert cell, "cell should not be nil"
3954
+ assert_equal "Elite", cell.to_s('utf-8')
3955
+ end
3956
+ line += 1
3957
+ }
3958
+ end
3959
+ end
3960
+ end
3961
+
3962
+ def test_bug_c2_excelx
3963
+ after Date.new(2008,9,15) do
3964
+ local_only do
3965
+ expected = ['Supermodel X','T6','Shaun White','Jeremy','Custom',
3966
+ 'Warhol','Twin','Malolo','Supermodel','Air','Elite',
3967
+ 'King','Dominant','Dominant Slick','Blunt','Clash',
3968
+ 'Bullet','Tadashi Fuse','Jussi','Royale','S-Series',
3969
+ 'Fish','Love','Feelgood ES','Feelgood','GTwin','Troop',
3970
+ 'Lux','Stigma','Feather','Stria','Alpha','Feelgood ICS']
3971
+ result = []
3972
+ @e = Excelx.new(File.join(TESTDIR,"problem.xlsx"))
3973
+ @e.sheets[2..@e.sheets.length].each do |s|
3974
+ @e.default_sheet = s
3975
+ # assert_equal "A.",@e.cell('a',13)
3976
+ name = @e.cell(2,'C')
3977
+ result << name
3978
+ #puts "#{name} (sheet: #{s})"
3979
+ #assert_equal :string, @e.celltype('c',2)
3980
+ #assert_equal "Vapor (sheet: Vapor)", "#{name} (sheet: #{@e.sheets.first})"
3981
+ assert @e.cell(2,'c')
3982
+ end
3983
+ assert_equal expected, result
3984
+
3985
+ @e = Excelx.new(File.join(TESTDIR,"problem.xlsx"))
3986
+ #@e.sheets[2..@e.sheets.length].each do |s|
3987
+ (13..13).each do |s|
3988
+ @e.default_sheet = s
3989
+ name = @e.cell(2,'C')
3990
+ #puts "#{name} (sheet: #{s})"
3991
+ assert_equal "Elite (sheet: 13)", "#{name} (sheet: #{s})"
3992
+ end
3993
+ end
3994
+ end
3995
+ end
3996
+
3997
+ def test_compare_csv_excelx_excel
3998
+ if EXCELX
3999
+ after Date.new(2008,12,30) do
4000
+ # parseexcel bug
4001
+ local_only do
4002
+ s1 = Excel.new(File.join(TESTDIR,"problem.xls"))
4003
+ s2 = Excelx.new(File.join(TESTDIR,"problem.xlsx"))
4004
+ s1.sheets.each {|sh| #TODO:
4005
+ s1.default_sheet = sh
4006
+ s2.default_sheet = sh
4007
+ File.delete_if_exist("/tmp/problem.csv")
4008
+ File.delete_if_exist("/tmp/problemx.csv")
4009
+ assert s1.to_csv("/tmp/problem.csv")
4010
+ assert s2.to_csv("/tmp/problemx.csv")
4011
+ assert File.exists?("/tmp/problem.csv")
4012
+ assert File.exists?("/tmp/problemx.csv")
4013
+ assert_equal "", `diff /tmp/problem.csv /tmp/problemx.csv`, "Unterschied in Sheet #{sh} #{s1.sheets.index(sh)}"
4014
+ }
4015
+ end
4016
+ end
4017
+ end
4018
+ end
4019
+
4020
+ def test_problemx_csv_imported
4021
+ after Date.new(2009,1,6) do
4022
+ if EXCEL
4023
+ local_only do
4024
+ # wieder eingelesene CSV-Datei aus obigem Test
4025
+ # muss identisch mit problem.xls sein
4026
+ # Importieren aus csv-Datei muss manuell gemacht werden
4027
+ ex = Excel.new(File.join(TESTDIR,"problem.xls"))
4028
+ cs = Excel.new(File.join(TESTDIR,"problemx_csv_imported.xls"))
4029
+ # nur das erste sheet betrachten
4030
+ ex.default_sheet = ex.sheets.first
4031
+ cs.default_sheet = cs.sheets.first
4032
+ ex.first_row.upto(ex.last_row) do |row|
4033
+ ex.first_column.upto(ex.last_column) do |col|
4034
+ assert_equal ex.cell(row,col), cs.cell(row,col), "cell #{row}/#{col} does not match '#{ex.cell(row,col)}' '#{cs.cell(row,col)}'"
4035
+ assert_equal ex.celltype(row,col), cs.celltype(row,col), "celltype #{row}/#{col} does not match"
4036
+ assert_equal ex.empty?(row,col), cs.empty?(row,col), "empty? #{row}/#{col} does not match"
4037
+ if defined? excel_supports_formulas
4038
+ assert_equal ex.formula?(row,col), cs.formula?(row,col), "formula? #{row}/#{col} does not match"
4039
+ assert_equal ex.formula(row,col), cs.formula(row,col), "formula #{row}/#{col} does not match"
4040
+ end
4041
+ end
4042
+ end
4043
+ cs.first_row.upto(cs.last_row) do |row|
4044
+ cs.first_column.upto(cs.last_column) do |col|
4045
+ assert_equal ex.cell(row,col), cs.cell(row,col), "cell #{row}/#{col} does not match '#{ex.cell(row,col)}' '#{cs.cell(row,col)}'"
4046
+ assert_equal ex.celltype(row,col), cs.celltype(row,col), "celltype #{row}/#{col} does not match"
4047
+ assert_equal ex.empty?(row,col), cs.empty?(row,col), "empty? #{row}/#{col} does not match"
4048
+ if defined? excel_supports_formulas
4049
+ assert_equal ex.formula?(row,col), cs.formula?(row,col), "formula? #{row}/#{col} does not match"
4050
+ assert_equal ex.formula(row,col), cs.formula(row,col), "formula #{row}/#{col} does not match"
4051
+ end
4052
+ end
4053
+ end
4054
+ end
4055
+ end
4056
+ end
4057
+ end
4058
+
4059
+ def test_file_warning_default
4060
+ if OPENOFFICE
4061
+ assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls")) }
4062
+ assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx")) }
4063
+ assert_equal [], Dir.glob("oo_*")
4064
+ end
4065
+ if EXCEL
4066
+ assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.ods")) }
4067
+ assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx")) }
4068
+ assert_equal [], Dir.glob("oo_*")
4069
+ end
4070
+ if EXCELX
4071
+ assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.ods")) }
4072
+ assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.xls")) }
4073
+ assert_equal [], Dir.glob("oo_*")
4074
+ end
4075
+ end
4076
+
4077
+ def test_file_warning_error
4078
+ if OPENOFFICE
4079
+ assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls"),false,:error) }
4080
+ assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) }
4081
+ assert_equal [], Dir.glob("oo_*")
4082
+ end
4083
+ if EXCEL
4084
+ assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.ods"),false,:error) }
4085
+ assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) }
4086
+ assert_equal [], Dir.glob("oo_*")
4087
+ end
4088
+ if EXCELX
4089
+ assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.ods"),false,:error) }
4090
+ assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.xls"),false,:error) }
4091
+ assert_equal [], Dir.glob("oo_*")
4092
+ end
4093
+ end
4094
+
4095
+ def test_file_warning_warning
4096
+ if OPENOFFICE
4097
+ assert_nothing_raised(TypeError) {
4098
+ assert_raises(Zip::ZipError) {
4099
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls"),false, :warning)
4100
+ }
4101
+ }
4102
+ assert_nothing_raised(TypeError) {
4103
+ assert_raises(Errno::ENOENT) {
4104
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx"),false, :warning)
4105
+ }
4106
+ }
4107
+ assert_equal [], Dir.glob("oo_*")
4108
+ end
4109
+ if EXCEL
4110
+ assert_nothing_raised(TypeError) {
4111
+ assert_raises(Ole::Storage::FormatError) {
4112
+ oo = Excel.new(File.join(TESTDIR,"numbers1.ods"),false, :warning) }
4113
+ }
4114
+ assert_nothing_raised(TypeError) {
4115
+ assert_raises(Ole::Storage::FormatError) {
4116
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx"),false, :warning) }
4117
+ }
4118
+ assert_equal [], Dir.glob("oo_*")
4119
+ end
4120
+ if EXCELX
4121
+ assert_nothing_raised(TypeError) {
4122
+ assert_raises(Errno::ENOENT) {
4123
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.ods"),false, :warning) }
4124
+ }
4125
+ assert_nothing_raised(TypeError) {
4126
+ assert_raises(Zip::ZipError) {
4127
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xls"),false, :warning) }
4128
+ }
4129
+ assert_equal [], Dir.glob("oo_*")
4130
+ end
4131
+ end
4132
+
4133
+ def test_file_warning_ignore
4134
+ if OPENOFFICE
4135
+ assert_nothing_raised(TypeError) {
4136
+ assert_raises(Zip::ZipError) {
4137
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls"),false, :ignore) }
4138
+ }
4139
+ assert_nothing_raised(TypeError) {
4140
+ assert_raises(Errno::ENOENT) {
4141
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx"),false, :ignore) }
4142
+ }
4143
+ assert_equal [], Dir.glob("oo_*")
4144
+ end
4145
+ if EXCEL
4146
+ assert_nothing_raised(TypeError) {
4147
+ assert_raises(Ole::Storage::FormatError) {
4148
+ oo = Excel.new(File.join(TESTDIR,"numbers1.ods"),false, :ignore) }
4149
+ }
4150
+ assert_nothing_raised(TypeError) {
4151
+ assert_raises(Ole::Storage::FormatError) {oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx"),false, :ignore) }}
4152
+ assert_equal [], Dir.glob("oo_*")
4153
+ end
4154
+ if EXCELX
4155
+ assert_nothing_raised(TypeError) {
4156
+ assert_raises(Errno::ENOENT) {
4157
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.ods"),false, :ignore)
4158
+ }
4159
+ }
4160
+ assert_nothing_raised(TypeError) {
4161
+ assert_raises(Zip::ZipError) {
4162
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xls"),false, :ignore)
4163
+ }
4164
+ }
4165
+ assert_equal [], Dir.glob("oo_*")
4166
+ end
4167
+ end
4168
+
4169
+ def SKIP_test_open_from_uri
4170
+ if ONLINE
4171
+ if OPENOFFICE
4172
+ assert_raises(RuntimeError) {
4173
+ oo = Openoffice.new("http://gibbsnichtdomainxxxxx.com/file.ods")
4174
+ }
4175
+ end
4176
+ if EXCEL
4177
+ assert_raises(RuntimeError) {
4178
+ oo = Excel.new("http://gibbsnichtdomainxxxxx.com/file.xls")
4179
+ }
4180
+ end
4181
+ if EXCELX
4182
+ assert_raises(RuntimeError) {
4183
+ oo = Excelx.new("http://gibbsnichtdomainxxxxx.com/file.xlsx")
4184
+ }
4185
+ end
4186
+ end
4187
+ end
4188
+
4189
+ def test_bug_last_row_excel
4190
+ if EXCEL
4191
+ oo = Excel.new(File.join(TESTDIR,"time-test.xls"))
4192
+ oo.default_sheet = oo.sheets.first
4193
+ assert_equal 2, oo.last_row
4194
+ end
4195
+ end
4196
+
4197
+ def test_bug_to_xml_with_empty_sheets_openoffice
4198
+ if OPENOFFICE
4199
+ oo = Openoffice.new(File.join(TESTDIR,"emptysheets.ods"))
4200
+ oo.sheets.each { |sheet|
4201
+ oo.default_sheet = sheet
4202
+ assert_equal nil, oo.first_row, "first_row not nil in sheet #{sheet}"
4203
+ assert_equal nil, oo.last_row, "last_row not nil in sheet #{sheet}"
4204
+ assert_equal nil, oo.first_column, "first_column not nil in sheet #{sheet}"
4205
+ assert_equal nil, oo.last_column, "last_column not nil in sheet #{sheet}"
4206
+ assert_equal nil, oo.first_row(sheet), "first_row not nil in sheet #{sheet}"
4207
+ assert_equal nil, oo.last_row(sheet), "last_row not nil in sheet #{sheet}"
4208
+ assert_equal nil, oo.first_column(sheet), "first_column not nil in sheet #{sheet}"
4209
+ assert_equal nil, oo.last_column(sheet), "last_column not nil in sheet #{sheet}"
4210
+ }
4211
+ assert_nothing_raised() {
4212
+ result = oo.to_xml
4213
+ }
4214
+ end
4215
+ end
4216
+
4217
+ def test_bug_to_xml_with_empty_sheets_excel
4218
+ if EXCEL
4219
+ oo = Excel.new(File.join(TESTDIR,"emptysheets.xls"))
4220
+ oo.sheets.each { |sheet|
4221
+ oo.default_sheet = sheet
4222
+ assert_equal nil, oo.first_row, "first_row not nil in sheet #{sheet}"
4223
+ assert_equal nil, oo.last_row, "last_row not nil in sheet #{sheet}"
4224
+ assert_equal nil, oo.first_column, "first_column not nil in sheet #{sheet}"
4225
+ assert_equal nil, oo.last_column, "last_column not nil in sheet #{sheet}"
4226
+ assert_equal nil, oo.first_row(sheet), "first_row not nil in sheet #{sheet}"
4227
+ assert_equal nil, oo.last_row(sheet), "last_row not nil in sheet #{sheet}"
4228
+ assert_equal nil, oo.first_column(sheet), "first_column not nil in sheet #{sheet}"
4229
+ assert_equal nil, oo.last_column(sheet), "last_column not nil in sheet #{sheet}"
4230
+ }
4231
+ assert_nothing_raised() {
4232
+ result = oo.to_xml
4233
+ }
4234
+ end
4235
+ end
4236
+
4237
+ def test_bug_to_xml_with_empty_sheets_excelx
4238
+ # kann ich nicht testen, da ich selbst keine .xlsx Files anlegen kann
4239
+ if EXCELX
4240
+ # oo = Excelx.new(File.join(TESTDIR,"emptysheets.xlsx"))
4241
+ # oo.sheets.each { |sheet|
4242
+ # oo.default_sheet = sheet
4243
+ # assert_equal nil, oo.first_row, "first_row not nil in sheet #{sheet}"
4244
+ # assert_equal nil, oo.last_row, "last_row not nil in sheet #{sheet}"
4245
+ # assert_equal nil, oo.first_column, "first_column not nil in sheet #{sheet}"
4246
+ # assert_equal nil, oo.last_column, "last_column not nil in sheet #{sheet}"
4247
+ # assert_equal nil, oo.first_row(sheet), "first_row not nil in sheet #{sheet}"
4248
+ # assert_equal nil, oo.last_row(sheet), "last_row not nil in sheet #{sheet}"
4249
+ # assert_equal nil, oo.first_column(sheet), "first_column not nil in sheet #{sheet}"
4250
+ # assert_equal nil, oo.last_column(sheet), "last_column not nil in sheet #{sheet}"
4251
+ # }
4252
+ # assert_nothing_raised() {
4253
+ # result = oo.to_xml
4254
+ # p result
4255
+ # }
4256
+ end
4257
+ end
4258
+
4259
+ def test_bug_simple_spreadsheet_time_bug
4260
+ # really a bug? are cells really of type time?
4261
+ # No! :float must be the correct type
4262
+ if EXCELX
4263
+ oo = Excelx.new(File.join(TESTDIR,"simple_spreadsheet.xlsx"))
4264
+ oo.default_sheet = oo.sheets.first
4265
+ # puts oo.cell('B',5).to_s
4266
+ # assert_equal :time, oo.celltype('B',5)
4267
+ assert_equal :float, oo.celltype('B',5)
4268
+ assert_equal 10.75, oo.cell('B',5)
4269
+
4270
+ assert_equal 12.50, oo.cell('C',5)
4271
+ assert_equal 0, oo.cell('D',5)
4272
+ assert_equal 1.75, oo.cell('E',5)
4273
+ assert_equal 'Task 1', oo.cell('F',5)
4274
+ assert_equal Date.new(2007,5,7), oo.cell('A',5)
4275
+ end
4276
+ end
4277
+
4278
+
4279
+ def test_to_ascii_openoffice
4280
+ if OPENOFFICE
4281
+ after Date.new(9999,12,31) do
4282
+ oo = Openoffice.new(File.join(TESTDIR,"verysimple_spreadsheet.ods"))
4283
+ oo.default_sheet = oo.sheets.first
4284
+ expected="
4285
+ A | B | C |
4286
+ -------+-------+------|
4287
+ 7| 8| 9|
4288
+ -------+-------+------|
4289
+ 4| 5| 6|
4290
+ -------+-------+------|
4291
+ 1| 2| 3|
4292
+ ----------------------/
4293
+ "
4294
+ assert_equal expected, oo.to_ascii
4295
+ end
4296
+ end
4297
+ end
4298
+
4299
+ def test_simple2_excelx
4300
+ if EXCELX
4301
+ after Date.new(2008,8,2) do
4302
+ oo = Excelx.new(File.join(TESTDIR,"simple_spreadsheet.xlsx"))
4303
+ oo.default_sheet = oo.sheets.first
4304
+ assert_equal [:numeric_or_formula, "yyyy\\-mm\\-dd"], oo.excelx_type('A',4)
4305
+ assert_equal [:numeric_or_formula, "#,##0.00"], oo.excelx_type('B',4)
4306
+ assert_equal [:numeric_or_formula, "#,##0.00"], oo.excelx_type('c',4)
4307
+ assert_equal [:numeric_or_formula, "General"], oo.excelx_type('d',4)
4308
+ assert_equal [:numeric_or_formula, "General"], oo.excelx_type('e',4)
4309
+ assert_equal :string, oo.excelx_type('f',4)
4310
+
4311
+ assert_equal "39209", oo.excelx_value('a',4)
4312
+ assert_equal "yyyy\\-mm\\-dd", oo.excelx_format('a',4)
4313
+ assert_equal "9.25", oo.excelx_value('b',4)
4314
+ assert_equal "10.25", oo.excelx_value('c',4)
4315
+ assert_equal "0", oo.excelx_value('d',4)
4316
+ #... Sum-Spalte
4317
+ # assert_equal "Task 1", oo.excelx_value('f',4)
4318
+ assert_equal "Task 1", oo.cell('f',4)
4319
+ assert_equal Date.new(2007,05,07), oo.cell('a',4)
4320
+ assert_equal "9.25", oo.excelx_value('b',4)
4321
+ assert_equal "#,##0.00", oo.excelx_format('b',4)
4322
+ assert_equal 9.25, oo.cell('b',4)
4323
+ assert_equal :float, oo.celltype('b',4)
4324
+ assert_equal :float, oo.celltype('d',4)
4325
+ assert_equal 0, oo.cell('d',4)
4326
+ assert_equal :formula, oo.celltype('e',4)
4327
+ assert_equal 1, oo.cell('e',4)
4328
+ assert_equal 'C4-B4-D4', oo.formula('e',4)
4329
+ assert_equal :string, oo.celltype('f',4)
4330
+ assert_equal "Task 1", oo.cell('f',4)
4331
+ end
4332
+ end
4333
+ end
4334
+
4335
+ def test_possible_bug_snowboard_borders
4336
+ after Date.new(2008,12,15) do
4337
+ local_only do
4338
+ if EXCEL
4339
+ ex = Excel.new(File.join(TESTDIR,'problem.xls'))
4340
+ ex.default_sheet = ex.sheets.first
4341
+ assert_equal 2, ex.first_row
4342
+ assert_equal 30, ex.last_row
4343
+ assert_equal 'A', ex.first_column_as_letter
4344
+ assert_equal 'J', ex.last_column_as_letter
4345
+ end
4346
+ if EXCELX
4347
+ ex = Excelx.new(File.join(TESTDIR,'problem.xlsx'))
4348
+ ex.default_sheet = ex.sheets.first
4349
+ assert_equal 2, ex.first_row
4350
+ assert_equal 30, ex.last_row
4351
+ assert_equal 'A', ex.first_column_as_letter
4352
+ assert_equal 'J', ex.last_column_as_letter
4353
+ end
4354
+ end
4355
+ end
4356
+ end
4357
+
4358
+ def common_possible_bug_snowboard_cells(ss)
4359
+ assert_equal "A.", ss.cell(13,'A'), ss.class
4360
+ assert_equal 147, ss.cell(13,'f'), ss.class
4361
+ assert_equal 152, ss.cell(13,'g'), ss.class
4362
+ assert_equal 156, ss.cell(13,'h'), ss.class
4363
+ assert_equal 158, ss.cell(13,'i'), ss.class
4364
+ assert_equal 160, ss.cell(13,'j'), ss.class
4365
+ assert_equal 164, ss.cell(13,'k'), ss.class
4366
+ assert_equal 168, ss.cell(13,'l'), ss.class
4367
+ assert_equal :string, ss.celltype(13,'m'), ss.class
4368
+ assert_equal "159W", ss.cell(13,'m'), ss.class
4369
+ assert_equal "164W", ss.cell(13,'n'), ss.class
4370
+ assert_equal "168W", ss.cell(13,'o'), ss.class
4371
+ end
4372
+
4373
+ def test_possible_bug_snowboard_cells
4374
+ local_only do
4375
+ after Date.new(2009,1,6) do
4376
+ # warten auf Bugfix in parseexcel
4377
+ if EXCEL
4378
+ ex = Excel.new(File.join(TESTDIR,'problem.xls'))
4379
+ ex.default_sheet = 'Custom X'
4380
+ common_possible_bug_snowboard_cells(ex)
4381
+ end
4382
+ end
4383
+ if EXCELX
4384
+ ex = Excelx.new(File.join(TESTDIR,'problem.xlsx'))
4385
+ ex.default_sheet = 'Custom X'
4386
+ common_possible_bug_snowboard_cells(ex)
4387
+ end
4388
+ end
4389
+ end
4390
+
4391
+ if EXCELX
4392
+ def test_possible_bug_2008_09_13
4393
+ local_only do
4394
+ # war nur in der 1.0.0 Release ein Fehler und sollte mit aktueller
4395
+ # Release nicht mehr auftreten.
4396
+ =begin
4397
+
4398
+ <sst count="46" uniqueCount="39">
4399
+
4400
+ 0<si>
4401
+ <t>Bond</t>
4402
+ <phoneticPr fontId="1" type="noConversion"/>
4403
+ </si>
4404
+
4405
+ 1<si>
4406
+ <t>James</t>
4407
+ <phoneticPr fontId="1" type="noConversion"/>
4408
+ </si>
4409
+
4410
+ 2<si>
4411
+ <t>8659</t>
4412
+ <phoneticPr fontId="1" type="noConversion"/>
4413
+ </si>
4414
+
4415
+ 3<si>
4416
+ <t>12B</t>
4417
+ <phoneticPr fontId="1" type="noConversion"/>
4418
+ </si>
4419
+
4420
+ 4<si>
4421
+ <t>087692</t>
4422
+ <phoneticPr fontId="1" type="noConversion"/>
4423
+ </si>
4424
+
4425
+ 5<si>
4426
+ <t>Rowe</t>
4427
+ <phoneticPr fontId="1" type="noConversion"/>
4428
+ </si>
4429
+
4430
+ 6<si>
4431
+ <t>Karl</t>
4432
+ <phoneticPr fontId="1" type="noConversion"/>
4433
+ </si>
4434
+
4435
+ 7<si>
4436
+ <t>9128</t>
4437
+ <phoneticPr fontId="1" type="noConversion"/>
4438
+ </si>
4439
+
4440
+ 8<si>
4441
+ <t>79A</t>
4442
+ <phoneticPr fontId="1" type="noConversion"/>
4443
+ </si>
4444
+
4445
+ 9<si>
4446
+ <t>Benson</t>
4447
+ <phoneticPr fontId="1" type="noConversion"/>
4448
+ </si>
4449
+
4450
+ 10<si>
4451
+ <t>Cedric</t>
4452
+ <phoneticPr fontId="1" type="noConversion"/>
4453
+ </si>
4454
+
4455
+ 11<si>
4456
+ <t>Greenstreet</t>
4457
+ <phoneticPr fontId="1" type="noConversion"/>
4458
+ </si>
4459
+
4460
+ 12<si>
4461
+ <t>Jenny</t>
4462
+ <phoneticPr fontId="1" type="noConversion"/>
4463
+ </si>
4464
+
4465
+ 13<si>
4466
+ <t>Smith</t>
4467
+ <phoneticPr fontId="1" type="noConversion"/>
4468
+ </si>
4469
+
4470
+ 14<si>
4471
+ <t>Greame</t>
4472
+ <phoneticPr fontId="1" type="noConversion"/>
4473
+ </si>
4474
+
4475
+ 15<si>
4476
+ <t>Lucas</t>
4477
+ <phoneticPr fontId="1" type="noConversion"/>
4478
+ </si>
4479
+
4480
+ 16<si>
4481
+ <t>Ward</t>
4482
+ <phoneticPr fontId="1" type="noConversion"/>
4483
+ </si>
4484
+
4485
+ 17<si>
4486
+ <t>Lee</t>
4487
+ <phoneticPr fontId="1" type="noConversion"/>
4488
+ </si>
4489
+
4490
+ 18<si>
4491
+ <t>Bret</t>
4492
+ <phoneticPr fontId="1" type="noConversion"/>
4493
+ </si>
4494
+
4495
+ 19<si>
4496
+ <t>Warne</t>
4497
+ <phoneticPr fontId="1" type="noConversion"/>
4498
+ </si>
4499
+
4500
+ 20<si>
4501
+ <t>Shane</t>
4502
+ <phoneticPr fontId="1" type="noConversion"/>
4503
+ </si>
4504
+
4505
+ 21<si>
4506
+ <t>782</t>
4507
+ <phoneticPr fontId="1" type="noConversion"/>
4508
+ </si>
4509
+
4510
+ 22<si>
4511
+ <t>876</t>
4512
+ <phoneticPr fontId="1" type="noConversion"/>
4513
+ </si>
4514
+
4515
+ 23<si>
4516
+ <t>9901</t>
4517
+ <phoneticPr fontId="1" type="noConversion"/>
4518
+ </si>
4519
+
4520
+ 24<si>
4521
+ <t>1235</t>
4522
+ <phoneticPr fontId="1" type="noConversion"/>
4523
+ </si>
4524
+
4525
+ 25<si>
4526
+ <t>16547</t>
4527
+ <phoneticPr fontId="1" type="noConversion"/>
4528
+ </si>
4529
+
4530
+ 26<si>
4531
+ <t>7789</t>
4532
+ <phoneticPr fontId="1" type="noConversion"/>
4533
+ </si>
4534
+
4535
+ 27<si>
4536
+ <t>89</t>
4537
+ <phoneticPr fontId="1" type="noConversion"/>
4538
+ </si>
4539
+
4540
+ 28<si>
4541
+ <t>12A</t>
4542
+ <phoneticPr fontId="1" type="noConversion"/>
4543
+ </si>
4544
+
4545
+ 29<si>
4546
+ <t>19A</t>
4547
+ <phoneticPr fontId="1" type="noConversion"/>
4548
+ </si>
4549
+
4550
+ 30<si>
4551
+ <t>256</t>
4552
+ <phoneticPr fontId="1" type="noConversion"/>
4553
+ </si>
4554
+
4555
+ 31<si>
4556
+ <t>129B</t>
4557
+ <phoneticPr fontId="1" type="noConversion"/>
4558
+ </si>
4559
+
4560
+ 32<si>
4561
+ <t>11</t>
4562
+ <phoneticPr fontId="1" type="noConversion"/>
4563
+ </si>
4564
+
4565
+ 33<si>
4566
+ <t>Last Name</t>
4567
+ </si>
4568
+
4569
+ 34<si>
4570
+ <t>First Name</t>
4571
+ </si>
4572
+
4573
+ 35 <si>
4574
+ <t>Middle Name</t>
4575
+ </si>
4576
+
4577
+ 36<si>
4578
+ <t>Resident ID</t>
4579
+ </si>
4580
+
4581
+ 37<si>
4582
+ <t>Room Number</t>
4583
+ </si>
4584
+
4585
+ 38<si>
4586
+ <t>Provider ID #</t>
4587
+ </si>
4588
+ </sst>
4589
+ Hello Thomas,
4590
+ How are you doing ? I am running into this strange issue with roo plugin (1.0.0). The attached
4591
+ spreadsheet has all the cells formatted as "text", when I view in the Excel spreadsheet. But when it
4592
+ get's into roo plugin (set_cell_values method - line 299), the values for the cells 1,1, 1,2, 1,3...1,6
4593
+ show as 'date' instead of 'string'.
4594
+ Because of this my parser is failing to get the proper values from the spreadsheet. Any ideas why
4595
+ the formatting is getting set to the wrong value ?
4596
+ Even stranger is if I save this file as ".XLS" and parse it the cells parse out fine as they are treated as
4597
+ 'string' instead of 'date'.
4598
+ This attached file is the newer format of Microsoft Excel (.xlsx).
4599
+
4600
+ =end
4601
+ xx = Excelx.new(File.join(TESTDIR,'sample_file_2008-09-13.xlsx'))
4602
+ assert_equal 1, xx.sheets.size
4603
+
4604
+ assert_equal 1, xx.first_row
4605
+ assert_equal 9, xx.last_row # 9 ist richtig. Es sind zwar 44 Zeilen definiert, aber der Rest hat keinen Inhalt
4606
+ assert_equal 1, xx.first_column
4607
+ assert_equal 6, xx.last_column
4608
+ assert_equal 'A', xx.first_column_as_letter
4609
+ assert_equal 'F', xx.last_column_as_letter
4610
+
4611
+ assert_nothing_raised() {
4612
+ puts xx.info
4613
+ }
4614
+ p xx.cell(1,1)
4615
+ p xx.cell(1,2)
4616
+ p xx.cell(1,3)
4617
+ p xx.cell(1,4)
4618
+ p xx.cell(1,5)
4619
+ p xx.cell(1,6)
4620
+ xx.default_sheet = xx.sheets.first
4621
+
4622
+ assert_equal 'Last Name', xx.cell('A',1)
4623
+
4624
+ 1.upto(6) do |col|
4625
+ assert_equal :string, xx.celltype(1,col)
4626
+ end
4627
+ #for col in (1..6)
4628
+ # assert_equal "1234", xx.cell(1,col)
4629
+ #end
4630
+ end
4631
+ end
4632
+ end
4633
+
4634
+ def do_datetime_tests(oo)
4635
+ val = oo.cell('c',3)
4636
+ assert_kind_of DateTime, val
4637
+ assert_equal :datetime, oo.celltype('c',3)
4638
+ assert_equal DateTime.new(1961,11,21,12,17,18), val
4639
+ val = oo.cell('a',1)
4640
+ assert_kind_of Date, val
4641
+ assert_equal :date, oo.celltype('a',1)
4642
+ assert_equal Date.new(1961,11,21), val
4643
+
4644
+ assert_equal Date.new(1961,11,21), oo.cell('a',1)
4645
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('a',3)
4646
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('b',3)
4647
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('c',3)
4648
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('a',4)
4649
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('b',4)
4650
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('c',4)
4651
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('a',5)
4652
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('b',5)
4653
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('c',5)
4654
+ assert_equal Date.new(1961,11,21), oo.cell('a',6)
4655
+ assert_equal Date.new(1961,11,21), oo.cell('b',6)
4656
+ assert_equal Date.new(1961,11,21), oo.cell('c',6)
4657
+ assert_equal Date.new(1961,11,21), oo.cell('a',7)
4658
+ assert_equal Date.new(1961,11,21), oo.cell('b',7)
4659
+ assert_equal Date.new(1961,11,21), oo.cell('c',7)
4660
+ end
4661
+
4662
+ def test_datetime_openoffice
4663
+ if OPENOFFICE
4664
+ oo = Openoffice.new(File.join(TESTDIR,"datetime.ods"))
4665
+ oo.default_sheet = oo.sheets.first
4666
+ do_datetime_tests(oo)
4667
+ end
4668
+ end
4669
+
4670
+ def test_datetime_excel
4671
+ if EXCEL
4672
+ oo = Excel.new(File.join(TESTDIR,"datetime.xls"))
4673
+ oo.default_sheet = oo.sheets.first
4674
+ do_datetime_tests(oo)
4675
+ end
4676
+ end
4677
+
4678
+ def test_datetime_excelx
4679
+ if EXCELX
4680
+ oo = Excelx.new(File.join(TESTDIR,"datetime.xlsx"))
4681
+ oo.default_sheet = oo.sheets.first
4682
+ do_datetime_tests(oo)
4683
+ end
4684
+ end
4685
+
4686
+ def test_datetime_google
4687
+ if GOOGLE
4688
+ begin
4689
+ oo = Google.new(key_of('datetime'))
4690
+ oo.default_sheet = oo.sheets.first
4691
+ do_datetime_tests(oo)
4692
+ ensure
4693
+ $log.level = Logger::WARN
4694
+ end
4695
+ end
4696
+ end
4697
+
4698
+ #-- bei diesen Test bekomme ich seltsamerweise einen Fehler can't allocate
4699
+ #-- memory innerhalb der zip-Routinen => erstmal deaktiviert
4700
+ def test_huge_table_timing_10_000_openoffice
4701
+ after Date.new(2009,1,1) do
4702
+ if OPENOFFICE
4703
+ if LONG_RUN
4704
+ assert_nothing_raised(Timeout::Error) {
4705
+ Timeout::timeout(3.minutes) do |timeout_length|
4706
+ oo = Openoffice.new("/home/tp/ruby-test/too-testing/speedtest_10000.ods")
4707
+ # process every cell
4708
+ sum = 0
4709
+ oo.sheets.each {|sheet|
4710
+ oo.default_sheet = sheet
4711
+ for row in oo.first_row..oo.last_row do
4712
+ for col in oo.first_column..oo.last_column do
4713
+ c = oo.cell(row,col)
4714
+ sum += c.length if c
4715
+ end
4716
+ end
4717
+ p sum
4718
+ assert sum > 0
4719
+ }
4720
+ end
4721
+ }
4722
+ end
4723
+ end
4724
+ end
4725
+ end
4726
+
4727
+ def test_huge_table_timing_10_000_excel
4728
+ after Date.new(2009,1,1) do
4729
+ if EXCEL
4730
+ if LONG_RUN
4731
+ assert_nothing_raised(Timeout::Error) {
4732
+ Timeout::timeout(3.minutes) do |timeout_length|
4733
+ oo = Excel.new("/home/tp/ruby-test/too-testing/speedtest_10000.xls")
4734
+ # process every cell
4735
+ sum = 0
4736
+ oo.sheets.each {|sheet|
4737
+ oo.default_sheet = sheet
4738
+ for row in oo.first_row..oo.last_row do
4739
+ for col in oo.first_column..oo.last_column do
4740
+ c = oo.cell(row,col)
4741
+ sum += c.length if c
4742
+ end
4743
+ end
4744
+ p sum
4745
+ assert sum > 0
4746
+ }
4747
+ end
4748
+ }
4749
+ end
4750
+ end
4751
+ end
4752
+ end
4753
+
4754
+ def test_huge_table_timing_10_000_google
4755
+ after Date.new(2009,1,1) do
4756
+ if GOOGLE
4757
+ if LONG_RUN
4758
+ assert_nothing_raised(Timeout::Error) {
4759
+ Timeout::timeout(3.minutes) do |timeout_length|
4760
+ oo = Excel.new(key_of("/home/tp/ruby-test/too-testing/speedtest_10000.xls"))
4761
+ # process every cell
4762
+ sum = 0
4763
+ oo.sheets.each {|sheet|
4764
+ oo.default_sheet = sheet
4765
+ for row in oo.first_row..oo.last_row do
4766
+ for col in oo.first_column..oo.last_column do
4767
+ c = oo.cell(row,col)
4768
+ sum += c.length if c
4769
+ end
4770
+ end
4771
+ p sum
4772
+ assert sum > 0
4773
+ }
4774
+ end
4775
+ }
4776
+ end
4777
+ end
4778
+ end
4779
+ end
4780
+
4781
+ def test_huge_table_timing_10_000_excelx
4782
+ after Date.new(2009,1,1) do
4783
+ if EXCELX
4784
+ if LONG_RUN
4785
+ assert_nothing_raised(Timeout::Error) {
4786
+ Timeout::timeout(3.minutes) do |timeout_length|
4787
+ oo = Excelx.new("/home/tp/ruby-test/too-testing/speedtest_10000.xlsx")
4788
+ # process every cell
4789
+ sum = 0
4790
+ oo.sheets.each {|sheet|
4791
+ oo.default_sheet = sheet
4792
+ for row in oo.first_row..oo.last_row do
4793
+ for col in oo.first_column..oo.last_column do
4794
+ c = oo.cell(row,col)
4795
+ sum += c.length if c
4796
+ end
4797
+ end
4798
+ p sum
4799
+ assert sum > 0
4800
+ }
4801
+ end
4802
+ }
4803
+ end
4804
+ end
4805
+ end
4806
+ end
4807
+
4808
+ # Eine Spreadsheetdatei wird nicht als Dateiname sondern direkt als Dokument
4809
+ # geoeffnettest_problemx_csv_imported
4810
+ def SKIP_test_from_stream_openoffice
4811
+ after Date.new(2009,1,6) do
4812
+ if OPENOFFICE
4813
+ filecontent = nil
4814
+ File.open(File.join(TESTDIR,"numbers1.ods")) do |f|
4815
+ filecontent = f.read
4816
+ p filecontent.class
4817
+ p filecontent.size
4818
+ #p filecontent
4819
+ assert filecontent.size > 0
4820
+ # #stream macht das gleiche wie #new liest abe aus Stream anstatt Datei
4821
+ oo = Openoffice.stream(filecontent)
4822
+ end
4823
+ #oo = Openoffice.open()
4824
+ end
4825
+ end
4826
+ end
4827
+
4828
+
4829
+ def SKIP_test_bug_encoding_exported_from_google
4830
+ if EXCEL
4831
+ xl = Excel.new(File.join(TESTDIR,"numbers1_from_google.xls"))
4832
+ xl.default_sheet = xl.sheets.first
4833
+ assert_equal 'test', xl.cell(2,'F')
4834
+ end
4835
+ end
4836
+
4837
+ def test_cell_openoffice_html_escape
4838
+ if OPENOFFICE
4839
+ oo = Openoffice.new(File.join(TESTDIR,"html-escape.ods"))
4840
+ oo.default_sheet = oo.sheets.first
4841
+ assert_equal "'", oo.cell(1,1)
4842
+ assert_equal "&", oo.cell(2,1)
4843
+ assert_equal ">", oo.cell(3,1)
4844
+ assert_equal "<", oo.cell(4,1)
4845
+ assert_equal "`", oo.cell(5,1)
4846
+ # test_openoffice_zipped catches the &quot;
4847
+ end
4848
+ end
4849
+
4850
+ def test_cell_excel_boolean
4851
+ if EXCEL
4852
+ oo = Excel.new(File.join(TESTDIR,"boolean.xls"))
4853
+ oo.default_sheet = oo.sheets.first
4854
+ assert_equal "true", oo.cell(1,1)
4855
+ assert_equal "false", oo.cell(2,1)
4856
+ end
4857
+ if OPENOFFICE
4858
+ oo = Openoffice.new(File.join(TESTDIR,"boolean.ods"))
4859
+ oo.default_sheet = oo.sheets.first
4860
+ assert_equal "true", oo.cell(1,1)
4861
+ assert_equal "false", oo.cell(2,1)
4862
+ end
4863
+ if EXCELX
4864
+ oo = Excelx.new(File.join(TESTDIR,"boolean.xlsx"))
4865
+ oo.default_sheet = oo.sheets.first
4866
+ assert_equal "TRUE", oo.cell(1,1)
4867
+ assert_equal "FALSE", oo.cell(2,1)
4868
+ end
4869
+ end
4870
+
4871
+ # for test_cell_styles
4872
+ def verify_cell_fonts(oo)
4873
+ oo.default_sheet = oo.sheets.first
4874
+
4875
+ # bold
4876
+ assert_equal true, oo.font(1,1).bold?
4877
+ assert_equal false, oo.font(1,1).italic?
4878
+ assert_equal false, oo.font(1,1).underline?
4879
+
4880
+ # italic
4881
+ assert_equal false, oo.font(2,1).bold?
4882
+ assert_equal true, oo.font(2,1).italic?
4883
+ assert_equal false, oo.font(2,1).underline?
4884
+
4885
+ # normal
4886
+ assert_equal false, oo.font(3,1).bold?
4887
+ assert_equal false, oo.font(3,1).italic?
4888
+ assert_equal false, oo.font(3,1).underline?
4889
+
4890
+ # underline
4891
+ assert_equal false, oo.font(4,1).bold?
4892
+ assert_equal false, oo.font(4,1).italic?
4893
+ assert_equal true, oo.font(4,1).underline?
4894
+
4895
+ # bold italic
4896
+ assert_equal true, oo.font(5,1).bold?
4897
+ assert_equal true, oo.font(5,1).italic?
4898
+ assert_equal false, oo.font(5,1).underline?
4899
+
4900
+ # bold underline
4901
+ assert_equal true, oo.font(6,1).bold?
4902
+ assert_equal false, oo.font(6,1).italic?
4903
+ assert_equal true, oo.font(6,1).underline?
4904
+
4905
+ # italic underline
4906
+ assert_equal false, oo.font(7,1).bold?
4907
+ assert_equal true, oo.font(7,1).italic?
4908
+ assert_equal true, oo.font(7,1).underline?
4909
+
4910
+ # bolded row
4911
+ assert_equal true, oo.font(8,1).bold?
4912
+ assert_equal false, oo.font(8,1).italic?
4913
+ assert_equal false, oo.font(8,1).underline?
4914
+
4915
+ # bolded col
4916
+ assert_equal true, oo.font(9,2).bold?
4917
+ assert_equal false, oo.font(9,2).italic?
4918
+ assert_equal false, oo.font(9,2).underline?
4919
+
4920
+ # bolded row, italic col
4921
+ assert_equal true, oo.font(10,3).bold?
4922
+ assert_equal true, oo.font(10,3).italic?
4923
+ assert_equal false, oo.font(10,3).underline?
4924
+
4925
+ # normal
4926
+ assert_equal false, oo.font(11,4).bold?
4927
+ assert_equal false, oo.font(11,4).italic?
4928
+ assert_equal false, oo.font(11,4).underline?
4929
+ end
4930
+
4931
+ def test_cell_styles
4932
+ if OPENOFFICE
4933
+ oo = Openoffice.new(File.join(TESTDIR,"style.ods"))
4934
+ verify_cell_fonts(oo)
4935
+ end
4936
+ if EXCELX
4937
+ oo = Excelx.new(File.join(TESTDIR,"style.xlsx"))
4938
+ verify_cell_fonts(oo)
4939
+ end
4940
+ if EXCEL
4941
+ oo = Excel.new(File.join(TESTDIR,"style.xls"))
4942
+ verify_cell_fonts(oo)
4943
+ end
4944
+ end
4945
+
4946
+ end # class