roo 1.13.2 → 2.0.0beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -0
  3. data/.simplecov +4 -0
  4. data/.travis.yml +13 -0
  5. data/CHANGELOG +21 -0
  6. data/Gemfile +16 -10
  7. data/Guardfile +24 -0
  8. data/LICENSE +3 -1
  9. data/README.md +254 -0
  10. data/Rakefile +23 -23
  11. data/examples/roo_soap_client.rb +28 -31
  12. data/examples/roo_soap_server.rb +4 -6
  13. data/examples/write_me.rb +9 -10
  14. data/lib/roo.rb +18 -24
  15. data/lib/roo/base.rb +303 -388
  16. data/lib/roo/csv.rb +120 -113
  17. data/lib/roo/excelx.rb +452 -484
  18. data/lib/roo/excelx/comments.rb +24 -0
  19. data/lib/roo/excelx/extractor.rb +20 -0
  20. data/lib/roo/excelx/relationships.rb +26 -0
  21. data/lib/roo/excelx/shared_strings.rb +40 -0
  22. data/lib/roo/excelx/sheet_doc.rb +202 -0
  23. data/lib/roo/excelx/styles.rb +62 -0
  24. data/lib/roo/excelx/workbook.rb +59 -0
  25. data/lib/roo/font.rb +17 -0
  26. data/lib/roo/libre_office.rb +5 -0
  27. data/lib/roo/link.rb +15 -0
  28. data/lib/roo/{openoffice.rb → open_office.rb} +678 -496
  29. data/lib/roo/spreadsheet.rb +20 -23
  30. data/lib/roo/utils.rb +78 -0
  31. data/lib/roo/version.rb +3 -0
  32. data/roo.gemspec +20 -204
  33. data/spec/lib/roo/base_spec.rb +1 -4
  34. data/spec/lib/roo/csv_spec.rb +21 -13
  35. data/spec/lib/roo/excelx/format_spec.rb +7 -6
  36. data/spec/lib/roo/excelx_spec.rb +388 -11
  37. data/spec/lib/roo/libreoffice_spec.rb +16 -6
  38. data/spec/lib/roo/openoffice_spec.rb +2 -8
  39. data/spec/lib/roo/spreadsheet_spec.rb +40 -12
  40. data/spec/lib/roo/utils_spec.rb +106 -0
  41. data/spec/spec_helper.rb +2 -1
  42. data/test/test_generic_spreadsheet.rb +19 -67
  43. data/test/test_helper.rb +9 -56
  44. data/test/test_roo.rb +252 -477
  45. metadata +63 -302
  46. data/Gemfile.lock +0 -78
  47. data/README.markdown +0 -126
  48. data/VERSION +0 -1
  49. data/lib/roo/excel.rb +0 -355
  50. data/lib/roo/excel2003xml.rb +0 -300
  51. data/lib/roo/google.rb +0 -292
  52. data/lib/roo/roo_rails_helper.rb +0 -83
  53. data/lib/roo/worksheet.rb +0 -18
  54. data/spec/lib/roo/excel2003xml_spec.rb +0 -15
  55. data/spec/lib/roo/excel_spec.rb +0 -17
  56. data/spec/lib/roo/google_spec.rb +0 -64
  57. data/test/files/1900_base.xls +0 -0
  58. data/test/files/1900_base.xlsx +0 -0
  59. data/test/files/1904_base.xls +0 -0
  60. data/test/files/1904_base.xlsx +0 -0
  61. data/test/files/Bibelbund.csv +0 -3741
  62. data/test/files/Bibelbund.ods +0 -0
  63. data/test/files/Bibelbund.xls +0 -0
  64. data/test/files/Bibelbund.xlsx +0 -0
  65. data/test/files/Bibelbund.xml +0 -62518
  66. data/test/files/Bibelbund1.ods +0 -0
  67. data/test/files/Pfand_from_windows_phone.xlsx +0 -0
  68. data/test/files/bad_excel_date.xls +0 -0
  69. data/test/files/bbu.ods +0 -0
  70. data/test/files/bbu.xls +0 -0
  71. data/test/files/bbu.xlsx +0 -0
  72. data/test/files/bbu.xml +0 -152
  73. data/test/files/bode-v1.ods.zip +0 -0
  74. data/test/files/bode-v1.xls.zip +0 -0
  75. data/test/files/boolean.csv +0 -2
  76. data/test/files/boolean.ods +0 -0
  77. data/test/files/boolean.xls +0 -0
  78. data/test/files/boolean.xlsx +0 -0
  79. data/test/files/boolean.xml +0 -112
  80. data/test/files/borders.ods +0 -0
  81. data/test/files/borders.xls +0 -0
  82. data/test/files/borders.xlsx +0 -0
  83. data/test/files/borders.xml +0 -144
  84. data/test/files/bug-numbered-sheet-names.xlsx +0 -0
  85. data/test/files/bug-row-column-fixnum-float.xls +0 -0
  86. data/test/files/bug-row-column-fixnum-float.xml +0 -127
  87. data/test/files/comments.ods +0 -0
  88. data/test/files/comments.xls +0 -0
  89. data/test/files/comments.xlsx +0 -0
  90. data/test/files/csvtypes.csv +0 -1
  91. data/test/files/datetime.ods +0 -0
  92. data/test/files/datetime.xls +0 -0
  93. data/test/files/datetime.xlsx +0 -0
  94. data/test/files/datetime.xml +0 -142
  95. data/test/files/datetime_floatconv.xls +0 -0
  96. data/test/files/datetime_floatconv.xml +0 -148
  97. data/test/files/dreimalvier.ods +0 -0
  98. data/test/files/emptysheets.ods +0 -0
  99. data/test/files/emptysheets.xls +0 -0
  100. data/test/files/emptysheets.xlsx +0 -0
  101. data/test/files/emptysheets.xml +0 -105
  102. data/test/files/excel2003.xml +0 -21140
  103. data/test/files/false_encoding.xls +0 -0
  104. data/test/files/false_encoding.xml +0 -132
  105. data/test/files/file_item_error.xlsx +0 -0
  106. data/test/files/formula.ods +0 -0
  107. data/test/files/formula.xls +0 -0
  108. data/test/files/formula.xlsx +0 -0
  109. data/test/files/formula.xml +0 -134
  110. data/test/files/formula_parse_error.xls +0 -0
  111. data/test/files/formula_parse_error.xml +0 -1833
  112. data/test/files/formula_string_error.xlsx +0 -0
  113. data/test/files/html-escape.ods +0 -0
  114. data/test/files/link.xls +0 -0
  115. data/test/files/link.xlsx +0 -0
  116. data/test/files/matrix.ods +0 -0
  117. data/test/files/matrix.xls +0 -0
  118. data/test/files/named_cells.ods +0 -0
  119. data/test/files/named_cells.xls +0 -0
  120. data/test/files/named_cells.xlsx +0 -0
  121. data/test/files/no_spreadsheet_file.txt +0 -1
  122. data/test/files/numbers1.csv +0 -18
  123. data/test/files/numbers1.ods +0 -0
  124. data/test/files/numbers1.xls +0 -0
  125. data/test/files/numbers1.xlsx +0 -0
  126. data/test/files/numbers1.xml +0 -312
  127. data/test/files/numeric-link.xlsx +0 -0
  128. data/test/files/only_one_sheet.ods +0 -0
  129. data/test/files/only_one_sheet.xls +0 -0
  130. data/test/files/only_one_sheet.xlsx +0 -0
  131. data/test/files/only_one_sheet.xml +0 -67
  132. data/test/files/paragraph.ods +0 -0
  133. data/test/files/paragraph.xls +0 -0
  134. data/test/files/paragraph.xlsx +0 -0
  135. data/test/files/paragraph.xml +0 -127
  136. data/test/files/prova.xls +0 -0
  137. data/test/files/ric.ods +0 -0
  138. data/test/files/simple_spreadsheet.ods +0 -0
  139. data/test/files/simple_spreadsheet.xls +0 -0
  140. data/test/files/simple_spreadsheet.xlsx +0 -0
  141. data/test/files/simple_spreadsheet.xml +0 -225
  142. data/test/files/simple_spreadsheet_from_italo.ods +0 -0
  143. data/test/files/simple_spreadsheet_from_italo.xls +0 -0
  144. data/test/files/simple_spreadsheet_from_italo.xml +0 -242
  145. data/test/files/so_datetime.csv +0 -7
  146. data/test/files/style.ods +0 -0
  147. data/test/files/style.xls +0 -0
  148. data/test/files/style.xlsx +0 -0
  149. data/test/files/style.xml +0 -154
  150. data/test/files/time-test.csv +0 -2
  151. data/test/files/time-test.ods +0 -0
  152. data/test/files/time-test.xls +0 -0
  153. data/test/files/time-test.xlsx +0 -0
  154. data/test/files/time-test.xml +0 -131
  155. data/test/files/type_excel.ods +0 -0
  156. data/test/files/type_excel.xlsx +0 -0
  157. data/test/files/type_excelx.ods +0 -0
  158. data/test/files/type_excelx.xls +0 -0
  159. data/test/files/type_openoffice.xls +0 -0
  160. data/test/files/type_openoffice.xlsx +0 -0
  161. data/test/files/whitespace.ods +0 -0
  162. data/test/files/whitespace.xls +0 -0
  163. data/test/files/whitespace.xlsx +0 -0
  164. data/test/files/whitespace.xml +0 -184
  165. data/test/rm_sub_test.rb +0 -12
  166. data/test/rm_test.rb +0 -7
  167. data/website/index.html +0 -385
  168. data/website/index.txt +0 -423
  169. data/website/javascripts/rounded_corners_lite.inc.js +0 -285
  170. data/website/stylesheets/screen.css +0 -130
  171. data/website/template.rhtml +0 -48
