roo 2.3.0 → 2.10.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 (95) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +17 -0
  3. data/.github/issue_template.md +16 -0
  4. data/.github/pull_request_template.md +14 -0
  5. data/.github/workflows/pull-request.yml +15 -0
  6. data/.github/workflows/ruby.yml +34 -0
  7. data/.gitignore +4 -0
  8. data/.rubocop.yml +186 -0
  9. data/CHANGELOG.md +148 -0
  10. data/Gemfile +4 -4
  11. data/LICENSE +2 -0
  12. data/README.md +84 -27
  13. data/Rakefile +1 -1
  14. data/lib/roo/base.rb +111 -237
  15. data/lib/roo/constants.rb +5 -3
  16. data/lib/roo/csv.rb +106 -85
  17. data/lib/roo/errors.rb +2 -0
  18. data/lib/roo/excelx/cell/base.rb +26 -12
  19. data/lib/roo/excelx/cell/boolean.rb +9 -6
  20. data/lib/roo/excelx/cell/date.rb +7 -7
  21. data/lib/roo/excelx/cell/datetime.rb +50 -44
  22. data/lib/roo/excelx/cell/empty.rb +3 -2
  23. data/lib/roo/excelx/cell/number.rb +60 -47
  24. data/lib/roo/excelx/cell/string.rb +3 -3
  25. data/lib/roo/excelx/cell/time.rb +17 -16
  26. data/lib/roo/excelx/cell.rb +11 -7
  27. data/lib/roo/excelx/comments.rb +3 -3
  28. data/lib/roo/excelx/coordinate.rb +11 -4
  29. data/lib/roo/excelx/extractor.rb +20 -3
  30. data/lib/roo/excelx/format.rb +38 -31
  31. data/lib/roo/excelx/images.rb +26 -0
  32. data/lib/roo/excelx/relationships.rb +12 -4
  33. data/lib/roo/excelx/shared.rb +10 -3
  34. data/lib/roo/excelx/shared_strings.rb +113 -9
  35. data/lib/roo/excelx/sheet.rb +49 -10
  36. data/lib/roo/excelx/sheet_doc.rb +101 -48
  37. data/lib/roo/excelx/styles.rb +4 -4
  38. data/lib/roo/excelx/workbook.rb +8 -3
  39. data/lib/roo/excelx.rb +85 -42
  40. data/lib/roo/formatters/base.rb +15 -0
  41. data/lib/roo/formatters/csv.rb +84 -0
  42. data/lib/roo/formatters/matrix.rb +23 -0
  43. data/lib/roo/formatters/xml.rb +31 -0
  44. data/lib/roo/formatters/yaml.rb +40 -0
  45. data/lib/roo/helpers/default_attr_reader.rb +20 -0
  46. data/lib/roo/helpers/weak_instance_cache.rb +41 -0
  47. data/lib/roo/open_office.rb +41 -27
  48. data/lib/roo/spreadsheet.rb +8 -2
  49. data/lib/roo/tempdir.rb +24 -0
  50. data/lib/roo/utils.rb +76 -26
  51. data/lib/roo/version.rb +1 -1
  52. data/lib/roo.rb +5 -0
  53. data/roo.gemspec +22 -12
  54. data/spec/lib/roo/base_spec.rb +65 -3
  55. data/spec/lib/roo/csv_spec.rb +19 -0
  56. data/spec/lib/roo/excelx/cell/time_spec.rb +15 -0
  57. data/spec/lib/roo/excelx/relationships_spec.rb +43 -0
  58. data/spec/lib/roo/excelx/sheet_doc_spec.rb +11 -0
  59. data/spec/lib/roo/excelx_spec.rb +237 -5
  60. data/spec/lib/roo/openoffice_spec.rb +2 -2
  61. data/spec/lib/roo/spreadsheet_spec.rb +1 -1
  62. data/spec/lib/roo/strict_spec.rb +43 -0
  63. data/spec/lib/roo/utils_spec.rb +22 -9
  64. data/spec/lib/roo/weak_instance_cache_spec.rb +92 -0
  65. data/spec/lib/roo_spec.rb +0 -0
  66. data/spec/spec_helper.rb +2 -7
  67. data/test/excelx/cell/test_attr_reader_default.rb +72 -0
  68. data/test/excelx/cell/test_base.rb +6 -2
  69. data/test/excelx/cell/test_boolean.rb +1 -3
  70. data/test/excelx/cell/test_date.rb +1 -6
  71. data/test/excelx/cell/test_datetime.rb +7 -10
  72. data/test/excelx/cell/test_empty.rb +12 -2
  73. data/test/excelx/cell/test_number.rb +28 -4
  74. data/test/excelx/cell/test_string.rb +21 -3
  75. data/test/excelx/cell/test_time.rb +7 -10
  76. data/test/excelx/test_coordinate.rb +51 -0
  77. data/test/formatters/test_csv.rb +136 -0
  78. data/test/formatters/test_matrix.rb +76 -0
  79. data/test/formatters/test_xml.rb +78 -0
  80. data/test/formatters/test_yaml.rb +20 -0
  81. data/test/helpers/test_accessing_files.rb +81 -0
  82. data/test/helpers/test_comments.rb +43 -0
  83. data/test/helpers/test_formulas.rb +9 -0
  84. data/test/helpers/test_labels.rb +103 -0
  85. data/test/helpers/test_sheets.rb +55 -0
  86. data/test/helpers/test_styles.rb +62 -0
  87. data/test/roo/test_base.rb +182 -0
  88. data/test/roo/test_csv.rb +88 -0
  89. data/test/roo/test_excelx.rb +360 -0
  90. data/test/roo/test_libre_office.rb +9 -0
  91. data/test/roo/test_open_office.rb +289 -0
  92. data/test/test_helper.rb +129 -14
  93. data/test/test_roo.rb +60 -1765
  94. metadata +91 -21
  95. data/.travis.yml +0 -14
data/test/test_roo.rb CHANGED
@@ -1,102 +1,23 @@
1
1
  # encoding: utf-8
2
- # damit keine falschen Vermutungen aufkommen: Ich habe religioes rein gar nichts
3
- # mit diesem Bibelbund zu tun, aber die hatten eine ziemlich grosse
4
- # Spreadsheet-Datei mit ca. 3500 Zeilen oeffentlich im Netz, die sich ganz gut
5
- # zum Testen eignete.
6
- #
7
- #--
8
- # these test cases were developed to run under Linux OS, some commands
9
- # (like 'diff') must be changed (or commented out ;-)) if you want to run
10
- # the tests under another OS
11
- #
12
-
13
- #TODO
14
- # Look at formulas in excel - does not work with date/time
15
2
 
16
3
  # Dump warnings that come from the test to open files
17
4
  # with the wrong spreadsheet class
18
5
  #STDERR.reopen "/dev/null","w"
19
6
 
7
+ Encoding.default_external = "UTF-8"
8
+
20
9
  require 'test_helper'
21
10
  require 'stringio'
22
11
 
23
12
  class TestRoo < Minitest::Test
24
-
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)
29
-
30
- FORMATS = [
31
- :excelx,
32
- :excelxm,
33
- :openoffice,
34
- :libreoffice
35
- ]
36
-
37
- ONLINE = false
38
- LONG_RUN = false
39
-
40
- def fixture_filename(name, format)
41
- case format
42
- when :excelx
43
- "#{name}.xlsx"
44
- when :excelxm
45
- "#{name}.xlsm"
46
- when :openoffice, :libreoffice
47
- "#{name}.ods"
48
- else
49
- raise ArgumentError, "unexpected format #{format}"
50
- end
51
- end
52
-
53
- # call a block of code for each spreadsheet type
54
- # and yield a reference to the roo object
55
- def with_each_spreadsheet(options)
56
- if options[:format]
57
- formats = Array(options[:format])
58
- invalid_formats = formats - FORMATS
59
- unless invalid_formats.empty?
60
- raise "invalid spreadsheet types: #{invalid_formats.join(', ')}"
61
- end
62
- else
63
- formats = FORMATS
64
- end
65
- formats.each do |format|
66
- begin
67
- yield Roo::Spreadsheet.open(File.join(TESTDIR,
68
- fixture_filename(options[:name], format)))
69
- rescue => e
70
- raise e, "#{e.message} for #{format}", e.backtrace unless options[:ignore_errors]
71
- end
72
- end
73
- end
74
-
75
- def test_sheets_csv
76
- if CSV
77
- oo = Roo::CSV.new(File.join(TESTDIR,'numbers1.csv'))
78
- assert_equal ["default"], oo.sheets
79
- assert_raises(RangeError) { oo.default_sheet = "no_sheet" }
80
- assert_raises(TypeError) { oo.default_sheet = [1,2,3] }
81
- oo.sheets.each { |sh|
82
- oo.default_sheet = sh
83
- assert_equal sh, oo.default_sheet
84
- }
85
- end
86
- end
87
-
88
- def test_sheets
89
- with_each_spreadsheet(:name=>'numbers1') do |oo|
90
- assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets
91
- assert_raises(RangeError) { oo.default_sheet = "no_sheet" }
92
- assert_raises(TypeError) { oo.default_sheet = [1,2,3] }
93
- oo.sheets.each { |sh|
94
- oo.default_sheet = sh
95
- assert_equal sh, oo.default_sheet
96
- }
97
- end
98
- end
99
-
13
+ include TestSheets
14
+ include TestAccesingFiles
15
+ include TestFormulas
16
+ include TestComments
17
+ include TestLabels
18
+ include TestStyles
19
+
20
+ # Cell related tests
100
21
  def test_cells
101
22
  with_each_spreadsheet(:name=>'numbers1') do |oo|
102
23
  # warum ist Auswaehlen erstes sheet hier nicht
@@ -135,12 +56,6 @@ class TestRoo < Minitest::Test
135
56
  end
136
57
  end
137
58
 
138
- def test_celltype
139
- with_each_spreadsheet(:name=>'numbers1') do |oo|
140
- assert_equal :string, oo.celltype(2,6)
141
- end
142
- end
143
-
144
59
  def test_cell_address
145
60
  with_each_spreadsheet(:name=>'numbers1') do |oo|
146
61
  assert_equal "tata", oo.cell(6,1)
@@ -160,54 +75,6 @@ class TestRoo < Minitest::Test
160
75
  end
161
76
  end
162
77
 
