roo 1.13.2 → 2.0.1

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 (175) 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.md +515 -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/base.rb +334 -395
  15. data/lib/roo/csv.rb +120 -113
  16. data/lib/roo/excelx/cell.rb +77 -0
  17. data/lib/roo/excelx/comments.rb +22 -0
  18. data/lib/roo/excelx/extractor.rb +22 -0
  19. data/lib/roo/excelx/relationships.rb +25 -0
  20. data/lib/roo/excelx/shared_strings.rb +37 -0
  21. data/lib/roo/excelx/sheet.rb +107 -0
  22. data/lib/roo/excelx/sheet_doc.rb +200 -0
  23. data/lib/roo/excelx/styles.rb +64 -0
  24. data/lib/roo/excelx/workbook.rb +59 -0
  25. data/lib/roo/excelx.rb +413 -597
  26. data/lib/roo/font.rb +17 -0
  27. data/lib/roo/libre_office.rb +5 -0
  28. data/lib/roo/link.rb +15 -0
  29. data/lib/roo/{openoffice.rb → open_office.rb} +681 -496
  30. data/lib/roo/spreadsheet.rb +20 -23
  31. data/lib/roo/utils.rb +78 -0
  32. data/lib/roo/version.rb +3 -0
  33. data/lib/roo.rb +18 -24
  34. data/roo.gemspec +20 -204
  35. data/spec/lib/roo/base_spec.rb +1 -4
  36. data/spec/lib/roo/csv_spec.rb +21 -13
  37. data/spec/lib/roo/excelx/format_spec.rb +7 -6
  38. data/spec/lib/roo/excelx_spec.rb +424 -11
  39. data/spec/lib/roo/libreoffice_spec.rb +16 -6
  40. data/spec/lib/roo/openoffice_spec.rb +13 -8
  41. data/spec/lib/roo/spreadsheet_spec.rb +40 -12
  42. data/spec/lib/roo/utils_spec.rb +106 -0
  43. data/spec/spec_helper.rb +2 -1
  44. data/test/test_generic_spreadsheet.rb +117 -139
  45. data/test/test_helper.rb +9 -56
  46. data/test/test_roo.rb +274 -478
  47. metadata +65 -303
  48. data/CHANGELOG +0 -417
  49. data/Gemfile.lock +0 -78
  50. data/README.markdown +0 -126
  51. data/VERSION +0 -1
  52. data/lib/roo/excel.rb +0 -355
  53. data/lib/roo/excel2003xml.rb +0 -300
  54. data/lib/roo/google.rb +0 -292
  55. data/lib/roo/roo_rails_helper.rb +0 -83
  56. data/lib/roo/worksheet.rb +0 -18
  57. data/scripts/txt2html +0 -67
  58. data/spec/lib/roo/excel2003xml_spec.rb +0 -15
  59. data/spec/lib/roo/excel_spec.rb +0 -17
  60. data/spec/lib/roo/google_spec.rb +0 -64
  61. data/test/files/1900_base.xls +0 -0
  62. data/test/files/1900_base.xlsx +0 -0
  63. data/test/files/1904_base.xls +0 -0
  64. data/test/files/1904_base.xlsx +0 -0
  65. data/test/files/Bibelbund.csv +0 -3741
  66. data/test/files/Bibelbund.ods +0 -0
  67. data/test/files/Bibelbund.xls +0 -0
  68. data/test/files/Bibelbund.xlsx +0 -0
  69. data/test/files/Bibelbund.xml +0 -62518
  70. data/test/files/Bibelbund1.ods +0 -0
  71. data/test/files/Pfand_from_windows_phone.xlsx +0 -0
  72. data/test/files/bad_excel_date.xls +0 -0
  73. data/test/files/bbu.ods +0 -0
  74. data/test/files/bbu.xls +0 -0
  75. data/test/files/bbu.xlsx +0 -0
  76. data/test/files/bbu.xml +0 -152
  77. data/test/files/bode-v1.ods.zip +0 -0
  78. data/test/files/bode-v1.xls.zip +0 -0
  79. data/test/files/boolean.csv +0 -2
  80. data/test/files/boolean.ods +0 -0
  81. data/test/files/boolean.xls +0 -0
  82. data/test/files/boolean.xlsx +0 -0
  83. data/test/files/boolean.xml +0 -112
  84. data/test/files/borders.ods +0 -0
  85. data/test/files/borders.xls +0 -0
  86. data/test/files/borders.xlsx +0 -0
  87. data/test/files/borders.xml +0 -144
  88. data/test/files/bug-numbered-sheet-names.xlsx +0 -0
  89. data/test/files/bug-row-column-fixnum-float.xls +0 -0
  90. data/test/files/bug-row-column-fixnum-float.xml +0 -127
  91. data/test/files/comments.ods +0 -0
  92. data/test/files/comments.xls +0 -0
  93. data/test/files/comments.xlsx +0 -0
  94. data/test/files/csvtypes.csv +0 -1
  95. data/test/files/datetime.ods +0 -0
  96. data/test/files/datetime.xls +0 -0
  97. data/test/files/datetime.xlsx +0 -0
  98. data/test/files/datetime.xml +0 -142
  99. data/test/files/datetime_floatconv.xls +0 -0
  100. data/test/files/datetime_floatconv.xml +0 -148
  101. data/test/files/dreimalvier.ods +0 -0
  102. data/test/files/emptysheets.ods +0 -0
  103. data/test/files/emptysheets.xls +0 -0
  104. data/test/files/emptysheets.xlsx +0 -0
  105. data/test/files/emptysheets.xml +0 -105
  106. data/test/files/excel2003.xml +0 -21140
  107. data/test/files/false_encoding.xls +0 -0
  108. data/test/files/false_encoding.xml +0 -132
  109. data/test/files/file_item_error.xlsx +0 -0
  110. data/test/files/formula.ods +0 -0
  111. data/test/files/formula.xls +0 -0
  112. data/test/files/formula.xlsx +0 -0
  113. data/test/files/formula.xml +0 -134
  114. data/test/files/formula_parse_error.xls +0 -0
  115. data/test/files/formula_parse_error.xml +0 -1833
  116. data/test/files/formula_string_error.xlsx +0 -0
  117. data/test/files/html-escape.ods +0 -0
  118. data/test/files/link.xls +0 -0
  119. data/test/files/link.xlsx +0 -0
  120. data/test/files/matrix.ods +0 -0
  121. data/test/files/matrix.xls +0 -0
  122. data/test/files/named_cells.ods +0 -0
  123. data/test/files/named_cells.xls +0 -0
  124. data/test/files/named_cells.xlsx +0 -0
  125. data/test/files/no_spreadsheet_file.txt +0 -1
  126. data/test/files/numbers1.csv +0 -18
  127. data/test/files/numbers1.ods +0 -0
  128. data/test/files/numbers1.xls +0 -0
  129. data/test/files/numbers1.xlsx +0 -0
  130. data/test/files/numbers1.xml +0 -312
  131. data/test/files/numeric-link.xlsx +0 -0
  132. data/test/files/only_one_sheet.ods +0 -0
  133. data/test/files/only_one_sheet.xls +0 -0
  134. data/test/files/only_one_sheet.xlsx +0 -0
  135. data/test/files/only_one_sheet.xml +0 -67
  136. data/test/files/paragraph.ods +0 -0
  137. data/test/files/paragraph.xls +0 -0
  138. data/test/files/paragraph.xlsx +0 -0
  139. data/test/files/paragraph.xml +0 -127
  140. data/test/files/prova.xls +0 -0
  141. data/test/files/ric.ods +0 -0
  142. data/test/files/simple_spreadsheet.ods +0 -0
  143. data/test/files/simple_spreadsheet.xls +0 -0
  144. data/test/files/simple_spreadsheet.xlsx +0 -0
  145. data/test/files/simple_spreadsheet.xml +0 -225
  146. data/test/files/simple_spreadsheet_from_italo.ods +0 -0
  147. data/test/files/simple_spreadsheet_from_italo.xls +0 -0
  148. data/test/files/simple_spreadsheet_from_italo.xml +0 -242
  149. data/test/files/so_datetime.csv +0 -7
  150. data/test/files/style.ods +0 -0
  151. data/test/files/style.xls +0 -0
  152. data/test/files/style.xlsx +0 -0
  153. data/test/files/style.xml +0 -154
  154. data/test/files/time-test.csv +0 -2
  155. data/test/files/time-test.ods +0 -0
  156. data/test/files/time-test.xls +0 -0
  157. data/test/files/time-test.xlsx +0 -0
  158. data/test/files/time-test.xml +0 -131
  159. data/test/files/type_excel.ods +0 -0
  160. data/test/files/type_excel.xlsx +0 -0
  161. data/test/files/type_excelx.ods +0 -0
  162. data/test/files/type_excelx.xls +0 -0
  163. data/test/files/type_openoffice.xls +0 -0
  164. data/test/files/type_openoffice.xlsx +0 -0
  165. data/test/files/whitespace.ods +0 -0
  166. data/test/files/whitespace.xls +0 -0
  167. data/test/files/whitespace.xlsx +0 -0
  168. data/test/files/whitespace.xml +0 -184
  169. data/test/rm_sub_test.rb +0 -12
  170. data/test/rm_test.rb +0 -7
  171. data/website/index.html +0 -385
  172. data/website/index.txt +0 -423
  173. data/website/javascripts/rounded_corners_lite.inc.js +0 -285
  174. data/website/stylesheets/screen.css +0 -130
  175. data/website/template.rhtml +0 -48