@@ -17,38 +17,32 @@
17
17
  # with the wrong spreadsheet class
18
18
  #STDERR.reopen "/dev/null","w"
19
19
 
20
- require File.dirname(__FILE__) + '/test_helper'
20
+ require 'test_helper'
21
21
 
22
- class TestRoo < Test::Unit::TestCase
22
+ class TestRoo < Minitest::Test
23
23
 
24
- OPENOFFICE = true # do OpenOffice-Spreadsheet Tests? (.ods files)
25
- EXCEL = true # do Excel Tests? (.xls files)
26
- GOOGLE = false # do Google-Spreadsheet Tests?
27
- EXCELX = true # do Excelx Tests? (.xlsx files)
28
- LIBREOFFICE = true # do LibreOffice tests? (.ods files)
29
- CSV = true # do CSV tests? (.csv files)
24
+ OPENOFFICE = true # do OpenOffice-Spreadsheet Tests? (.ods files)
25
+ EXCELX = true # do Excelx Tests? (.xlsx files)
26
+ LIBREOFFICE = true # do LibreOffice tests? (.ods files)
27
+ CSV = true # do CSV tests? (.csv files)
30
28
 
31
- FORMATS = {
32
- excel: EXCEL,
33
- excelx: EXCELX,
34
- openoffice: OPENOFFICE,
35
- google: GOOGLE,
36
- libreoffice: LIBREOFFICE
37
- }
29
+ FORMATS = [
30
+ :excelx,
31
+ :openoffice,
32
+ :libreoffice
33
+ ]
38
34
 
39
35
  ONLINE = false
40
36
  LONG_RUN = false
41
37
 
42
38
  def fixture_filename(name, format)
43
39
  case format
44
- when :excel
45
- "#{name}.xls"
46
40
  when :excelx
47
41
  "#{name}.xlsx"
48
42
  when :openoffice, :libreoffice
49
43
  "#{name}.ods"
50
- when :google
51
- key_of(name)
44
+ else
45
+ raise ArgumentError, "unexpected format #{format}"
52
46
  end
53
47
  end
54
48
 
@@ -56,48 +50,30 @@ class TestRoo < Test::Unit::TestCase
56
50
  # and yield a reference to the roo object
57
51
  def with_each_spreadsheet(options)
58
52
  if options[:format]
59
- options[:format] = Array(options[:format])
60
- invalid_formats = options[:format] - FORMATS.keys
53
+ formats = Array(options[:format])
54
+ invalid_formats = formats - FORMATS
61
55
  unless invalid_formats.empty?
62
56
  raise "invalid spreadsheet types: #{invalid_formats.join(', ')}"
63
57
  end
64
58
  else
65
- options[:format] = FORMATS.keys
59
+ formats = FORMATS
66
60
  end
67
- options[:format].each do |format|
61
+ formats.each do |format|
68
62
  begin
69
- if FORMATS[format]
70
- yield Roo::Spreadsheet.open(File.join(TESTDIR,
71
- fixture_filename(options[:name], format)))
72
- end
63
+ yield Roo::Spreadsheet.open(File.join(TESTDIR,
64
+ fixture_filename(options[:name], format)))
73
65
  rescue => e
74
66
  raise e, "#{e.message} for #{format}", e.backtrace
75
67
  end
76
68
  end
77
69
  end
78
70
 
79
- # Using Date.strptime so check that it's using the method
80
- # with the value set in date_format
81
- def test_date
82
- with_each_spreadsheet(:name=>'numbers1', :format=>:google) do |oo|
83
- # should default to DDMMYYYY
84
- assert oo.date?("21/11/1962")
85
- assert !oo.date?("11/21/1962")
86
- oo.date_format = '%m/%d/%Y'
87
- assert !oo.date?("21/11/1962")
88
- assert oo.date?("11/21/1962")
89
- oo.date_format = '%Y-%m-%d'
90
- assert(oo.date?("1962-11-21"))
91
- assert(!oo.date?("1962-21-11"))
92
- end
93
- end
94
-
95
71
  def test_sheets_csv
96
72
  if CSV
97
73
  oo = Roo::CSV.new(File.join(TESTDIR,'numbers1.csv'))
98
74
  assert_equal ["default"], oo.sheets