163
- def test_office_version
164
- with_each_spreadsheet(:name=>'numbers1', :format=>:openoffice) do |oo|
165
- assert_equal "1.0", oo.officeversion
166
- end
167
- end
168
-
169
- def test_libre_office
170
- if LIBREOFFICE
171
- oo = Roo::LibreOffice.new(File.join(TESTDIR, "numbers1.ods"))
172
- oo.default_sheet = oo.sheets.first
173
- assert_equal 41, oo.cell('a',12)
174
- end
175
- end
176
-
177
- def test_sheetname
178
- with_each_spreadsheet(:name=>'numbers1') do |oo|
179
- oo.default_sheet = "Name of Sheet 2"
180
- assert_equal 'I am sheet 2', oo.cell('C',5)
181
- assert_raises(RangeError) { oo.default_sheet = "non existing sheet name" }
182
- assert_raises(RangeError) { oo.default_sheet = "non existing sheet name" }
183
- assert_raises(RangeError) { oo.cell('C',5,"non existing sheet name")}
184
- assert_raises(RangeError) { oo.celltype('C',5,"non existing sheet name")}
185
- assert_raises(RangeError) { oo.empty?('C',5,"non existing sheet name")}
186
- assert_raises(RangeError) { oo.formula?('C',5,"non existing sheet name")}
187
- assert_raises(RangeError) { oo.formula('C',5,"non existing sheet name")}
188
- assert_raises(RangeError) { oo.set('C',5,42,"non existing sheet name")}
189
- assert_raises(RangeError) { oo.formulas("non existing sheet name")}
190
- assert_raises(RangeError) { oo.to_yaml({},1,1,1,1,"non existing sheet name")}
191
- end
192
- end
193
-
194
- def test_argument_error
195
- with_each_spreadsheet(:name=>'numbers1') do |oo|
196
- oo.default_sheet = "Tabelle1"
197
- end
198
- end
199
-
200
- def test_bug_contiguous_cells
201
- with_each_spreadsheet(:name=>'numbers1', :format=>:openoffice) do |oo|
202
- oo.default_sheet = "Sheet4"
203
- assert_equal Date.new(2007,06,16), oo.cell('a',1)
204
- assert_equal 10, oo.cell('b',1)
205
- assert_equal 10, oo.cell('c',1)
206
- assert_equal 10, oo.cell('d',1)
207
- assert_equal 10, oo.cell('e',1)
208
- end
209
- end
210
-
211
78
  def test_bug_italo_ve
212
79
  with_each_spreadsheet(:name=>'numbers1') do |oo|
213
80
  oo.default_sheet = "Sheet5"
@@ -219,127 +86,15 @@ class TestRoo < Minitest::Test
219
86
  end
220
87
  end
221
88
 
222
- def test_italo_table
223
- with_each_spreadsheet(:name=>'simple_spreadsheet_from_italo', :format=>:openoffice) do |oo|
224
- assert_equal '1', oo.cell('A',1)
225
- assert_equal '1', oo.cell('B',1)
226
- assert_equal '1', oo.cell('C',1)
227
- assert_equal 1, oo.cell('A',2).to_i
228
- assert_equal 2, oo.cell('B',2).to_i
229
- assert_equal 1, oo.cell('C',2).to_i
230
- assert_equal 1, oo.cell('A',3)
231
- assert_equal 3, oo.cell('B',3)
232
- assert_equal 1, oo.cell('C',3)
233
- assert_equal 'A', oo.cell('A',4)
234
- assert_equal 'A', oo.cell('B',4)
235
- assert_equal 'A', oo.cell('C',4)
236
- assert_equal 0.01, oo.cell('A',5)
237
- assert_equal 0.01, oo.cell('B',5)
238
- assert_equal 0.01, oo.cell('C',5)
239
- assert_equal 0.03, oo.cell('a',5)+oo.cell('b',5)+oo.cell('c',5)
240
-
241
- # Cells values in row 1:
242
- assert_equal "1:string", oo.cell(1, 1)+":"+oo.celltype(1, 1).to_s
243
- assert_equal "1:string",oo.cell(1, 2)+":"+oo.celltype(1, 2).to_s
244
- assert_equal "1:string",oo.cell(1, 3)+":"+oo.celltype(1, 3).to_s
245
-
246
- # Cells values in row 2:
247
- assert_equal "1:string",oo.cell(2, 1)+":"+oo.celltype(2, 1).to_s
248
- assert_equal "2:string",oo.cell(2, 2)+":"+oo.celltype(2, 2).to_s
249
- assert_equal "1:string",oo.cell(2, 3)+":"+oo.celltype(2, 3).to_s
250
-
251
- # Cells values in row 3:
252
- assert_equal "1:float",oo.cell(3, 1).to_s+":"+oo.celltype(3, 1).to_s
253
- assert_equal "3:float",oo.cell(3, 2).to_s+":"+oo.celltype(3, 2).to_s
254
- assert_equal "1:float",oo.cell(3, 3).to_s+":"+oo.celltype(3, 3).to_s
255
-
256
- # Cells values in row 4:
257
- assert_equal "A:string",oo.cell(4, 1)+":"+oo.celltype(4, 1).to_s
258
- assert_equal "A:string",oo.cell(4, 2)+":"+oo.celltype(4, 2).to_s
259
- assert_equal "A:string",oo.cell(4, 3)+":"+oo.celltype(4, 3).to_s
260
-
261
- # Cells values in row 5:
262
- if oo.class == Roo::OpenOffice
263
- assert_equal "0.01:percentage",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
264
- assert_equal "0.01:percentage",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
265
- assert_equal "0.01:percentage",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
266
- else
267
- assert_equal "0.01:float",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
268
- assert_equal "0.01:float",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
269
- assert_equal "0.01:float",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
270
- end
271
- end
272
- end
273
-
274
- def test_formula_openoffice
275
- with_each_spreadsheet(:name=>'formula', :format=>:openoffice) do |oo|
276
- assert_equal 1, oo.cell('A',1)
277
- assert_equal 2, oo.cell('A',2)
278
- assert_equal 3, oo.cell('A',3)
279
- assert_equal 4, oo.cell('A',4)
280
- assert_equal 5, oo.cell('A',5)
281
- assert_equal 6, oo.cell('A',6)
282
- assert_equal 21, oo.cell('A',7)
283
- assert_equal :formula, oo.celltype('A',7)
284
- assert_equal "=[Sheet2.A1]", oo.formula('C',7)
285
- assert_nil oo.formula('A',6)
286
- assert_equal [[7, 1, "=SUM([.A1:.A6])"],
287
- [7, 2, "=SUM([.$A$1:.B6])"],
288
- [7, 3, "=[Sheet2.A1]"],
289
- [8, 2, "=SUM([.$A$1:.B7])"],
290
- ], oo.formulas(oo.sheets.first)
291
-
292
- # setting a cell
293
- oo.set('A',15, 41)
294
- assert_equal 41, oo.cell('A',15)
295
- oo.set('A',16, "41")
296
- assert_equal "41", oo.cell('A',16)
297
- oo.set('A',17, 42.5)
298
- assert_equal 42.5, oo.cell('A',17)
299
- end
300
- end
301
-
302
- def test_header_with_brackets_excelx
303
- with_each_spreadsheet(:name => 'advanced_header', :format => :openoffice) do |oo|
304
- parsed_head = oo.parse(:headers => true)
305
- assert_equal "Date(yyyy-mm-dd)", oo.cell('A',1)
306
- assert_equal parsed_head[0].keys, ["Date(yyyy-mm-dd)"]
307
- assert_equal parsed_head[0].values, ["Date(yyyy-mm-dd)"]
89
+ def test_celltype
90
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
91
+ assert_equal :string, oo.celltype(2,6)
308
92
  end
309
93
  end
310
94
 
311
- def test_formula_excelx
312
- with_each_spreadsheet(:name=>'formula', :format=>:excelx) do |oo|
313
- assert_equal 1, oo.cell('A',1)
314
- assert_equal 2, oo.cell('A',2)
315
- assert_equal 3, oo.cell('A',3)
316
- assert_equal 4, oo.cell('A',4)
317
- assert_equal 5, oo.cell('A',5)
318
- assert_equal 6, oo.cell('A',6)
319
- assert_equal 21, oo.cell('A',7)
320
- assert_equal :formula, oo.celltype('A',7)
321
- #steht nicht in Datei, oder?
322
- #nein, diesen Bezug habe ich nur in der OpenOffice-Datei
323
- #assert_equal "=[Sheet2.A1]", oo.formula('C',7)
324
- assert_nil oo.formula('A',6)
325
- # assert_equal [[7, 1, "=SUM([.A1:.A6])"],
326
- # [7, 2, "=SUM([.$A$1:.B6])"],
327
- #[7, 3, "=[Sheet2.A1]"],
328
- #[8, 2, "=SUM([.$A$1:.B7])"],
329
- #], oo.formulas(oo.sheets.first)
330
- assert_equal [[7, 1, 'SUM(A1:A6)'],
331
- [7, 2, 'SUM($A$1:B6)'],
332
- # [7, 3, "=[Sheet2.A1]"],
333
- # [8, 2, "=SUM([.$A$1:.B7])"],
334
- ], oo.formulas(oo.sheets.first)
335
-
336
- # setting a cell
337
- oo.set('A',15, 41)
338
- assert_equal 41, oo.cell('A',15)
339
- oo.set('A',16, "41")
340
- assert_equal "41", oo.cell('A',16)
341
- oo.set('A',17, 42.5)
342
- assert_equal 42.5, oo.cell('A',17)
95
+ def test_argument_error
96
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
97
+ oo.default_sheet = "Tabelle1"
343
98
  end
344
99
  end
345
100
 
@@ -377,121 +132,6 @@ class TestRoo < Minitest::Test
377
132
  end
378
133
  end
379
134
 
380
- def test_openoffice_download_uri_and_zipped
381
- if OPENOFFICE
382
- if ONLINE
383
- url = 'http://spazioinwind.libero.it/s2/rata.ods.zip'
384
- sheet = Roo::OpenOffice.new(url, packed: :zip)
385
- #has been changed: assert_equal 'ist "e" im Nenner von H(s)', sheet.cell('b', 5)
386
- assert_in_delta 0.001, 505.14, sheet.cell('c', 33).to_f
387
- end
388
- end
389
- end
390
-
391
- def test_openoffice_zipped
392
- if OPENOFFICE
393
- oo = Roo::OpenOffice.new(File.join(TESTDIR,"bode-v1.ods.zip"), packed: :zip)
394
- assert oo
395
- assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
396
- end
397
- end
398
-
399
- def test_bug_ric
400
- with_each_spreadsheet(:name=>'ric', :format=>:openoffice) do |oo|
401
- assert oo.empty?('A',1)
402
- assert oo.empty?('B',1)
403
- assert oo.empty?('C',1)
404
- assert oo.empty?('D',1)
405
- expected = 1
406
- letter = 'e'
407
- while letter <= 'u'
408
- assert_equal expected, oo.cell(letter,1)
409
- letter.succ!
410
- expected += 1
411
- end
412
- assert_equal 'J', oo.cell('v',1)
413
- assert_equal 'P', oo.cell('w',1)
414
- assert_equal 'B', oo.cell('x',1)
415
- assert_equal 'All', oo.cell('y',1)
416
- assert_equal 0, oo.cell('a',2)
417
- assert oo.empty?('b',2)
418
- assert oo.empty?('c',2)
419
- assert oo.empty?('d',2)
420
- assert_equal 'B', oo.cell('e',2)
421
- assert_equal 'B', oo.cell('f',2)
422
- assert_equal 'B', oo.cell('g',2)
423
- assert_equal 'B', oo.cell('h',2)
424
- assert_equal 'B', oo.cell('i',2)
425
- assert_equal 'B', oo.cell('j',2)
426
- assert_equal 'B', oo.cell('k',2)
427
- assert_equal 'B', oo.cell('l',2)
428
- assert_equal 'B', oo.cell('m',2)
429
- assert_equal 'B', oo.cell('n',2)
430
- assert_equal 'B', oo.cell('o',2)
431
- assert_equal 'B', oo.cell('p',2)
432
- assert_equal 'B', oo.cell('q',2)
433
- assert_equal 'B', oo.cell('r',2)
434
- assert_equal 'B', oo.cell('s',2)
435
- assert oo.empty?('t',2)
436
- assert oo.empty?('u',2)
437
- assert_equal 0 , oo.cell('v',2)
438
- assert_equal 0 , oo.cell('w',2)
439
- assert_equal 15 , oo.cell('x',2)
440
- assert_equal 15 , oo.cell('y',2)
441
- end
442
- end
443
-
444
- def test_mehrteilig
445
- with_each_spreadsheet(:name=>'Bibelbund1', :format=>:openoffice) do |oo|
446
- assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
447
- end
448
- #if EXCELX
449
- # #Datei gibt es noch nicht
450
- # oo = Roo::Excelx.new(File.join(TESTDIR,"Bibelbund1.xlsx"))
451
- # oo.default_sheet = oo.sheets.first
452
- # assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
453
- #end
454
- end
455
-
456
- # "/tmp/xxxx" darf man unter Windows nicht verwenden, weil das nicht erkannt
457
- # wird.
458
- # Besser: Methode um temporaeres Dir. portabel zu bestimmen
459
- def test_huge_document_to_csv
460
- if LONG_RUN
461
- with_each_spreadsheet(:name=>'Bibelbund', :format=>[
462
- :openoffice,
463
- :excelx
464
- # Google hier nicht, weil Google-Spreadsheets nicht so gross werden
465
- # duerfen
466
- ]) do |oo|
467
- Dir.mktmpdir do |tempdir|
468
- assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
469
- assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", oo.cell(46,'A')
470
- assert_equal "Tagebuch aus Chile Juli 1977", oo.cell(55,'A')
471
- assert oo.to_csv(File.join(tempdir,"Bibelbund.csv"))
472
- assert File.exists?(File.join(tempdir,"Bibelbund.csv"))
473
- assert_equal "", file_diff(File.join(TESTDIR, "Bibelbund.csv"), File.join(tempdir,"Bibelbund.csv")),
474
- "error in class #{oo.class}"
475
- #end
476
- end
477
- end
478
- end
479
- end
480
-
481
- def test_bug_quotes_excelx
482
- if LONG_RUN
483
- with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice, :excelx]) do |oo|
484
- oo.default_sheet = oo.sheets.first
485
- assert_equal 'Einflüsse der neuen Theologie in "de gereformeerde Kerken van Nederland"',
486
- oo.cell('a',76)
487
- oo.to_csv("csv#{$$}")
488
- assert_equal 'Einflüsse der neuen Theologie in "de gereformeerde Kerken van Nederland"',
489
- oo.cell('a',78)
490
- File.delete_if_exist("csv#{$$}")
491
- end
492
- end
493
- end
494
-
495
135
  def test_bug_mehrere_datum