data/test/test_roo.rb CHANGED
@@ -17,38 +17,33 @@
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
+ require 'stringio'
21
22
 
22
- class TestRoo < Test::Unit::TestCase
23
+ class TestRoo < Minitest::Test
23
24
 
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)
25
+ OPENOFFICE = true # do OpenOffice-Spreadsheet Tests? (.ods files)
26
+ EXCELX = true # do Excelx Tests? (.xlsx files)
27
+ LIBREOFFICE = true # do LibreOffice tests? (.ods files)
28
+ CSV = true # do CSV tests? (.csv files)
30
29
 
31
- FORMATS = {
32
- excel: EXCEL,
33
- excelx: EXCELX,
34
- openoffice: OPENOFFICE,
35
- google: GOOGLE,
36
- libreoffice: LIBREOFFICE
37
- }
30
+ FORMATS = [
31
+ :excelx,
32
+ :openoffice,
33
+ :libreoffice
34
+ ]
38
35
 
39
36
  ONLINE = false
40
37
  LONG_RUN = false
41
38
 
42
39
  def fixture_filename(name, format)
43
40
  case format
44
- when :excel
45
- "#{name}.xls"
46
41
  when :excelx
47
42
  "#{name}.xlsx"
48
43
  when :openoffice, :libreoffice
49
44
  "#{name}.ods"
50
- when :google
51
- key_of(name)
45
+ else
46
+ raise ArgumentError, "unexpected format #{format}"
52
47
  end
53
48
  end
54
49
 
@@ -56,48 +51,30 @@ class TestRoo < Test::Unit::TestCase
56
51
  # and yield a reference to the roo object
57
52
  def with_each_spreadsheet(options)
58
53
  if options[:format]
59
- options[:format] = Array(options[:format])
60
- invalid_formats = options[:format] - FORMATS.keys
54
+ formats = Array(options[:format])
55
+ invalid_formats = formats - FORMATS
61
56
  unless invalid_formats.empty?
62
57
  raise "invalid spreadsheet types: #{invalid_formats.join(', ')}"
63
58
  end
64
59
  else
65
- options[:format] = FORMATS.keys
60
+ formats = FORMATS
66
61
  end
67
- options[:format].each do |format|
62
+ formats.each do |format|
68
63
  begin
69
- if FORMATS[format]
70
- yield Roo::Spreadsheet.open(File.join(TESTDIR,
71
- fixture_filename(options[:name], format)))
72
- end
64
+ yield Roo::Spreadsheet.open(File.join(TESTDIR,
65
+ fixture_filename(options[:name], format)))
73
66
  rescue => e
