roo 1.13.2 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +17 -0
  3. data/.github/ISSUE_TEMPLATE +10 -0
  4. data/.gitignore +11 -0
  5. data/.simplecov +4 -0
  6. data/.travis.yml +17 -0
  7. data/CHANGELOG.md +626 -0
  8. data/Gemfile +17 -12
  9. data/Gemfile_ruby2 +30 -0
  10. data/Guardfile +23 -0
  11. data/LICENSE +3 -1
  12. data/README.md +285 -0
  13. data/Rakefile +23 -23
  14. data/examples/roo_soap_client.rb +28 -31
  15. data/examples/roo_soap_server.rb +4 -6
  16. data/examples/write_me.rb +9 -10
  17. data/lib/roo/base.rb +298 -495
  18. data/lib/roo/constants.rb +5 -0
  19. data/lib/roo/csv.rb +127 -113
  20. data/lib/roo/errors.rb +11 -0
  21. data/lib/roo/excelx/cell/base.rb +94 -0
  22. data/lib/roo/excelx/cell/boolean.rb +27 -0
  23. data/lib/roo/excelx/cell/date.rb +28 -0
  24. data/lib/roo/excelx/cell/datetime.rb +111 -0
  25. data/lib/roo/excelx/cell/empty.rb +19 -0
  26. data/lib/roo/excelx/cell/number.rb +87 -0
  27. data/lib/roo/excelx/cell/string.rb +19 -0
  28. data/lib/roo/excelx/cell/time.rb +43 -0
  29. data/lib/roo/excelx/cell.rb +106 -0
  30. data/lib/roo/excelx/comments.rb +55 -0
  31. data/lib/roo/excelx/coordinate.rb +12 -0
  32. data/lib/roo/excelx/extractor.rb +21 -0
  33. data/lib/roo/excelx/format.rb +64 -0
  34. data/lib/roo/excelx/relationships.rb +25 -0
  35. data/lib/roo/excelx/shared.rb +32 -0
  36. data/lib/roo/excelx/shared_strings.rb +157 -0
  37. data/lib/roo/excelx/sheet.rb +112 -0
  38. data/lib/roo/excelx/sheet_doc.rb +211 -0
  39. data/lib/roo/excelx/styles.rb +64 -0
  40. data/lib/roo/excelx/workbook.rb +59 -0
  41. data/lib/roo/excelx.rb +376 -602
  42. data/lib/roo/font.rb +17 -0
  43. data/lib/roo/formatters/base.rb +15 -0
  44. data/lib/roo/formatters/csv.rb +84 -0
  45. data/lib/roo/formatters/matrix.rb +23 -0
  46. data/lib/roo/formatters/xml.rb +31 -0
  47. data/lib/roo/formatters/yaml.rb +40 -0
  48. data/lib/roo/libre_office.rb +4 -0
  49. data/lib/roo/link.rb +34 -0
  50. data/lib/roo/open_office.rb +626 -0
  51. data/lib/roo/spreadsheet.rb +22 -23
  52. data/lib/roo/tempdir.rb +21 -0
  53. data/lib/roo/utils.rb +78 -0
  54. data/lib/roo/version.rb +3 -0
  55. data/lib/roo.rb +23 -24
  56. data/roo.gemspec +21 -204
  57. data/spec/helpers.rb +5 -0
  58. data/spec/lib/roo/base_spec.rb +229 -3
  59. data/spec/lib/roo/csv_spec.rb +38 -11
  60. data/spec/lib/roo/excelx/format_spec.rb +7 -6
  61. data/spec/lib/roo/excelx_spec.rb +510 -11
  62. data/spec/lib/roo/libreoffice_spec.rb +16 -6
  63. data/spec/lib/roo/openoffice_spec.rb +30 -8
  64. data/spec/lib/roo/spreadsheet_spec.rb +60 -12
  65. data/spec/lib/roo/utils_spec.rb +106 -0
  66. data/spec/spec_helper.rb +7 -6
  67. data/test/all_ss.rb +12 -11
  68. data/test/excelx/cell/test_base.rb +63 -0
  69. data/test/excelx/cell/test_boolean.rb +36 -0
  70. data/test/excelx/cell/test_date.rb +38 -0
  71. data/test/excelx/cell/test_datetime.rb +45 -0
  72. data/test/excelx/cell/test_empty.rb +7 -0
  73. data/test/excelx/cell/test_number.rb +74 -0
  74. data/test/excelx/cell/test_string.rb +28 -0
  75. data/test/excelx/cell/test_time.rb +30 -0
  76. data/test/formatters/test_csv.rb +119 -0
  77. data/test/formatters/test_matrix.rb +76 -0
  78. data/test/formatters/test_xml.rb +74 -0
  79. data/test/formatters/test_yaml.rb +20 -0
  80. data/test/roo/test_csv.rb +52 -0
  81. data/test/roo/test_excelx.rb +186 -0
  82. data/test/roo/test_libre_office.rb +9 -0
  83. data/test/roo/test_open_office.rb +126 -0
  84. data/test/test_helper.rb +73 -53
  85. data/test/test_roo.rb +1211 -2292
  86. metadata +119 -298
  87. data/CHANGELOG +0 -417
  88. data/Gemfile.lock +0 -78
  89. data/README.markdown +0 -126
  90. data/VERSION +0 -1
  91. data/lib/roo/excel.rb +0 -355
  92. data/lib/roo/excel2003xml.rb +0 -300
  93. data/lib/roo/google.rb +0 -292
  94. data/lib/roo/openoffice.rb +0 -496
  95. data/lib/roo/roo_rails_helper.rb +0 -83
  96. data/lib/roo/worksheet.rb +0 -18
  97. data/scripts/txt2html +0 -67
  98. data/spec/lib/roo/excel2003xml_spec.rb +0 -15
  99. data/spec/lib/roo/excel_spec.rb +0 -17
  100. data/spec/lib/roo/google_spec.rb +0 -64
  101. data/test/files/1900_base.xls +0 -0
  102. data/test/files/1900_base.xlsx +0 -0
  103. data/test/files/1904_base.xls +0 -0
  104. data/test/files/1904_base.xlsx +0 -0
  105. data/test/files/Bibelbund.csv +0 -3741
  106. data/test/files/Bibelbund.ods +0 -0
  107. data/test/files/Bibelbund.xls +0 -0
  108. data/test/files/Bibelbund.xlsx +0 -0
  109. data/test/files/Bibelbund.xml +0 -62518
  110. data/test/files/Bibelbund1.ods +0 -0
  111. data/test/files/Pfand_from_windows_phone.xlsx +0 -0
  112. data/test/files/bad_excel_date.xls +0 -0
  113. data/test/files/bbu.ods +0 -0
  114. data/test/files/bbu.xls +0 -0
  115. data/test/files/bbu.xlsx +0 -0
  116. data/test/files/bbu.xml +0 -152
  117. data/test/files/bode-v1.ods.zip +0 -0
  118. data/test/files/bode-v1.xls.zip +0 -0
  119. data/test/files/boolean.csv +0 -2
  120. data/test/files/boolean.ods +0 -0
  121. data/test/files/boolean.xls +0 -0
  122. data/test/files/boolean.xlsx +0 -0
  123. data/test/files/boolean.xml +0 -112
  124. data/test/files/borders.ods +0 -0
  125. data/test/files/borders.xls +0 -0
  126. data/test/files/borders.xlsx +0 -0
  127. data/test/files/borders.xml +0 -144
  128. data/test/files/bug-numbered-sheet-names.xlsx +0 -0
  129. data/test/files/bug-row-column-fixnum-float.xls +0 -0
  130. data/test/files/bug-row-column-fixnum-float.xml +0 -127
  131. data/test/files/comments.ods +0 -0
  132. data/test/files/comments.xls +0 -0
  133. data/test/files/comments.xlsx +0 -0
  134. data/test/files/csvtypes.csv +0 -1
  135. data/test/files/datetime.ods +0 -0
  136. data/test/files/datetime.xls +0 -0
  137. data/test/files/datetime.xlsx +0 -0
  138. data/test/files/datetime.xml +0 -142
  139. data/test/files/datetime_floatconv.xls +0 -0
  140. data/test/files/datetime_floatconv.xml +0 -148
  141. data/test/files/dreimalvier.ods +0 -0
  142. data/test/files/emptysheets.ods +0 -0
  143. data/test/files/emptysheets.xls +0 -0
  144. data/test/files/emptysheets.xlsx +0 -0
  145. data/test/files/emptysheets.xml +0 -105
  146. data/test/files/excel2003.xml +0 -21140
  147. data/test/files/false_encoding.xls +0 -0
  148. data/test/files/false_encoding.xml +0 -132
  149. data/test/files/file_item_error.xlsx +0 -0
  150. data/test/files/formula.ods +0 -0
  151. data/test/files/formula.xls +0 -0
  152. data/test/files/formula.xlsx +0 -0
  153. data/test/files/formula.xml +0 -134
  154. data/test/files/formula_parse_error.xls +0 -0
  155. data/test/files/formula_parse_error.xml +0 -1833
  156. data/test/files/formula_string_error.xlsx +0 -0
  157. data/test/files/html-escape.ods +0 -0
  158. data/test/files/link.xls +0 -0
  159. data/test/files/link.xlsx +0 -0
  160. data/test/files/matrix.ods +0 -0
  161. data/test/files/matrix.xls +0 -0
  162. data/test/files/named_cells.ods +0 -0
  163. data/test/files/named_cells.xls +0 -0
  164. data/test/files/named_cells.xlsx +0 -0
  165. data/test/files/no_spreadsheet_file.txt +0 -1
  166. data/test/files/numbers1.csv +0 -18
  167. data/test/files/numbers1.ods +0 -0
  168. data/test/files/numbers1.xls +0 -0
  169. data/test/files/numbers1.xlsx +0 -0
  170. data/test/files/numbers1.xml +0 -312
  171. data/test/files/numeric-link.xlsx +0 -0
  172. data/test/files/only_one_sheet.ods +0 -0
  173. data/test/files/only_one_sheet.xls +0 -0
  174. data/test/files/only_one_sheet.xlsx +0 -0
  175. data/test/files/only_one_sheet.xml +0 -67
  176. data/test/files/paragraph.ods +0 -0
  177. data/test/files/paragraph.xls +0 -0
  178. data/test/files/paragraph.xlsx +0 -0
  179. data/test/files/paragraph.xml +0 -127
  180. data/test/files/prova.xls +0 -0
  181. data/test/files/ric.ods +0 -0
  182. data/test/files/simple_spreadsheet.ods +0 -0
  183. data/test/files/simple_spreadsheet.xls +0 -0
  184. data/test/files/simple_spreadsheet.xlsx +0 -0
  185. data/test/files/simple_spreadsheet.xml +0 -225
  186. data/test/files/simple_spreadsheet_from_italo.ods +0 -0
  187. data/test/files/simple_spreadsheet_from_italo.xls +0 -0
  188. data/test/files/simple_spreadsheet_from_italo.xml +0 -242
  189. data/test/files/so_datetime.csv +0 -7
  190. data/test/files/style.ods +0 -0
  191. data/test/files/style.xls +0 -0
  192. data/test/files/style.xlsx +0 -0
  193. data/test/files/style.xml +0 -154
  194. data/test/files/time-test.csv +0 -2
  195. data/test/files/time-test.ods +0 -0
  196. data/test/files/time-test.xls +0 -0
  197. data/test/files/time-test.xlsx +0 -0
  198. data/test/files/time-test.xml +0 -131
  199. data/test/files/type_excel.ods +0 -0
  200. data/test/files/type_excel.xlsx +0 -0
  201. data/test/files/type_excelx.ods +0 -0
  202. data/test/files/type_excelx.xls +0 -0
  203. data/test/files/type_openoffice.xls +0 -0
  204. data/test/files/type_openoffice.xlsx +0 -0
  205. data/test/files/whitespace.ods +0 -0
  206. data/test/files/whitespace.xls +0 -0
  207. data/test/files/whitespace.xlsx +0 -0
  208. data/test/files/whitespace.xml +0 -184
  209. data/test/rm_sub_test.rb +0 -12
  210. data/test/rm_test.rb +0 -7
  211. data/test/test_generic_spreadsheet.rb +0 -259
  212. data/website/index.html +0 -385
  213. data/website/index.txt +0 -423
  214. data/website/javascripts/rounded_corners_lite.inc.js +0 -285
  215. data/website/stylesheets/screen.css +0 -130
  216. data/website/template.rhtml +0 -48