496
136
  with_each_spreadsheet(:name=>'numbers1') do |oo|
497
137
  oo.default_sheet = 'Sheet5'
@@ -571,296 +211,7 @@ class TestRoo < Minitest::Test
571
211
  end
572
212
  end
573
213
 
574
-
575
- def test_bug_empty_sheet
576
- with_each_spreadsheet(:name=>'formula', :format=>[:openoffice, :excelx]) do |oo|
577
- oo.default_sheet = 'Sheet3' # is an empty sheet
578
- Dir.mktmpdir do |tempdir|
579
- oo.to_csv(File.join(tempdir,"emptysheet.csv"))
580
- assert_equal "", `cat #{File.join(tempdir,"emptysheet.csv")}`
581
- end
582
- end
583
- end
584
-
585
- def test_find_by_row_huge_document
586
- if LONG_RUN
587
- with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice, :excelx]) do |oo|
588
- oo.default_sheet = oo.sheets.first
589
- rec = oo.find 20
590
- assert rec
591
- # assert_equal "Brief aus dem Sekretariat", rec[0]
592
- #p rec
593
- assert_equal "Brief aus dem Sekretariat", rec[0]['TITEL']
594
- rec = oo.find 22
595
- assert rec
596
- # assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]
597
- assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]['TITEL']
598
- end
599
- end
600
- end
601
-
602
- def test_find_by_row
603
- with_each_spreadsheet(:name=>'numbers1') do |oo|
604
- oo.header_line = nil
605
- rec = oo.find 16
606
- assert rec
607
- assert_nil oo.header_line
608
- # keine Headerlines in diesem Beispiel definiert
609
- assert_equal "einundvierzig", rec[0]
610
- #assert_equal false, rec
611
- rec = oo.find 15
612
- assert rec
613
- assert_equal 41,rec[0]
614
- end
615
- end
616
-
617
- def test_find_by_row_if_header_line_is_not_nil
618
- with_each_spreadsheet(:name=>'numbers1') do |oo|
619
- oo.header_line = 2
620
- refute_nil oo.header_line
621
- rec = oo.find 1
622
- assert rec
623
- assert_equal 5, rec[0]
624
- assert_equal 6, rec[1]
625
- rec = oo.find 15
626
- assert rec
627
- assert_equal "einundvierzig", rec[0]
628
- end
629
- end
630
-
631
- def test_find_by_conditions
632
- if LONG_RUN
633
- with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
634
- :excelx]) do |oo|
635
- #-----------------------------------------------------------------
636
- zeilen = oo.find(:all, :conditions => {
637
- 'TITEL' => 'Brief aus dem Sekretariat'
638
- }
639
- )
640
- assert_equal 2, zeilen.size
641
- assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
642
- "INTERNET"=>nil,
643
- "SEITE"=>316.0,
644
- "KENNUNG"=>"Aus dem Bibelbund",
645
- "OBJEKT"=>"Bibel+Gem",
646
- "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
647
- "NUMMER"=>"1982-3",
648
- "TITEL"=>"Brief aus dem Sekretariat"},
649
- {"VERFASSER"=>"Almassy, Annelene von",
650
- "INTERNET"=>nil,
651
- "SEITE"=>222.0,
652
- "KENNUNG"=>"Aus dem Bibelbund",
653
- "OBJEKT"=>"Bibel+Gem",
654
- "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
655
- "NUMMER"=>"1983-2",
656
- "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
657
-
658
- #----------------------------------------------------------
659
- zeilen = oo.find(:all,
660
- :conditions => { 'VERFASSER' => 'Almassy, Annelene von' }
661
- )
662
- assert_equal 13, zeilen.size
663
- #----------------------------------------------------------
664
- zeilen = oo.find(:all, :conditions => {
665
- 'TITEL' => 'Brief aus dem Sekretariat',
666
- 'VERFASSER' => 'Almassy, Annelene von',
667
- }
668
- )
669
- assert_equal 2, zeilen.size
670
- assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
671
- "INTERNET"=>nil,
672
- "SEITE"=>316.0,
673
- "KENNUNG"=>"Aus dem Bibelbund",
674
- "OBJEKT"=>"Bibel+Gem",
675
- "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
676
- "NUMMER"=>"1982-3",
677
- "TITEL"=>"Brief aus dem Sekretariat"},
678
- {"VERFASSER"=>"Almassy, Annelene von",
679
- "INTERNET"=>nil,
680
- "SEITE"=>222.0,
681
- "KENNUNG"=>"Aus dem Bibelbund",
682
- "OBJEKT"=>"Bibel+Gem",
683
- "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
684
- "NUMMER"=>"1983-2",
685
- "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
686
-
687
- # Result as an array
688
- zeilen = oo.find(:all,
689
- :conditions => {
690
- 'TITEL' => 'Brief aus dem Sekretariat',
691
- 'VERFASSER' => 'Almassy, Annelene von',
692
- }, :array => true)
693
- assert_equal 2, zeilen.size
694
- assert_equal [
695
- [
696
- "Brief aus dem Sekretariat",
697
- "Almassy, Annelene von",
698
- "Bibel+Gem",
699
- "1982-3",
700
- 316.0,
701
- nil,
702
- "#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
703
- "Aus dem Bibelbund",
704
- ],
705
- [
706
- "Brief aus dem Sekretariat",
707
- "Almassy, Annelene von",
708
- "Bibel+Gem",
709
- "1983-2",
710
- 222.0,
711
- nil,
712
- "#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
713
- "Aus dem Bibelbund",
714
- ]] , zeilen
715
- end
716
- end
717
- end
718
-
719
-
720
- #TODO: temporaerer Test
721
- def test_seiten_als_date
722
- if LONG_RUN
723
- with_each_spreadsheet(:name=>'Bibelbund', :format=>:excelx) do |oo|
724
- assert_equal 'Bericht aus dem Sekretariat', oo.cell(13,1)
725
- assert_equal '1981-4', oo.cell(13,'D')
726
- assert_equal String, oo.excelx_type(13,'E')[1].class
727
- assert_equal [:numeric_or_formula,"General"], oo.excelx_type(13,'E')
728
- assert_equal '428', oo.excelx_value(13,'E')
729
- assert_equal 428.0, oo.cell(13,'E')
730
- end
731
- end
732
- end
733
-
734
- def test_column
735
- with_each_spreadsheet(:name=>'numbers1') do |oo|
736
- expected = [1.0,5.0,nil,10.0,Date.new(1961,11,21),'tata',nil,nil,nil,nil,'thisisa11',41.0,nil,nil,41.0,'einundvierzig',nil,Date.new(2007,5,31)]
737
- assert_equal expected, oo.column(1)
738
- assert_equal expected, oo.column('a')
739
- end
740
- end
741
-
742
- def test_column_huge_document
743
- if LONG_RUN
744
- with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
745
- :excelx]) do |oo|
746
- oo.default_sheet = oo.sheets.first
747
- assert_equal 3735, oo.column('a').size
748
- #assert_equal 499, oo.column('a').size
749
- end
750
- end
751
- end
752
-
753
- def test_simple_spreadsheet_find_by_condition
754
- with_each_spreadsheet(:name=>'simple_spreadsheet') do |oo|
755
- oo.header_line = 3
756
- # oo.date_format = '%m/%d/%Y' if oo.class == Google
757
- erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'})
758
- assert_equal Date.new(2007,05,07), erg[1]['Date']
759
- assert_equal 10.75 , erg[1]['Start time']
760
- assert_equal 12.50 , erg[1]['End time']
761
- assert_equal 0 , erg[1]['Pause']
762
- assert_equal 1.75 , erg[1]['Sum']
763
- assert_equal "Task 1" , erg[1]['Comment']
764
- end
765
- end
766
-
767
- def get_extension(oo)
768
- case oo
769
- when Roo::OpenOffice
770
- ".ods"
771
- when Roo::Excelx
772
- ".xlsx"
773
- end
774
- end
775
-
776
- def test_info
777
- expected_templ = "File: numbers1%s\n"+
778
- "Number of sheets: 5\n"+
779
- "Sheets: Tabelle1, Name of Sheet 2, Sheet3, Sheet4, Sheet5\n"+
780
- "Sheet 1:\n"+
781
- " First row: 1\n"+
782
- " Last row: 18\n"+
783
- " First column: A\n"+
784
- " Last column: G\n"+
785
- "Sheet 2:\n"+
786
- " First row: 5\n"+
787
- " Last row: 14\n"+
788
- " First column: B\n"+
789
- " Last column: E\n"+
790
- "Sheet 3:\n"+
791
- " First row: 1\n"+
792
- " Last row: 1\n"+
793
- " First column: A\n"+
794
- " Last column: BA\n"+
795
- "Sheet 4:\n"+
796
- " First row: 1\n"+
797
- " Last row: 1\n"+
798
- " First column: A\n"+
799
- " Last column: E\n"+
800
- "Sheet 5:\n"+
801
- " First row: 1\n"+
802
- " Last row: 6\n"+
803
- " First column: A\n"+
804
- " Last column: E"
805
- with_each_spreadsheet(:name=>'numbers1') do |oo|
806
- ext = get_extension(oo)
807
- expected = sprintf(expected_templ,ext)
808
- begin
809
- if oo.class == Google
810
- assert_equal expected.gsub(/numbers1/,key_of("numbers1")), oo.info
811
- else
812
- assert_equal expected, oo.info
813
- end
814
- rescue NameError
815
- #
816
- end
817
- end
818
- end
819
-
820
- def test_info_doesnt_set_default_sheet
821
- with_each_spreadsheet(:name=>'numbers1') do |oo|
822
- oo.default_sheet = 'Sheet3'
823
- oo.info
824
- assert_equal 'Sheet3', oo.default_sheet
825
- end
826
- end
827
-
828
- def test_should_raise_file_not_found_error
829
- if OPENOFFICE
830
- assert_raises(IOError) {
831
- Roo::OpenOffice.new(File.join('testnichtvorhanden','Bibelbund.ods'))
832
- }
833
- end
834
- if EXCELX
835
- assert_raises(IOError) {
836
- Roo::Excelx.new(File.join('testnichtvorhanden','Bibelbund.xlsx'))
837
- }
838
- end
839
- end
840
-
841
- def test_bug_bbu
842
- with_each_spreadsheet(:name=>'bbu', :format=>[:openoffice, :excelx]) do |oo|
843
- assert_equal "File: bbu#{get_extension(oo)}
844
- Number of sheets: 3
845
- Sheets: 2007_12, Tabelle2, Tabelle3
846
- Sheet 1:
847
- First row: 1
848
- Last row: 4
849
- First column: A
850
- Last column: F
851
- Sheet 2:
852
- - empty -
853
- Sheet 3:
854
- - empty -", oo.info
855
-
856
- oo.default_sheet = oo.sheets[1] # empty sheet
857
- assert_nil oo.first_row
858
- assert_nil oo.last_row
859
- assert_nil oo.first_column
860
- assert_nil oo.last_column
861
- end
862
- end
863
-
214
+ # Tests for Specific Cell types (time, etc)
864
215
 