99
- assert_raise(RangeError) { oo.default_sheet = "no_sheet" }
100
- assert_raise(TypeError) { oo.default_sheet = [1,2,3] }
75
+ assert_raises(RangeError) { oo.default_sheet = "no_sheet" }
76
+ assert_raises(TypeError) { oo.default_sheet = [1,2,3] }
101
77
  oo.sheets.each { |sh|
102
78
  oo.default_sheet = sh
103
79
  assert_equal sh, oo.default_sheet
@@ -108,8 +84,8 @@ class TestRoo < Test::Unit::TestCase
108
84
  def test_sheets
109
85
  with_each_spreadsheet(:name=>'numbers1') do |oo|
110
86
  assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets
111
- assert_raise(RangeError) { oo.default_sheet = "no_sheet" }
112
- assert_raise(TypeError) { oo.default_sheet = [1,2,3] }
87
+ assert_raises(RangeError) { oo.default_sheet = "no_sheet" }
88
+ assert_raises(TypeError) { oo.default_sheet = [1,2,3] }
113
89
  oo.sheets.each { |sh|
114
90
  oo.default_sheet = sh
115
91
  assert_equal sh, oo.default_sheet
@@ -168,8 +144,8 @@ class TestRoo < Test::Unit::TestCase
168
144
  assert_equal "tata", oo.cell('A',6)
169
145
  assert_equal "tata", oo.cell(6,'a')
170
146
  assert_equal "tata", oo.cell('a',6)
171
- assert_raise(ArgumentError) { assert_equal "tata", oo.cell('a','f') }
172
- assert_raise(ArgumentError) { assert_equal "tata", oo.cell('f','a') }
147
+ assert_raises(ArgumentError) { assert_equal "tata", oo.cell('a','f') }
148
+ assert_raises(ArgumentError) { assert_equal "tata", oo.cell('f','a') }
173
149
  assert_equal "thisisc8", oo.cell(8,3)
174
150
  assert_equal "thisisc8", oo.cell(8,'C')
175
151
  assert_equal "thisisc8", oo.cell('C',8)
@@ -198,27 +174,22 @@ class TestRoo < Test::Unit::TestCase
198
174
  with_each_spreadsheet(:name=>'numbers1') do |oo|
199
175
  oo.default_sheet = "Name of Sheet 2"
200
176
  assert_equal 'I am sheet 2', oo.cell('C',5)
201
- assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
202
- assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
203
- assert_raise(RangeError) { oo.cell('C',5,"non existing sheet name")}
204
- assert_raise(RangeError) { oo.celltype('C',5,"non existing sheet name")}
205
- assert_raise(RangeError) { oo.empty?('C',5,"non existing sheet name")}
206
- if oo.class == Roo::Excel
207
- assert_raise(NotImplementedError) { oo.formula?('C',5,"non existing sheet name")}
208
- assert_raise(NotImplementedError) { oo.formula('C',5,"non existing sheet name")}
209
- else
210
- assert_raise(RangeError) { oo.formula?('C',5,"non existing sheet name")}
211
- assert_raise(RangeError) { oo.formula('C',5,"non existing sheet name")}
212
- assert_raise(RangeError) { oo.set('C',5,42,"non existing sheet name")}
213
- assert_raise(RangeError) { oo.formulas("non existing sheet name")}
214
- end
215
- assert_raise(RangeError) { oo.to_yaml({},1,1,1,1,"non existing sheet name")}
177
+ assert_raises(RangeError) { oo.default_sheet = "non existing sheet name" }
178
+ assert_raises(RangeError) { oo.default_sheet = "non existing sheet name" }
179
+ assert_raises(RangeError) { oo.cell('C',5,"non existing sheet name")}
180
+ assert_raises(RangeError) { oo.celltype('C',5,"non existing sheet name")}
181
+ assert_raises(RangeError) { oo.empty?('C',5,"non existing sheet name")}
182
+ assert_raises(RangeError) { oo.formula?('C',5,"non existing sheet name")}
183
+ assert_raises(RangeError) { oo.formula('C',5,"non existing sheet name")}
184
+ assert_raises(RangeError) { oo.set('C',5,42,"non existing sheet name")}
185
+ assert_raises(RangeError) { oo.formulas("non existing sheet name")}
186
+ assert_raises(RangeError) { oo.to_yaml({},1,1,1,1,"non existing sheet name")}
216
187
  end
217
188
  end
218
189
 
219
190
  def test_argument_error
220
191
  with_each_spreadsheet(:name=>'numbers1') do |oo|
221
- assert_nothing_raised(ArgumentError) { oo.default_sheet = "Tabelle1" }
192
+ oo.default_sheet = "Tabelle1"
222
193
  end
223
194
  end
224
195
 
@@ -245,7 +216,7 @@ class TestRoo < Test::Unit::TestCase
245
216
  end
246
217
 
247
218
  def test_italo_table
248
- with_each_spreadsheet(:name=>'simple_spreadsheet_from_italo', :format=>[:openoffice, :excel]) do |oo|
219
+ with_each_spreadsheet(:name=>'simple_spreadsheet_from_italo', :format=>:openoffice) do |oo|
249
220
  assert_equal '1', oo.cell('A',1)
250
221
  assert_equal '1', oo.cell('B',1)
251
222
  assert_equal '1', oo.cell('C',1)
@@ -324,41 +295,12 @@ class TestRoo < Test::Unit::TestCase
324
295
  end
325
296
  end
326
297
 
327
- def test_formula_google
328
- with_each_spreadsheet(:name=>'formula', :format=>:google) do |oo|
329
- oo.default_sheet = oo.sheets.first
330
- assert_equal 1, oo.cell('A',1)
331
- assert_equal 2, oo.cell('A',2)
332
- assert_equal 3, oo.cell('A',3)
333
- assert_equal 4, oo.cell('A',4)
334
- assert_equal 5, oo.cell('A',5)
335
- assert_equal 6, oo.cell('A',6)
336
- # assert_equal 21, oo.cell('A',7)
337
- assert_equal 21.0, oo.cell('A',7) #TODO: better solution Fixnum/Float
338
- assert_equal :formula, oo.celltype('A',7)
339
- # assert_equal "=[Sheet2.A1]", oo.formula('C',7)
340
- # !!! different from formulas in OpenOffice
341
- #was: assert_equal "=sheet2!R[-6]C[-2]", oo.formula('C',7)
342
- # has Google changed their format of formulas/references to other sheets?
343
- assert_equal "=Sheet2!R[-6]C[-2]", oo.formula('C',7)
344
- assert_nil oo.formula('A',6)
345
- # assert_equal [[7, 1, "=SUM([.A1:.A6])"],
346
- # [7, 2, "=SUM([.$A$1:.B6])"],
347
- # [7, 3, "=[Sheet2.A1]"],
348
- # [8, 2, "=SUM([.$A$1:.B7])"],
349
- # ], oo.formulas(oo.sheets.first)
350
- # different format than in openoffice spreadsheets:
351
- #was:
352
- # assert_equal [[7, 1, "=SUM(R[-6]C[0]:R[-1]C[0])"],
353
- # [7, 2, "=SUM(R1C1:R[-1]C[0])"],
354
- # [7, 3, "=sheet2!R[-6]C[-2]"],
355
- # [8, 2, "=SUM(R1C1:R[-1]C[0])"]],
356
- # oo.formulas(oo.sheets.first)
357
- assert_equal [[7, 1, "=SUM(R[-6]C:R[-1]C)"],
358
- [7, 2, "=SUM(R1C1:R[-1]C)"],
359
- [7, 3, "=Sheet2!R[-6]C[-2]"],
360
- [8, 2, "=SUM(R1C1:R[-1]C)"]],
361
- oo.formulas(oo.sheets.first)
298
+ def test_header_with_brackets_excelx
299
+ with_each_spreadsheet(:name => 'advanced_header', :format => :openoffice) do |oo|
300
+ parsed_head = oo.parse(:headers => true)
301
+ assert_equal "Date(yyyy-mm-dd)", oo.cell('A',1)
302
+ assert_equal parsed_head[0].keys, ["Date(yyyy-mm-dd)"]
303
+ assert_equal parsed_head[0].values, ["Date(yyyy-mm-dd)"]
362
304
  end
363
305
  end
364
306
 
@@ -397,14 +339,6 @@ class TestRoo < Test::Unit::TestCase
397
339
  end
398
340
  end
399
341
 
400
- # Excel can only read the cell's value
401
- def test_formula_excel
402
- with_each_spreadsheet(:name=>'formula', :format=>:excel) do |oo|
403
- assert_equal 21, oo.cell('A',7)
404
- assert_equal 21, oo.cell('B',7)
405
- end
406
- end
407
-
408
342
  def test_borders_sheets
409
343
  with_each_spreadsheet(:name=>'borders') do |oo|
410
344
  oo.default_sheet = oo.sheets[1]
@@ -439,43 +373,22 @@ class TestRoo < Test::Unit::TestCase
439
373
  end
440
374
  end
441
375
 
442
- def test_excel_download_uri_and_zipped
443
- if EXCEL
444
- if ONLINE
445
- url = 'http://stiny-leonhard.de/bode-v1.xls.zip'
446
- excel = Roo::Excel.new(url, :zip)
447
- excel.default_sheet = excel.sheets.first
448
- assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
449
- end
450
- end
451
- end
452
-
453
376
  def test_openoffice_download_uri_and_zipped
454
377
  if OPENOFFICE
455
378
  if ONLINE
456
379
  url = 'http://spazioinwind.libero.it/s2/rata.ods.zip'
457
- sheet = Roo::OpenOffice.new(url, :zip)
380
+ sheet = Roo::OpenOffice.new(url, packed: :zip)
458
381
  #has been changed: assert_equal 'ist "e" im Nenner von H(s)', sheet.cell('b', 5)
459
382
  assert_in_delta 0.001, 505.14, sheet.cell('c', 33).to_f
460
383
  end
461
384
  end
462
385
  end
463
386
 
464
- def test_excel_zipped
465
- if EXCEL
466
- oo = Roo::Excel.new(File.join(TESTDIR,"bode-v1.xls.zip"), :zip)
467
- assert oo
468
- assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
469
- end
470
- end
471
-
472
387
  def test_openoffice_zipped
473
388
  if OPENOFFICE
474
- begin
475
- oo = Roo::OpenOffice.new(File.join(TESTDIR,"bode-v1.ods.zip"), :zip)
476
- assert oo
477
- assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
478
- end
389
+ oo = Roo::OpenOffice.new(File.join(TESTDIR,"bode-v1.ods.zip"), packed: :zip)
390
+ assert oo
391
+ assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
479
392
  end
480
393
  end
481
394
 
@@ -543,7 +456,6 @@ class TestRoo < Test::Unit::TestCase
543
456
  if LONG_RUN
544
457
  with_each_spreadsheet(:name=>'Bibelbund', :format=>[
545
458
  :openoffice,
546
- :excel,
547
459
  :excelx
548
460
  # Google hier nicht, weil Google-Spreadsheets nicht so gross werden
549
461
  # duerfen
@@ -564,9 +476,7 @@ class TestRoo < Test::Unit::TestCase
564
476
 
565
477
  def test_bug_quotes_excelx
566
478
  if LONG_RUN
567
- with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
568
- :excel,
569
- :excelx]) do |oo|
479
+ with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice, :excelx]) do |oo|
570
480
  oo.default_sheet = oo.sheets.first
571
481
  assert_equal 'Einflüsse der neuen Theologie in "de gereformeerde Kerken van Nederland"',