data/test/test_roo.rb CHANGED
@@ -1,2292 +1,1211 @@
1
- # encoding: utf-8
2
- # damit keine falschen Vermutungen aufkommen: Ich habe religioes rein gar nichts
3
- # mit diesem Bibelbund zu tun, aber die hatten eine ziemlich grosse
4
- # Spreadsheet-Datei mit ca. 3500 Zeilen oeffentlich im Netz, die sich ganz gut
5
- # zum Testen eignete.
6
- #
7
- #--
8
- # these test cases were developed to run under Linux OS, some commands
9
- # (like 'diff') must be changed (or commented out ;-)) if you want to run
10
- # the tests under another OS
11
- #
12
-
13
- #TODO
14
- # Look at formulas in excel - does not work with date/time
15
-
16
- # Dump warnings that come from the test to open files
17
- # with the wrong spreadsheet class
18
- #STDERR.reopen "/dev/null","w"
19
-
20
- require File.dirname(__FILE__) + '/test_helper'
21
-
22
- class TestRoo < Test::Unit::TestCase
23
-
24
- OPENOFFICE = true # do OpenOffice-Spreadsheet Tests? (.ods files)
25
- EXCEL = true # do Excel Tests? (.xls files)
26
- GOOGLE = false # do Google-Spreadsheet Tests?
27
- EXCELX = true # do Excelx Tests? (.xlsx files)
28
- LIBREOFFICE = true # do LibreOffice tests? (.ods files)
29
- CSV = true # do CSV tests? (.csv files)
30
-
31
- FORMATS = {
32
- excel: EXCEL,
33
- excelx: EXCELX,
34
- openoffice: OPENOFFICE,
35
- google: GOOGLE,
36
- libreoffice: LIBREOFFICE
37
- }
38
-
39
- ONLINE = false
40
- LONG_RUN = false
41
-
42
- def fixture_filename(name, format)
43
- case format
44
- when :excel
45
- "#{name}.xls"
46
- when :excelx
47
- "#{name}.xlsx"
48
- when :openoffice, :libreoffice
49
- "#{name}.ods"
50
- when :google
51
- key_of(name)
52
- end
53
- end
54
-
55
- # call a block of code for each spreadsheet type
56
- # and yield a reference to the roo object
57
- def with_each_spreadsheet(options)
58
- if options[:format]
59
- options[:format] = Array(options[:format])
60
- invalid_formats = options[:format] - FORMATS.keys
61
- unless invalid_formats.empty?
62
- raise "invalid spreadsheet types: #{invalid_formats.join(', ')}"
63
- end
64
- else
65
- options[:format] = FORMATS.keys
66
- end
67
- options[:format].each do |format|
68
- begin
69
- if FORMATS[format]
70
- yield Roo::Spreadsheet.open(File.join(TESTDIR,
71
- fixture_filename(options[:name], format)))
72
- end
73
- rescue => e
74
- raise e, "#{e.message} for #{format}", e.backtrace
75
- end
76
- end
77
- end
78
-
79
- # Using Date.strptime so check that it's using the method
80
- # with the value set in date_format
81
- def test_date
82
- with_each_spreadsheet(:name=>'numbers1', :format=>:google) do |oo|
83
- # should default to DDMMYYYY
84
- assert oo.date?("21/11/1962")
85
- assert !oo.date?("11/21/1962")
86
- oo.date_format = '%m/%d/%Y'
87
- assert !oo.date?("21/11/1962")
88
- assert oo.date?("11/21/1962")
89
- oo.date_format = '%Y-%m-%d'
90
- assert(oo.date?("1962-11-21"))
91
- assert(!oo.date?("1962-21-11"))
92
- end
93
- end
94
-
95
- def test_sheets_csv
96
- if CSV
97
- oo = Roo::CSV.new(File.join(TESTDIR,'numbers1.csv'))
98
- assert_equal ["default"], oo.sheets
99
- assert_raise(RangeError) { oo.default_sheet = "no_sheet" }
100
- assert_raise(TypeError) { oo.default_sheet = [1,2,3] }
101
- oo.sheets.each { |sh|
102
- oo.default_sheet = sh
103
- assert_equal sh, oo.default_sheet
104
- }
105
- end
106
- end
107
-
108
- def test_sheets
109
- with_each_spreadsheet(:name=>'numbers1') do |oo|
110
- assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets
111
- assert_raise(RangeError) { oo.default_sheet = "no_sheet" }
112
- assert_raise(TypeError) { oo.default_sheet = [1,2,3] }
113
- oo.sheets.each { |sh|
114
- oo.default_sheet = sh
115
- assert_equal sh, oo.default_sheet
116
- }
117
- end
118
- end
119
-
120
- def test_cells
121
- with_each_spreadsheet(:name=>'numbers1') do |oo|
122
- # warum ist Auswaehlen erstes sheet hier nicht
123
- # mehr drin?
124
- oo.default_sheet = oo.sheets.first
125
- assert_equal 1, oo.cell(1,1)
126
- assert_equal 2, oo.cell(1,2)
127
- assert_equal 3, oo.cell(1,3)
128
- assert_equal 4, oo.cell(1,4)
129
- assert_equal 5, oo.cell(2,1)
130
- assert_equal 6, oo.cell(2,2)
131
- assert_equal 7, oo.cell(2,3)
132
- assert_equal 8, oo.cell(2,4)
133
- assert_equal 9, oo.cell(2,5)
134
- assert_equal "test", oo.cell(2,6)
135
- assert_equal :string, oo.celltype(2,6)
136
- assert_equal 11, oo.cell(2,7)
137
- unless oo.kind_of? Roo::CSV
138
- assert_equal :float, oo.celltype(2,7)
139
- end
140
- assert_equal 10, oo.cell(4,1)
141
- assert_equal 11, oo.cell(4,2)
142
- assert_equal 12, oo.cell(4,3)
143
- assert_equal 13, oo.cell(4,4)
144
- assert_equal 14, oo.cell(4,5)
145
- assert_equal 10, oo.cell(4,'A')
146
- assert_equal 11, oo.cell(4,'B')
147
- assert_equal 12, oo.cell(4,'C')
148
- assert_equal 13, oo.cell(4,'D')
149
- assert_equal 14, oo.cell(4,'E')
150
- unless oo.kind_of? Roo::CSV
151
- assert_equal :date, oo.celltype(5,1)
152
- assert_equal Date.new(1961,11,21), oo.cell(5,1)
153
- assert_equal "1961-11-21", oo.cell(5,1).to_s
154
- end
155
- end
156
- end
157
-
158
- def test_celltype
159
- with_each_spreadsheet(:name=>'numbers1') do |oo|
160
- assert_equal :string, oo.celltype(2,6)
161
- end
162
- end
163
-
164
- def test_cell_address
165
- with_each_spreadsheet(:name=>'numbers1') do |oo|
166
- assert_equal "tata", oo.cell(6,1)
167
- assert_equal "tata", oo.cell(6,'A')
168
- assert_equal "tata", oo.cell('A',6)
169
- assert_equal "tata", oo.cell(6,'a')
170
- assert_equal "tata", oo.cell('a',6)
171
- assert_raise(ArgumentError) { assert_equal "tata", oo.cell('a','f') }
172
- assert_raise(ArgumentError) { assert_equal "tata", oo.cell('f','a') }
173
- assert_equal "thisisc8", oo.cell(8,3)
174
- assert_equal "thisisc8", oo.cell(8,'C')
175
- assert_equal "thisisc8", oo.cell('C',8)
176
- assert_equal "thisisc8", oo.cell(8,'c')
177
- assert_equal "thisisc8", oo.cell('c',8)
178
- assert_equal "thisisd9", oo.cell('d',9)
179
- assert_equal "thisisa11", oo.cell('a',11)
180
- end
181
- end
182
-
183
- def test_office_version
184
- with_each_spreadsheet(:name=>'numbers1', :format=>:openoffice) do |oo|
185
- assert_equal "1.0", oo.officeversion
186
- end
187
- end
188
-
189
- def test_libre_office
190
- if LIBREOFFICE
191
- oo = Roo::LibreOffice.new(File.join(TESTDIR, "numbers1.ods"))
192
- oo.default_sheet = oo.sheets.first
193
- assert_equal 41, oo.cell('a',12)
194
- end
195
- end
196
-
197
- def test_sheetname
198
- with_each_spreadsheet(:name=>'numbers1') do |oo|
199
- oo.default_sheet = "Name of Sheet 2"
200
- assert_equal 'I am sheet 2', oo.cell('C',5)
201
- assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
202
- assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
203
- assert_raise(RangeError) { oo.cell('C',5,"non existing sheet name")}
204
- assert_raise(RangeError) { oo.celltype('C',5,"non existing sheet name")}
205
- assert_raise(RangeError) { oo.empty?('C',5,"non existing sheet name")}
206
- if oo.class == Roo::Excel
207
- assert_raise(NotImplementedError) { oo.formula?('C',5,"non existing sheet name")}
208
- assert_raise(NotImplementedError) { oo.formula('C',5,"non existing sheet name")}
209
- else
210
- assert_raise(RangeError) { oo.formula?('C',5,"non existing sheet name")}
211
- assert_raise(RangeError) { oo.formula('C',5,"non existing sheet name")}
212
- assert_raise(RangeError) { oo.set('C',5,42,"non existing sheet name")}
213
- assert_raise(RangeError) { oo.formulas("non existing sheet name")}
214
- end
215
- assert_raise(RangeError) { oo.to_yaml({},1,1,1,1,"non existing sheet name")}
216
- end
217
- end
218
-
219
- def test_argument_error
220
- with_each_spreadsheet(:name=>'numbers1') do |oo|
221
- assert_nothing_raised(ArgumentError) { oo.default_sheet = "Tabelle1" }
222
- end
223
- end
224
-
225
- def test_bug_contiguous_cells
226
- with_each_spreadsheet(:name=>'numbers1', :format=>:openoffice) do |oo|
227
- oo.default_sheet = "Sheet4"
228
- assert_equal Date.new(2007,06,16), oo.cell('a',1)
229
- assert_equal 10, oo.cell('b',1)
230
- assert_equal 10, oo.cell('c',1)
231
- assert_equal 10, oo.cell('d',1)
232
- assert_equal 10, oo.cell('e',1)
233
- end
234
- end
235
-
236
- def test_bug_italo_ve
237
- with_each_spreadsheet(:name=>'numbers1') do |oo|
238
- oo.default_sheet = "Sheet5"
239
- assert_equal 1, oo.cell('A',1)
240
- assert_equal 5, oo.cell('b',1)
241
- assert_equal 5, oo.cell('c',1)
242
- assert_equal 2, oo.cell('a',2)
243
- assert_equal 3, oo.cell('a',3)
244
- end
245
- end
246
-
247
- def test_italo_table
248
- with_each_spreadsheet(:name=>'simple_spreadsheet_from_italo', :format=>[:openoffice, :excel]) do |oo|
249
- assert_equal '1', oo.cell('A',1)
250
- assert_equal '1', oo.cell('B',1)
251
- assert_equal '1', oo.cell('C',1)
252
- assert_equal 1, oo.cell('A',2).to_i
253
- assert_equal 2, oo.cell('B',2).to_i
254
- assert_equal 1, oo.cell('C',2).to_i
255
- assert_equal 1, oo.cell('A',3)
256
- assert_equal 3, oo.cell('B',3)
257
- assert_equal 1, oo.cell('C',3)
258
- assert_equal 'A', oo.cell('A',4)
259
- assert_equal 'A', oo.cell('B',4)
260
- assert_equal 'A', oo.cell('C',4)
261
- assert_equal 0.01, oo.cell('A',5)
262
- assert_equal 0.01, oo.cell('B',5)
263
- assert_equal 0.01, oo.cell('C',5)
264
- assert_equal 0.03, oo.cell('a',5)+oo.cell('b',5)+oo.cell('c',5)
265
-
266
- # Cells values in row 1:
267
- assert_equal "1:string", oo.cell(1, 1)+":"+oo.celltype(1, 1).to_s
268
- assert_equal "1:string",oo.cell(1, 2)+":"+oo.celltype(1, 2).to_s
269
- assert_equal "1:string",oo.cell(1, 3)+":"+oo.celltype(1, 3).to_s
270
-
271
- # Cells values in row 2:
272
- assert_equal "1:string",oo.cell(2, 1)+":"+oo.celltype(2, 1).to_s
273
- assert_equal "2:string",oo.cell(2, 2)+":"+oo.celltype(2, 2).to_s
274
- assert_equal "1:string",oo.cell(2, 3)+":"+oo.celltype(2, 3).to_s
275
-
276
- # Cells values in row 3:
277
- assert_equal "1.0:float",oo.cell(3, 1).to_s+":"+oo.celltype(3, 1).to_s
278
- assert_equal "3.0:float",oo.cell(3, 2).to_s+":"+oo.celltype(3, 2).to_s
279
- assert_equal "1.0:float",oo.cell(3, 3).to_s+":"+oo.celltype(3, 3).to_s
280
-
281
- # Cells values in row 4:
282
- assert_equal "A:string",oo.cell(4, 1)+":"+oo.celltype(4, 1).to_s
283
- assert_equal "A:string",oo.cell(4, 2)+":"+oo.celltype(4, 2).to_s
284
- assert_equal "A:string",oo.cell(4, 3)+":"+oo.celltype(4, 3).to_s
285
-
286
- # Cells values in row 5:
287
- if oo.class == Roo::OpenOffice
288
- assert_equal "0.01:percentage",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
289
- assert_equal "0.01:percentage",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
290
- assert_equal "0.01:percentage",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
291
- else
292
- assert_equal "0.01:float",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
293
- assert_equal "0.01:float",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
294
- assert_equal "0.01:float",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
295
- end
296
- end
297
- end
298
-
299
- def test_formula_openoffice
300
- with_each_spreadsheet(:name=>'formula', :format=>:openoffice) do |oo|
301
- assert_equal 1, oo.cell('A',1)
302
- assert_equal 2, oo.cell('A',2)
303
- assert_equal 3, oo.cell('A',3)
304
- assert_equal 4, oo.cell('A',4)
305
- assert_equal 5, oo.cell('A',5)
306
- assert_equal 6, oo.cell('A',6)
307
- assert_equal 21, oo.cell('A',7)
308
- assert_equal :formula, oo.celltype('A',7)
309
- assert_equal "=[Sheet2.A1]", oo.formula('C',7)
310
- assert_nil oo.formula('A',6)
311
- assert_equal [[7, 1, "=SUM([.A1:.A6])"],
312
- [7, 2, "=SUM([.$A$1:.B6])"],
313
- [7, 3, "=[Sheet2.A1]"],
314
- [8, 2, "=SUM([.$A$1:.B7])"],
315
- ], oo.formulas(oo.sheets.first)
316
-
317
- # setting a cell
318
- oo.set('A',15, 41)
319
- assert_equal 41, oo.cell('A',15)
320
- oo.set('A',16, "41")
321
- assert_equal "41", oo.cell('A',16)
322
- oo.set('A',17, 42.5)
323
- assert_equal 42.5, oo.cell('A',17)
324
- end
325
- end
326
-
327
- def test_formula_google
328
- with_each_spreadsheet(:name=>'formula', :format=>:google) do |oo|
329
- oo.default_sheet = oo.sheets.first
330
- assert_equal 1, oo.cell('A',1)
331
- assert_equal 2, oo.cell('A',2)
332
- assert_equal 3, oo.cell('A',3)
333
- assert_equal 4, oo.cell('A',4)
334
- assert_equal 5, oo.cell('A',5)
335
- assert_equal 6, oo.cell('A',6)
336
- # assert_equal 21, oo.cell('A',7)
337
- assert_equal 21.0, oo.cell('A',7) #TODO: better solution Fixnum/Float
338
- assert_equal :formula, oo.celltype('A',7)
339
- # assert_equal "=[Sheet2.A1]", oo.formula('C',7)
340
- # !!! different from formulas in OpenOffice
341
- #was: assert_equal "=sheet2!R[-6]C[-2]", oo.formula('C',7)
342
- # has Google changed their format of formulas/references to other sheets?
343
- assert_equal "=Sheet2!R[-6]C[-2]", oo.formula('C',7)
344
- assert_nil oo.formula('A',6)
345
- # assert_equal [[7, 1, "=SUM([.A1:.A6])"],
346
- # [7, 2, "=SUM([.$A$1:.B6])"],
347
- # [7, 3, "=[Sheet2.A1]"],
348
- # [8, 2, "=SUM([.$A$1:.B7])"],
349
- # ], oo.formulas(oo.sheets.first)
350
- # different format than in openoffice spreadsheets:
351
- #was:
352
- # assert_equal [[7, 1, "=SUM(R[-6]C[0]:R[-1]C[0])"],
353
- # [7, 2, "=SUM(R1C1:R[-1]C[0])"],
354
- # [7, 3, "=sheet2!R[-6]C[-2]"],
355
- # [8, 2, "=SUM(R1C1:R[-1]C[0])"]],
356
- # oo.formulas(oo.sheets.first)
357
- assert_equal [[7, 1, "=SUM(R[-6]C:R[-1]C)"],
358
- [7, 2, "=SUM(R1C1:R[-1]C)"],
359
- [7, 3, "=Sheet2!R[-6]C[-2]"],
360
- [8, 2, "=SUM(R1C1:R[-1]C)"]],
361
- oo.formulas(oo.sheets.first)
362
- end
363
- end
364
-
365
- def test_formula_excelx
366
- with_each_spreadsheet(:name=>'formula', :format=>:excelx) do |oo|
367
- assert_equal 1, oo.cell('A',1)
368
- assert_equal 2, oo.cell('A',2)
369
- assert_equal 3, oo.cell('A',3)
370
- assert_equal 4, oo.cell('A',4)
371
- assert_equal 5, oo.cell('A',5)
372
- assert_equal 6, oo.cell('A',6)
373
- assert_equal 21, oo.cell('A',7)
374
- assert_equal :formula, oo.celltype('A',7)
375
- #steht nicht in Datei, oder?
376
- #nein, diesen Bezug habe ich nur in der OpenOffice-Datei
377
- #assert_equal "=[Sheet2.A1]", oo.formula('C',7)
378
- assert_nil oo.formula('A',6)
379
- # assert_equal [[7, 1, "=SUM([.A1:.A6])"],
380
- # [7, 2, "=SUM([.$A$1:.B6])"],
381
- #[7, 3, "=[Sheet2.A1]"],
382
- #[8, 2, "=SUM([.$A$1:.B7])"],
383
- #], oo.formulas(oo.sheets.first)
384
- assert_equal [[7, 1, 'SUM(A1:A6)'],
385
- [7, 2, 'SUM($A$1:B6)'],
386
- # [7, 3, "=[Sheet2.A1]"],
387
- # [8, 2, "=SUM([.$A$1:.B7])"],
388
- ], oo.formulas(oo.sheets.first)
389
-
390
- # setting a cell
391
- oo.set('A',15, 41)
392
- assert_equal 41, oo.cell('A',15)
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 &quot;
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
+ LONG_RUN = ENV["LONG_RUN"] ? true : false
14
+
15
+ def test_sheets
16
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
17
+ assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets
18
+ assert_raises(RangeError) { oo.default_sheet = "no_sheet" }
19
+ assert_raises(TypeError) { oo.default_sheet = [1,2,3] }
20
+ oo.sheets.each { |sh|
21
+ oo.default_sheet = sh
22
+ assert_equal sh, oo.default_sheet
23
+ }
24
+ end
25
+ end
26
+
27
+ def test_cells
28
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
29
+ # warum ist Auswaehlen erstes sheet hier nicht
30
+ # mehr drin?
31
+ oo.default_sheet = oo.sheets.first
32
+ assert_equal 1, oo.cell(1,1)
33
+ assert_equal 2, oo.cell(1,2)
34
+ assert_equal 3, oo.cell(1,3)
35
+ assert_equal 4, oo.cell(1,4)
36
+ assert_equal 5, oo.cell(2,1)
37
+ assert_equal 6, oo.cell(2,2)
38
+ assert_equal 7, oo.cell(2,3)
39
+ assert_equal 8, oo.cell(2,4)
40
+ assert_equal 9, oo.cell(2,5)
41
+ assert_equal "test", oo.cell(2,6)
42
+ assert_equal :string, oo.celltype(2,6)
43
+ assert_equal 11, oo.cell(2,7)
44
+ unless oo.kind_of? Roo::CSV
45
+ assert_equal :float, oo.celltype(2,7)
46
+ end
47
+ assert_equal 10, oo.cell(4,1)
48
+ assert_equal 11, oo.cell(4,2)
49
+ assert_equal 12, oo.cell(4,3)
50
+ assert_equal 13, oo.cell(4,4)
51
+ assert_equal 14, oo.cell(4,5)
52
+ assert_equal 10, oo.cell(4,'A')
53
+ assert_equal 11, oo.cell(4,'B')
54
+ assert_equal 12, oo.cell(4,'C')
55
+ assert_equal 13, oo.cell(4,'D')
56
+ assert_equal 14, oo.cell(4,'E')
57
+ unless oo.kind_of? Roo::CSV
58
+ assert_equal :date, oo.celltype(5,1)
59
+ assert_equal Date.new(1961,11,21), oo.cell(5,1)
60
+ assert_equal "1961-11-21", oo.cell(5,1).to_s
61
+ end
62
+ end
63
+ end
64
+
65
+ def test_celltype
66
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
67
+ assert_equal :string, oo.celltype(2,6)
68
+ end
69
+ end
70
+
71
+ def test_cell_address
72
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
73
+ assert_equal "tata", oo.cell(6,1)
74
+ assert_equal "tata", oo.cell(6,'A')
75
+ assert_equal "tata", oo.cell('A',6)
76
+ assert_equal "tata", oo.cell(6,'a')
77
+ assert_equal "tata", oo.cell('a',6)
78
+ assert_raises(ArgumentError) { assert_equal "tata", oo.cell('a','f') }
79
+ assert_raises(ArgumentError) { assert_equal "tata", oo.cell('f','a') }
80
+ assert_equal "thisisc8", oo.cell(8,3)
81
+ assert_equal "thisisc8", oo.cell(8,'C')
82
+ assert_equal "thisisc8", oo.cell('C',8)
83
+ assert_equal "thisisc8", oo.cell(8,'c')
84
+ assert_equal "thisisc8", oo.cell('c',8)
85
+ assert_equal "thisisd9", oo.cell('d',9)
86
+ assert_equal "thisisa11", oo.cell('a',11)
87
+ end
88
+ end
89
+
90
+ def test_office_version
91
+ with_each_spreadsheet(:name=>'numbers1', :format=>:openoffice) do |oo|
92
+ assert_equal "1.0", oo.officeversion
93
+ end
94
+ end
95
+
96
+ def test_sheetname
97
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
98
+ oo.default_sheet = "Name of Sheet 2"
99
+ assert_equal 'I am sheet 2', oo.cell('C',5)
100
+ assert_raises(RangeError) { oo.default_sheet = "non existing sheet name" }
101
+ assert_raises(RangeError) { oo.default_sheet = "non existing sheet name" }
102
+ assert_raises(RangeError) { oo.cell('C',5,"non existing sheet name")}
103
+ assert_raises(RangeError) { oo.celltype('C',5,"non existing sheet name")}
104
+ assert_raises(RangeError) { oo.empty?('C',5,"non existing sheet name")}
105
+ assert_raises(RangeError) { oo.formula?('C',5,"non existing sheet name")}
106
+ assert_raises(RangeError) { oo.formula('C',5,"non existing sheet name")}
107
+ assert_raises(RangeError) { oo.set('C',5,42,"non existing sheet name")}
108
+ assert_raises(RangeError) { oo.formulas("non existing sheet name")}
109
+ assert_raises(RangeError) { oo.to_yaml({},1,1,1,1,"non existing sheet name")}
110
+ end
111
+ end
112
+
113
+ def test_argument_error
114
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
115
+ oo.default_sheet = "Tabelle1"
116
+ end
117
+ end
118
+
119
+ def test_bug_contiguous_cells
120
+ with_each_spreadsheet(:name=>'numbers1', :format=>:openoffice) do |oo|
121
+ oo.default_sheet = "Sheet4"
122
+ assert_equal Date.new(2007,06,16), oo.cell('a',1)
123
+ assert_equal 10, oo.cell('b',1)
124
+ assert_equal 10, oo.cell('c',1)
125
+ assert_equal 10, oo.cell('d',1)
126
+ assert_equal 10, oo.cell('e',1)
127
+ end
128
+ end
129
+
130
+ def test_bug_italo_ve
131
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
132
+ oo.default_sheet = "Sheet5"
133
+ assert_equal 1, oo.cell('A',1)
134
+ assert_equal 5, oo.cell('b',1)
135
+ assert_equal 5, oo.cell('c',1)
136
+ assert_equal 2, oo.cell('a',2)
137
+ assert_equal 3, oo.cell('a',3)
138
+ end
139
+ end
140
+
141
+ def test_italo_table
142
+ with_each_spreadsheet(:name=>'simple_spreadsheet_from_italo', :format=>:openoffice) do |oo|
143
+ assert_equal '1', oo.cell('A',1)
144
+ assert_equal '1', oo.cell('B',1)
145
+ assert_equal '1', oo.cell('C',1)
146
+ assert_equal 1, oo.cell('A',2).to_i
147
+ assert_equal 2, oo.cell('B',2).to_i
148
+ assert_equal 1, oo.cell('C',2).to_i
149
+ assert_equal 1, oo.cell('A',3)
150
+ assert_equal 3, oo.cell('B',3)
151
+ assert_equal 1, oo.cell('C',3)
152
+ assert_equal 'A', oo.cell('A',4)
153
+ assert_equal 'A', oo.cell('B',4)
154
+ assert_equal 'A', oo.cell('C',4)
155
+ assert_equal 0.01, oo.cell('A',5)
156
+ assert_equal 0.01, oo.cell('B',5)
157
+ assert_equal 0.01, oo.cell('C',5)
158
+ assert_equal 0.03, oo.cell('a',5)+oo.cell('b',5)+oo.cell('c',5)
159
+
160
+ # Cells values in row 1:
161
+ assert_equal "1:string", oo.cell(1, 1)+":"+oo.celltype(1, 1).to_s
162
+ assert_equal "1:string",oo.cell(1, 2)+":"+oo.celltype(1, 2).to_s
163
+ assert_equal "1:string",oo.cell(1, 3)+":"+oo.celltype(1, 3).to_s
164
+
165
+ # Cells values in row 2:
166
+ assert_equal "1:string",oo.cell(2, 1)+":"+oo.celltype(2, 1).to_s
167
+ assert_equal "2:string",oo.cell(2, 2)+":"+oo.celltype(2, 2).to_s
168
+ assert_equal "1:string",oo.cell(2, 3)+":"+oo.celltype(2, 3).to_s
169
+
170
+ # Cells values in row 3:
171
+ assert_equal "1:float",oo.cell(3, 1).to_s+":"+oo.celltype(3, 1).to_s
172
+ assert_equal "3:float",oo.cell(3, 2).to_s+":"+oo.celltype(3, 2).to_s
173
+ assert_equal "1:float",oo.cell(3, 3).to_s+":"+oo.celltype(3, 3).to_s
174
+
175
+ # Cells values in row 4:
176
+ assert_equal "A:string",oo.cell(4, 1)+":"+oo.celltype(4, 1).to_s
177
+ assert_equal "A:string",oo.cell(4, 2)+":"+oo.celltype(4, 2).to_s
178
+ assert_equal "A:string",oo.cell(4, 3)+":"+oo.celltype(4, 3).to_s
179
+
180
+ # Cells values in row 5:
181
+ if oo.class == Roo::OpenOffice
182
+ assert_equal "0.01:percentage",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
183
+ assert_equal "0.01:percentage",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
184
+ assert_equal "0.01:percentage",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
185
+ else
186
+ assert_equal "0.01:float",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
187
+ assert_equal "0.01:float",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
188
+ assert_equal "0.01:float",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
189
+ end
190
+ end
191
+ end
192
+
193
+ def test_formula_openoffice
194
+ with_each_spreadsheet(:name=>'formula', :format=>:openoffice) do |oo|
195
+ assert_equal 1, oo.cell('A',1)
196
+ assert_equal 2, oo.cell('A',2)
197
+ assert_equal 3, oo.cell('A',3)
198
+ assert_equal 4, oo.cell('A',4)
199
+ assert_equal 5, oo.cell('A',5)
200
+ assert_equal 6, oo.cell('A',6)
201
+ assert_equal 21, oo.cell('A',7)
202
+ assert_equal :formula, oo.celltype('A',7)
203
+ assert_equal "=[Sheet2.A1]", oo.formula('C',7)
204
+ assert_nil oo.formula('A',6)
205
+ assert_equal [[7, 1, "=SUM([.A1:.A6])"],
206
+ [7, 2, "=SUM([.$A$1:.B6])"],
207
+ [7, 3, "=[Sheet2.A1]"],
208
+ [8, 2, "=SUM([.$A$1:.B7])"],
209
+ ], oo.formulas(oo.sheets.first)
210
+
211
+ # setting a cell
212
+ oo.set('A',15, 41)
213
+ assert_equal 41, oo.cell('A',15)
214
+ oo.set('A',16, "41")
215
+ assert_equal "41", oo.cell('A',16)
216
+ oo.set('A',17, 42.5)
217
+ assert_equal 42.5, oo.cell('A',17)
218
+ end
219
+ end
220
+
221
+ def test_header_with_brackets_excelx
222
+ with_each_spreadsheet(:name => 'advanced_header', :format => :openoffice) do |oo|
223
+ parsed_head = oo.parse(:headers => true)
224
+ assert_equal "Date(yyyy-mm-dd)", oo.cell('A',1)
225
+ assert_equal parsed_head[0].keys, ["Date(yyyy-mm-dd)"]
226
+ assert_equal parsed_head[0].values, ["Date(yyyy-mm-dd)"]
227
+ end
228
+ end
229
+
230
+ def test_formula_excelx
231
+ with_each_spreadsheet(:name=>'formula', :format=>:excelx) do |oo|
232
+ assert_equal 1, oo.cell('A',1)
233
+ assert_equal 2, oo.cell('A',2)
234
+ assert_equal 3, oo.cell('A',3)
235
+ assert_equal 4, oo.cell('A',4)
236
+ assert_equal 5, oo.cell('A',5)
237
+ assert_equal 6, oo.cell('A',6)
238
+ assert_equal 21, oo.cell('A',7)
239
+ assert_equal :formula, oo.celltype('A',7)
240
+ #steht nicht in Datei, oder?
241
+ #nein, diesen Bezug habe ich nur in der OpenOffice-Datei
242
+ #assert_equal "=[Sheet2.A1]", oo.formula('C',7)
243
+ assert_nil oo.formula('A',6)
244
+ # assert_equal [[7, 1, "=SUM([.A1:.A6])"],
245
+ # [7, 2, "=SUM([.$A$1:.B6])"],
246
+ #[7, 3, "=[Sheet2.A1]"],
247
+ #[8, 2, "=SUM([.$A$1:.B7])"],
248
+ #], oo.formulas(oo.sheets.first)
249
+ assert_equal [[7, 1, 'SUM(A1:A6)'],
250
+ [7, 2, 'SUM($A$1:B6)'],
251
+ # [7, 3, "=[Sheet2.A1]"],
252
+ # [8, 2, "=SUM([.$A$1:.B7])"],
253
+ ], oo.formulas(oo.sheets.first)
254
+
255
+ # setting a cell
256
+ oo.set('A',15, 41)
257
+ assert_equal 41, oo.cell('A',15)
258
+ oo.set('A',16, "41")
259
+ assert_equal "41", oo.cell('A',16)
260
+ oo.set('A',17, 42.5)
261
+ assert_equal 42.5, oo.cell('A',17)
262
+ end
263
+ end
264
+
265
+ def test_borders_sheets
266
+ with_each_spreadsheet(:name=>'borders') do |oo|
267
+ oo.default_sheet = oo.sheets[1]
268
+ assert_equal 6, oo.first_row
269
+ assert_equal 11, oo.last_row
270
+ assert_equal 4, oo.first_column
271
+ assert_equal 8, oo.last_column
272
+
273
+ oo.default_sheet = oo.sheets.first
274
+ assert_equal 5, oo.first_row
275
+ assert_equal 10, oo.last_row
276
+ assert_equal 3, oo.first_column
277
+ assert_equal 7, oo.last_column
278
+
279
+ oo.default_sheet = oo.sheets[2]
280
+ assert_equal 7, oo.first_row
281
+ assert_equal 12, oo.last_row
282
+ assert_equal 5, oo.first_column
283
+ assert_equal 9, oo.last_column
284
+ end
285
+ end
286
+
287
+ def test_only_one_sheet
288
+ with_each_spreadsheet(:name=>'only_one_sheet') do |oo|
289
+ assert_equal 42, oo.cell('B',4)
290
+ assert_equal 43, oo.cell('C',4)
291
+ assert_equal 44, oo.cell('D',4)
292
+ oo.default_sheet = oo.sheets.first
293
+ assert_equal 42, oo.cell('B',4)
294
+ assert_equal 43, oo.cell('C',4)
295
+ assert_equal 44, oo.cell('D',4)
296
+ end
297
+ end
298
+
299
+ def test_bug_ric
300
+ with_each_spreadsheet(:name=>'ric', :format=>:openoffice) do |oo|
301
+ assert oo.empty?('A',1)
302
+ assert oo.empty?('B',1)
303
+ assert oo.empty?('C',1)
304
+ assert oo.empty?('D',1)
305
+ expected = 1
306
+ letter = 'e'
307
+ while letter <= 'u'
308
+ assert_equal expected, oo.cell(letter,1)
309
+ letter.succ!
310
+ expected += 1
311
+ end
312
+ assert_equal 'J', oo.cell('v',1)
313
+ assert_equal 'P', oo.cell('w',1)
314
+ assert_equal 'B', oo.cell('x',1)
315
+ assert_equal 'All', oo.cell('y',1)
316
+ assert_equal 0, oo.cell('a',2)
317
+ assert oo.empty?('b',2)
318
+ assert oo.empty?('c',2)
319
+ assert oo.empty?('d',2)
320
+ assert_equal 'B', oo.cell('e',2)
321
+ assert_equal 'B', oo.cell('f',2)
322
+ assert_equal 'B', oo.cell('g',2)
323
+ assert_equal 'B', oo.cell('h',2)
324
+ assert_equal 'B', oo.cell('i',2)
325
+ assert_equal 'B', oo.cell('j',2)
326
+ assert_equal 'B', oo.cell('k',2)
327
+ assert_equal 'B', oo.cell('l',2)
328
+ assert_equal 'B', oo.cell('m',2)
329
+ assert_equal 'B', oo.cell('n',2)
330
+ assert_equal 'B', oo.cell('o',2)
331
+ assert_equal 'B', oo.cell('p',2)
332
+ assert_equal 'B', oo.cell('q',2)
333
+ assert_equal 'B', oo.cell('r',2)
334
+ assert_equal 'B', oo.cell('s',2)
335
+ assert oo.empty?('t',2)
336
+ assert oo.empty?('u',2)
337
+ assert_equal 0 , oo.cell('v',2)
338
+ assert_equal 0 , oo.cell('w',2)
339
+ assert_equal 15 , oo.cell('x',2)
340
+ assert_equal 15 , oo.cell('y',2)
341
+ end
342
+ end
343
+
344
+ def test_mehrteilig
345
+ with_each_spreadsheet(:name=>'Bibelbund1', :format=>:openoffice) do |oo|
346
+ assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
347
+ end
348
+ end
349
+
350
+ def test_bug_mehrere_datum
351
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
352
+ oo.default_sheet = 'Sheet5'
353
+ assert_equal :date, oo.celltype('A',4)
354
+ assert_equal :date, oo.celltype('B',4)
355
+ assert_equal :date, oo.celltype('C',4)
356
+ assert_equal :date, oo.celltype('D',4)
357
+ assert_equal :date, oo.celltype('E',4)
358
+ assert_equal Date.new(2007,11,21), oo.cell('A',4)
359
+ assert_equal Date.new(2007,11,21), oo.cell('B',4)
360
+ assert_equal Date.new(2007,11,21), oo.cell('C',4)
361
+ assert_equal Date.new(2007,11,21), oo.cell('D',4)
362
+ assert_equal Date.new(2007,11,21), oo.cell('E',4)
363
+ assert_equal :float, oo.celltype('A',5)
364
+ assert_equal :float, oo.celltype('B',5)
365
+ assert_equal :float, oo.celltype('C',5)
366
+ assert_equal :float, oo.celltype('D',5)
367
+ assert_equal :float, oo.celltype('E',5)
368
+ assert_equal 42, oo.cell('A',5)
369
+ assert_equal 42, oo.cell('B',5)
370
+ assert_equal 42, oo.cell('C',5)
371
+ assert_equal 42, oo.cell('D',5)
372
+ assert_equal 42, oo.cell('E',5)
373
+ assert_equal :string, oo.celltype('A',6)
374
+ assert_equal :string, oo.celltype('B',6)
375
+ assert_equal :string, oo.celltype('C',6)
376
+ assert_equal :string, oo.celltype('D',6)
377
+ assert_equal :string, oo.celltype('E',6)
378
+ assert_equal "ABC", oo.cell('A',6)
379
+ assert_equal "ABC", oo.cell('B',6)
380
+ assert_equal "ABC", oo.cell('C',6)
381
+ assert_equal "ABC", oo.cell('D',6)
382
+ assert_equal "ABC", oo.cell('E',6)
383
+ end
384
+ end
385
+
386
+ def test_multiple_sheets
387
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
388
+ 2.times do
389
+ oo.default_sheet = "Tabelle1"
390
+ assert_equal 1, oo.cell(1,1)
391
+ assert_equal 1, oo.cell(1,1,"Tabelle1")
392
+ assert_equal "I am sheet 2", oo.cell('C',5,"Name of Sheet 2")
393
+ sheetname = 'Sheet5'
394
+ assert_equal :date, oo.celltype('A',4,sheetname)
395
+ assert_equal :date, oo.celltype('B',4,sheetname)
396
+ assert_equal :date, oo.celltype('C',4,sheetname)
397
+ assert_equal :date, oo.celltype('D',4,sheetname)
398
+ assert_equal :date, oo.celltype('E',4,sheetname)
399
+ assert_equal Date.new(2007,11,21), oo.cell('A',4,sheetname)
400
+ assert_equal Date.new(2007,11,21), oo.cell('B',4,sheetname)
401
+ assert_equal Date.new(2007,11,21), oo.cell('C',4,sheetname)
402
+ assert_equal Date.new(2007,11,21), oo.cell('D',4,sheetname)
403
+ assert_equal Date.new(2007,11,21), oo.cell('E',4,sheetname)
404
+ assert_equal :float, oo.celltype('A',5,sheetname)
405
+ assert_equal :float, oo.celltype('B',5,sheetname)
406
+ assert_equal :float, oo.celltype('C',5,sheetname)
407
+ assert_equal :float, oo.celltype('D',5,sheetname)
408
+ assert_equal :float, oo.celltype('E',5,sheetname)
409
+ assert_equal 42, oo.cell('A',5,sheetname)
410
+ assert_equal 42, oo.cell('B',5,sheetname)
411
+ assert_equal 42, oo.cell('C',5,sheetname)
412
+ assert_equal 42, oo.cell('D',5,sheetname)
413
+ assert_equal 42, oo.cell('E',5,sheetname)
414
+ assert_equal :string, oo.celltype('A',6,sheetname)
415
+ assert_equal :string, oo.celltype('B',6,sheetname)
416
+ assert_equal :string, oo.celltype('C',6,sheetname)
417
+ assert_equal :string, oo.celltype('D',6,sheetname)
418
+ assert_equal :string, oo.celltype('E',6,sheetname)
419
+ assert_equal "ABC", oo.cell('A',6,sheetname)
420
+ assert_equal "ABC", oo.cell('B',6,sheetname)
421
+ assert_equal "ABC", oo.cell('C',6,sheetname)
422
+ assert_equal "ABC", oo.cell('D',6,sheetname)
423
+ assert_equal "ABC", oo.cell('E',6,sheetname)
424
+ oo.reload
425
+ end
426
+ end
427
+ end
428
+
429
+ def test_find_by_row_huge_document
430
+ if LONG_RUN
431
+ with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice, :excelx]) do |oo|
432
+ oo.default_sheet = oo.sheets.first
433
+ rec = oo.find 20
434
+ assert rec
435
+ # assert_equal "Brief aus dem Sekretariat", rec[0]
436
+ #p rec
437
+ assert_equal "Brief aus dem Sekretariat", rec[0]['TITEL']
438
+ rec = oo.find 22
439
+ assert rec
440
+ # assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]
441
+ assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]['TITEL']
442
+ end
443
+ end
444
+ end
445
+
446
+ def test_find_by_row
447
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
448
+ oo.header_line = nil
449
+ rec = oo.find 16
450
+ assert rec
451
+ assert_nil oo.header_line
452
+ # keine Headerlines in diesem Beispiel definiert
453
+ assert_equal "einundvierzig", rec[0]
454
+ #assert_equal false, rec
455
+ rec = oo.find 15
456
+ assert rec
457
+ assert_equal 41,rec[0]
458
+ end
459
+ end
460
+
461
+ def test_find_by_row_if_header_line_is_not_nil
462
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
463
+ oo.header_line = 2
464
+ refute_nil oo.header_line
465
+ rec = oo.find 1
466
+ assert rec
467
+ assert_equal 5, rec[0]
468
+ assert_equal 6, rec[1]
469
+ rec = oo.find 15
470
+ assert rec
471
+ assert_equal "einundvierzig", rec[0]
472
+ end
473
+ end
474
+
475
+ def test_find_by_conditions
476
+ if LONG_RUN
477
+ with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
478
+ :excelx]) do |oo|
479
+ #-----------------------------------------------------------------
480
+ zeilen = oo.find(:all, :conditions => {
481
+ 'TITEL' => 'Brief aus dem Sekretariat'
482
+ }
483
+ )
484
+ assert_equal 2, zeilen.size
485
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
486
+ "INTERNET"=>nil,
487
+ "SEITE"=>316.0,
488
+ "KENNUNG"=>"Aus dem Bibelbund",
489
+ "OBJEKT"=>"Bibel+Gem",
490
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
491
+ "NUMMER"=>"1982-3",
492
+ "TITEL"=>"Brief aus dem Sekretariat"},
493
+ {"VERFASSER"=>"Almassy, Annelene von",
494
+ "INTERNET"=>nil,
495
+ "SEITE"=>222.0,
496
+ "KENNUNG"=>"Aus dem Bibelbund",
497
+ "OBJEKT"=>"Bibel+Gem",
498
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
499
+ "NUMMER"=>"1983-2",
500
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
501
+
502
+ #----------------------------------------------------------
503
+ zeilen = oo.find(:all,
504
+ :conditions => { 'VERFASSER' => 'Almassy, Annelene von' }
505
+ )
506
+ assert_equal 13, zeilen.size
507
+ #----------------------------------------------------------
508
+ zeilen = oo.find(:all, :conditions => {
509
+ 'TITEL' => 'Brief aus dem Sekretariat',
510
+ 'VERFASSER' => 'Almassy, Annelene von',
511
+ }
512
+ )
513
+ assert_equal 2, zeilen.size
514
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
515
+ "INTERNET"=>nil,
516
+ "SEITE"=>316.0,
517
+ "KENNUNG"=>"Aus dem Bibelbund",
518
+ "OBJEKT"=>"Bibel+Gem",
519
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
520
+ "NUMMER"=>"1982-3",
521
+ "TITEL"=>"Brief aus dem Sekretariat"},
522
+ {"VERFASSER"=>"Almassy, Annelene von",
523
+ "INTERNET"=>nil,
524
+ "SEITE"=>222.0,
525
+ "KENNUNG"=>"Aus dem Bibelbund",
526
+ "OBJEKT"=>"Bibel+Gem",
527
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
528
+ "NUMMER"=>"1983-2",
529
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
530
+
531
+ # Result as an array
532
+ zeilen = oo.find(:all,
533
+ :conditions => {
534
+ 'TITEL' => 'Brief aus dem Sekretariat',
535
+ 'VERFASSER' => 'Almassy, Annelene von',
536
+ }, :array => true)
537
+ assert_equal 2, zeilen.size
538
+ assert_equal [
539
+ [
540
+ "Brief aus dem Sekretariat",
541
+ "Almassy, Annelene von",
542
+ "Bibel+Gem",
543
+ "1982-3",
544
+ 316.0,
545
+ nil,
546
+ "#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
547
+ "Aus dem Bibelbund",
548
+ ],
549
+ [
550
+ "Brief aus dem Sekretariat",
551
+ "Almassy, Annelene von",
552
+ "Bibel+Gem",
553
+ "1983-2",
554
+ 222.0,
555
+ nil,
556
+ "#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
557
+ "Aus dem Bibelbund",
558
+ ]] , zeilen
559
+ end
560
+ end
561
+ end
562
+
563
+ #TODO: temporaerer Test
564
+ def test_seiten_als_date
565
+ if LONG_RUN
566
+ with_each_spreadsheet(:name=>'Bibelbund', :format=>:excelx) do |oo|
567
+ assert_equal 'Bericht aus dem Sekretariat', oo.cell(13,1)
568
+ assert_equal '1981-4', oo.cell(13,'D')
569
+ assert_equal String, oo.excelx_type(13,'E')[1].class
570
+ assert_equal [:numeric_or_formula,"General"], oo.excelx_type(13,'E')
571
+ assert_equal '428', oo.excelx_value(13,'E')
572
+ assert_equal 428.0, oo.cell(13,'E')
573
+ end
574
+ end
575
+ end
576
+
577
+ def test_column
578
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
579
+ 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)]
580
+ assert_equal expected, oo.column(1)
581
+ assert_equal expected, oo.column('a')
582
+ end
583
+ end
584
+
585
+ def test_column_huge_document
586
+ if LONG_RUN
587
+ with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
588
+ :excelx]) do |oo|
589
+ oo.default_sheet = oo.sheets.first
590
+ assert_equal 3735, oo.column('a').size
591
+ #assert_equal 499, oo.column('a').size
592
+ end
593
+ end
594
+ end
595
+
596
+ def test_simple_spreadsheet_find_by_condition
597
+ with_each_spreadsheet(:name=>'simple_spreadsheet') do |oo|
598
+ oo.header_line = 3
599
+ # oo.date_format = '%m/%d/%Y' if oo.class == Google
600
+ erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'})
601
+ assert_equal Date.new(2007,05,07), erg[1]['Date']
602
+ assert_equal 10.75 , erg[1]['Start time']
603
+ assert_equal 12.50 , erg[1]['End time']
604
+ assert_equal 0 , erg[1]['Pause']
605
+ assert_equal 1.75 , erg[1]['Sum']
606
+ assert_equal "Task 1" , erg[1]['Comment']
607
+ end
608
+ end
609
+
610
+ def get_extension(oo)
611
+ case oo
612
+ when Roo::OpenOffice
613
+ ".ods"
614
+ when Roo::Excelx
615
+ ".xlsx"
616
+ end
617
+ end
618
+
619
+ def test_info
620
+ expected_templ = "File: numbers1%s\n"+
621
+ "Number of sheets: 5\n"+
622
+ "Sheets: Tabelle1, Name of Sheet 2, Sheet3, Sheet4, Sheet5\n"+
623
+ "Sheet 1:\n"+
624
+ " First row: 1\n"+
625
+ " Last row: 18\n"+
626
+ " First column: A\n"+
627
+ " Last column: G\n"+
628
+ "Sheet 2:\n"+
629
+ " First row: 5\n"+
630
+ " Last row: 14\n"+
631
+ " First column: B\n"+
632
+ " Last column: E\n"+
633
+ "Sheet 3:\n"+
634
+ " First row: 1\n"+
635
+ " Last row: 1\n"+
636
+ " First column: A\n"+
637
+ " Last column: BA\n"+
638
+ "Sheet 4:\n"+
639
+ " First row: 1\n"+
640
+ " Last row: 1\n"+
641
+ " First column: A\n"+
642
+ " Last column: E\n"+
643
+ "Sheet 5:\n"+
644
+ " First row: 1\n"+
645
+ " Last row: 6\n"+
646
+ " First column: A\n"+
647
+ " Last column: E"
648
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
649
+ ext = get_extension(oo)
650
+ expected = sprintf(expected_templ,ext)
651
+ begin
652
+ if oo.class == Google
653
+ assert_equal expected.gsub(/numbers1/,key_of("numbers1")), oo.info
654
+ else
655
+ assert_equal expected, oo.info
656
+ end
657
+ rescue NameError
658
+ #
659
+ end
660
+ end
661
+ end
662
+
663
+ def test_info_doesnt_set_default_sheet
664
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
665
+ oo.default_sheet = 'Sheet3'
666
+ oo.info
667
+ assert_equal 'Sheet3', oo.default_sheet
668
+ end
669
+ end
670
+
671
+ def test_bug_bbu
672
+ with_each_spreadsheet(:name=>'bbu', :format=>[:openoffice, :excelx]) do |oo|
673
+ assert_equal "File: bbu#{get_extension(oo)}
674
+ Number of sheets: 3
675
+ Sheets: 2007_12, Tabelle2, Tabelle3
676
+ Sheet 1:
677
+ First row: 1
678
+ Last row: 4
679
+ First column: A
680
+ Last column: F
681
+ Sheet 2:
682
+ - empty -
683
+ Sheet 3:
684
+ - empty -", oo.info
685
+
686
+ oo.default_sheet = oo.sheets[1] # empty sheet
687
+ assert_nil oo.first_row
688
+ assert_nil oo.last_row
689
+ assert_nil oo.first_column
690
+ assert_nil oo.last_column
691
+ end
692
+ end
693
+
694
+
695
+ def test_bug_time_nil
696
+ with_each_spreadsheet(:name=>'time-test') do |oo|
697
+ assert_equal 12*3600+13*60+14, oo.cell('B',1) # 12:13:14 (secs since midnight)
698
+ assert_equal :time, oo.celltype('B',1)
699
+ assert_equal 15*3600+16*60, oo.cell('C',1) # 15:16 (secs since midnight)
700
+ assert_equal :time, oo.celltype('C',1)
701
+ assert_equal 23*3600, oo.cell('D',1) # 23:00 (secs since midnight)
702
+ assert_equal :time, oo.celltype('D',1)
703
+ end
704
+ end
705
+
706
+ def test_bug_simple_spreadsheet_time_bug
707
+ # really a bug? are cells really of type time?
708
+ # No! :float must be the correct type
709
+ with_each_spreadsheet(:name=>'simple_spreadsheet', :format=>:excelx) do |oo|
710
+ # puts oo.cell('B',5).to_s
711
+ # assert_equal :time, oo.celltype('B',5)
712
+ assert_equal :float, oo.celltype('B',5)
713
+ assert_equal 10.75, oo.cell('B',5)
714
+ assert_equal 12.50, oo.cell('C',5)
715
+ assert_equal 0, oo.cell('D',5)
716
+ assert_equal 1.75, oo.cell('E',5)
717
+ assert_equal 'Task 1', oo.cell('F',5)
718
+ assert_equal Date.new(2007,5,7), oo.cell('A',5)
719
+ end
720
+ end
721
+
722
+ def test_simple2_excelx
723
+ with_each_spreadsheet(:name=>'simple_spreadsheet', :format=>:excelx) do |oo|
724
+ assert_equal [:numeric_or_formula, "yyyy\\-mm\\-dd"], oo.excelx_type('A',4)
725
+ assert_equal [:numeric_or_formula, "#,##0.00"], oo.excelx_type('B',4)
726
+ assert_equal [:numeric_or_formula, "#,##0.00"], oo.excelx_type('c',4)
727
+ assert_equal [:numeric_or_formula, "General"], oo.excelx_type('d',4)
728
+ assert_equal [:numeric_or_formula, "General"], oo.excelx_type('e',4)
729
+ assert_equal :string, oo.excelx_type('f',4)
730
+
731
+ assert_equal "39209", oo.excelx_value('a',4)
732
+ assert_equal "yyyy\\-mm\\-dd", oo.excelx_format('a',4)
733
+ assert_equal "9.25", oo.excelx_value('b',4)
734
+ assert_equal "10.25", oo.excelx_value('c',4)
735
+ assert_equal "0", oo.excelx_value('d',4)
736
+ #... Sum-Spalte
737
+ # assert_equal "Task 1", oo.excelx_value('f',4)
738
+ assert_equal "Task 1", oo.cell('f',4)
739
+ assert_equal Date.new(2007,05,07), oo.cell('a',4)
740
+ assert_equal "9.25", oo.excelx_value('b',4)
741
+ assert_equal "#,##0.00", oo.excelx_format('b',4)
742
+ assert_equal 9.25, oo.cell('b',4)
743
+ assert_equal :float, oo.celltype('b',4)
744
+ assert_equal :float, oo.celltype('d',4)
745
+ assert_equal 0, oo.cell('d',4)
746
+ assert_equal :formula, oo.celltype('e',4)
747
+ assert_equal 1, oo.cell('e',4)
748
+ assert_equal 'C4-B4-D4', oo.formula('e',4)
749
+ assert_equal :string, oo.celltype('f',4)
750
+ assert_equal "Task 1", oo.cell('f',4)
751
+ end
752
+ end
753
+
754
+ def test_datetime
755
+ with_each_spreadsheet(:name=>'datetime') do |oo|
756
+ val = oo.cell('c',3)
757
+ assert_equal :datetime, oo.celltype('c',3)
758
+ assert_equal DateTime.new(1961,11,21,12,17,18), val
759
+ assert_kind_of DateTime, val
760
+ val = oo.cell('a',1)
761
+ assert_equal :date, oo.celltype('a',1)
762
+ assert_kind_of Date, val
763
+ assert_equal Date.new(1961,11,21), val
764
+ assert_equal Date.new(1961,11,21), oo.cell('a',1)
765
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('a',3)
766
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('b',3)
767
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('c',3)
768
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('a',4)
769
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('b',4)
770
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('c',4)
771
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('a',5)
772
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('b',5)
773
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('c',5)
774
+ assert_equal Date.new(1961,11,21), oo.cell('a',6)
775
+ assert_equal Date.new(1961,11,21), oo.cell('b',6)
776
+ assert_equal Date.new(1961,11,21), oo.cell('c',6)
777
+ assert_equal Date.new(1961,11,21), oo.cell('a',7)
778
+ assert_equal Date.new(1961,11,21), oo.cell('b',7)
779
+ assert_equal Date.new(1961,11,21), oo.cell('c',7)
780
+ assert_equal DateTime.new(2013,11,5,11,45,00), oo.cell('a',8)
781
+ assert_equal DateTime.new(2013,11,5,11,45,00), oo.cell('b',8)
782
+ assert_equal DateTime.new(2013,11,5,11,45,00), oo.cell('c',8)
783
+ end
784
+ end
785
+
786
+ def test_cell_openoffice_html_escape
787
+ with_each_spreadsheet(:name=>'html-escape', :format=>:openoffice) do |oo|
788
+ assert_equal "'", oo.cell(1,1)
789
+ assert_equal "&", oo.cell(2,1)
790
+ assert_equal ">", oo.cell(3,1)
791
+ assert_equal "<", oo.cell(4,1)
792
+ assert_equal "`", oo.cell(5,1)
793
+ # test_openoffice_zipped will catch issues with &quot;
794
+ end
795
+ end
796
+
797
+ def test_cell_boolean
798
+ with_each_spreadsheet(:name=>'boolean', :format=>[:openoffice, :excelx]) do |oo|
799
+ if oo.class == Roo::Excelx
800
+ assert_equal true, oo.cell(1, 1), "failure in #{oo.class}"
801
+ assert_equal false, oo.cell(2, 1), "failure in #{oo.class}"
802
+
803
+ cell = oo.sheet_for(oo.default_sheet).cells[[1, 1,]]
804
+ assert_equal 'TRUE', cell.formatted_value
805
+
806
+ cell = oo.sheet_for(oo.default_sheet).cells[[2, 1,]]
807
+ assert_equal 'FALSE', cell.formatted_value
808
+ else
809
+ assert_equal "true", oo.cell(1,1), "failure in "+oo.class.to_s
810
+ assert_equal "false", oo.cell(2,1), "failure in "+oo.class.to_s
811
+ end
812
+ end
813
+ end
814
+
815
+ def test_cell_multiline
816
+ with_each_spreadsheet(:name=>'paragraph', :format=>[:openoffice, :excelx]) do |oo|
817
+ assert_equal "This is a test\nof a multiline\nCell", oo.cell(1,1)
818
+ assert_equal "This is a test\n¶\nof a multiline\n\nCell", oo.cell(1,2)
819
+ assert_equal "first p\n\nsecond p\n\nlast p", oo.cell(2,1)
820
+ end
821
+ end
822
+
823
+ def test_cell_styles
824
+ # styles only valid in excel spreadsheets?
825
+ # TODO: what todo with other spreadsheet types
826
+ with_each_spreadsheet(:name=>'style', :format=>[# :openoffice,
827
+ :excelx
828
+ ]) do |oo|
829
+ # bold
830
+ assert_equal true, oo.font(1,1).bold?
831
+ assert_equal false, oo.font(1,1).italic?
832
+ assert_equal false, oo.font(1,1).underline?
833
+
834
+ # italic
835
+ assert_equal false, oo.font(2,1).bold?
836
+ assert_equal true, oo.font(2,1).italic?
837
+ assert_equal false, oo.font(2,1).underline?
838
+
839
+ # normal
840
+ assert_equal false, oo.font(3,1).bold?
841
+ assert_equal false, oo.font(3,1).italic?
842
+ assert_equal false, oo.font(3,1).underline?
843
+
844
+ # underline
845
+ assert_equal false, oo.font(4,1).bold?
846
+ assert_equal false, oo.font(4,1).italic?
847
+ assert_equal true, oo.font(4,1).underline?
848
+
849
+ # bold italic
850
+ assert_equal true, oo.font(5,1).bold?
851
+ assert_equal true, oo.font(5,1).italic?
852
+ assert_equal false, oo.font(5,1).underline?
853
+
854
+ # bold underline
855
+ assert_equal true, oo.font(6,1).bold?
856
+ assert_equal false, oo.font(6,1).italic?
857
+ assert_equal true, oo.font(6,1).underline?
858
+
859
+ # italic underline
860
+ assert_equal false, oo.font(7,1).bold?
861
+ assert_equal true, oo.font(7,1).italic?
862
+ assert_equal true, oo.font(7,1).underline?
863
+
864
+ # bolded row
865
+ assert_equal true, oo.font(8,1).bold?
866
+ assert_equal false, oo.font(8,1).italic?
867
+ assert_equal false, oo.font(8,1).underline?
868
+
869
+ # bolded col
870
+ assert_equal true, oo.font(9,2).bold?
871
+ assert_equal false, oo.font(9,2).italic?
872
+ assert_equal false, oo.font(9,2).underline?
873
+
874
+ # bolded row, italic col
875
+ assert_equal true, oo.font(10,3).bold?
876
+ assert_equal true, oo.font(10,3).italic?
877
+ assert_equal false, oo.font(10,3).underline?
878
+
879
+ # normal
880
+ assert_equal false, oo.font(11,4).bold?
881
+ assert_equal false, oo.font(11,4).italic?
882
+ assert_equal false, oo.font(11,4).underline?
883
+ end
884
+ end
885
+
886
+ # Need to extend to other formats
887
+ def test_row_whitespace
888
+ # auf dieses Dokument habe ich keinen Zugriff TODO:
889
+ with_each_spreadsheet(:name=>'whitespace') do |oo|
890
+ oo.default_sheet = "Sheet1"
891
+ assert_equal [nil, nil, nil, nil, nil, nil], oo.row(1)
892
+ assert_equal [nil, nil, nil, nil, nil, nil], oo.row(2)
893
+ assert_equal ["Date", "Start time", "End time", "Pause", "Sum", "Comment"], oo.row(3)
894
+ assert_equal [Date.new(2007,5,7), 9.25, 10.25, 0.0, 1.0, "Task 1"], oo.row(4)
895
+ assert_equal [nil, nil, nil, nil, nil, nil], oo.row(5)
896
+ assert_equal [Date.new(2007,5,7), 10.75, 10.75, 0.0, 0.0, "Task 1"], oo.row(6)
897
+ oo.default_sheet = "Sheet2"
898
+ assert_equal ["Date", nil, "Start time"], oo.row(1)
899
+ assert_equal [Date.new(2007,5,7), nil, 9.25], oo.row(2)
900
+ assert_equal [Date.new(2007,5,7), nil, 10.75], oo.row(3)
901
+ end
902
+ end
903
+
904
+ def test_col_whitespace
905
+ #TODO:
906
+ # kein Zugriff auf Dokument whitespace
907
+ with_each_spreadsheet(:name=>'whitespace') do |oo|
908
+ oo.default_sheet = "Sheet1"
909
+ assert_equal ["Date", Date.new(2007,5,7), nil, Date.new(2007,5,7)], oo.column(1)
910
+ assert_equal ["Start time", 9.25, nil, 10.75], oo.column(2)
911
+ assert_equal ["End time", 10.25, nil, 10.75], oo.column(3)
912
+ assert_equal ["Pause", 0.0, nil, 0.0], oo.column(4)
913
+ assert_equal ["Sum", 1.0, nil, 0.0], oo.column(5)
914
+ assert_equal ["Comment","Task 1", nil, "Task 1"], oo.column(6)
915
+ oo.default_sheet = "Sheet2"
916
+ assert_equal [nil, nil, nil], oo.column(1)
917
+ assert_equal [nil, nil, nil], oo.column(2)
918
+ assert_equal ["Date", Date.new(2007,5,7), Date.new(2007,5,7)], oo.column(3)
919
+ assert_equal [nil, nil, nil], oo.column(4)
920
+ assert_equal [ "Start time", 9.25, 10.75], oo.column(5)
921
+ end
922
+ end
923
+
924
+ def test_excelx_links
925
+ with_each_spreadsheet(:name=>'link', :format=>:excelx) do |oo|
926
+ assert_equal 'Google', oo.cell(1,1)
927
+ assert_equal 'http://www.google.com', oo.cell(1,1).href
928
+ end
929
+ end
930
+
931
+ # Excel has two base date formats one from 1900 and the other from 1904.
932
+ # see #test_base_dates_in_excel
933
+ def test_base_dates_in_excelx
934
+ with_each_spreadsheet(:name=>'1900_base', :format=>:excelx) do |oo|
935
+ assert_equal Date.new(2009,06,15), oo.cell(1,1)
936
+ assert_equal :date, oo.celltype(1,1)
937
+ end
938
+ with_each_spreadsheet(:name=>'1904_base', :format=>:excelx) do |oo|
939
+ assert_equal Date.new(2009,06,15), oo.cell(1,1)
940
+ assert_equal :date, oo.celltype(1,1)
941
+ end
942
+ end
943
+
944
+ def test_cell_methods
945
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
946
+ assert_equal 10, oo.a4 # cell(4,'A')
947
+ assert_equal 11, oo.b4 # cell(4,'B')
948
+ assert_equal 12, oo.c4 # cell(4,'C')
949
+ assert_equal 13, oo.d4 # cell(4,'D')
950
+ assert_equal 14, oo.e4 # cell(4,'E')
951
+ assert_equal 'ABC', oo.c6('Sheet5')
952
+ assert_equal 41, oo.a12
953
+
954
+ assert_raises(NoMethodError) do
955
+ # a42a is not a valid cell name, should raise ArgumentError
956
+ assert_equal 9999, oo.a42a
957
+ end
958
+ end
959
+ end
960
+
961
+ # compare large spreadsheets
962
+ def test_compare_large_spreadsheets
963
+ # problematisch, weil Formeln in Excel nicht unterstützt werden
964
+ if LONG_RUN
965
+ qq = Roo::OpenOffice.new(File.join('test',"Bibelbund.ods"))
966
+ with_each_spreadsheet(:name=>'Bibelbund') do |oo|
967
+ # p "comparing Bibelbund.ods with #{oo.class}"
968
+ oo.sheets.each do |sh|
969
+ oo.first_row.upto(oo.last_row) do |row|
970
+ oo.first_column.upto(oo.last_column) do |col|
971
+ c1 = qq.cell(row,col,sh)
972
+ c1.force_encoding("UTF-8") if c1.class == String
973
+ c2 = oo.cell(row,col,sh)
974
+ c2.force_encoding("UTF-8") if c2.class == String
975
+ assert_equal c1, c2, "diff in #{sh}/#{row}/#{col}}"
976
+ assert_equal qq.celltype(row,col,sh), oo.celltype(row,col,sh)
977
+ assert_equal qq.formula?(row,col,sh), oo.formula?(row,col,sh) if oo.class != Roo::Excel
978
+ end
979
+ end
980
+ end
981
+ end
982
+ end # LONG_RUN
983
+ end
984
+
985
+ def test_label
986
+ with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo|
987
+ # oo.default_sheet = oo.sheets.first
988
+ begin
989
+ row,col = oo.label('anton')
990
+ rescue ArgumentError
991
+ puts "labels error at #{oo.class}"
992
+ raise
993
+ end
994
+ assert_equal 5, row, "error with label in class #{oo.class}"
995
+ assert_equal 3, col, "error with label in class #{oo.class}"
996
+
997
+ row,col = oo.label('anton')
998
+ assert_equal 'Anton', oo.cell(row,col), "error with label in class #{oo.class}"
999
+
1000
+ row,col = oo.label('berta')
1001
+ assert_equal 'Bertha', oo.cell(row,col), "error with label in class #{oo.class}"
1002
+
1003
+ row,col = oo.label('caesar')
1004
+ assert_equal 'Cäsar', oo.cell(row,col),"error with label in class #{oo.class}"
1005
+
1006
+ row,col = oo.label('never')
1007
+ assert_nil row
1008
+ assert_nil col
1009
+
1010
+ row,col,sheet = oo.label('anton')
1011
+ assert_equal 5, row
1012
+ assert_equal 3, col
1013
+ assert_equal "Sheet1", sheet
1014
+ end
1015
+ end
1016
+
1017
+ def test_method_missing_anton
1018
+ with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo|
1019
+ # oo.default_sheet = oo.sheets.first
1020
+ assert_equal "Anton", oo.anton
1021
+ assert_raises(NoMethodError) {
1022
+ oo.never
1023
+ }
1024
+ end
1025
+ end
1026
+
1027
+ def test_labels
1028
+ with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo|
1029
+ # oo.default_sheet = oo.sheets.first
1030
+ assert_equal [
1031
+ ['anton',[5,3,'Sheet1']],
1032
+ ['berta',[4,2,'Sheet1']],
1033
+ ['caesar',[7,2,'Sheet1']],
1034
+ ], oo.labels, "error with labels array in class #{oo.class}"
1035
+ end
1036
+ end
1037
+
1038
+ def test_labeled_cells
1039
+ with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo|
1040
+ oo.default_sheet = oo.sheets.first
1041
+ begin
1042
+ row,col = oo.label('anton')
1043
+ rescue ArgumentError
1044
+ puts "labels error at #{oo.class}"
1045
+ raise
1046
+ end
1047
+ assert_equal 5, row
1048
+ assert_equal 3, col
1049
+
1050
+ row,col = oo.label('anton')
1051
+ assert_equal 'Anton', oo.cell(row,col)
1052
+
1053
+ row,col = oo.label('berta')
1054
+ assert_equal 'Bertha', oo.cell(row,col)
1055
+
1056
+ row,col = oo.label('caesar')
1057
+ assert_equal 'Cäsar', oo.cell(row,col)
1058
+
1059
+ row,col = oo.label('never')
1060
+ assert_nil row
1061
+ assert_nil col
1062
+
1063
+ row,col,sheet = oo.label('anton')
1064
+ assert_equal 5, row
1065
+ assert_equal 3, col
1066
+ assert_equal "Sheet1", sheet
1067
+
1068
+ assert_equal "Anton", oo.anton
1069
+ assert_raises(NoMethodError) {
1070
+ row,col = oo.never
1071
+ }
1072
+
1073
+ # Reihenfolge row,col,sheet analog zu #label
1074
+ assert_equal [
1075
+ ['anton',[5,3,'Sheet1']],
1076
+ ['berta',[4,2,'Sheet1']],
1077
+ ['caesar',[7,2,'Sheet1']],
1078
+ ], oo.labels, "error with labels array in class #{oo.class}"
1079
+ end
1080
+ end
1081
+
1082
+ # #formulas of an empty sheet should return an empty array and not result in
1083
+ # an error message
1084
+ # 2011-06-24
1085
+ def test_bug_formulas_empty_sheet
1086
+ with_each_spreadsheet(:name =>'emptysheets',
1087
+ :format=>[:openoffice,:excelx]) do |oo|
1088
+ oo.default_sheet = oo.sheets.first
1089
+ oo.formulas
1090
+ assert_equal([], oo.formulas)
1091
+ end
1092
+ end
1093
+
1094
+ def test_bug_pfand_from_windows_phone_xlsx
1095
+ return if defined? JRUBY_VERSION
1096
+ with_each_spreadsheet(:name=>'Pfand_from_windows_phone', :format=>:excelx) do |oo|
1097
+ oo.default_sheet = oo.sheets.first
1098
+ assert_equal ['Blatt1','Blatt2','Blatt3'], oo.sheets
1099
+ assert_equal 'Summe', oo.cell('b',1)
1100
+
1101
+ assert_equal Date.new(2011,9,14), oo.cell('a',2)
1102
+ assert_equal :date, oo.celltype('a',2)
1103
+ assert_equal Date.new(2011,9,15), oo.cell('a',3)
1104
+ assert_equal :date, oo.celltype('a',3)
1105
+
1106
+ assert_equal 3.81, oo.cell('b',2)
1107
+ assert_equal "SUM(C2:L2)", oo.formula('b',2)
1108
+ assert_equal 0.7, oo.cell('c',2)
1109
+ end # each
1110
+ end
1111
+
1112
+ def test_comment
1113
+ with_each_spreadsheet(:name=>'comments', :format=>[:openoffice,:libreoffice,
1114
+ :excelx]) do |oo|
1115
+ oo.default_sheet = oo.sheets.first
1116
+ assert_equal 'Kommentar fuer B4',oo.comment('b',4)
1117
+ assert_equal 'Kommentar fuer B5',oo.comment('b',5)
1118
+ assert_nil oo.comment('b',99)
1119
+ # no comment at the second page
1120
+ oo.default_sheet = oo.sheets[1]
1121
+ assert_nil oo.comment('b',4)
1122
+ end
1123
+ end
1124
+
1125
+ def test_comments
1126
+ with_each_spreadsheet(:name=>'comments', :format=>[:openoffice,:libreoffice,
1127
+ :excelx]) do |oo|
1128
+ oo.default_sheet = oo.sheets.first
1129
+ assert_equal [
1130
+ [4, 2, "Kommentar fuer B4"],
1131
+ [5, 2, "Kommentar fuer B5"],
1132
+ ], oo.comments(oo.sheets.first), "comments error in class #{oo.class}"
1133
+ # no comments at the second page
1134
+ oo.default_sheet = oo.sheets[1]
1135
+ assert_equal [], oo.comments, "comments error in class #{oo.class}"
1136
+ end
1137
+
1138
+ with_each_spreadsheet(:name=>'comments-google', :format=>[:excelx]) do |oo|
1139
+ oo.default_sheet = oo.sheets.first
1140
+ assert_equal [[1, 1, "this is a comment\n\t-Steven Daniels"]], oo.comments(oo.sheets.first), "comments error in class #{oo.class}"
1141
+ end
1142
+ end
1143
+
1144
+ def common_possible_bug_snowboard_cells(ss)
1145
+ assert_equal "A.", ss.cell(13,'A'), ss.class
1146
+ assert_equal 147, ss.cell(13,'f'), ss.class
1147
+ assert_equal 152, ss.cell(13,'g'), ss.class
1148
+ assert_equal 156, ss.cell(13,'h'), ss.class
1149
+ assert_equal 158, ss.cell(13,'i'), ss.class
1150
+ assert_equal 160, ss.cell(13,'j'), ss.class
1151
+ assert_equal 164, ss.cell(13,'k'), ss.class
1152
+ assert_equal 168, ss.cell(13,'l'), ss.class
1153
+ assert_equal :string, ss.celltype(13,'m'), ss.class
1154
+ assert_equal "159W", ss.cell(13,'m'), ss.class
1155
+ assert_equal "164W", ss.cell(13,'n'), ss.class
1156
+ assert_equal "168W", ss.cell(13,'o'), ss.class
1157
+ end
1158
+
1159
+ def test_bug_numbered_sheet_names
1160
+ with_each_spreadsheet(:name=>'bug-numbered-sheet-names', :format=>:excelx) do |oo|
1161
+ oo.each_with_pagename { }
1162
+ end
1163
+ end
1164
+
1165
+ def test_close
1166
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
1167
+ next unless (tempdir = oo.instance_variable_get('@tmpdir'))
1168
+ oo.close
1169
+ assert !File.exists?(tempdir), "Expected #{tempdir} to be cleaned up, but it still exists"
1170
+ end
1171
+ end
1172
+
1173
+ # NOTE: Ruby 2.4.0 changed the way GC works. The last Roo object created by
1174
+ # with_each_spreadsheet wasn't getting GC'd until after the process
1175
+ # ended.
1176
+ #
1177
+ # That behavior change broke this test. In order to fix it, I forked the
1178
+ # process and passed the temp directories from the forked process in
1179
+ # order to check if they were removed properly.
1180
+ def test_finalize
1181
+ skip if defined? JRUBY_VERSION
1182
+
1183
+ read, write = IO.pipe
1184
+ pid = Process.fork do
1185
+ with_each_spreadsheet(name: "numbers1") do |oo|
1186
+ write.puts oo.instance_variable_get("@tmpdir")
1187
+ end
1188
+ end
1189
+
1190
+ Process.wait(pid)
1191
+ write.close
1192
+ tempdirs = read.read.split("\n")
1193
+ read.close
1194
+
1195
+ refute tempdirs.empty?
1196
+ tempdirs.each do |tempdir|
1197
+ refute File.exist?(tempdir), "Expected #{tempdir} to be cleaned up, but it still exists"
1198
+ end
1199
+ end
1200
+
1201
+ def test_cleanup_on_error
1202
+ old_temp_files = Dir.open(Dir.tmpdir).to_a
1203
+ with_each_spreadsheet(:name=>'non_existent_file', :ignore_errors=>true) do |oo|; end
1204
+ assert_equal Dir.open(Dir.tmpdir).to_a, old_temp_files
1205
+ end
1206
+
1207
+ def test_name_with_leading_slash
1208
+ xlsx = Roo::Excelx.new(File.join(TESTDIR,'name_with_leading_slash.xlsx'))
1209
+ assert_equal 1, xlsx.sheets.count
1210
+ end
1211
+ end # class