865
216
  def test_bug_time_nil
866
217
  with_each_spreadsheet(:name=>'time-test') do |oo|
@@ -873,248 +224,6 @@ Sheet 3:
873
224
  end
874
225
  end
875
226
 
876
- def test_date_time_to_csv
877
- with_each_spreadsheet(:name=>'time-test') do |oo|
878
- Dir.mktmpdir do |tempdir|
879
- csv_output = File.join(tempdir,'time_test.csv')
880
- assert oo.to_csv(csv_output)
881
- assert File.exists?(csv_output)
882
- assert_equal "", `diff --strip-trailing-cr #{TESTDIR}/time-test.csv #{csv_output}`
883
- # --strip-trailing-cr is needed because the test-file use 0A and
884
- # the test on an windows box generates 0D 0A as line endings
885
- end
886
- end
887
- end
888
-
889
- def test_boolean_to_csv
890
- with_each_spreadsheet(:name=>'boolean') do |oo|
891
- Dir.mktmpdir do |tempdir|
892
- csv_output = File.join(tempdir,'boolean.csv')
893
- assert oo.to_csv(csv_output)
894
- assert File.exists?(csv_output)
895
- assert_equal "", `diff --strip-trailing-cr #{TESTDIR}/boolean.csv #{csv_output}`
896
- # --strip-trailing-cr is needed because the test-file use 0A and
897
- # the test on an windows box generates 0D 0A as line endings
898
- end
899
- end
900
- end
901
- def test_link_to_csv
902
- with_each_spreadsheet(:name=>'link',:format=>:excelx) do |oo|
903
- Dir.mktmpdir do |tempdir|
904
- csv_output = File.join(tempdir,'link.csv')
905
- assert oo.to_csv(csv_output)
906
- assert File.exists?(csv_output)
907
- assert_equal "", `diff --strip-trailing-cr #{TESTDIR}/link.csv #{csv_output}`
908
- # --strip-trailing-cr is needed because the test-file use 0A and
909
- # the test on an windows box generates 0D 0A as line endings
910
- end
911
- end
912
- end
913
- def test_date_time_yaml
914
- with_each_spreadsheet(:name=>'time-test') do |oo|
915
- expected =
916
- "--- \ncell_1_1: \n row: 1 \n col: 1 \n celltype: string \n value: Mittags: \ncell_1_2: \n row: 1 \n col: 2 \n celltype: time \n value: 12:13:14 \ncell_1_3: \n row: 1 \n col: 3 \n celltype: time \n value: 15:16:00 \ncell_1_4: \n row: 1 \n col: 4 \n celltype: time \n value: 23:00:00 \ncell_2_1: \n row: 2 \n col: 1 \n celltype: date \n value: 2007-11-21 \n"
917
- assert_equal expected, oo.to_yaml
918
- end
919
- end
920
-
921
- # Erstellt eine Liste aller Zellen im Spreadsheet. Dies ist nötig, weil ein einfacher
922
- # Textvergleich des XML-Outputs nicht funktioniert, da xml-builder die Attribute
923
- # nicht immer in der gleichen Reihenfolge erzeugt.
924
- def init_all_cells(oo,sheet)
925
- all = []
926
- oo.first_row(sheet).upto(oo.last_row(sheet)) do |row|
927
- oo.first_column(sheet).upto(oo.last_column(sheet)) do |col|
928
- unless oo.empty?(row,col,sheet)
929
- all << {:row => row.to_s,
930
- :column => col.to_s,
931
- :content => oo.cell(row,col,sheet).to_s,
932
- :type => oo.celltype(row,col,sheet).to_s,
933
- }
934
- end
935
- end
936
- end
937
- all
938
- end
939
-
940
- def test_to_xml
941
- with_each_spreadsheet(:name=>'numbers1', :encoding => 'utf8') do |oo|
942
- skip if defined? JRUBY_VERSION
943
- oo.to_xml
944
- sheetname = oo.sheets.first
945
- doc = Nokogiri::XML(oo.to_xml)
946
- sheet_count = 0
947
- doc.xpath('//spreadsheet/sheet').each {|tmpelem|
948
- sheet_count += 1
949
- }
950
- assert_equal 5, sheet_count
951
- doc.xpath('//spreadsheet/sheet').each { |xml_sheet|
952
- all_cells = init_all_cells(oo, sheetname)
953
- x = 0
954
- assert_equal sheetname, xml_sheet.attributes['name'].value
955
- xml_sheet.children.each {|cell|
956
- if cell.attributes['name']
957
- expected = [all_cells[x][:row],
958
- all_cells[x][:column],
959
- all_cells[x][:content],
960
- all_cells[x][:type],
961
- ]
962
- result = [
963
- cell.attributes['row'],
964
- cell.attributes['column'],
965
- cell.content,
966
- cell.attributes['type'],
967
- ]
968
- assert_equal expected, result
969
- x += 1
970
- end # if
971
- } # end of sheet
972
- sheetname = oo.sheets[oo.sheets.index(sheetname)+1]
973
- }
974
- end
975
- end
976
-
977
- def test_file_warning_default
978
- if OPENOFFICE
979
- assert_raises(TypeError, "test/files/numbers1.xls is not an openoffice spreadsheet") {
980
- Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xls"))
981
- }
982
- assert_raises(TypeError) { Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xlsx")) }
983
- end
984
- if EXCELX
985
- assert_raises(TypeError) { Roo::Excelx.new(File.join(TESTDIR,"numbers1.ods")) }
986
- assert_raises(TypeError) { Roo::Excelx.new(File.join(TESTDIR,"numbers1.xls")) }
987
- end
988
- end
989
-
990
- def test_file_warning_error
991
- if OPENOFFICE
992
- assert_raises(TypeError) {
993
- Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xls"),
994
- packed: false,
995
- file_warning: :error
996
- )
997
- }
998
- assert_raises(TypeError) {
999
- Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xlsx"),
1000
- packed: false,
1001
- file_warning: :error)
1002
- }
1003
- end
1004
- if EXCELX
1005
- assert_raises(TypeError) {
1006
- Roo::Excelx.new(File.join(TESTDIR,"numbers1.ods"),
1007
- packed: false,
1008
- file_warning: :error)
1009
- }
1010
- assert_raises(TypeError) {
1011
- Roo::Excelx.new(File.join(TESTDIR,"numbers1.xls"),
1012
- packed: false,
1013
- file_warning: :error)
1014
- }
1015
- end
1016
- end
1017
-
1018
- def test_file_warning_warning
1019
- if OPENOFFICE
1020
- assert_raises(ArgumentError) {
1021
- Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xlsx"),
1022
- packed: false,
1023
- file_warning: :warning)
1024
- }
1025
- end
1026
- if EXCELX
1027
- assert_raises(ArgumentError) {
1028
- Roo::Excelx.new(File.join(TESTDIR,"numbers1.ods"),
1029
- packed: false,
1030
- file_warning: :warning)
1031
- }
1032
- end
1033
- end
1034
-
1035
- def test_file_warning_ignore
1036
- if OPENOFFICE
1037
- # Files, die eigentlich OpenOffice-
1038
- # Files sind, aber die falsche Endung haben.
1039
- # Es soll ohne Fehlermeldung oder Warnung
1040
- # oder Abbruch die Datei geoffnet werden
1041
-
1042
- # xlsx
1043
- Roo::OpenOffice.new(File.join(TESTDIR,"type_openoffice.xlsx"),
1044
- packed: false,
1045
- file_warning: :ignore)
1046
- end
1047
- if EXCELX
1048
- Roo::Excelx.new(File.join(TESTDIR,"type_excelx.ods"),
1049
- packed: false,
1050
- file_warning: :ignore)
1051
- end
1052
- end
1053
-
1054
- def test_bug_to_xml_with_empty_sheets
1055
- with_each_spreadsheet(:name=>'emptysheets', :format=>[:openoffice, :excelx]) do |oo|
1056
- oo.sheets.each { |sheet|
1057
- assert_equal nil, oo.first_row, "first_row not nil in sheet #{sheet}"
1058
- assert_equal nil, oo.last_row, "last_row not nil in sheet #{sheet}"
1059
- assert_equal nil, oo.first_column, "first_column not nil in sheet #{sheet}"
1060
- assert_equal nil, oo.last_column, "last_column not nil in sheet #{sheet}"
1061
- assert_equal nil, oo.first_row(sheet), "first_row not nil in sheet #{sheet}"
1062
- assert_equal nil, oo.last_row(sheet), "last_row not nil in sheet #{sheet}"
1063
- assert_equal nil, oo.first_column(sheet), "first_column not nil in sheet #{sheet}"
1064
- assert_equal nil, oo.last_column(sheet), "last_column not nil in sheet #{sheet}"
1065
- }
1066
- oo.to_xml
1067
- end
1068
- end
1069
-
1070
- def test_bug_simple_spreadsheet_time_bug
1071
- # really a bug? are cells really of type time?
1072
- # No! :float must be the correct type
1073
- with_each_spreadsheet(:name=>'simple_spreadsheet', :format=>:excelx) do |oo|
1074
- # puts oo.cell('B',5).to_s
1075
- # assert_equal :time, oo.celltype('B',5)
1076
- assert_equal :float, oo.celltype('B',5)
1077
- assert_equal 10.75, oo.cell('B',5)
1078
- assert_equal 12.50, oo.cell('C',5)
1079
- assert_equal 0, oo.cell('D',5)
1080
- assert_equal 1.75, oo.cell('E',5)
1081
- assert_equal 'Task 1', oo.cell('F',5)
1082
- assert_equal Date.new(2007,5,7), oo.cell('A',5)
1083
- end
1084
- end
1085
-
1086
- def test_simple2_excelx
1087
- with_each_spreadsheet(:name=>'simple_spreadsheet', :format=>:excelx) do |oo|
1088
- assert_equal [:numeric_or_formula, "yyyy\\-mm\\-dd"], oo.excelx_type('A',4)
1089
- assert_equal [:numeric_or_formula, "#,##0.00"], oo.excelx_type('B',4)
1090
- assert_equal [:numeric_or_formula, "#,##0.00"], oo.excelx_type('c',4)
1091
- assert_equal [:numeric_or_formula, "General"], oo.excelx_type('d',4)
1092
- assert_equal [:numeric_or_formula, "General"], oo.excelx_type('e',4)
1093
- assert_equal :string, oo.excelx_type('f',4)
1094
-
1095
- assert_equal "39209", oo.excelx_value('a',4)
1096
- assert_equal "yyyy\\-mm\\-dd", oo.excelx_format('a',4)
1097
- assert_equal "9.25", oo.excelx_value('b',4)
1098
- assert_equal "10.25", oo.excelx_value('c',4)
1099
- assert_equal "0", oo.excelx_value('d',4)
1100
- #... Sum-Spalte
1101
- # assert_equal "Task 1", oo.excelx_value('f',4)
1102
- assert_equal "Task 1", oo.cell('f',4)
1103
- assert_equal Date.new(2007,05,07), oo.cell('a',4)
1104
- assert_equal "9.25", oo.excelx_value('b',4)
1105
- assert_equal "#,##0.00", oo.excelx_format('b',4)
1106
- assert_equal 9.25, oo.cell('b',4)
1107
- assert_equal :float, oo.celltype('b',4)
1108
- assert_equal :float, oo.celltype('d',4)
1109
- assert_equal 0, oo.cell('d',4)
1110
- assert_equal :formula, oo.celltype('e',4)
1111
- assert_equal 1, oo.cell('e',4)
1112
- assert_equal 'C4-B4-D4', oo.formula('e',4)
1113
- assert_equal :string, oo.celltype('f',4)
1114
- assert_equal "Task 1", oo.cell('f',4)
1115
- end
1116
- end
1117
-
1118
227
  def test_datetime