74
- raise e, "#{e.message} for #{format}", e.backtrace
67
+ raise e, "#{e.message} for #{format}", e.backtrace unless options[:ignore_errors]
75
68
  end
76
69
  end
77
70
  end
78
71
 
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
72
  def test_sheets_csv
96
73
  if CSV
97
74
  oo = Roo::CSV.new(File.join(TESTDIR,'numbers1.csv'))
98
75
  assert_equal ["default"], oo.sheets
99
- assert_raise(RangeError) { oo.default_sheet = "no_sheet" }
100
- assert_raise(TypeError) { oo.default_sheet = [1,2,3] }
76
+ assert_raises(RangeError) { oo.default_sheet = "no_sheet" }
77
+ assert_raises(TypeError) { oo.default_sheet = [1,2,3] }
101
78
  oo.sheets.each { |sh|
102
79
  oo.default_sheet = sh
103
80
  assert_equal sh, oo.default_sheet
@@ -108,8 +85,8 @@ class TestRoo < Test::Unit::TestCase
108
85
  def test_sheets
109
86
  with_each_spreadsheet(:name=>'numbers1') do |oo|
110
87
  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] }
88
+ assert_raises(RangeError) { oo.default_sheet = "no_sheet" }
89
+ assert_raises(TypeError) { oo.default_sheet = [1,2,3] }
113
90
  oo.sheets.each { |sh|
114
91
  oo.default_sheet = sh
115
92
  assert_equal sh, oo.default_sheet
@@ -168,8 +145,8 @@ class TestRoo < Test::Unit::TestCase
168
145
  assert_equal "tata", oo.cell('A',6)
169
146
  assert_equal "tata", oo.cell(6,'a')
170
147
  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') }
148
+ assert_raises(ArgumentError) { assert_equal "tata", oo.cell('a','f') }
149
+ assert_raises(ArgumentError) { assert_equal "tata", oo.cell('f','a') }
173
150
  assert_equal "thisisc8", oo.cell(8,3)
174
151
  assert_equal "thisisc8", oo.cell(8,'C')
175
152
  assert_equal "thisisc8", oo.cell('C',8)
@@ -198,27 +175,22 @@ class TestRoo < Test::Unit::TestCase
198
175
  with_each_spreadsheet(:name=>'numbers1') do |oo|
199
176
  oo.default_sheet = "Name of Sheet 2"
200
177
  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")}
178
+ assert_raises(RangeError) { oo.default_sheet = "non existing sheet name" }
179
+ assert_raises(RangeError) { oo.default_sheet = "non existing sheet name" }
180
+ assert_raises(RangeError) { oo.cell('C',5,"non existing sheet name")}
181
+ assert_raises(RangeError) { oo.celltype('C',5,"non existing sheet name")}
182
+ assert_raises(RangeError) { oo.empty?('C',5,"non existing sheet name")}
183
+ assert_raises(RangeError) { oo.formula?('C',5,"non existing sheet name")}
184
+ assert_raises(RangeError) { oo.formula('C',5,"non existing sheet name")}
185
+ assert_raises(RangeError) { oo.set('C',5,42,"non existing sheet name")}
186
+ assert_raises(RangeError) { oo.formulas("non existing sheet name")}
187
+ assert_raises(RangeError) { oo.to_yaml({},1,1,1,1,"non existing sheet name")}
216
188
  end
217
189
  end
218
190
 
219
191
  def test_argument_error
220
192
  with_each_spreadsheet(:name=>'numbers1') do |oo|
221
- assert_nothing_raised(ArgumentError) { oo.default_sheet = "Tabelle1" }
193
+ oo.default_sheet = "Tabelle1"
222
194
  end
223
195
  end
224
196
 
@@ -245,7 +217,7 @@ class TestRoo < Test::Unit::TestCase
245
217
  end
246
218
 
247
219
  def test_italo_table
248
- with_each_spreadsheet(:name=>'simple_spreadsheet_from_italo', :format=>[:openoffice, :excel]) do |oo|
220
+ with_each_spreadsheet(:name=>'simple_spreadsheet_from_italo', :format=>:openoffice) do |oo|
249
221
  assert_equal '1', oo.cell('A',1)
250
222
  assert_equal '1', oo.cell('B',1)
251
223
  assert_equal '1', oo.cell('C',1)
@@ -324,41 +296,12 @@ class TestRoo < Test::Unit::TestCase
324
296
  end
325
297
  end
326
298
 
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)
299
+ def test_header_with_brackets_excelx
300
+ with_each_spreadsheet(:name => 'advanced_header', :format => :openoffice) do |oo|
301
+ parsed_head = oo.parse(:headers => true)
302
+ assert_equal "Date(yyyy-mm-dd)", oo.cell('A',1)
303
+ assert_equal parsed_head[0].keys, ["Date(yyyy-mm-dd)"]
304
+ assert_equal parsed_head[0].values, ["Date(yyyy-mm-dd)"]
362
305
  end
363
306
  end
364
307
 
@@ -397,14 +340,6 @@ class TestRoo < Test::Unit::TestCase
397
340
  end
398
341
  end
399
342
 
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
343
  def test_borders_sheets
409
344
  with_each_spreadsheet(:name=>'borders') do |oo|
410
345
  oo.default_sheet = oo.sheets[1]
@@ -439,43 +374,22 @@ class TestRoo < Test::Unit::TestCase
439
374
  end
440
375
  end
441
376
 
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
377
  def test_openoffice_download_uri_and_zipped
454
378
  if OPENOFFICE
455
379
  if ONLINE
456
380
  url = 'http://spazioinwind.libero.it/s2/rata.ods.zip'
457
- sheet = Roo::OpenOffice.new(url, :zip)
381
+ sheet = Roo::OpenOffice.new(url, packed: :zip)
458
382
  #has been changed: assert_equal 'ist "e" im Nenner von H(s)', sheet.cell('b', 5)
459
383
  assert_in_delta 0.001, 505.14, sheet.cell('c', 33).to_f
460
384
  end
461
385
  end
462
386
  end