572
482
  oo.cell('a',76)
@@ -662,7 +572,7 @@ class TestRoo < Test::Unit::TestCase
662
572
  with_each_spreadsheet(:name=>'formula', :format=>[:openoffice, :excelx]) do |oo|
663
573
  oo.default_sheet = 'Sheet3' # is an empty sheet
664
574
  Dir.mktmpdir do |tempdir|
665
- assert_nothing_raised() { oo.to_csv(File.join(tempdir,"emptysheet.csv")) }
575
+ oo.to_csv(File.join(tempdir,"emptysheet.csv"))
666
576
  assert_equal "", `cat #{File.join(tempdir,"emptysheet.csv")}`
667
577
  end
668
578
  end
@@ -670,9 +580,7 @@ class TestRoo < Test::Unit::TestCase
670
580
 
671
581
  def test_find_by_row_huge_document
672
582
  if LONG_RUN
673
- with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
674
- :excel,
675
- :excelx]) do |oo|
583
+ with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice, :excelx]) do |oo|
676
584
  oo.default_sheet = oo.sheets.first
677
585
  rec = oo.find 20
678
586
  assert rec
@@ -702,10 +610,23 @@ class TestRoo < Test::Unit::TestCase
702
610
  end
703
611
  end
704
612
 
613
+ def test_find_by_row_if_header_line_is_not_nil
614
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
615
+ oo.header_line = 2
616
+ refute_nil oo.header_line
617
+ rec = oo.find 1
618
+ assert rec
619
+ assert_equal 5, rec[0]
620
+ assert_equal 6, rec[1]
621
+ rec = oo.find 15
622
+ assert rec
623
+ assert_equal "einundvierzig", rec[0]
624
+ end
625
+ end
626
+
705
627
  def test_find_by_conditions
706
628
  if LONG_RUN
707
629
  with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
708
- :excel,
709
630
  :excelx]) do |oo|
710
631
  #-----------------------------------------------------------------
711
632
  zeilen = oo.find(:all, :conditions => {
@@ -817,7 +738,6 @@ class TestRoo < Test::Unit::TestCase
817
738
  def test_column_huge_document
818
739
  if LONG_RUN
819
740
  with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
820
- :excel,
821
741
  :excelx]) do |oo|
822
742
  oo.default_sheet = oo.sheets.first
823
743
  assert_equal 3735, oo.column('a').size
@@ -835,67 +755,17 @@ class TestRoo < Test::Unit::TestCase
835
755
  assert_equal 10.75 , erg[1]['Start time']
836
756
  assert_equal 12.50 , erg[1]['End time']
837
757
  assert_equal 0 , erg[1]['Pause']
838
- assert_equal 1.75 , erg[1]['Sum'] unless oo.class == Roo::Excel
758
+ assert_equal 1.75 , erg[1]['Sum']
839
759
  assert_equal "Task 1" , erg[1]['Comment']
840
760
  end
841
761
  end
842
762
 
843
- # Ruby-spreadsheet now allows us to at least give the current value
844
- # from a cell with a formula (no possible with parseexcel)
845
- def test_bug_false_borders_with_formulas
846
- with_each_spreadsheet(:name=>'false_encoding', :format=>:excel) do |oo|
847
- assert_equal 1, oo.first_row
848
- assert_equal 3, oo.last_row
849
- assert_equal 1, oo.first_column
850
- assert_equal 4, oo.last_column
851
- end
852
- end
853
-
854
- # We'ce added minimal formula support so we can now read these
855
- # though not sure how the spreadsheet reports older values....
856
- def test_fe
857
- with_each_spreadsheet(:name=>'false_encoding', :format=>:excel) do |oo|
858
- assert_equal Date.new(2007,11,1), oo.cell('a',1)
859
- #DOES NOT WORK IN EXCEL FILES: assert_equal true, oo.formula?('a',1)
860
- #DOES NOT WORK IN EXCEL FILES: assert_equal '=TODAY()', oo.formula('a',1)
861
-
862
- assert_equal Date.new(2008,2,9), oo.cell('B',1)
863
- #DOES NOT WORK IN EXCEL FILES: assert_equal true, oo.formula?('B',1)
864
- #DOES NOT WORK IN EXCEL FILES: assert_equal "=A1+100", oo.formula('B',1)
865
-
866
- assert_kind_of DateTime, oo.cell('C',1)
867
- #DOES NOT WORK IN EXCEL FILES: assert_equal true, oo.formula?('C',1)
868
- #DOES NOT WORK IN EXCEL FILES: assert_equal "=C1", oo.formula('C',1)
869
-
870
- assert_equal 'H1', oo.cell('A',2)
871
- assert_equal 'H2', oo.cell('B',2)
872
- assert_equal 'H3', oo.cell('C',2)
873
- assert_equal 'H4', oo.cell('D',2)
874
- assert_equal 'R1', oo.cell('A',3)
875
- assert_equal 'R2', oo.cell('B',3)
876
- assert_equal 'R3', oo.cell('C',3)
877
- assert_equal 'R4', oo.cell('D',3)
878
- end
879
- end
880
-
881
- def test_excel_does_not_support_formulas
882
- with_each_spreadsheet(:name=>'false_encoding', :format=>:excel) do |oo|
883
- assert_raise(NotImplementedError) { oo.formula('a',1) }
884
- assert_raise(NotImplementedError) { oo.formula?('a',1) }
885
- assert_raise(NotImplementedError) { oo.formulas(oo.sheets.first) }
886
- end
887
- end
888
-
889
763
  def get_extension(oo)
890
764
  case oo
891
765
  when Roo::OpenOffice
892
766
  ".ods"
893
- when Roo::Excel
894
- ".xls"
895
767
  when Roo::Excelx
896
768
  ".xlsx"
897
- when Roo::Google
898
- ""
899
769
  end
900
770
  end
901
771
 
@@ -951,109 +821,21 @@ class TestRoo < Test::Unit::TestCase
951
821
  end
952
822
  end
953
823
 
954
- def test_bug_excel_numbers1_sheet5_last_row
955
- with_each_spreadsheet(:name=>'numbers1', :format=>:excel) do |oo|
956
- oo.default_sheet = "Tabelle1"
957
- assert_equal 1, oo.first_row
958
- assert_equal 18, oo.last_row
959
- assert_equal Roo::OpenOffice.letter_to_number('A'), oo.first_column
960
- assert_equal Roo::OpenOffice.letter_to_number('G'), oo.last_column
961
- oo.default_sheet = "Name of Sheet 2"
962
- assert_equal 5, oo.first_row
963
- assert_equal 14, oo.last_row
964
- assert_equal Roo::OpenOffice.letter_to_number('B'), oo.first_column
965
- assert_equal Roo::OpenOffice.letter_to_number('E'), oo.last_column
966
- oo.default_sheet = "Sheet3"
967
- assert_equal 1, oo.first_row
968
- assert_equal 1, oo.last_row
969
- assert_equal Roo::OpenOffice.letter_to_number('A'), oo.first_column
970
- assert_equal Roo::OpenOffice.letter_to_number('BA'), oo.last_column
971
- oo.default_sheet = "Sheet4"
972
- assert_equal 1, oo.first_row
973
- assert_equal 1, oo.last_row
974
- assert_equal Roo::OpenOffice.letter_to_number('A'), oo.first_column
975
- assert_equal Roo::OpenOffice.letter_to_number('E'), oo.last_column
976
- oo.default_sheet = "Sheet5"
977
- assert_equal 1, oo.first_row
978
- assert_equal 6, oo.last_row
979
- assert_equal Roo::OpenOffice.letter_to_number('A'), oo.first_column
980
- assert_equal Roo::OpenOffice.letter_to_number('E'), oo.last_column
981
- end
982
- end
983
-
984
824
  def test_should_raise_file_not_found_error
985
825
  if OPENOFFICE