1119
228
  with_each_spreadsheet(:name=>'datetime') do |oo|
1120
229
  val = oo.cell('c',3)
@@ -1147,17 +256,6 @@ Sheet 3:
1147
256
  end
1148
257
  end
1149
258
 
1150
- def test_cell_openoffice_html_escape
1151
- with_each_spreadsheet(:name=>'html-escape', :format=>:openoffice) do |oo|
1152
- assert_equal "'", oo.cell(1,1)
1153
- assert_equal "&", oo.cell(2,1)
1154
- assert_equal ">", oo.cell(3,1)
1155
- assert_equal "<", oo.cell(4,1)
1156
- assert_equal "`", oo.cell(5,1)
1157
- # test_openoffice_zipped will catch issues with &quot;
1158
- end
1159
- end
1160
-
1161
259
  def test_cell_boolean
1162
260
  with_each_spreadsheet(:name=>'boolean', :format=>[:openoffice, :excelx]) do |oo|
1163
261
  if oo.class == Roo::Excelx
@@ -1176,6 +274,24 @@ Sheet 3:
1176
274
  end
1177
275
  end
1178
276
 
277
+ def test_cell_boolean_from_google_sheets
278
+ with_each_spreadsheet(:name=>'boolean-from-google-sheets', :format=>[:openoffice, :excelx]) do |oo|
279
+ if oo.class == Roo::Excelx
280
+ assert_equal true, oo.cell(1, 1), "failure in #{oo.class}"
281
+ assert_equal false, oo.cell(2, 1), "failure in #{oo.class}"
282
+
283
+ cell = oo.sheet_for(oo.default_sheet).cells[[1, 1,]]
284
+ assert_equal 'TRUE', cell.formatted_value
285
+
286
+ cell = oo.sheet_for(oo.default_sheet).cells[[2, 1,]]
287
+ assert_equal 'FALSE', cell.formatted_value
288
+ else
289
+ assert_equal "true", oo.cell(1,1), "failure in #{oo.class}"
290
+ assert_equal "false", oo.cell(2,1), "failure in #{oo.class}"
291
+ end
292
+ end
293
+ end
294
+
1179
295
  def test_cell_multiline
1180
296
  with_each_spreadsheet(:name=>'paragraph', :format=>[:openoffice, :excelx]) do |oo|
1181
297
  assert_equal "This is a test\nof a multiline\nCell", oo.cell(1,1)
@@ -1184,72 +300,21 @@ Sheet 3:
1184
300
  end
1185
301
  end
1186
302
 
1187
- def test_cell_styles
1188
- # styles only valid in excel spreadsheets?
1189
- # TODO: what todo with other spreadsheet types
1190
- with_each_spreadsheet(:name=>'style', :format=>[# :openoffice,
1191
- :excelx
1192
- ]) do |oo|
1193
- # bold
1194
- assert_equal true, oo.font(1,1).bold?
1195
- assert_equal false, oo.font(1,1).italic?
1196
- assert_equal false, oo.font(1,1).underline?
1197
-
1198
- # italic
1199
- assert_equal false, oo.font(2,1).bold?
1200
- assert_equal true, oo.font(2,1).italic?
1201
- assert_equal false, oo.font(2,1).underline?
1202
-
1203
- # normal
1204
- assert_equal false, oo.font(3,1).bold?
1205
- assert_equal false, oo.font(3,1).italic?
1206
- assert_equal false, oo.font(3,1).underline?
1207
-
1208
- # underline
1209
- assert_equal false, oo.font(4,1).bold?
1210
- assert_equal false, oo.font(4,1).italic?
1211
- assert_equal true, oo.font(4,1).underline?
1212
-
1213
- # bold italic
1214
- assert_equal true, oo.font(5,1).bold?
1215
- assert_equal true, oo.font(5,1).italic?
1216
- assert_equal false, oo.font(5,1).underline?
1217
-
1218
- # bold underline
1219
- assert_equal true, oo.font(6,1).bold?
1220
- assert_equal false, oo.font(6,1).italic?
1221
- assert_equal true, oo.font(6,1).underline?
1222
-
1223
- # italic underline
1224
- assert_equal false, oo.font(7,1).bold?
1225
- assert_equal true, oo.font(7,1).italic?
1226
- assert_equal true, oo.font(7,1).underline?
1227
-
1228
- # bolded row
1229
- assert_equal true, oo.font(8,1).bold?
1230
- assert_equal false, oo.font(8,1).italic?
1231
- assert_equal false, oo.font(8,1).underline?
1232
-
1233
- # bolded col
1234
- assert_equal true, oo.font(9,2).bold?
1235
- assert_equal false, oo.font(9,2).italic?
1236
- assert_equal false, oo.font(9,2).underline?
1237
-
1238
- # bolded row, italic col
1239
- assert_equal true, oo.font(10,3).bold?
1240
- assert_equal true, oo.font(10,3).italic?
1241
- assert_equal false, oo.font(10,3).underline?
303
+ def test_apostrophe_replacement
304
+ with_each_spreadsheet(:name=>'apostrophe', :format=>[:openoffice]) do |oo|
305
+ assert_equal "'", oo.cell(1,1)
306
+ end
307
+ end
1242
308
 
1243
- # normal
1244
- assert_equal false, oo.font(11,4).bold?
1245
- assert_equal false, oo.font(11,4).italic?
1246
- assert_equal false, oo.font(11,4).underline?
309
+ def test_frozen_string_usage
310
+ with_each_spreadsheet(:name=>'frozen_string', :format=>[:openoffice]) do |oo|
311
+ assert_equal "", oo.cell(1,1)
1247
312
  end
1248
313
  end
1249
314
 
1250
- # Need to extend to other formats
1251
315
  def test_row_whitespace
1252
316
  # auf dieses Dokument habe ich keinen Zugriff TODO:
317
+ # TODO: No access to document whitespace?
1253
318
  with_each_spreadsheet(:name=>'whitespace') do |oo|
1254
319
  oo.default_sheet = "Sheet1"
1255
320
  assert_equal [nil, nil, nil, nil, nil, nil], oo.row(1)
@@ -1285,26 +350,6 @@ Sheet 3:
1285
350
  end
1286
351
  end
1287
352
 
1288
- def test_excelx_links
1289
- with_each_spreadsheet(:name=>'link', :format=>:excelx) do |oo|
1290
- assert_equal 'Google', oo.cell(1,1)
1291
- assert_equal 'http://www.google.com', oo.cell(1,1).href
1292
- end
1293
- end
1294
-
1295
- # Excel has two base date formats one from 1900 and the other from 1904.
1296
- # see #test_base_dates_in_excel
1297
- def test_base_dates_in_excelx
1298
- with_each_spreadsheet(:name=>'1900_base', :format=>:excelx) do |oo|
1299
- assert_equal Date.new(2009,06,15), oo.cell(1,1)
1300
- assert_equal :date, oo.celltype(1,1)
1301
- end
1302
- with_each_spreadsheet(:name=>'1904_base', :format=>:excelx) do |oo|
1303
- assert_equal Date.new(2009,06,15), oo.cell(1,1)
1304
- assert_equal :date, oo.celltype(1,1)
1305
- end
1306
- end
1307
-
1308
353
  def test_cell_methods
1309
354
  with_each_spreadsheet(:name=>'numbers1') do |oo|
1310
355
  assert_equal 10, oo.a4 # cell(4,'A')
@@ -1322,776 +367,26 @@ Sheet 3:
1322
367
  end
1323
368
  end
1324
369
 
1325
-
1326
370
  # compare large spreadsheets
1327
371
  def test_compare_large_spreadsheets
1328
- # problematisch, weil Formeln in Excel nicht unterstützt werden
1329
- if LONG_RUN
1330
- qq = Roo::OpenOffice.new(File.join('test',"Bibelbund.ods"))
1331
- with_each_spreadsheet(:name=>'Bibelbund') do |oo|
1332
- # p "comparing Bibelbund.ods with #{oo.class}"
1333
- oo.sheets.each do |sh|
1334
- oo.first_row.upto(oo.last_row) do |row|
1335
- oo.first_column.upto(oo.last_column) do |col|
1336
- c1 = qq.cell(row,col,sh)
1337
- c1.force_encoding("UTF-8") if c1.class == String
1338
- c2 = oo.cell(row,col,sh)
1339
- c2.force_encoding("UTF-8") if c2.class == String
1340
- assert_equal c1, c2, "diff in #{sh}/#{row}/#{col}}"
1341
- assert_equal qq.celltype(row,col,sh), oo.celltype(row,col,sh)
1342
- assert_equal qq.formula?(row,col,sh), oo.formula?(row,col,sh) if oo.class != Roo::Excel
1343
- end
372
+ skip_long_test
373
+ qq = Roo::OpenOffice.new(File.join('test', 'files', "Bibelbund.ods"))
374
+ with_each_spreadsheet(name: 'Bibelbund') do |oo|
375
+ oo.sheets.each do |sh|
376
+ oo.first_row.upto(oo.last_row) do |row|
377
+ oo.first_column.upto(oo.last_column) do |col|
378
+ c1 = qq.cell(row, col, sh)
379
+ c1.force_encoding("UTF-8") if c1.class == String
380
+ c2 = oo.cell(row,col,sh)
381
+ c2.force_encoding("UTF-8") if c2.class == String
382
+ next if c1.nil? && c2.nil?
383
+
384
+ assert_equal c1, c2, "diff in #{sh}/#{row}/#{col}}"
385
+ assert_equal qq.celltype(row, col, sh), oo.celltype(row, col, sh)
386
+ assert_equal qq.formula?(row, col, sh), oo.formula?(row, col, sh)
1344
387
  end