463
387
 
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
388
  def test_openoffice_zipped
473
389
  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
390
+ oo = Roo::OpenOffice.new(File.join(TESTDIR,"bode-v1.ods.zip"), packed: :zip)
391
+ assert oo
392
+ assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
479
393
  end
480
394
  end
481
395
 
@@ -543,7 +457,6 @@ class TestRoo < Test::Unit::TestCase
543
457
  if LONG_RUN
544
458
  with_each_spreadsheet(:name=>'Bibelbund', :format=>[
545
459
  :openoffice,
546
- :excel,
547
460
  :excelx
548
461
  # Google hier nicht, weil Google-Spreadsheets nicht so gross werden
549
462
  # duerfen
@@ -564,9 +477,7 @@ class TestRoo < Test::Unit::TestCase
564
477
 
565
478
  def test_bug_quotes_excelx
566
479
  if LONG_RUN
567
- with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
568
- :excel,
569
- :excelx]) do |oo|
480
+ with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice, :excelx]) do |oo|
570
481
  oo.default_sheet = oo.sheets.first
571
482
  assert_equal 'Einflüsse der neuen Theologie in "de gereformeerde Kerken van Nederland"',
572
483
  oo.cell('a',76)
@@ -662,7 +573,7 @@ class TestRoo < Test::Unit::TestCase
662
573
  with_each_spreadsheet(:name=>'formula', :format=>[:openoffice, :excelx]) do |oo|
663
574
  oo.default_sheet = 'Sheet3' # is an empty sheet
664
575
  Dir.mktmpdir do |tempdir|
665
- assert_nothing_raised() { oo.to_csv(File.join(tempdir,"emptysheet.csv")) }
576
+ oo.to_csv(File.join(tempdir,"emptysheet.csv"))
666
577
  assert_equal "", `cat #{File.join(tempdir,"emptysheet.csv")}`
667
578
  end
668
579
  end
@@ -670,9 +581,7 @@ class TestRoo < Test::Unit::TestCase
670
581
 
671
582
  def test_find_by_row_huge_document
672
583
  if LONG_RUN
673
- with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
674
- :excel,
675
- :excelx]) do |oo|
584
+ with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice, :excelx]) do |oo|
676
585
  oo.default_sheet = oo.sheets.first
677
586
  rec = oo.find 20
678
587
  assert rec
@@ -702,10 +611,23 @@ class TestRoo < Test::Unit::TestCase
702
611
  end
703
612
  end
704
613
 
614
+ def test_find_by_row_if_header_line_is_not_nil
615
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
616
+ oo.header_line = 2
617
+ refute_nil oo.header_line
618
+ rec = oo.find 1
619
+ assert rec
620
+ assert_equal 5, rec[0]
621
+ assert_equal 6, rec[1]
622
+ rec = oo.find 15
623
+ assert rec
624
+ assert_equal "einundvierzig", rec[0]
625
+ end
626
+ end
627
+
705
628
  def test_find_by_conditions
706
629
  if LONG_RUN
707
630
  with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
708
- :excel,
709
631
  :excelx]) do |oo|
710
632
  #-----------------------------------------------------------------
711
633
  zeilen = oo.find(:all, :conditions => {
@@ -817,7 +739,6 @@ class TestRoo < Test::Unit::TestCase
817
739
  def test_column_huge_document
818
740
  if LONG_RUN
819
741
  with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
820
- :excel,
821
742
  :excelx]) do |oo|
822
743
  oo.default_sheet = oo.sheets.first
823
744
  assert_equal 3735, oo.column('a').size
@@ -835,67 +756,17 @@ class TestRoo < Test::Unit::TestCase
835
756
  assert_equal 10.75 , erg[1]['Start time']
836
757
  assert_equal 12.50 , erg[1]['End time']
837
758
  assert_equal 0 , erg[1]['Pause']
838
- assert_equal 1.75 , erg[1]['Sum'] unless oo.class == Roo::Excel
759
+ assert_equal 1.75 , erg[1]['Sum']
839
760
  assert_equal "Task 1" , erg[1]['Comment']
840
761
  end
841
762
  end
842
763
 
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
764
  def get_extension(oo)
890
765
  case oo
891
766
  when Roo::OpenOffice
892
767
  ".ods"
893
- when Roo::Excel
894
- ".xls"
895
768
  when Roo::Excelx
896
769
  ".xlsx"
897
- when Roo::Google
898
- ""
899
770
  end
900
771
  end
901
772
 
@@ -951,109 +822,21 @@ class TestRoo < Test::Unit::TestCase
951
822
  end
952
823
  end
953
824
 
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
825
  def test_should_raise_file_not_found_error
985
826
  if OPENOFFICE