986
- assert_raise(IOError) {
826
+ assert_raises(IOError) {
987
827
  Roo::OpenOffice.new(File.join('testnichtvorhanden','Bibelbund.ods'))
988
828
  }
989
829
  end
990
- if EXCEL
991
- assert_raise(IOError) {
992
- Roo::Excel.new(File.join('testnichtvorhanden','Bibelbund.xls'))
993
- }
994
- end
995
830
  if EXCELX
996
- assert_raise(IOError) {
831
+ assert_raises(IOError) {
997
832
  Roo::Excelx.new(File.join('testnichtvorhanden','Bibelbund.xlsx'))
998
833
  }
999
834
  end
1000
- if GOOGLE
1001
- # assert_raise(Net::HTTPServerException) {
1002
- # Google.new(key_of('testnichtvorhanden'+'Bibelbund.ods'))
1003
- # Google.new('testnichtvorhanden')
1004
- # }
1005
- end
1006
- end
1007
-
1008
- def test_write_google
1009
- # write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB
1010
- with_each_spreadsheet(:name=>'write.me', :format=>:google) do |oo|
1011
- oo.default_sheet = oo.sheets.first
1012
- oo.set(1,1,"hello from the tests")
1013
- assert_equal "hello from the tests", oo.cell(1,1)
1014
- oo.set(1,1, 1.0)
1015
- assert_equal 1.0, oo.cell(1,1)
1016
- end
1017
- end
1018
-
1019
- def test_bug_set_with_more_than_one_sheet_google
1020
- # write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB
1021
- with_each_spreadsheet(:name=>'write.me', :format=>:google) do |oo|
1022
- content1 = 'AAA'
1023
- content2 = 'BBB'
1024
- oo.default_sheet = oo.sheets.first
1025
- oo.set(1,1,content1)
1026
- oo.default_sheet = oo.sheets[1]
1027
- oo.set(1,1,content2) # in the second sheet
1028
- oo.default_sheet = oo.sheets.first
1029
- assert_equal content1, oo.cell(1,1)
1030
- oo.default_sheet = oo.sheets[1]
1031
- assert_equal content2, oo.cell(1,1)
1032
- end
1033
- end
1034
-
1035
- def test_set_with_sheet_argument_google
1036
- with_each_spreadsheet(:name=>'write.me', :format=>:google) do |oo|
1037
- random_row = rand(10)+1
1038
- random_column = rand(10)+1
1039
- content1 = 'ABC'
1040
- content2 = 'DEF'
1041
- oo.set(random_row,random_column,content1,oo.sheets.first)
1042
- oo.set(random_row,random_column,content2,oo.sheets[1])
1043
- assert_equal content1, oo.cell(random_row,random_column,oo.sheets.first)
1044
- assert_equal content2, oo.cell(random_row,random_column,oo.sheets[1])
1045
- end
1046
- end
1047
-
1048
- def test_set_for_non_existing_sheet_google
1049
- with_each_spreadsheet(:name=>'ptu6bbahNZpY0N0RrxQbWdw', :format=>:google) do |oo|
1050
- assert_raise(RangeError) { oo.set(1,1,"dummy","no_sheet") }
1051
- end
1052
835
  end
1053
836
 
1054
837
  def test_bug_bbu
1055
- with_each_spreadsheet(:name=>'bbu', :format=>[:openoffice, :excelx, :excel]) do |oo|
1056
- assert_nothing_raised() {
838
+ with_each_spreadsheet(:name=>'bbu', :format=>[:openoffice, :excelx]) do |oo|
1057
839
  assert_equal "File: bbu#{get_extension(oo)}
1058
840
  Number of sheets: 3
1059
841
  Sheets: 2007_12, Tabelle2, Tabelle3
@@ -1066,7 +848,6 @@ Sheet 2:
1066
848
  - empty -
1067
849
  Sheet 3:
1068
850
  - empty -", oo.info
1069
- }
1070
851
 
1071
852
  oo.default_sheet = oo.sheets[1] # empty sheet
1072
853
  assert_nil oo.first_row
@@ -1113,7 +894,18 @@ Sheet 3:
1113
894
  end
1114
895
  end
1115
896
  end
1116
-
897
+ def test_link_to_csv
898
+ with_each_spreadsheet(:name=>'link',:format=>:excelx) do |oo|
899
+ Dir.mktmpdir do |tempdir|
900
+ csv_output = File.join(tempdir,'link.csv')
901
+ assert oo.to_csv(csv_output)
902
+ assert File.exists?(csv_output)
903
+ assert_equal "", `diff --strip-trailing-cr #{TESTDIR}/link.csv #{csv_output}`
904
+ # --strip-trailing-cr is needed because the test-file use 0A and
905
+ # the test on an windows box generates 0D 0A as line endings
906
+ end
907
+ end
908
+ end
1117
909
  def test_date_time_yaml
1118
910
  with_each_spreadsheet(:name=>'time-test') do |oo|
1119
911
  expected =
@@ -1143,7 +935,8 @@ Sheet 3:
1143
935
 
1144
936
  def test_to_xml
1145
937
  with_each_spreadsheet(:name=>'numbers1', :encoding => 'utf8') do |oo|
1146
- assert_nothing_raised {oo.to_xml}
938
+ skip if defined? JRUBY_VERSION
939
+ oo.to_xml
1147
940
  sheetname = oo.sheets.first
1148
941
  doc = Nokogiri::XML(oo.to_xml)
1149
942
  sheet_count = 0
@@ -1177,15 +970,6 @@ Sheet 3:
1177
970
  end
1178
971
  end
1179
972
 
1180
- def test_bug_row_column_fixnum_float
1181
- with_each_spreadsheet(:name=>'bug-row-column-fixnum-float', :format=>:excel) do |oo|
1182
- assert_equal 42.5, oo.cell('b',2)
1183
- assert_equal 43 , oo.cell('c',2)
1184
- assert_equal ['hij',42.5, 43], oo.row(2)
1185
- assert_equal ['def',42.5, 'nop'], oo.column(2)
1186
- end
1187
- end
1188
-
1189
973
  def test_file_warning_default
1190
974
  if OPENOFFICE
1191
975
  assert_raises(TypeError, "test/files/numbers1.xls is not an openoffice spreadsheet") {
@@ -1193,10 +977,6 @@ Sheet 3:
1193
977
  }
1194
978
  assert_raises(TypeError) { Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xlsx")) }
1195
979
  end
1196
- if EXCEL
1197
- assert_raises(TypeError) { Roo::Excel.new(File.join(TESTDIR,"numbers1.ods")) }
1198
- assert_raises(TypeError) { Roo::Excel.new(File.join(TESTDIR,"numbers1.xlsx")) }
1199
- end
1200
980
  if EXCELX
1201
981
  assert_raises(TypeError) { Roo::Excelx.new(File.join(TESTDIR,"numbers1.ods")) }
1202
982
  assert_raises(TypeError) { Roo::Excelx.new(File.join(TESTDIR,"numbers1.xls")) }
@@ -1205,54 +985,45 @@ Sheet 3:
1205
985
 
1206
986
  def test_file_warning_error
1207
987
  if OPENOFFICE
1208
- assert_raises(TypeError) { Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xls"),false,:error) }
1209
- assert_raises(TypeError) { Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) }
1210
- end
1211
- if EXCEL
1212
- assert_raises(TypeError) { Roo::Excel.new(File.join(TESTDIR,"numbers1.ods"),false,:error) }
1213
- assert_raises(TypeError) { Roo::Excel.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) }
988
+ assert_raises(TypeError) {
989
+ Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xls"),
990
+ packed: false,
991
+ file_warning: :error
992
+ )
993
+ }
994
+ assert_raises(TypeError) {
995
+ Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xlsx"),
996
+ packed: false,
997
+ file_warning: :error)
998
+ }
1214
999
  end
1215
1000
  if EXCELX
1216
- assert_raises(TypeError) { Roo::Excelx.new(File.join(TESTDIR,"numbers1.ods"),false,:error) }
1217
- assert_raises(TypeError) { Roo::Excelx.new(File.join(TESTDIR,"numbers1.xls"),false,:error) }
1001
+ assert_raises(TypeError) {
1002
+ Roo::Excelx.new(File.join(TESTDIR,"numbers1.ods"),
1003
+ packed: false,
1004
+ file_warning: :error)
1005
+ }
1006
+ assert_raises(TypeError) {
1007
+ Roo::Excelx.new(File.join(TESTDIR,"numbers1.xls"),
1008
+ packed: false,
1009
+ file_warning: :error)
1010
+ }
1218
1011
  end
1219
1012
  end
1220
1013
 
1221
1014
  def test_file_warning_warning
1222
1015
  if OPENOFFICE