1345
388
  end
1346
389
  end
1347
- end # LONG_RUN
1348
- end
1349
-
1350
- def test_label
1351
- with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo|
1352
- # oo.default_sheet = oo.sheets.first
1353
- begin
1354
- row,col = oo.label('anton')
1355
- rescue ArgumentError
1356
- puts "labels error at #{oo.class}"
1357
- raise
1358
- end
1359
- assert_equal 5, row, "error with label in class #{oo.class}"
1360
- assert_equal 3, col, "error with label in class #{oo.class}"
1361
-
1362
- row,col = oo.label('anton')
1363
- assert_equal 'Anton', oo.cell(row,col), "error with label in class #{oo.class}"
1364
-
1365
- row,col = oo.label('berta')
1366
- assert_equal 'Bertha', oo.cell(row,col), "error with label in class #{oo.class}"
1367
-
1368
- row,col = oo.label('caesar')
1369
- assert_equal 'Cäsar', oo.cell(row,col),"error with label in class #{oo.class}"
1370
-
1371
- row,col = oo.label('never')
1372
- assert_nil row
1373
- assert_nil col
1374
-
1375
- row,col,sheet = oo.label('anton')
1376
- assert_equal 5, row
1377
- assert_equal 3, col
1378
- assert_equal "Sheet1", sheet
1379
- end
1380
- end
1381
-
1382
- def test_method_missing_anton
1383
- with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo|
1384
- # oo.default_sheet = oo.sheets.first
1385
- assert_equal "Anton", oo.anton
1386
- assert_raises(NoMethodError) {
1387
- oo.never
1388
- }
1389
- end
1390
- end
1391
-
1392
- def test_labels
1393
- with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo|
1394
- # oo.default_sheet = oo.sheets.first
1395
- assert_equal [
1396
- ['anton',[5,3,'Sheet1']],
1397
- ['berta',[4,2,'Sheet1']],
1398
- ['caesar',[7,2,'Sheet1']],
1399
- ], oo.labels, "error with labels array in class #{oo.class}"
1400
- end
1401
- end
1402
-
1403
- def test_labeled_cells
1404
- with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo|
1405
- oo.default_sheet = oo.sheets.first
1406
- begin
1407
- row,col = oo.label('anton')
1408
- rescue ArgumentError
1409
- puts "labels error at #{oo.class}"
1410
- raise
1411
- end
1412
- assert_equal 5, row
1413
- assert_equal 3, col
1414
-
1415
- row,col = oo.label('anton')
1416
- assert_equal 'Anton', oo.cell(row,col)
1417
-
1418
- row,col = oo.label('berta')
1419
- assert_equal 'Bertha', oo.cell(row,col)
1420
-
1421
- row,col = oo.label('caesar')
1422
- assert_equal 'Cäsar', oo.cell(row,col)
1423
-
1424
- row,col = oo.label('never')
1425
- assert_nil row
1426
- assert_nil col
1427
-
1428
- row,col,sheet = oo.label('anton')
1429
- assert_equal 5, row
1430
- assert_equal 3, col
1431
- assert_equal "Sheet1", sheet
1432
-
1433
- assert_equal "Anton", oo.anton
1434
- assert_raises(NoMethodError) {
1435
- row,col = oo.never
1436
- }
1437
-
1438
- # Reihenfolge row,col,sheet analog zu #label
1439
- assert_equal [
1440
- ['anton',[5,3,'Sheet1']],
1441
- ['berta',[4,2,'Sheet1']],
1442
- ['caesar',[7,2,'Sheet1']],
1443
- ], oo.labels, "error with labels array in class #{oo.class}"
1444
- end
1445
- end
1446
-
1447
- require 'matrix'
1448
- def test_matrix
1449
- with_each_spreadsheet(:name => 'matrix', :format => :openoffice) do |oo|
1450
- oo.default_sheet = oo.sheets.first
1451
- assert_equal Matrix[
1452
- [1.0, 2.0, 3.0],
1453
- [4.0, 5.0, 6.0],
1454
- [7.0, 8.0, 9.0] ], oo.to_matrix
1455
- end
1456
- end
1457
-
1458
- def test_matrix_selected_range
1459
- with_each_spreadsheet(:name => 'matrix', :format=>:openoffice) do |oo|
1460
- oo.default_sheet = 'Sheet2'
1461
- assert_equal Matrix[
1462
- [1.0, 2.0, 3.0],
1463
- [4.0, 5.0, 6.0],
1464
- [7.0, 8.0, 9.0] ], oo.to_matrix(3,4,5,6)
1465
- end
1466
- end
1467
-
1468
- def test_matrix_all_nil
1469
- with_each_spreadsheet(:name => 'matrix', :format=>:openoffice) do |oo|
1470
- oo.default_sheet = 'Sheet2'
1471
- assert_equal Matrix[
1472
- [nil, nil, nil],
1473
- [nil, nil, nil],
1474
- [nil, nil, nil] ], oo.to_matrix(10,10,12,12)
1475
- end
1476
- end
1477
-
1478
- def test_matrix_values_and_nil
1479
- with_each_spreadsheet(:name => 'matrix', :format=>:openoffice) do |oo|
1480
- oo.default_sheet = 'Sheet3'
1481
- assert_equal Matrix[
1482
- [1.0, nil, 3.0],
1483
- [4.0, 5.0, 6.0],
1484
- [7.0, 8.0, nil] ], oo.to_matrix(1,1,3,3)
1485
- end
1486
- end
1487
-
1488
- def test_matrix_specifying_sheet
1489
- with_each_spreadsheet(:name => 'matrix', :format => :openoffice) do |oo|
1490
- oo.default_sheet = oo.sheets.first
1491
- assert_equal Matrix[
1492
- [1.0, nil, 3.0],
1493
- [4.0, 5.0, 6.0],
1494
- [7.0, 8.0, nil] ], oo.to_matrix(nil, nil, nil, nil, 'Sheet3')
1495
- end
1496
- end
1497
-
1498
- # unter Windows soll es laut Bug-Reports nicht moeglich sein, eine Excel-Datei, die
1499
- # mit Excel.new geoeffnet wurde nach dem Processing anschliessend zu loeschen.
1500
- # Anmerkung: Das Spreadsheet-Gem erlaubt kein explizites Close von Spreadsheet-Dateien,
1501
- # was verhindern koennte, das die Datei geloescht werden kann.
1502
- # def test_bug_cannot_delete_opened_excel_sheet
1503
- # with_each_spreadsheet(:name=>'simple_spreadsheet') do |oo|
1504
- # 'kopiere nach temporaere Datei und versuche diese zu oeffnen und zu loeschen'
1505
- # end
1506
- # end
1507
-
1508
- def test_bug_xlsx_reference_cell
1509
-
1510
- if EXCELX
1511
- =begin
1512
- If cell A contains a string and cell B references cell A. When reading the value of cell B, the result will be
1513
- "0.0" instead of the value of cell A.
1514
-
1515
- With the attached test case, I ran the following code:
1516
- spreadsheet = Roo::Excelx.new('formula_string_error.xlsx')
1517
- spreadsheet.default_sheet = 'sheet1'
1518
- p "A: #{spreadsheet.cell(1, 1)}"
1519
- p "B: #{spreadsheet.cell(2, 1)}"
1520
-
1521
- with the following results
1522
- "A: TestString"
1523
- "B: 0.0"
1524
-
1525
- where the expected result is
1526
- "A: TestString"
1527
- "B: TestString"
1528
- =end
1529
- xlsx = Roo::Excelx.new(File.join(TESTDIR, "formula_string_error.xlsx"))
1530
- xlsx.default_sheet = xlsx.sheets.first
1531
- assert_equal 'Teststring', xlsx.cell('a',1)
1532
- assert_equal 'Teststring', xlsx.cell('a',2)
1533
- end
1534
- end
1535
-
1536
- # #formulas of an empty sheet should return an empty array and not result in
1537
- # an error message
1538
- # 2011-06-24
1539
- def test_bug_formulas_empty_sheet
1540
- with_each_spreadsheet(:name =>'emptysheets',
1541
- :format=>[:openoffice,:excelx]) do |oo|
1542
- oo.default_sheet = oo.sheets.first
1543
- oo.formulas
1544
- assert_equal([], oo.formulas)
1545
- end
1546
- end
1547
-
1548
- # #to_yaml of an empty sheet should return an empty string and not result in
1549
- # an error message
1550
- # 2011-06-24
1551
- def test_bug_to_yaml_empty_sheet
1552
- with_each_spreadsheet(:name =>'emptysheets',
1553
- :format=>[:openoffice,:excelx]) do |oo|
1554
- oo.default_sheet = oo.sheets.first
1555
- oo.to_yaml
1556
- assert_equal('', oo.to_yaml)
1557
- end
1558
- end
1559
-
1560
- # #to_matrix of an empty sheet should return an empty matrix and not result in
1561
- # an error message
1562
- # 2011-06-25
1563
- def test_bug_to_matrix_empty_sheet
1564
- with_each_spreadsheet(:name =>'emptysheets',
1565
- :format=>[:openoffice,:excelx]) do |oo|
1566
- oo.default_sheet = oo.sheets.first
1567
- oo.to_matrix
1568
- assert_equal(Matrix.empty(0,0), oo.to_matrix)
1569
- end
1570
- end
1571
-
1572
- # 2011-08-03
1573
- def test_bug_datetime_to_csv
1574
- with_each_spreadsheet(:name=>'datetime') do |oo|
1575
- Dir.mktmpdir do |tempdir|
1576
- datetime_csv_file = File.join(tempdir,"datetime.csv")
1577
-
1578
- assert oo.to_csv(datetime_csv_file)
1579
- assert File.exists?(datetime_csv_file)
1580
- assert_equal "", file_diff('test/files/so_datetime.csv', datetime_csv_file)
1581
- end
1582
390
  end
1583
391
  end
