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