1223
- assert_nothing_raised(TypeError) {
1224
- assert_raises(Zip::ZipError) {
1225
- Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xls"),false, :warning)
1226
- }
1227
- }
1228
- assert_nothing_raised(TypeError) {
1229
- assert_raises(Errno::ENOENT) {
1230
- Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xlsx"),false, :warning)
1231
- }
1232
- }
1233
- end
1234
- if EXCEL
1235
- assert_nothing_raised(TypeError) {
1236
- assert_raises(Ole::Storage::FormatError) {
1237
- Roo::Excel.new(File.join(TESTDIR,"numbers1.ods"),false, :warning)
1238
- }
1239
- }
1240
- assert_nothing_raised(TypeError) {
1241
- assert_raises(Ole::Storage::FormatError) {
1242
- Roo::Excel.new(File.join(TESTDIR,"numbers1.xlsx"),false, :warning)
1243
- }
1016
+ assert_raises(ArgumentError) {
1017
+ Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xlsx"),
1018
+ packed: false,
1019
+ file_warning: :warning)
1244
1020
  }
1245
1021
  end
1246
1022
  if EXCELX
1247
- assert_nothing_raised(TypeError) {
1248
- assert_raises(Errno::ENOENT) {
1249
- Roo::Excelx.new(File.join(TESTDIR,"numbers1.ods"),false, :warning)
1250
- }
1251
- }
1252
- assert_nothing_raised(TypeError) {
1253
- assert_raises(Zip::ZipError) {
1254
- Roo::Excelx.new(File.join(TESTDIR,"numbers1.xls"),false, :warning)
1255
- }
1023
+ assert_raises(ArgumentError) {
1024
+ Roo::Excelx.new(File.join(TESTDIR,"numbers1.ods"),
1025
+ packed: false,
1026
+ file_warning: :warning)
1256
1027
  }
1257
1028
  end
1258
1029
  end
@@ -1264,41 +1035,20 @@ Sheet 3:
1264
1035
  # Es soll ohne Fehlermeldung oder Warnung
1265
1036
  # oder Abbruch die Datei geoffnet werden
1266
1037
 
1267
- # xls
1268
- assert_nothing_raised() {
1269
- Roo::OpenOffice.new(File.join(TESTDIR,"type_openoffice.xls"),false, :ignore)
1270
- }
1271
1038
  # xlsx
1272
- assert_nothing_raised() {
1273
- Roo::OpenOffice.new(File.join(TESTDIR,"type_openoffice.xlsx"),false, :ignore)
1274
- }
1275
- end
1276
- if EXCEL
1277
- assert_nothing_raised() {
1278
- Roo::Excel.new(File.join(TESTDIR,"type_excel.ods"),false, :ignore)
1279
- }
1280
- assert_nothing_raised() {
1281
- Roo::Excel.new(File.join(TESTDIR,"type_excel.xlsx"),false, :ignore)
1282
- }
1039
+ Roo::OpenOffice.new(File.join(TESTDIR,"type_openoffice.xlsx"),
1040
+ packed: false,
1041
+ file_warning: :ignore)
1283
1042
  end
1284
1043
  if EXCELX
1285
- assert_nothing_raised() {
1286
- Roo::Excelx.new(File.join(TESTDIR,"type_excelx.ods"),false, :ignore)
1287
- }
1288
- assert_nothing_raised() {
1289
- Roo::Excelx.new(File.join(TESTDIR,"type_excelx.xls"),false, :ignore)
1290
- }
1291
- end
1292
- end
1293
-
1294
- def test_bug_last_row_excel
1295
- with_each_spreadsheet(:name=>'time-test', :format=>:excel) do |oo|
1296
- assert_equal 2, oo.last_row
1044
+ Roo::Excelx.new(File.join(TESTDIR,"type_excelx.ods"),
1045
+ packed: false,
1046
+ file_warning: :ignore)
1297
1047
  end
1298
1048
  end
1299
1049
 
1300
1050
  def test_bug_to_xml_with_empty_sheets
1301
- with_each_spreadsheet(:name=>'emptysheets', :format=>[:openoffice, :excel]) do |oo|
1051
+ with_each_spreadsheet(:name=>'emptysheets', :format=>[:openoffice, :excelx]) do |oo|
1302
1052
  oo.sheets.each { |sheet|
1303
1053
  assert_equal nil, oo.first_row, "first_row not nil in sheet #{sheet}"
1304
1054
  assert_equal nil, oo.last_row, "last_row not nil in sheet #{sheet}"
@@ -1309,7 +1059,7 @@ Sheet 3:
1309
1059
  assert_equal nil, oo.first_column(sheet), "first_column not nil in sheet #{sheet}"
1310
1060
  assert_equal nil, oo.last_column(sheet), "last_column not nil in sheet #{sheet}"
1311
1061
  }
1312
- assert_nothing_raised() { oo.to_xml }
1062
+ oo.to_xml
1313
1063
  end
1314
1064
  end
1315
1065
 
@@ -1364,12 +1114,12 @@ Sheet 3:
1364
1114
  def test_datetime
1365
1115
  with_each_spreadsheet(:name=>'datetime') do |oo|
1366
1116
  val = oo.cell('c',3)
1367
- assert_kind_of DateTime, val
1368
1117
  assert_equal :datetime, oo.celltype('c',3)
1369
1118
  assert_equal DateTime.new(1961,11,21,12,17,18), val
1119
+ assert_kind_of DateTime, val
1370
1120
  val = oo.cell('a',1)
1371
- assert_kind_of Date, val
1372
1121
  assert_equal :date, oo.celltype('a',1)
1122
+ assert_kind_of Date, val
1373
1123
  assert_equal Date.new(1961,11,21), val
1374
1124
  assert_equal Date.new(1961,11,21), oo.cell('a',1)
1375
1125
  assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('a',3)
@@ -1387,6 +1137,9 @@ Sheet 3:
1387
1137
  assert_equal Date.new(1961,11,21), oo.cell('a',7)
1388
1138
  assert_equal Date.new(1961,11,21), oo.cell('b',7)
1389
1139
  assert_equal Date.new(1961,11,21), oo.cell('c',7)
1140
+ assert_equal DateTime.new(2013,11,5,11,45,00), oo.cell('a',8)
1141
+ assert_equal DateTime.new(2013,11,5,11,45,00), oo.cell('b',8)
1142
+ assert_equal DateTime.new(2013,11,5,11,45,00), oo.cell('c',8)
1390
1143
  end
1391
1144
  end
1392
1145
 
@@ -1402,7 +1155,7 @@ Sheet 3:
1402
1155
  end
1403
1156
 
1404
1157
  def test_cell_boolean
1405
- with_each_spreadsheet(:name=>'boolean', :format=>[:openoffice, :excel, :excelx]) do |oo|
1158
+ with_each_spreadsheet(:name=>'boolean', :format=>[:openoffice, :excelx]) do |oo|
1406
1159
  if oo.class == Roo::Excelx
1407
1160
  assert_equal "TRUE", oo.cell(1,1), "failure in "+oo.class.to_s
1408
1161
  assert_equal "FALSE", oo.cell(2,1), "failure in "+oo.class.to_s
@@ -1414,7 +1167,7 @@ Sheet 3:
1414
1167
  end
1415
1168
 
1416
1169
  def test_cell_multiline
1417
- with_each_spreadsheet(:name=>'paragraph', :format=>[:openoffice, :excel, :excelx]) do |oo|
1170
+ with_each_spreadsheet(:name=>'paragraph', :format=>[:openoffice, :excelx]) do |oo|
1418
1171
  assert_equal "This is a test\nof a multiline\nCell", oo.cell(1,1)
1419
1172
  assert_equal "This is a test\n¶\nof a multiline\n\nCell", oo.cell(1,2)
1420
1173
  assert_equal "first p\n\nsecond p\n\nlast p", oo.cell(2,1)
@@ -1425,8 +1178,7 @@ Sheet 3:
1425
1178
  # styles only valid in excel spreadsheets?
1426
1179
  # TODO: what todo with other spreadsheet types
1427
1180
  with_each_spreadsheet(:name=>'style', :format=>[# :openoffice,
1428
- :excel,
1429
- # :excelx
1181
+ :excelx
1430
1182
  ]) do |oo|
1431
1183
  # bold
1432
1184
  assert_equal true, oo.font(1,1).bold?
@@ -1485,18 +1237,6 @@ Sheet 3:
1485
1237
  end
1486
1238
  end
1487
1239
 
1488
- # If a cell has a date-like string but is preceeded by a '
1489
- # to force that date to be treated like a string, we were getting an exception.
1490
- # This test just checks for that exception to make sure it's not raised in this case
1491
- def test_date_to_float_conversion
1492
- with_each_spreadsheet(:name=>'datetime_floatconv', :format=>:excel) do |oo|
1493
- assert_nothing_raised(NoMethodError) do
1494
- oo.cell('a',1)
1495
- oo.cell('a',2)
1496
- end
1497
- end
1498
- end
1499
-
1500
1240
  # Need to extend to other formats
1501
1241
  def test_row_whitespace
1502
1242
  # auf dieses Dokument habe ich keinen Zugriff TODO:
@@ -1535,45 +1275,10 @@ Sheet 3:
1535
1275
  end
1536
1276
  end
1537
1277
 
1538
- def test_ruby_spreadsheet_formula_bug
1539
- with_each_spreadsheet(:name=>'formula_parse_error', :format=>:excel) do |oo|
1540
- assert_equal '5026', oo.cell(2,3)
1541
- assert_equal '5026', oo.cell(3,3)
1542
- end
1543
- end
1544
-
1545
-
1546
- def test_excel_links
1547
- with_each_spreadsheet(:name=>'link', :format=>:excel) do |oo|
1548
- assert_equal 'Google', oo.cell(1,1)
1549
- assert_equal 'http://www.google.com', oo.cell(1,1).url
1550
- end
1551
- end
1552
-
1553
1278
  def test_excelx_links
1554
1279
  with_each_spreadsheet(:name=>'link', :format=>:excelx) do |oo|
1555
1280
  assert_equal 'Google', oo.cell(1,1)
1556
- assert_equal 'http://www.google.com', oo.cell(1,1).url
1557
- end
1558
- end
1559
-
1560
- # Excel has two base date formats one from 1900 and the other from 1904.
1561
- # There's a MS bug that 1900 base dates include an extra day due to erroneously
1562
- # including 1900 as a leap yar.
1563
- def test_base_dates_in_excel
1564
- with_each_spreadsheet(:name=>'1900_base', :format=>:excel) do |oo|
1565
- assert_equal Date.new(2009,06,15), oo.cell(1,1)
1566
- #we don't want to to 'interpret' formulas assert_equal Date.new(Time.now.year,Time.now.month,Time.now.day), oo.cell(2,1) #formula for TODAY()
1567
- # if we test TODAY() we have also have to calculate
1568
- # other date calculations
1569
- #
1570
- assert_equal :date, oo.celltype(1,1)
1571
- end
1572
- with_each_spreadsheet(:name=>'1904_base', :format=>:excel) do |oo|
1573
- assert_equal Date.new(2009,06,15), oo.cell(1,1)
1574
- # see comment above
1575
- # assert_equal Date.new(Time.now.year,Time.now.month,Time.now.day), oo.cell(2,1) #formula for TODAY()
1576
- assert_equal :date, oo.celltype(1,1)
1281
+ assert_equal 'http://www.google.com', oo.cell(1,1).href
1577
1282
  end
1578
1283
  end
1579
1284
 
@@ -1590,22 +1295,6 @@ Sheet 3:
1590
1295
  end
1591
1296
  end
1592
1297
 
1593
- def test_bad_date
1594
- with_each_spreadsheet(:name=>'prova', :format=>:excel) do |oo|
1595
- assert_nothing_raised(ArgumentError) {
1596
- assert_equal DateTime.new(2006,2,2,10,0,0), oo.cell('a',1)
1597
- }
1598
- end
1599
- end
1600
-
1601
- def test_bad_excel_date
1602
- with_each_spreadsheet(:name=>'bad_excel_date', :format=>:excel) do |oo|
1603
- assert_nothing_raised(ArgumentError) {
1604
- assert_equal DateTime.new(2006,2,2,10,0,0), oo.cell('a',1)
1605
- }
1606
- end
1607
- end
1608
-
1609
1298
  def test_cell_methods
1610
1299
  with_each_spreadsheet(:name=>'numbers1') do |oo|
1611
1300
  assert_equal 10, oo.a4 # cell(4,'A')
@@ -1747,7 +1436,7 @@ Sheet 3:
1747
1436
 
1748
1437
  require 'matrix'
1749
1438
  def test_matrix
1750
- with_each_spreadsheet(:name => 'matrix', :format => [:openoffice, :excel, :google]) do |oo|
1439
+ with_each_spreadsheet(:name => 'matrix', :format => :openoffice) do |oo|
1751
1440
  oo.default_sheet = oo.sheets.first
1752
1441
  assert_equal Matrix[
1753
1442
  [1.0, 2.0, 3.0],
@@ -1757,7 +1446,7 @@ Sheet 3:
1757
1446
  end
1758
1447
 
1759
1448
  def test_matrix_selected_range
1760
- with_each_spreadsheet(:name => 'matrix', :format=>[:excel,:openoffice,:google]) do |oo|
1449
+ with_each_spreadsheet(:name => 'matrix', :format=>:openoffice) do |oo|
1761
1450
  oo.default_sheet = 'Sheet2'
1762
1451
  assert_equal Matrix[
1763
1452
  [1.0, 2.0, 3.0],
@@ -1767,7 +1456,7 @@ Sheet 3:
1767
1456
  end
1768
1457
 
1769
1458
  def test_matrix_all_nil
1770
- with_each_spreadsheet(:name => 'matrix', :format=>[:excel,:openoffice,:google]) do |oo|
1459
+ with_each_spreadsheet(:name => 'matrix', :format=>:openoffice) do |oo|
1771
1460
  oo.default_sheet = 'Sheet2'
1772
1461
  assert_equal Matrix[
1773
1462
  [nil, nil, nil],
@@ -1777,7 +1466,7 @@ Sheet 3:
1777
1466
  end
1778
1467
 
1779
1468
  def test_matrix_values_and_nil
1780
- with_each_spreadsheet(:name => 'matrix', :format=>[:excel,:openoffice,:google]) do |oo|
1469
+ with_each_spreadsheet(:name => 'matrix', :format=>:openoffice) do |oo|
1781
1470
  oo.default_sheet = 'Sheet3'
1782
1471
  assert_equal Matrix[
1783
1472
  [1.0, nil, 3.0],
@@ -1787,7 +1476,7 @@ Sheet 3:
1787
1476
  end
1788
1477
 
1789
1478
  def test_matrix_specifying_sheet
1790
- with_each_spreadsheet(:name => 'matrix', :format => [:openoffice, :excel, :google]) do |oo|
1479
+ with_each_spreadsheet(:name => 'matrix', :format => :openoffice) do |oo|
1791
1480
  oo.default_sheet = oo.sheets.first
1792
1481
  assert_equal Matrix[
1793
1482
  [1.0, nil, 3.0],
@@ -1839,11 +1528,9 @@ where the expected result is
1839
1528
  # 2011-06-24
1840
1529
  def test_bug_formulas_empty_sheet
1841
1530
  with_each_spreadsheet(:name =>'emptysheets',
1842
- :format=>[:openoffice,:excelx,:google]) do |oo|
1843
- assert_nothing_raised(NoMethodError) {
1531
+ :format=>[:openoffice,:excelx]) do |oo|
1844
1532
  oo.default_sheet = oo.sheets.first
1845
1533
  oo.formulas
1846
- }
1847
1534
  assert_equal([], oo.formulas)
1848
1535
  end
1849
1536
  end
@@ -1853,11 +1540,9 @@ where the expected result is
1853
1540
  # 2011-06-24
1854
1541
  def test_bug_to_yaml_empty_sheet
1855
1542
  with_each_spreadsheet(:name =>'emptysheets',
1856
- :format=>[:openoffice,:excelx,:google]) do |oo|
1857
- assert_nothing_raised(NoMethodError) {
1543
+ :format=>[:openoffice,:excelx]) do |oo|
1858
1544
  oo.default_sheet = oo.sheets.first
1859
1545
  oo.to_yaml
1860
- }
1861
1546
  assert_equal('', oo.to_yaml)
1862
1547
  end
1863
1548
  end
@@ -1867,11 +1552,9 @@ where the expected result is
1867
1552
  # 2011-06-25
1868
1553
  def test_bug_to_matrix_empty_sheet
1869
1554
  with_each_spreadsheet(:name =>'emptysheets',
1870
- :format=>[:openoffice,:excelx,:google]) do |oo|
1871
- assert_nothing_raised(NoMethodError) {
1555
+ :format=>[:openoffice,:excelx]) do |oo|
1872
1556
  oo.default_sheet = oo.sheets.first
1873
1557
  oo.to_matrix
1874
- }
1875
1558
  assert_equal(Matrix.empty(0,0), oo.to_matrix)
1876
1559
  end
1877
1560
  end
@@ -1963,6 +1646,7 @@ where the expected result is
1963
1646
  end
1964
1647
 
1965
1648
  def test_bug_pfand_from_windows_phone_xlsx
1649
+ return if defined? JRUBY_VERSION
1966
1650
  with_each_spreadsheet(:name=>'Pfand_from_windows_phone', :format=>:excelx) do |oo|
1967
1651
  oo.default_sheet = oo.sheets.first
1968
1652
  assert_equal ['Blatt1','Blatt2','Blatt3'], oo.sheets
@@ -1992,15 +1676,6 @@ where the expected result is
1992
1676
  end
1993
1677
  end
1994
1678
 
1995
- def test_comment?
1996
- with_each_spreadsheet(:name=>'comments', :format=>[:openoffice,:libreoffice,
1997
- :excelx]) do |oo|
1998
- oo.default_sheet = oo.sheets.first
1999
- assert_equal true, oo.comment?('b',4)
2000
- assert_equal false, oo.comment?('b',99)
2001
- end
2002
- end
2003
-
2004
1679
  def test_comments
2005
1680
  with_each_spreadsheet(:name=>'comments', :format=>[:openoffice,:libreoffice,
2006
1681
  :excelx]) do |oo|
@@ -2013,6 +1688,11 @@ where the expected result is
2013
1688
  oo.default_sheet = oo.sheets[1]
2014
1689
  assert_equal [], oo.comments, "comments error in class #{oo.class}"
2015
1690
  end
1691
+
1692
+ with_each_spreadsheet(:name=>'comments-google', :format=>[:excelx]) do |oo|
1693
+ oo.default_sheet = oo.sheets.first
1694
+ assert_equal [[1, 1, "this is a comment\n\t-Steven Daniels"]], oo.comments(oo.sheets.first), "comments error in class #{oo.class}"
1695
+ end
2016
1696
  end
2017
1697
 
2018
1698
  ## PREVIOUSLY SKIPPED
@@ -2091,13 +1771,6 @@ where the expected result is
2091
1771
  # end
2092
1772
  # end
2093
1773
 
2094
- def test_simple_google
2095
- if GOOGLE
2096
- go = Roo::Google.new("egal")
2097
- assert_equal "42", go.cell(1,1)
2098
- end
2099
- end
2100
-
2101
1774
  def test_download_uri
2102
1775
  if ONLINE
2103
1776
  if OPENOFFICE
@@ -2105,11 +1778,6 @@ where the expected result is
2105
1778
  Roo::OpenOffice.new("http://gibbsnichtdomainxxxxx.com/file.ods")
2106
1779
  }
2107
1780
  end
2108
- if EXCEL
2109
- assert_raises(RuntimeError) {
2110
- Roo::Excel.new("http://gibbsnichtdomainxxxxx.com/file.xls")
2111
- }
2112
- end
2113
1781
  if EXCELX
2114
1782
  assert_raises(RuntimeError) {
2115
1783
  Roo::Excelx.new("http://gibbsnichtdomainxxxxx.com/file.xlsx")
@@ -2120,8 +1788,7 @@ where the expected result is
2120
1788
 
2121
1789
  def test_download_uri_with_query_string
2122
1790
  dir = File.expand_path("#{File.dirname __FILE__}/files")
2123
- { xls: [EXCEL, Roo::Excel],
2124
- xlsx: [EXCELX, Roo::Excelx],
1791
+ { xlsx: [EXCELX, Roo::Excelx],
2125
1792
  ods: [OPENOFFICE, Roo::OpenOffice]}.each do |extension, (flag, type)|
2126
1793
  if flag
2127
1794
  file = "#{dir}/simple_spreadsheet.#{extension}"
@@ -2285,8 +1952,116 @@ where the expected result is
2285
1952
 
2286
1953
  def test_bug_numbered_sheet_names
2287
1954
  with_each_spreadsheet(:name=>'bug-numbered-sheet-names', :format=>:excelx) do |oo|
2288
- assert_nothing_raised() { oo.each_with_pagename { } }
1955
+ oo.each_with_pagename { }
2289
1956
  end
2290
1957
  end
2291
1958
 
1959
+ def test_parsing_xslx_from_numbers
1960
+ return unless EXCELX
1961
+ xlsx = Roo::Excelx.new(File.join(TESTDIR, "numbers-export.xlsx"))
1962
+
1963
+ xlsx.default_sheet = xlsx.sheets.first
1964
+ assert_equal 'Sheet 1', xlsx.cell('a',1)
1965
+
1966
+ # Another buggy behavior of Numbers 3.1: if a warkbook has more than a
1967
+ # single sheet, all sheets except the first one will have an extra row and
1968
+ # column added to the beginning. That's why we assert against cell B2 and
1969
+ # not A1
1970
+ xlsx.default_sheet = xlsx.sheets.last
1971
+ assert_equal 'Sheet 2', xlsx.cell('b',2)
1972
+ end
1973
+
1974
+ def test_openoffice_encryption
1975
+ if OPENOFFICE
1976
+ assert_raises(ArgumentError) { Roo::LibreOffice.new(File.join(TESTDIR, "encrypted-letmein.ods")) }
1977
+ assert_raises(ArgumentError) { Roo::LibreOffice.new(File.join(TESTDIR, "encrypted-letmein.ods"), :password => "badpassword") }
1978
+ oo = Roo::LibreOffice.new(File.join(TESTDIR, "encrypted-letmein.ods"), :password => "letmein")
1979
+ oo.default_sheet = oo.sheets.first
1980
+ assert_equal "Hello World", oo.cell('a',1)
1981
+ end
1982
+ end
1983
+
1984
+ def test_expand_merged_range
1985
+ return unless EXCELX
1986
+ xlsx = Roo::Excelx.new(File.join(TESTDIR, "merged_ranges.xlsx"), {:expand_merged_ranges => true})
1987
+ for row in 3..7 do
1988
+ for col in 'a'..'b'
1989
+ if row > 3 && row < 7 && col == 'a'
1990
+ assert_equal 'vertical1', xlsx.cell(col,row)
1991
+ else
1992
+ assert_nil xlsx.cell(col,row)
1993
+ end
1994
+ end
1995
+ end
1996
+ for row in 3..11 do
1997
+ for col in 'f'..'h'
1998
+ if row > 3 && row < 11 && col == 'g'
1999
+ assert_equal 'vertical2', xlsx.cell(col,row)
2000
+ else
2001
+ assert_nil xlsx.cell(col,row)
2002
+ end
2003
+ end
2004
+ end
2005
+ for row in 3..5 do
2006
+ for col in 'b'..'f'
2007
+ if row == 4 && col > 'b' && col < 'f'
2008
+ assert_equal 'horizontal', xlsx.cell(col,row)
2009
+ else
2010
+ assert_nil xlsx.cell(col,row)
2011
+ end
2012
+ end
2013
+ end
2014
+ for row in 8..13 do
2015
+ for col in 'a'..'e'
2016
+ if row > 8 && row < 13 && col > 'a' && col < 'e'
2017
+ assert_equal 'block', xlsx.cell(col,row)
2018
+ else
2019
+ assert_nil xlsx.cell(col,row)
2020
+ end
2021
+ end
2022
+ end
2023
+ end
2024
+
2025
+ def test_noexpand_merged_range
2026
+ return unless EXCELX
2027
+ xlsx = Roo::Excelx.new(File.join(TESTDIR, "merged_ranges.xlsx"))
2028
+ for row in 3..7 do
2029
+ for col in 'a'..'b'
2030
+ if row == 4 && col == 'a'
2031
+ assert_equal 'vertical1', xlsx.cell(col,row)
2032
+ else
2033
+ assert_nil xlsx.cell(col,row)
2034
+ end
2035
+ end
2036
+ end
2037
+ for row in 3..11 do
2038
+ for col in 'f'..'h'
2039
+ if row == 4 && col == 'g'
2040
+ assert_equal 'vertical2', xlsx.cell(col,row)
2041
+ else
2042
+ assert_nil xlsx.cell(col,row)
2043
+ end
2044
+ end
2045
+ end
2046
+ for row in 3..5 do
2047
+ for col in 'b'..'f'
2048
+ if row == 4 && col == 'c'
2049
+ assert_equal 'horizontal', xlsx.cell(col,row)
2050
+ else
2051
+ assert_nil xlsx.cell(col,row)
2052
+ end
2053
+ end
2054
+ end
2055
+ for row in 8..13 do
2056
+ for col in 'a'..'e'
2057
+ if row == 9 && col == 'b'
2058
+ assert_equal 'block', xlsx.cell(col,row)
2059
+ else
2060
+ assert_nil xlsx.cell(col,row)
2061
+ end
2062
+ end
2063
+ end
2064
+ end
2065
+
2066
+
2292
2067
  end # class