1584
-
1585
- # 2011-08-11
1586
- def test_bug_openoffice_formula_missing_letters
1587
- if LIBREOFFICE
1588
- # Dieses Dokument wurde mit LibreOffice angelegt.
1589
- # Keine Ahnung, ob es damit zusammenhaengt, das diese
1590
- # Formeln anders sind, als in der Datei formula.ods, welche
1591
- # mit OpenOffice angelegt wurde.
1592
- # Bei den OpenOffice-Dateien ist in diesem Feld in der XML-
1593
- # Datei of: als Prefix enthalten, waehrend in dieser Datei
1594
- # irgendetwas mit oooc: als Prefix verwendet wird.
1595
- oo = Roo::OpenOffice.new(File.join(TESTDIR,'dreimalvier.ods'))
1596
- oo.default_sheet = oo.sheets.first
1597
- assert_equal '=SUM([.A1:.D1])', oo.formula('e',1)
1598
- assert_equal '=SUM([.A2:.D2])', oo.formula('e',2)
1599
- assert_equal '=SUM([.A3:.D3])', oo.formula('e',3)
1600
- assert_equal [
1601
- [1,5,'=SUM([.A1:.D1])'],
1602
- [2,5,'=SUM([.A2:.D2])'],
1603
- [3,5,'=SUM([.A3:.D3])'],
1604
- ], oo.formulas
1605
-
1606
- end
1607
- end
1608
-
1609
- =begin
1610
- def test_postprocessing_and_types_in_csv
1611
- if CSV
1612
- oo = CSV.new(File.join(TESTDIR,'csvtypes.csv'))
1613
- oo.default_sheet = oo.sheets.first
1614
- assert_equal(1,oo.a1)
1615
- assert_equal(:float,oo.celltype('A',1))
1616
- assert_equal("2",oo.b1)
1617
- assert_equal(:string,oo.celltype('B',1))
1618
- assert_equal("Mayer",oo.c1)
1619
- assert_equal(:string,oo.celltype('C',1))
1620
- end
1621
- end
1622
- =end
1623
-
1624
- =begin
1625
- def test_postprocessing_with_callback_function
1626
- if CSV
1627
- oo = CSV.new(File.join(TESTDIR,'csvtypes.csv'))
1628
- oo.default_sheet = oo.sheets.first
1629
-
1630
- #
1631
- assert_equal(1, oo.last_column)
1632
- end
1633
- end
1634
- =end
1635
-
1636
- =begin
1637
- def x_123
1638
- class ::CSV
1639
- def cell_postprocessing(row,col,value)
1640
- if row < 3
1641
- return nil
1642
- end
1643
- return value
1644
- end
1645
- end
1646
- end
1647
- =end
1648
-
1649
- def test_nil_rows_and_lines_csv
1650
- # x_123
1651
- if CSV
1652
- oo = Roo::CSV.new(File.join(TESTDIR,'Bibelbund.csv'))
1653
- oo.default_sheet = oo.sheets.first
1654
- assert_equal 1, oo.first_row
1655
- end
1656
- end
1657
-
1658
- def test_bug_pfand_from_windows_phone_xlsx
1659
- return if defined? JRUBY_VERSION
1660
- with_each_spreadsheet(:name=>'Pfand_from_windows_phone', :format=>:excelx) do |oo|
1661
- oo.default_sheet = oo.sheets.first
1662
- assert_equal ['Blatt1','Blatt2','Blatt3'], oo.sheets
1663
- assert_equal 'Summe', oo.cell('b',1)
1664
-
1665
- assert_equal Date.new(2011,9,14), oo.cell('a',2)
1666
- assert_equal :date, oo.celltype('a',2)
1667
- assert_equal Date.new(2011,9,15), oo.cell('a',3)
1668
- assert_equal :date, oo.celltype('a',3)
1669
-
1670
- assert_equal 3.81, oo.cell('b',2)
1671
- assert_equal "SUM(C2:L2)", oo.formula('b',2)
1672
- assert_equal 0.7, oo.cell('c',2)
1673
- end # each
1674
- end
1675
-
1676
- def test_comment
1677
- with_each_spreadsheet(:name=>'comments', :format=>[:openoffice,:libreoffice,
1678
- :excelx]) do |oo|
1679
- oo.default_sheet = oo.sheets.first
1680
- assert_equal 'Kommentar fuer B4',oo.comment('b',4)
1681
- assert_equal 'Kommentar fuer B5',oo.comment('b',5)
1682
- assert_nil oo.comment('b',99)
1683
- # no comment at the second page
1684
- oo.default_sheet = oo.sheets[1]
1685
- assert_nil oo.comment('b',4)
1686
- end
1687
- end
1688
-
1689
- def test_comments
1690
- with_each_spreadsheet(:name=>'comments', :format=>[:openoffice,:libreoffice,
1691
- :excelx]) do |oo|
1692
- oo.default_sheet = oo.sheets.first
1693
- assert_equal [
1694
- [4, 2, "Kommentar fuer B4"],
1695
- [5, 2, "Kommentar fuer B5"],
1696
- ], oo.comments(oo.sheets.first), "comments error in class #{oo.class}"
1697
- # no comments at the second page
1698
- oo.default_sheet = oo.sheets[1]
1699
- assert_equal [], oo.comments, "comments error in class #{oo.class}"
1700
- end
1701
-
1702
- with_each_spreadsheet(:name=>'comments-google', :format=>[:excelx]) do |oo|
1703
- oo.default_sheet = oo.sheets.first
1704
- assert_equal [[1, 1, "this is a comment\n\t-Steven Daniels"]], oo.comments(oo.sheets.first), "comments error in class #{oo.class}"
1705
- end
1706
- end
1707
-
1708
- ## PREVIOUSLY SKIPPED
1709
-
1710
- # don't have these test files so removing. We can easily add in
1711
- # by modifying with_each_spreadsheet
1712
- GNUMERIC_ODS = false # do gnumeric with ods files Tests?
1713
- OPENOFFICEWRITE = false # experimental: write access with OO-Documents
1714
-
1715
- def test_writeopenoffice
1716
- if OPENOFFICEWRITE
1717
- File.cp(File.join(TESTDIR,"numbers1.ods"),
1718
- File.join(TESTDIR,"numbers2.ods"))
1719
- File.cp(File.join(TESTDIR,"numbers2.ods"),
1720
- File.join(TESTDIR,"bak_numbers2.ods"))
1721
- oo = OpenOffice.new(File.join(TESTDIR,"numbers2.ods"))
1722
- oo.default_sheet = oo.sheets.first
1723
- oo.first_row.upto(oo.last_row) {|y|
1724
- oo.first_column.upto(oo.last_column) {|x|
1725
- unless oo.empty?(y,x)
1726
- # oo.set(y, x, oo.cell(y,x) + 7) if oo.celltype(y,x) == "float"
1727
- oo.set(y, x, oo.cell(y,x) + 7) if oo.celltype(y,x) == :float
1728
- end
1729
- }
1730
- }
1731
- oo.save
1732
-
1733
- oo1 = Roo::OpenOffice.new(File.join(TESTDIR,"numbers2.ods"))
1734
- oo2 = Roo::OpenOffice.new(File.join(TESTDIR,"bak_numbers2.ods"))
1735
- #p oo2.to_s
1736
- assert_equal 999, oo2.cell('a',1), oo2.cell('a',1)
1737
- assert_equal oo2.cell('a',1) + 7, oo1.cell('a',1)
1738
- assert_equal oo2.cell('b',1)+7, oo1.cell('b',1)
1739
- assert_equal oo2.cell('c',1)+7, oo1.cell('c',1)
1740
- assert_equal oo2.cell('d',1)+7, oo1.cell('d',1)
1741
- assert_equal oo2.cell('a',2)+7, oo1.cell('a',2)
1742
- assert_equal oo2.cell('b',2)+7, oo1.cell('b',2)
1743
- assert_equal oo2.cell('c',2)+7, oo1.cell('c',2)
1744
- assert_equal oo2.cell('d',2)+7, oo1.cell('d',2)
1745
- assert_equal oo2.cell('e',2)+7, oo1.cell('e',2)
1746
-
1747
- File.cp(File.join(TESTDIR,"bak_numbers2.ods"),
1748
- File.join(TESTDIR,"numbers2.ods"))
1749
- end
1750
- end
1751
-
1752
- def common_possible_bug_snowboard_cells(ss)
1753
- assert_equal "A.", ss.cell(13,'A'), ss.class
1754
- assert_equal 147, ss.cell(13,'f'), ss.class
1755
- assert_equal 152, ss.cell(13,'g'), ss.class
1756
- assert_equal 156, ss.cell(13,'h'), ss.class
1757
- assert_equal 158, ss.cell(13,'i'), ss.class
1758
- assert_equal 160, ss.cell(13,'j'), ss.class
1759
- assert_equal 164, ss.cell(13,'k'), ss.class
1760
- assert_equal 168, ss.cell(13,'l'), ss.class
1761
- assert_equal :string, ss.celltype(13,'m'), ss.class
1762
- assert_equal "159W", ss.cell(13,'m'), ss.class
1763
- assert_equal "164W", ss.cell(13,'n'), ss.class
1764
- assert_equal "168W", ss.cell(13,'o'), ss.class
1765
- end
1766
-
1767
- # def test_false_encoding
1768
- # ex = Roo::Excel.new(File.join(TESTDIR,'false_encoding.xls'))
1769
- # ex.default_sheet = ex.sheets.first
1770
- # assert_equal "Sheet1", ex.sheets.first
1771
- # ex.first_row.upto(ex.last_row) do |row|
1772
- # ex.first_column.upto(ex.last_column) do |col|
1773
- # content = ex.cell(row,col)
1774
- # puts "#{row}/#{col}"
1775
- # #puts content if ! ex.empty?(row,col) or ex.formula?(row,col)
1776
- # if ex.formula?(row,col)
1777
- # #! ex.empty?(row,col)
1778
- # puts content
1779
- # end
1780
- # end
1781
- # end
1782
- # end
1783
-
1784
- def test_download_uri
1785
- if ONLINE
1786
- if OPENOFFICE
1787
- assert_raises(RuntimeError) {
1788
- Roo::OpenOffice.new("http://gibbsnichtdomainxxxxx.com/file.ods")
1789
- }
1790
- end
1791
- if EXCELX
1792
- assert_raises(RuntimeError) {
1793
- Roo::Excelx.new("http://gibbsnichtdomainxxxxx.com/file.xlsx")
1794
- }
1795
- end
1796
- end
1797
- end
1798
-
1799
- def test_download_uri_with_query_string
1800
- dir = File.expand_path("#{File.dirname __FILE__}/files")
1801
- { xlsx: [EXCELX, Roo::Excelx],
1802
- ods: [OPENOFFICE, Roo::OpenOffice]}.each do |extension, (flag, type)|
1803
- if flag
1804
- file = "#{dir}/simple_spreadsheet.#{extension}"
1805
- url = "http://test.example.com/simple_spreadsheet.#{extension}?query-param=value"
1806
- stub_request(:any, url).to_return(body: File.read(file))
1807
- spreadsheet = type.new(url)
1808
- spreadsheet.default_sheet = spreadsheet.sheets.first
1809
- assert_equal 'Task 1', spreadsheet.cell('f', 4)
1810
- end
1811
- end
1812
- end
1813
-
1814
- # def test_soap_server
1815
- # #threads = []
1816
- # #threads << Thread.new("serverthread") do
1817
- # fork do
1818
- # p "serverthread started"
1819
- # puts "in child, pid = #$$"
1820
- # puts `/usr/bin/ruby rooserver.rb`
1821
- # p "serverthread finished"
1822
- # end
1823
- # #threads << Thread.new("clientthread") do
1824
- # p "clientthread started"
1825
- # sleep 10
1826
- # proxy = SOAP::RPC::Driver.new("http://localhost:12321","spreadsheetserver")
1827
- # proxy.add_method('cell','row','col')
1828
- # proxy.add_method('officeversion')
1829
- # proxy.add_method('last_row')
1830
- # proxy.add_method('last_column')
1831
- # proxy.add_method('first_row')
1832
- # proxy.add_method('first_column')
1833
- # proxy.add_method('sheets')
1834
- # proxy.add_method('set_default_sheet','s')
1835
- # proxy.add_method('ferien_fuer_region', 'region')
1836
-
1837
- # sheets = proxy.sheets
1838
- # p sheets
1839
- # proxy.set_default_sheet(sheets.first)
1840
-
1841
- # assert_equal 1, proxy.first_row
1842
- # assert_equal 1, proxy.first_column
1843
- # assert_equal 187, proxy.last_row
1844
- # assert_equal 7, proxy.last_column
1845
- # assert_equal 42, proxy.cell('C',8)
1846
- # assert_equal 43, proxy.cell('F',12)
1847
- # assert_equal "1.0", proxy.officeversion
1848
- # p "clientthread finished"
1849
- # #end
1850
- # #threads.each {|t| t.join }
1851
- # puts "fertig"
1852
- # Process.kill("INT",pid)
1853
- # pid = Process.wait
1854
- # puts "child terminated, pid= #{pid}, status= #{$?.exitstatus}"
1855
- # end
1856
-
1857
- def split_coord(s)
1858
- letter = ""
1859
- number = 0
1860
- i = 0
1861
- while i<s.length and "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".include?(s[i,1])
1862
- letter += s[i,1]
1863
- i+=1
1864
- end
1865
- while i<s.length and "01234567890".include?(s[i,1])
1866
- number = number*10 + s[i,1].to_i
1867
- i+=1
1868
- end
1869
- if letter=="" or number==0
1870
- raise ArgumentError
1871
- end
1872
- return letter,number
1873
- end
1874
-
1875
- #def sum(s,expression)
1876
- # arg = expression.split(':')
1877
- # b,z = split_coord(arg[0])
1878
- # first_row = z
1879
- # first_col = OpenOffice.letter_to_number(b)
1880
- # b,z = split_coord(arg[1])
1881
- # last_row = z
1882
- # last_col = OpenOffice.letter_to_number(b)
1883
- # result = 0
1884
- # first_row.upto(last_row) {|row|
1885
- # first_col.upto(last_col) {|col|
1886
- # result = result + s.cell(row,col)
1887
- # }
1888
- # }
1889
- # result
1890
- #end
1891
-
1892
- #def test_dsl
1893
- # s = OpenOffice.new(File.join(TESTDIR,"numbers1.ods"))
1894
- # s.default_sheet = s.sheets.first
1895
- #
1896
- # s.set 'a',1, 5
1897
- # s.set 'b',1, 3
1898
- # s.set 'c',1, 7
1899
- # s.set('a',2, s.cell('a',1)+s.cell('b',1))
1900
- # assert_equal 8, s.cell('a',2)
1901
- #
1902
- # assert_equal 15, sum(s,'A1:C1')
1903
- # end
1904
-
1905
- #def test_create_spreadsheet1
1906
- # name = File.join(TESTDIR,'createdspreadsheet.ods')
1907
- # rm(name) if File.exists?(File.join(TESTDIR,'createdspreadsheet.ods'))
1908
- # # anlegen, falls noch nicht existierend
1909
- # s = OpenOffice.new(name,true)
1910
- # assert File.exists?(name)
1911
- #end
1912
-
1913
- #def test_create_spreadsheet2
1914
- # # anlegen, falls noch nicht existierend
1915
- # s = OpenOffice.new(File.join(TESTDIR,"createdspreadsheet.ods"),true)
1916
- # s.set 'a',1,42
1917
- # s.set 'b',1,43
1918
- # s.set 'c',1,44
1919
- # s.save
1920
- #
1921
- # t = OpenOffice.new(File.join(TESTDIR,"createdspreadsheet.ods"))
1922
- # assert_equal 42, t.cell(1,'a')
1923
- # assert_equal 43, t.cell('b',1)
1924
- # assert_equal 44, t.cell('c',3)
1925
- #end
1926
-
1927
- # We don't have the bode-v1.xlsx test file
1928
- # #TODO: xlsx-Datei anpassen!
1929
- # def test_excelx_download_uri_and_zipped
1930
- # #TODO: gezippte xlsx Datei online zum Testen suchen
1931
- # if EXCELX
1932
- # if ONLINE
1933
- # url = 'http://stiny-leonhard.de/bode-v1.xlsx.zip'
1934
- # excel = Roo::Excelx.new(url, :zip)
1935
- # assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
1936
- # end
1937
- # end
1938
- # end
1939
-
1940
- # def test_excelx_zipped
1941
- # # TODO: bode...xls bei Gelegenheit nach .xlsx konverieren lassen und zippen!
1942
- # if EXCELX
1943
- # # diese Datei gibt es noch nicht gezippt
1944
- # excel = Roo::Excelx.new(File.join(TESTDIR,"bode-v1.xlsx.zip"), :zip)
1945
- # assert excel
1946
- # assert_raises(ArgumentError) {
1947
- # assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
1948
- # }
1949
- # excel.default_sheet = excel.sheets.first
1950
- # assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
1951
- # end
1952
- # end
1953
-
1954
- def test_csv_parsing_with_headers
1955
- return unless CSV
1956
- headers = ["TITEL", "VERFASSER", "OBJEKT", "NUMMER", "SEITE", "INTERNET", "PC", "KENNUNG"]
1957
-
1958
- oo = Roo::Spreadsheet.open(File.join(TESTDIR, 'Bibelbund.csv'))
1959
- parsed = oo.parse(:headers => true)
1960
- assert_equal headers, parsed[1].keys
1961
- end
1962
-
1963
- def test_bug_numbered_sheet_names
1964
- with_each_spreadsheet(:name=>'bug-numbered-sheet-names', :format=>:excelx) do |oo|
1965
- oo.each_with_pagename { }
1966
- end
1967
- end
1968
-
1969
- def test_parsing_xslx_from_numbers
1970
- return unless EXCELX
1971
- xlsx = Roo::Excelx.new(File.join(TESTDIR, "numbers-export.xlsx"))
1972
-
1973
- xlsx.default_sheet = xlsx.sheets.first
1974
- assert_equal 'Sheet 1', xlsx.cell('a',1)
1975
-
1976
- # Another buggy behavior of Numbers 3.1: if a warkbook has more than a
1977
- # single sheet, all sheets except the first one will have an extra row and
1978
- # column added to the beginning. That's why we assert against cell B2 and
1979
- # not A1
1980
- xlsx.default_sheet = xlsx.sheets.last
1981
- assert_equal 'Sheet 2', xlsx.cell('b',2)
1982
- end
1983
-
1984
- def test_openoffice_encryption
1985
- if OPENOFFICE
1986
- assert_raises(ArgumentError) { Roo::LibreOffice.new(File.join(TESTDIR, "encrypted-letmein.ods")) }
1987
- assert_raises(ArgumentError) { Roo::LibreOffice.new(File.join(TESTDIR, "encrypted-letmein.ods"), :password => "badpassword") }
1988
- oo = Roo::LibreOffice.new(File.join(TESTDIR, "encrypted-letmein.ods"), :password => "letmein")
1989
- oo.default_sheet = oo.sheets.first
1990
- assert_equal "Hello World", oo.cell('a',1)
1991
- end
1992
- end
1993
-
1994
- def test_expand_merged_range
1995
- return unless EXCELX
1996
- xlsx = Roo::Excelx.new(File.join(TESTDIR, "merged_ranges.xlsx"), {:expand_merged_ranges => true})
1997
- for row in 3..7 do
1998
- for col in 'a'..'b'
1999
- if row > 3 && row < 7 && col == 'a'
2000
- assert_equal 'vertical1', xlsx.cell(col,row)
2001
- else
2002
- assert_nil xlsx.cell(col,row)
2003
- end
2004
- end
2005
- end
2006
- for row in 3..11 do
2007
- for col in 'f'..'h'
2008
- if row > 3 && row < 11 && col == 'g'
2009
- assert_equal 'vertical2', xlsx.cell(col,row)
2010
- else
2011
- assert_nil xlsx.cell(col,row)
2012
- end
2013
- end
2014
- end
2015
- for row in 3..5 do
2016
- for col in 'b'..'f'
2017
- if row == 4 && col > 'b' && col < 'f'
2018
- assert_equal 'horizontal', xlsx.cell(col,row)
2019
- else
2020
- assert_nil xlsx.cell(col,row)
2021
- end
2022
- end
2023
- end
2024
- for row in 8..13 do
2025
- for col in 'a'..'e'
2026
- if row > 8 && row < 13 && col > 'a' && col < 'e'
2027
- assert_equal 'block', xlsx.cell(col,row)
2028
- else
2029
- assert_nil xlsx.cell(col,row)
2030
- end
2031
- end
2032
- end
2033
- end
2034
-
2035
- def test_noexpand_merged_range
2036
- return unless EXCELX
2037
- xlsx = Roo::Excelx.new(File.join(TESTDIR, "merged_ranges.xlsx"))
2038
- for row in 3..7 do
2039
- for col in 'a'..'b'
2040
- if row == 4 && col == 'a'
2041
- assert_equal 'vertical1', xlsx.cell(col,row)
2042
- else
2043
- assert_nil xlsx.cell(col,row)
2044
- end
2045
- end
2046
- end
2047
- for row in 3..11 do
2048
- for col in 'f'..'h'
2049
- if row == 4 && col == 'g'
2050
- assert_equal 'vertical2', xlsx.cell(col,row)
2051
- else
2052
- assert_nil xlsx.cell(col,row)
2053
- end
2054
- end
2055
- end
2056
- for row in 3..5 do
2057
- for col in 'b'..'f'
2058
- if row == 4 && col == 'c'
2059
- assert_equal 'horizontal', xlsx.cell(col,row)
2060
- else
2061
- assert_nil xlsx.cell(col,row)
2062
- end
2063
- end
2064
- end
2065
- for row in 8..13 do
2066
- for col in 'a'..'e'
2067
- if row == 9 && col == 'b'
2068
- assert_equal 'block', xlsx.cell(col,row)
2069
- else
2070
- assert_nil xlsx.cell(col,row)
2071
- end
2072
- end
2073
- end
2074
- end
2075
-
2076
- def test_open_stream
2077
- return unless EXCELX
2078
- file_contents = File.read File.join(TESTDIR, fixture_filename(:numbers1, :excelx)), encoding: 'BINARY'
2079
- stream = StringIO.new(file_contents)
2080
- xlsx = Roo::Excelx.new(stream)
2081
- assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], xlsx.sheets
2082
- end
2083
-
2084
- def test_close
2085
- with_each_spreadsheet(:name=>'numbers1') do |oo|
2086
- next unless (tempdir = oo.instance_variable_get('@tmpdir'))
2087
- oo.close
2088
- assert !File.exists?(tempdir), "Expected #{tempdir} to be cleaned up, but it still exists"
2089
- end
2090
- end
2091
-
2092
- def test_cleanup_on_error
2093
- old_temp_files = Dir.open(Dir.tmpdir).to_a
2094
- with_each_spreadsheet(:name=>'non_existent_file', :ignore_errors=>true) do |oo|; end
2095
- assert_equal Dir.open(Dir.tmpdir).to_a, old_temp_files
2096
- end
2097
- end # class
392
+ end