986
- assert_raise(IOError) {
827
+ assert_raises(IOError) {
987
828
  Roo::OpenOffice.new(File.join('testnichtvorhanden','Bibelbund.ods'))
988
829
  }
989
830
  end
990
- if EXCEL
991
- assert_raise(IOError) {
992
- Roo::Excel.new(File.join('testnichtvorhanden','Bibelbund.xls'))
993
- }
994
- end
995
831
  if EXCELX
996
- assert_raise(IOError) {
832
+ assert_raises(IOError) {
997
833
  Roo::Excelx.new(File.join('testnichtvorhanden','Bibelbund.xlsx'))
998
834
  }
999
835
  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
836
  end
1053
837
 
1054
838
  def test_bug_bbu
1055
- with_each_spreadsheet(:name=>'bbu', :format=>[:openoffice, :excelx, :excel]) do |oo|
1056
- assert_nothing_raised() {
839
+ with_each_spreadsheet(:name=>'bbu', :format=>[:openoffice, :excelx]) do |oo|
1057
840
  assert_equal "File: bbu#{get_extension(oo)}
1058
841
  Number of sheets: 3
1059
842
  Sheets: 2007_12, Tabelle2, Tabelle3
@@ -1066,7 +849,6 @@ Sheet 2:
1066
849
  - empty -
1067
850
  Sheet 3:
1068
851
  - empty -", oo.info
1069
- }
1070
852
 
1071
853
  oo.default_sheet = oo.sheets[1] # empty sheet
1072
854
  assert_nil oo.first_row
@@ -1113,7 +895,18 @@ Sheet 3:
1113
895
  end
1114
896
  end
1115
897
  end
1116
-
898
+ def test_link_to_csv
899
+ with_each_spreadsheet(:name=>'link',:format=>:excelx) do |oo|
900
+ Dir.mktmpdir do |tempdir|
901
+ csv_output = File.join(tempdir,'link.csv')
902
+ assert oo.to_csv(csv_output)
903
+ assert File.exists?(csv_output)
904
+ assert_equal "", `diff --strip-trailing-cr #{TESTDIR}/link.csv #{csv_output}`
905
+ # --strip-trailing-cr is needed because the test-file use 0A and
906
+ # the test on an windows box generates 0D 0A as line endings
907
+ end
908
+ end
909
+ end
1117
910
  def test_date_time_yaml
1118
911
  with_each_spreadsheet(:name=>'time-test') do |oo|
1119
912
  expected =
@@ -1143,7 +936,8 @@ Sheet 3:
1143
936
 
1144
937
  def test_to_xml
1145
938
  with_each_spreadsheet(:name=>'numbers1', :encoding => 'utf8') do |oo|
1146
- assert_nothing_raised {oo.to_xml}
939
+ skip if defined? JRUBY_VERSION
940
+ oo.to_xml
1147
941
  sheetname = oo.sheets.first
1148
942
  doc = Nokogiri::XML(oo.to_xml)
1149
943
  sheet_count = 0
@@ -1177,15 +971,6 @@ Sheet 3:
1177
971
  end
1178
972
  end
1179
973
 
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
974
  def test_file_warning_default
1190
975
  if OPENOFFICE
1191
976
  assert_raises(TypeError, "test/files/numbers1.xls is not an openoffice spreadsheet") {
@@ -1193,10 +978,6 @@ Sheet 3:
1193
978
  }
1194
979
  assert_raises(TypeError) { Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xlsx")) }
1195
980
  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
981
  if EXCELX
1201
982
  assert_raises(TypeError) { Roo::Excelx.new(File.join(TESTDIR,"numbers1.ods")) }
1202
983
  assert_raises(TypeError) { Roo::Excelx.new(File.join(TESTDIR,"numbers1.xls")) }
@@ -1205,54 +986,45 @@ Sheet 3:
1205
986
 
1206
987
  def test_file_warning_error
1207
988
  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) }
989
+ assert_raises(TypeError) {
990
+ Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xls"),
991
+ packed: false,
992
+ file_warning: :error
993
+ )
994
+ }
995
+ assert_raises(TypeError) {
996
+ Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xlsx"),
997
+ packed: false,
998
+ file_warning: :error)
999
+ }
1214
1000
  end
1215
1001
  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) }
1002
+ assert_raises(TypeError) {
1003
+ Roo::Excelx.new(File.join(TESTDIR,"numbers1.ods"),
1004
+ packed: false,
1005
+ file_warning: :error)
1006
+ }
1007
+ assert_raises(TypeError) {
1008
+ Roo::Excelx.new(File.join(TESTDIR,"numbers1.xls"),
1009
+ packed: false,
1010
+ file_warning: :error)
1011
+ }
1218
1012
  end
1219
1013
  end
1220
1014
 
1221
1015
  def test_file_warning_warning
1222
1016
  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
- }
1017
+ assert_raises(ArgumentError) {
1018
+ Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xlsx"),
1019
+ packed: false,
1020
+ file_warning: :warning)
1244
1021
  }
1245
1022
  end
1246
1023
  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
- }
1024
+ assert_raises(ArgumentError) {
1025
+ Roo::Excelx.new(File.join(TESTDIR,"numbers1.ods"),
1026
+ packed: false,
1027
+ file_warning: :warning)
1256
1028
  }
1257
1029
  end
1258
1030
  end
@@ -1264,41 +1036,20 @@ Sheet 3:
1264
1036
  # Es soll ohne Fehlermeldung oder Warnung
1265
1037
  # oder Abbruch die Datei geoffnet werden
1266
1038
 
1267
- # xls
1268
- assert_nothing_raised() {
1269
- Roo::OpenOffice.new(File.join(TESTDIR,"type_openoffice.xls"),false, :ignore)
1270
- }
1271
1039
  # 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
- }
1040
+ Roo::OpenOffice.new(File.join(TESTDIR,"type_openoffice.xlsx"),
1041
+ packed: false,
1042
+ file_warning: :ignore)
1283
1043
  end
1284
1044
  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
1045
+ Roo::Excelx.new(File.join(TESTDIR,"type_excelx.ods"),
1046
+ packed: false,
1047
+ file_warning: :ignore)
1297
1048
  end
1298
1049
  end
1299
1050
 
1300
1051
  def test_bug_to_xml_with_empty_sheets
1301
- with_each_spreadsheet(:name=>'emptysheets', :format=>[:openoffice, :excel]) do |oo|
1052
+ with_each_spreadsheet(:name=>'emptysheets', :format=>[:openoffice, :excelx]) do |oo|
1302
1053
  oo.sheets.each { |sheet|
1303
1054
  assert_equal nil, oo.first_row, "first_row not nil in sheet #{sheet}"
1304
1055
  assert_equal nil, oo.last_row, "last_row not nil in sheet #{sheet}"
@@ -1309,7 +1060,7 @@ Sheet 3:
1309
1060
  assert_equal nil, oo.first_column(sheet), "first_column not nil in sheet #{sheet}"
1310
1061
  assert_equal nil, oo.last_column(sheet), "last_column not nil in sheet #{sheet}"
1311
1062
  }
1312
- assert_nothing_raised() { oo.to_xml }
1063
+ oo.to_xml
1313
1064
  end
1314
1065
  end
1315
1066
 
@@ -1364,12 +1115,12 @@ Sheet 3:
1364
1115
  def test_datetime
1365
1116
  with_each_spreadsheet(:name=>'datetime') do |oo|
1366
1117
  val = oo.cell('c',3)
