roo-andyw8 2.0.0

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