1367
- assert_kind_of DateTime, val
1368
1118
  assert_equal :datetime, oo.celltype('c',3)
1369
1119
  assert_equal DateTime.new(1961,11,21,12,17,18), val
1120
+ assert_kind_of DateTime, val
1370
1121
  val = oo.cell('a',1)
1371
- assert_kind_of Date, val
1372
1122
  assert_equal :date, oo.celltype('a',1)
1123
+ assert_kind_of Date, val
1373
1124
  assert_equal Date.new(1961,11,21), val
1374
1125
  assert_equal Date.new(1961,11,21), oo.cell('a',1)
1375
1126
  assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('a',3)
@@ -1387,6 +1138,9 @@ Sheet 3:
1387
1138
  assert_equal Date.new(1961,11,21), oo.cell('a',7)
1388
1139
  assert_equal Date.new(1961,11,21), oo.cell('b',7)
1389
1140
  assert_equal Date.new(1961,11,21), oo.cell('c',7)
1141
+ assert_equal DateTime.new(2013,11,5,11,45,00), oo.cell('a',8)
1142
+ assert_equal DateTime.new(2013,11,5,11,45,00), oo.cell('b',8)
1143
+ assert_equal DateTime.new(2013,11,5,11,45,00), oo.cell('c',8)
1390
1144
  end
1391
1145
  end
1392
1146
 
@@ -1402,7 +1156,7 @@ Sheet 3:
1402
1156
  end
1403
1157
 
1404
1158
  def test_cell_boolean
1405
- with_each_spreadsheet(:name=>'boolean', :format=>[:openoffice, :excel, :excelx]) do |oo|
1159
+ with_each_spreadsheet(:name=>'boolean', :format=>[:openoffice, :excelx]) do |oo|
1406
1160
  if oo.class == Roo::Excelx
1407
1161
  assert_equal "TRUE", oo.cell(1,1), "failure in "+oo.class.to_s
1408
1162
  assert_equal "FALSE", oo.cell(2,1), "failure in "+oo.class.to_s
@@ -1414,7 +1168,7 @@ Sheet 3:
1414
1168
  end
1415
1169
 
1416
1170
  def test_cell_multiline
1417
- with_each_spreadsheet(:name=>'paragraph', :format=>[:openoffice, :excel, :excelx]) do |oo|
1171
+ with_each_spreadsheet(:name=>'paragraph', :format=>[:openoffice, :excelx]) do |oo|
1418
1172
  assert_equal "This is a test\nof a multiline\nCell", oo.cell(1,1)
1419
1173
  assert_equal "This is a test\n¶\nof a multiline\n\nCell", oo.cell(1,2)
1420
1174
  assert_equal "first p\n\nsecond p\n\nlast p", oo.cell(2,1)
@@ -1425,8 +1179,7 @@ Sheet 3:
1425
1179
  # styles only valid in excel spreadsheets?
1426
1180
  # TODO: what todo with other spreadsheet types
1427
1181
  with_each_spreadsheet(:name=>'style', :format=>[# :openoffice,
1428
- :excel,
1429
- # :excelx
1182
+ :excelx
1430
1183
  ]) do |oo|
1431
1184
  # bold
1432
1185
  assert_equal true, oo.font(1,1).bold?
@@ -1485,18 +1238,6 @@ Sheet 3:
1485
1238
  end
1486
1239
  end
1487
1240
 
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
1241
  # Need to extend to other formats
1501
1242
  def test_row_whitespace
1502
1243
  # auf dieses Dokument habe ich keinen Zugriff TODO:
@@ -1535,45 +1276,10 @@ Sheet 3:
1535
1276
  end
1536
1277
  end
1537
1278
 
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
1279
  def test_excelx_links
1554
1280
  with_each_spreadsheet(:name=>'link', :format=>:excelx) do |oo|
1555
1281
  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)
1282
+ assert_equal 'http://www.google.com', oo.cell(1,1).href
1577
1283
  end
1578
1284
  end
1579
1285
 
@@ -1590,22 +1296,6 @@ Sheet 3:
1590
1296
  end
1591
1297
  end
1592
1298
 
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
1299
  def test_cell_methods
1610
1300
  with_each_spreadsheet(:name=>'numbers1') do |oo|
1611
1301
  assert_equal 10, oo.a4 # cell(4,'A')
@@ -1747,7 +1437,7 @@ Sheet 3:
1747
1437
 
1748
1438
  require 'matrix'
1749
1439
  def test_matrix
1750
- with_each_spreadsheet(:name => 'matrix', :format => [:openoffice, :excel, :google]) do |oo|
1440
+ with_each_spreadsheet(:name => 'matrix', :format => :openoffice) do |oo|
1751
1441
  oo.default_sheet = oo.sheets.first
1752
1442
  assert_equal Matrix[
1753
1443
  [1.0, 2.0, 3.0],
@@ -1757,7 +1447,7 @@ Sheet 3:
1757
1447
  end
1758
1448
 
1759
1449
  def test_matrix_selected_range
1760
- with_each_spreadsheet(:name => 'matrix', :format=>[:excel,:openoffice,:google]) do |oo|
1450
+ with_each_spreadsheet(:name => 'matrix', :format=>:openoffice) do |oo|
1761
1451
  oo.default_sheet = 'Sheet2'
1762
1452
  assert_equal Matrix[
1763
1453
  [1.0, 2.0, 3.0],
@@ -1767,7 +1457,7 @@ Sheet 3:
1767
1457
  end
1768
1458
 
1769
1459
  def test_matrix_all_nil
1770
- with_each_spreadsheet(:name => 'matrix', :format=>[:excel,:openoffice,:google]) do |oo|
1460
+ with_each_spreadsheet(:name => 'matrix', :format=>:openoffice) do |oo|
1771
1461
  oo.default_sheet = 'Sheet2'
1772
1462
  assert_equal Matrix[
1773
1463
  [nil, nil, nil],
@@ -1777,7 +1467,7 @@ Sheet 3:
1777
1467
  end
1778
1468
 
1779
1469
  def test_matrix_values_and_nil
1780
- with_each_spreadsheet(:name => 'matrix', :format=>[:excel,:openoffice,:google]) do |oo|
1470
+ with_each_spreadsheet(:name => 'matrix', :format=>:openoffice) do |oo|
1781
1471
  oo.default_sheet = 'Sheet3'
1782
1472
  assert_equal Matrix[
1783
1473
  [1.0, nil, 3.0],
@@ -1787,7 +1477,7 @@ Sheet 3:
1787
1477
  end
1788
1478
 
1789
1479
  def test_matrix_specifying_sheet
1790
- with_each_spreadsheet(:name => 'matrix', :format => [:openoffice, :excel, :google]) do |oo|
1480
+ with_each_spreadsheet(:name => 'matrix', :format => :openoffice) do |oo|
1791
1481
  oo.default_sheet = oo.sheets.first
1792
1482
  assert_equal Matrix[
1793
1483
  [1.0, nil, 3.0],
@@ -1839,11 +1529,9 @@ where the expected result is
1839
1529
  # 2011-06-24
1840
1530
  def test_bug_formulas_empty_sheet
1841
1531
  with_each_spreadsheet(:name =>'emptysheets',
1842
- :format=>[:openoffice,:excelx,:google]) do |oo|
1843
- assert_nothing_raised(NoMethodError) {
1532
+ :format=>[:openoffice,:excelx]) do |oo|
1844
1533
  oo.default_sheet = oo.sheets.first
1845
1534
  oo.formulas
1846
- }
1847
1535
  assert_equal([], oo.formulas)
1848
1536
  end
1849
1537
  end
@@ -1853,11 +1541,9 @@ where the expected result is
1853
1541
  # 2011-06-24
1854
1542
  def test_bug_to_yaml_empty_sheet
1855
1543
  with_each_spreadsheet(:name =>'emptysheets',
1856
- :format=>[:openoffice,:excelx,:google]) do |oo|
1857
- assert_nothing_raised(NoMethodError) {
1544
+ :format=>[:openoffice,:excelx]) do |oo|
1858
1545
  oo.default_sheet = oo.sheets.first
1859
1546
  oo.to_yaml
1860
- }
1861
1547
  assert_equal('', oo.to_yaml)
1862
1548
  end
1863
1549
  end
@@ -1867,11 +1553,9 @@ where the expected result is
1867
1553
  # 2011-06-25
1868
1554
  def test_bug_to_matrix_empty_sheet
1869
1555
  with_each_spreadsheet(:name =>'emptysheets',
1870
- :format=>[:openoffice,:excelx,:google]) do |oo|
1871
- assert_nothing_raised(NoMethodError) {
1556
+ :format=>[:openoffice,:excelx]) do |oo|
1872
1557
  oo.default_sheet = oo.sheets.first
1873
1558
  oo.to_matrix
1874
- }
1875
1559
  assert_equal(Matrix.empty(0,0), oo.to_matrix)
1876
1560
  end
1877
1561
  end
@@ -1963,6 +1647,7 @@ where the expected result is
1963
1647
  end
1964
1648
 
1965
1649
  def test_bug_pfand_from_windows_phone_xlsx
1650
+ return if defined? JRUBY_VERSION
1966
1651
  with_each_spreadsheet(:name=>'Pfand_from_windows_phone', :format=>:excelx) do |oo|
1967
1652
  oo.default_sheet = oo.sheets.first
1968
1653
  assert_equal ['Blatt1','Blatt2','Blatt3'], oo.sheets
@@ -1992,15 +1677,6 @@ where the expected result is
1992
1677
  end
1993
1678
  end
1994
1679
 
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
1680
  def test_comments
2005
1681
  with_each_spreadsheet(:name=>'comments', :format=>[:openoffice,:libreoffice,
2006
1682
  :excelx]) do |oo|
@@ -2013,6 +1689,11 @@ where the expected result is
2013
1689
  oo.default_sheet = oo.sheets[1]
2014
1690
  assert_equal [], oo.comments, "comments error in class #{oo.class}"
2015
1691
  end
1692
+
1693
+ with_each_spreadsheet(:name=>'comments-google', :format=>[:excelx]) do |oo|
1694
+ oo.default_sheet = oo.sheets.first
1695
+ assert_equal [[1, 1, "this is a comment\n\t-Steven Daniels"]], oo.comments(oo.sheets.first), "comments error in class #{oo.class}"
1696
+ end
2016
1697
  end
2017
1698
 
2018
1699
  ## PREVIOUSLY SKIPPED
@@ -2091,13 +1772,6 @@ where the expected result is
2091
1772
  # end
2092
1773
  # end
2093
1774
 
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
1775
  def test_download_uri
2102
1776
  if ONLINE
2103
1777
  if OPENOFFICE
@@ -2105,11 +1779,6 @@ where the expected result is
2105
1779
  Roo::OpenOffice.new("http://gibbsnichtdomainxxxxx.com/file.ods")
2106
1780
  }
2107
1781
  end
2108
- if EXCEL
2109
- assert_raises(RuntimeError) {
2110
- Roo::Excel.new("http://gibbsnichtdomainxxxxx.com/file.xls")
2111
- }
2112
- end
2113
1782
  if EXCELX
2114
1783
  assert_raises(RuntimeError) {
2115
1784
  Roo::Excelx.new("http://gibbsnichtdomainxxxxx.com/file.xlsx")
@@ -2120,8 +1789,7 @@ where the expected result is
2120
1789
 
2121
1790
  def test_download_uri_with_query_string
2122
1791
  dir = File.expand_path("#{File.dirname __FILE__}/files")
2123
- { xls: [EXCEL, Roo::Excel],
2124
- xlsx: [EXCELX, Roo::Excelx],
1792
+ { xlsx: [EXCELX, Roo::Excelx],
2125
1793
  ods: [OPENOFFICE, Roo::OpenOffice]}.each do |extension, (flag, type)|
2126
1794
  if flag
2127
1795
  file = "#{dir}/simple_spreadsheet.#{extension}"
@@ -2285,8 +1953,136 @@ where the expected result is
2285
1953
 
2286
1954
  def test_bug_numbered_sheet_names
2287
1955
  with_each_spreadsheet(:name=>'bug-numbered-sheet-names', :format=>:excelx) do |oo|
2288
- assert_nothing_raised() { oo.each_with_pagename { } }
1956
+ oo.each_with_pagename { }
1957
+ end
1958
+ end
1959
+
1960
+ def test_parsing_xslx_from_numbers
1961
+ return unless EXCELX
1962
+ xlsx = Roo::Excelx.new(File.join(TESTDIR, "numbers-export.xlsx"))
1963
+
1964
+ xlsx.default_sheet = xlsx.sheets.first
1965
+ assert_equal 'Sheet 1', xlsx.cell('a',1)
1966
+
1967
+ # Another buggy behavior of Numbers 3.1: if a warkbook has more than a
1968
+ # single sheet, all sheets except the first one will have an extra row and
1969
+ # column added to the beginning. That's why we assert against cell B2 and
1970
+ # not A1
1971
+ xlsx.default_sheet = xlsx.sheets.last
1972
+ assert_equal 'Sheet 2', xlsx.cell('b',2)
1973
+ end
1974
+
1975
+ def test_openoffice_encryption
1976
+ if OPENOFFICE
1977
+ assert_raises(ArgumentError) { Roo::LibreOffice.new(File.join(TESTDIR, "encrypted-letmein.ods")) }
1978
+ assert_raises(ArgumentError) { Roo::LibreOffice.new(File.join(TESTDIR, "encrypted-letmein.ods"), :password => "badpassword") }
1979
+ oo = Roo::LibreOffice.new(File.join(TESTDIR, "encrypted-letmein.ods"), :password => "letmein")
1980
+ oo.default_sheet = oo.sheets.first
1981
+ assert_equal "Hello World", oo.cell('a',1)
1982
+ end
1983
+ end
1984
+
1985
+ def test_expand_merged_range
1986
+ return unless EXCELX
1987
+ xlsx = Roo::Excelx.new(File.join(TESTDIR, "merged_ranges.xlsx"), {:expand_merged_ranges => true})
1988
+ for row in 3..7 do
1989
+ for col in 'a'..'b'
1990
+ if row > 3 && row < 7 && col == 'a'
1991
+ assert_equal 'vertical1', xlsx.cell(col,row)
1992
+ else
1993
+ assert_nil xlsx.cell(col,row)
1994
+ end
1995
+ end
1996
+ end
1997
+ for row in 3..11 do
1998
+ for col in 'f'..'h'
1999
+ if row > 3 && row < 11 && col == 'g'
2000
+ assert_equal 'vertical2', xlsx.cell(col,row)
2001
+ else
2002
+ assert_nil xlsx.cell(col,row)
2003
+ end
2004
+ end
2005
+ end
2006
+ for row in 3..5 do
2007
+ for col in 'b'..'f'
2008
+ if row == 4 && col > 'b' && col < 'f'
2009
+ assert_equal 'horizontal', xlsx.cell(col,row)
2010
+ else
2011
+ assert_nil xlsx.cell(col,row)
2012
+ end
2013
+ end
2014
+ end
2015
+ for row in 8..13 do
2016
+ for col in 'a'..'e'
2017
+ if row > 8 && row < 13 && col > 'a' && col < 'e'
2018
+ assert_equal 'block', xlsx.cell(col,row)
2019
+ else
2020
+ assert_nil xlsx.cell(col,row)
2021
+ end
2022
+ end
2289
2023
  end
2290
2024
  end
2291
2025
 
2026
+ def test_noexpand_merged_range
2027
+ return unless EXCELX
2028
+ xlsx = Roo::Excelx.new(File.join(TESTDIR, "merged_ranges.xlsx"))
2029
+ for row in 3..7 do
2030
+ for col in 'a'..'b'
2031
+ if row == 4 && col == 'a'
2032
+ assert_equal 'vertical1', xlsx.cell(col,row)
2033
+ else
2034
+ assert_nil xlsx.cell(col,row)
2035
+ end
2036
+ end
2037
+ end
2038
+ for row in 3..11 do
2039
+ for col in 'f'..'h'
2040
+ if row == 4 && col == 'g'
2041
+ assert_equal 'vertical2', xlsx.cell(col,row)
2042
+ else
2043
+ assert_nil xlsx.cell(col,row)
2044
+ end
2045
+ end
2046
+ end
2047
+ for row in 3..5 do
2048
+ for col in 'b'..'f'
2049
+ if row == 4 && col == 'c'
2050
+ assert_equal 'horizontal', xlsx.cell(col,row)
2051
+ else
2052
+ assert_nil xlsx.cell(col,row)
2053
+ end
2054
+ end
2055
+ end
2056
+ for row in 8..13 do
2057
+ for col in 'a'..'e'
2058
+ if row == 9 && col == 'b'
2059
+ assert_equal 'block', xlsx.cell(col,row)
2060
+ else
2061
+ assert_nil xlsx.cell(col,row)
2062
+ end
2063
+ end
2064
+ end
2065
+ end
2066
+
2067
+ def test_open_stream
2068
+ return unless EXCELX
2069
+ file_contents = File.read File.join(TESTDIR, fixture_filename(:numbers1, :excelx))
2070
+ stream = StringIO.new(file_contents)
2071
+ xlsx = Roo::Excelx.new(stream)
2072
+ assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], xlsx.sheets
2073
+ end
2074
+
2075
+ def test_close
2076
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
2077
+ next unless (tempdir = oo.instance_variable_get('@tmpdir'))
2078
+ oo.close
2079
+ assert !File.exists?(tempdir), "Expected #{tempdir} to be cleaned up, but it still exists"
2080
+ end
2081
+ end
2082
+
2083
+ def test_cleanup_on_error
2084
+ old_temp_files = Dir.open(Dir.tmpdir).to_a
2085
+ with_each_spreadsheet(:name=>'non_existent_file', :ignore_errors=>true) do |oo|; end
2086
+ assert_equal Dir.open(Dir.tmpdir).to_a, old_temp_files
2087
+ end
2292
2088
  end # class