roo 1.13.2 → 2.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +17 -0
  3. data/.github/issue_template.md +16 -0
  4. data/.github/pull_request_template.md +14 -0
  5. data/.github/workflows/pull-request.yml +15 -0
  6. data/.github/workflows/ruby.yml +34 -0
  7. data/.gitignore +11 -0
  8. data/.rubocop.yml +186 -0
  9. data/.simplecov +4 -0
  10. data/CHANGELOG.md +702 -0
  11. data/Gemfile +18 -12
  12. data/Guardfile +23 -0
  13. data/LICENSE +5 -1
  14. data/README.md +328 -0
  15. data/Rakefile +23 -23
  16. data/examples/roo_soap_client.rb +28 -31
  17. data/examples/roo_soap_server.rb +4 -6
  18. data/examples/write_me.rb +9 -10
  19. data/lib/roo/base.rb +317 -504
  20. data/lib/roo/constants.rb +7 -0
  21. data/lib/roo/csv.rb +141 -113
  22. data/lib/roo/errors.rb +11 -0
  23. data/lib/roo/excelx/cell/base.rb +108 -0
  24. data/lib/roo/excelx/cell/boolean.rb +30 -0
  25. data/lib/roo/excelx/cell/date.rb +28 -0
  26. data/lib/roo/excelx/cell/datetime.rb +107 -0
  27. data/lib/roo/excelx/cell/empty.rb +20 -0
  28. data/lib/roo/excelx/cell/number.rb +99 -0
  29. data/lib/roo/excelx/cell/string.rb +19 -0
  30. data/lib/roo/excelx/cell/time.rb +44 -0
  31. data/lib/roo/excelx/cell.rb +110 -0
  32. data/lib/roo/excelx/comments.rb +55 -0
  33. data/lib/roo/excelx/coordinate.rb +19 -0
  34. data/lib/roo/excelx/extractor.rb +39 -0
  35. data/lib/roo/excelx/format.rb +71 -0
  36. data/lib/roo/excelx/images.rb +26 -0
  37. data/lib/roo/excelx/relationships.rb +33 -0
  38. data/lib/roo/excelx/shared.rb +39 -0
  39. data/lib/roo/excelx/shared_strings.rb +151 -0
  40. data/lib/roo/excelx/sheet.rb +151 -0
  41. data/lib/roo/excelx/sheet_doc.rb +257 -0
  42. data/lib/roo/excelx/styles.rb +64 -0
  43. data/lib/roo/excelx/workbook.rb +64 -0
  44. data/lib/roo/excelx.rb +407 -601
  45. data/lib/roo/font.rb +17 -0
  46. data/lib/roo/formatters/base.rb +15 -0
  47. data/lib/roo/formatters/csv.rb +84 -0
  48. data/lib/roo/formatters/matrix.rb +23 -0
  49. data/lib/roo/formatters/xml.rb +31 -0
  50. data/lib/roo/formatters/yaml.rb +40 -0
  51. data/lib/roo/helpers/default_attr_reader.rb +20 -0
  52. data/lib/roo/helpers/weak_instance_cache.rb +41 -0
  53. data/lib/roo/libre_office.rb +4 -0
  54. data/lib/roo/link.rb +34 -0
  55. data/lib/roo/open_office.rb +631 -0
  56. data/lib/roo/spreadsheet.rb +28 -23
  57. data/lib/roo/tempdir.rb +24 -0
  58. data/lib/roo/utils.rb +128 -0
  59. data/lib/roo/version.rb +3 -0
  60. data/lib/roo.rb +26 -24
  61. data/roo.gemspec +29 -203
  62. data/spec/helpers.rb +5 -0
  63. data/spec/lib/roo/base_spec.rb +291 -3
  64. data/spec/lib/roo/csv_spec.rb +38 -11
  65. data/spec/lib/roo/excelx/cell/time_spec.rb +15 -0
  66. data/spec/lib/roo/excelx/format_spec.rb +7 -6
  67. data/spec/lib/roo/excelx/relationships_spec.rb +43 -0
  68. data/spec/lib/roo/excelx/sheet_doc_spec.rb +11 -0
  69. data/spec/lib/roo/excelx_spec.rb +672 -11
  70. data/spec/lib/roo/libreoffice_spec.rb +16 -6
  71. data/spec/lib/roo/openoffice_spec.rb +30 -8
  72. data/spec/lib/roo/spreadsheet_spec.rb +60 -12
  73. data/spec/lib/roo/strict_spec.rb +43 -0
  74. data/spec/lib/roo/utils_spec.rb +119 -0
  75. data/spec/lib/roo/weak_instance_cache_spec.rb +92 -0
  76. data/spec/lib/roo_spec.rb +0 -0
  77. data/spec/spec_helper.rb +7 -6
  78. data/test/all_ss.rb +12 -11
  79. data/test/excelx/cell/test_attr_reader_default.rb +72 -0
  80. data/test/excelx/cell/test_base.rb +68 -0
  81. data/test/excelx/cell/test_boolean.rb +36 -0
  82. data/test/excelx/cell/test_date.rb +38 -0
  83. data/test/excelx/cell/test_datetime.rb +45 -0
  84. data/test/excelx/cell/test_empty.rb +18 -0
  85. data/test/excelx/cell/test_number.rb +90 -0
  86. data/test/excelx/cell/test_string.rb +48 -0
  87. data/test/excelx/cell/test_time.rb +30 -0
  88. data/test/excelx/test_coordinate.rb +51 -0
  89. data/test/formatters/test_csv.rb +136 -0
  90. data/test/formatters/test_matrix.rb +76 -0
  91. data/test/formatters/test_xml.rb +78 -0
  92. data/test/formatters/test_yaml.rb +20 -0
  93. data/test/helpers/test_accessing_files.rb +81 -0
  94. data/test/helpers/test_comments.rb +43 -0
  95. data/test/helpers/test_formulas.rb +9 -0
  96. data/test/helpers/test_labels.rb +103 -0
  97. data/test/helpers/test_sheets.rb +55 -0
  98. data/test/helpers/test_styles.rb +62 -0
  99. data/test/roo/test_base.rb +182 -0
  100. data/test/roo/test_csv.rb +88 -0
  101. data/test/roo/test_excelx.rb +360 -0
  102. data/test/roo/test_libre_office.rb +9 -0
  103. data/test/roo/test_open_office.rb +289 -0
  104. data/test/test_helper.rb +123 -59
  105. data/test/test_roo.rb +392 -2292
  106. metadata +153 -298
  107. data/CHANGELOG +0 -417
  108. data/Gemfile.lock +0 -78
  109. data/README.markdown +0 -126
  110. data/VERSION +0 -1
  111. data/lib/roo/excel.rb +0 -355
  112. data/lib/roo/excel2003xml.rb +0 -300
  113. data/lib/roo/google.rb +0 -292
  114. data/lib/roo/openoffice.rb +0 -496
  115. data/lib/roo/roo_rails_helper.rb +0 -83
  116. data/lib/roo/worksheet.rb +0 -18
  117. data/scripts/txt2html +0 -67
  118. data/spec/lib/roo/excel2003xml_spec.rb +0 -15
  119. data/spec/lib/roo/excel_spec.rb +0 -17
  120. data/spec/lib/roo/google_spec.rb +0 -64
  121. data/test/files/1900_base.xls +0 -0
  122. data/test/files/1900_base.xlsx +0 -0
  123. data/test/files/1904_base.xls +0 -0
  124. data/test/files/1904_base.xlsx +0 -0
  125. data/test/files/Bibelbund.csv +0 -3741
  126. data/test/files/Bibelbund.ods +0 -0
  127. data/test/files/Bibelbund.xls +0 -0
  128. data/test/files/Bibelbund.xlsx +0 -0
  129. data/test/files/Bibelbund.xml +0 -62518
  130. data/test/files/Bibelbund1.ods +0 -0
  131. data/test/files/Pfand_from_windows_phone.xlsx +0 -0
  132. data/test/files/bad_excel_date.xls +0 -0
  133. data/test/files/bbu.ods +0 -0
  134. data/test/files/bbu.xls +0 -0
  135. data/test/files/bbu.xlsx +0 -0
  136. data/test/files/bbu.xml +0 -152
  137. data/test/files/bode-v1.ods.zip +0 -0
  138. data/test/files/bode-v1.xls.zip +0 -0
  139. data/test/files/boolean.csv +0 -2
  140. data/test/files/boolean.ods +0 -0
  141. data/test/files/boolean.xls +0 -0
  142. data/test/files/boolean.xlsx +0 -0
  143. data/test/files/boolean.xml +0 -112
  144. data/test/files/borders.ods +0 -0
  145. data/test/files/borders.xls +0 -0
  146. data/test/files/borders.xlsx +0 -0
  147. data/test/files/borders.xml +0 -144
  148. data/test/files/bug-numbered-sheet-names.xlsx +0 -0
  149. data/test/files/bug-row-column-fixnum-float.xls +0 -0
  150. data/test/files/bug-row-column-fixnum-float.xml +0 -127
  151. data/test/files/comments.ods +0 -0
  152. data/test/files/comments.xls +0 -0
  153. data/test/files/comments.xlsx +0 -0
  154. data/test/files/csvtypes.csv +0 -1
  155. data/test/files/datetime.ods +0 -0
  156. data/test/files/datetime.xls +0 -0
  157. data/test/files/datetime.xlsx +0 -0
  158. data/test/files/datetime.xml +0 -142
  159. data/test/files/datetime_floatconv.xls +0 -0
  160. data/test/files/datetime_floatconv.xml +0 -148
  161. data/test/files/dreimalvier.ods +0 -0
  162. data/test/files/emptysheets.ods +0 -0
  163. data/test/files/emptysheets.xls +0 -0
  164. data/test/files/emptysheets.xlsx +0 -0
  165. data/test/files/emptysheets.xml +0 -105
  166. data/test/files/excel2003.xml +0 -21140
  167. data/test/files/false_encoding.xls +0 -0
  168. data/test/files/false_encoding.xml +0 -132
  169. data/test/files/file_item_error.xlsx +0 -0
  170. data/test/files/formula.ods +0 -0
  171. data/test/files/formula.xls +0 -0
  172. data/test/files/formula.xlsx +0 -0
  173. data/test/files/formula.xml +0 -134
  174. data/test/files/formula_parse_error.xls +0 -0
  175. data/test/files/formula_parse_error.xml +0 -1833
  176. data/test/files/formula_string_error.xlsx +0 -0
  177. data/test/files/html-escape.ods +0 -0
  178. data/test/files/link.xls +0 -0
  179. data/test/files/link.xlsx +0 -0
  180. data/test/files/matrix.ods +0 -0
  181. data/test/files/matrix.xls +0 -0
  182. data/test/files/named_cells.ods +0 -0
  183. data/test/files/named_cells.xls +0 -0
  184. data/test/files/named_cells.xlsx +0 -0
  185. data/test/files/no_spreadsheet_file.txt +0 -1
  186. data/test/files/numbers1.csv +0 -18
  187. data/test/files/numbers1.ods +0 -0
  188. data/test/files/numbers1.xls +0 -0
  189. data/test/files/numbers1.xlsx +0 -0
  190. data/test/files/numbers1.xml +0 -312
  191. data/test/files/numeric-link.xlsx +0 -0
  192. data/test/files/only_one_sheet.ods +0 -0
  193. data/test/files/only_one_sheet.xls +0 -0
  194. data/test/files/only_one_sheet.xlsx +0 -0
  195. data/test/files/only_one_sheet.xml +0 -67
  196. data/test/files/paragraph.ods +0 -0
  197. data/test/files/paragraph.xls +0 -0
  198. data/test/files/paragraph.xlsx +0 -0
  199. data/test/files/paragraph.xml +0 -127
  200. data/test/files/prova.xls +0 -0
  201. data/test/files/ric.ods +0 -0
  202. data/test/files/simple_spreadsheet.ods +0 -0
  203. data/test/files/simple_spreadsheet.xls +0 -0
  204. data/test/files/simple_spreadsheet.xlsx +0 -0
  205. data/test/files/simple_spreadsheet.xml +0 -225
  206. data/test/files/simple_spreadsheet_from_italo.ods +0 -0
  207. data/test/files/simple_spreadsheet_from_italo.xls +0 -0
  208. data/test/files/simple_spreadsheet_from_italo.xml +0 -242
  209. data/test/files/so_datetime.csv +0 -7
  210. data/test/files/style.ods +0 -0
  211. data/test/files/style.xls +0 -0
  212. data/test/files/style.xlsx +0 -0
  213. data/test/files/style.xml +0 -154
  214. data/test/files/time-test.csv +0 -2
  215. data/test/files/time-test.ods +0 -0
  216. data/test/files/time-test.xls +0 -0
  217. data/test/files/time-test.xlsx +0 -0
  218. data/test/files/time-test.xml +0 -131
  219. data/test/files/type_excel.ods +0 -0
  220. data/test/files/type_excel.xlsx +0 -0
  221. data/test/files/type_excelx.ods +0 -0
  222. data/test/files/type_excelx.xls +0 -0
  223. data/test/files/type_openoffice.xls +0 -0
  224. data/test/files/type_openoffice.xlsx +0 -0
  225. data/test/files/whitespace.ods +0 -0
  226. data/test/files/whitespace.xls +0 -0
  227. data/test/files/whitespace.xlsx +0 -0
  228. data/test/files/whitespace.xml +0 -184
  229. data/test/rm_sub_test.rb +0 -12
  230. data/test/rm_test.rb +0 -7
  231. data/test/test_generic_spreadsheet.rb +0 -259
  232. data/website/index.html +0 -385
  233. data/website/index.txt +0 -423
  234. data/website/javascripts/rounded_corners_lite.inc.js +0 -285
  235. data/website/stylesheets/screen.css +0 -130
  236. data/website/template.rhtml +0 -48
data/test/test_roo.rb CHANGED
@@ -1,2292 +1,392 @@
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
+ include TestSheets
14
+ include TestAccesingFiles
15
+ include TestFormulas
16
+ include TestComments
17
+ include TestLabels
18
+ include TestStyles
19
+
20
+ # Cell related tests
21
+ def test_cells
22
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
23
+ # warum ist Auswaehlen erstes sheet hier nicht
24
+ # mehr drin?
25
+ oo.default_sheet = oo.sheets.first
26
+ assert_equal 1, oo.cell(1,1)
27
+ assert_equal 2, oo.cell(1,2)
28
+ assert_equal 3, oo.cell(1,3)
29
+ assert_equal 4, oo.cell(1,4)
30
+ assert_equal 5, oo.cell(2,1)
31
+ assert_equal 6, oo.cell(2,2)
32
+ assert_equal 7, oo.cell(2,3)
33
+ assert_equal 8, oo.cell(2,4)
34
+ assert_equal 9, oo.cell(2,5)
35
+ assert_equal "test", oo.cell(2,6)
36
+ assert_equal :string, oo.celltype(2,6)
37
+ assert_equal 11, oo.cell(2,7)
38
+ unless oo.kind_of? Roo::CSV
39
+ assert_equal :float, oo.celltype(2,7)
40
+ end
41
+ assert_equal 10, oo.cell(4,1)
42
+ assert_equal 11, oo.cell(4,2)
43
+ assert_equal 12, oo.cell(4,3)
44
+ assert_equal 13, oo.cell(4,4)
45
+ assert_equal 14, oo.cell(4,5)
46
+ assert_equal 10, oo.cell(4,'A')
47
+ assert_equal 11, oo.cell(4,'B')
48
+ assert_equal 12, oo.cell(4,'C')
49
+ assert_equal 13, oo.cell(4,'D')
50
+ assert_equal 14, oo.cell(4,'E')
51
+ unless oo.kind_of? Roo::CSV
52
+ assert_equal :date, oo.celltype(5,1)
53
+ assert_equal Date.new(1961,11,21), oo.cell(5,1)
54
+ assert_equal "1961-11-21", oo.cell(5,1).to_s
55
+ end
56
+ end
57
+ end
58
+
59
+ def test_cell_address
60
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
61
+ assert_equal "tata", oo.cell(6,1)
62
+ assert_equal "tata", oo.cell(6,'A')
63
+ assert_equal "tata", oo.cell('A',6)
64
+ assert_equal "tata", oo.cell(6,'a')
65
+ assert_equal "tata", oo.cell('a',6)
66
+ assert_raises(ArgumentError) { assert_equal "tata", oo.cell('a','f') }
67
+ assert_raises(ArgumentError) { assert_equal "tata", oo.cell('f','a') }
68
+ assert_equal "thisisc8", oo.cell(8,3)
69
+ assert_equal "thisisc8", oo.cell(8,'C')
70
+ assert_equal "thisisc8", oo.cell('C',8)
71
+ assert_equal "thisisc8", oo.cell(8,'c')
72
+ assert_equal "thisisc8", oo.cell('c',8)
73
+ assert_equal "thisisd9", oo.cell('d',9)
74
+ assert_equal "thisisa11", oo.cell('a',11)
75
+ end
76
+ end
77
+
78
+ def test_bug_italo_ve
79
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
80
+ oo.default_sheet = "Sheet5"
81
+ assert_equal 1, oo.cell('A',1)
82
+ assert_equal 5, oo.cell('b',1)
83
+ assert_equal 5, oo.cell('c',1)
84
+ assert_equal 2, oo.cell('a',2)
85
+ assert_equal 3, oo.cell('a',3)
86
+ end
87
+ end
88
+
89
+ def test_celltype
90
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
91
+ assert_equal :string, oo.celltype(2,6)
92
+ end
93
+ end
94
+
95
+ def test_argument_error
96
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
97
+ oo.default_sheet = "Tabelle1"
98
+ end
99
+ end
100
+
101
+ def test_borders_sheets
102
+ with_each_spreadsheet(:name=>'borders') do |oo|
103
+ oo.default_sheet = oo.sheets[1]
104
+ assert_equal 6, oo.first_row
105
+ assert_equal 11, oo.last_row
106
+ assert_equal 4, oo.first_column
107
+ assert_equal 8, oo.last_column
108
+
109
+ oo.default_sheet = oo.sheets.first
110
+ assert_equal 5, oo.first_row
111
+ assert_equal 10, oo.last_row
112
+ assert_equal 3, oo.first_column
113
+ assert_equal 7, oo.last_column
114
+
115
+ oo.default_sheet = oo.sheets[2]
116
+ assert_equal 7, oo.first_row
117
+ assert_equal 12, oo.last_row
118
+ assert_equal 5, oo.first_column
119
+ assert_equal 9, oo.last_column
120
+ end
121
+ end
122
+
123
+ def test_only_one_sheet
124
+ with_each_spreadsheet(:name=>'only_one_sheet') do |oo|
125
+ assert_equal 42, oo.cell('B',4)
126
+ assert_equal 43, oo.cell('C',4)
127
+ assert_equal 44, oo.cell('D',4)
128
+ oo.default_sheet = oo.sheets.first
129
+ assert_equal 42, oo.cell('B',4)
130
+ assert_equal 43, oo.cell('C',4)
131
+ assert_equal 44, oo.cell('D',4)
132
+ end
133
+ end
134
+
135
+ def test_bug_mehrere_datum
136
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
137
+ oo.default_sheet = 'Sheet5'
138
+ assert_equal :date, oo.celltype('A',4)
139
+ assert_equal :date, oo.celltype('B',4)
140
+ assert_equal :date, oo.celltype('C',4)
141
+ assert_equal :date, oo.celltype('D',4)
142
+ assert_equal :date, oo.celltype('E',4)
143
+ assert_equal Date.new(2007,11,21), oo.cell('A',4)
144
+ assert_equal Date.new(2007,11,21), oo.cell('B',4)
145
+ assert_equal Date.new(2007,11,21), oo.cell('C',4)
146
+ assert_equal Date.new(2007,11,21), oo.cell('D',4)
147
+ assert_equal Date.new(2007,11,21), oo.cell('E',4)
148
+ assert_equal :float, oo.celltype('A',5)
149
+ assert_equal :float, oo.celltype('B',5)
150
+ assert_equal :float, oo.celltype('C',5)
151
+ assert_equal :float, oo.celltype('D',5)
152
+ assert_equal :float, oo.celltype('E',5)
153
+ assert_equal 42, oo.cell('A',5)
154
+ assert_equal 42, oo.cell('B',5)
155
+ assert_equal 42, oo.cell('C',5)
156
+ assert_equal 42, oo.cell('D',5)
157
+ assert_equal 42, oo.cell('E',5)
158
+ assert_equal :string, oo.celltype('A',6)
159
+ assert_equal :string, oo.celltype('B',6)
160
+ assert_equal :string, oo.celltype('C',6)
161
+ assert_equal :string, oo.celltype('D',6)
162
+ assert_equal :string, oo.celltype('E',6)
163
+ assert_equal "ABC", oo.cell('A',6)
164
+ assert_equal "ABC", oo.cell('B',6)
165
+ assert_equal "ABC", oo.cell('C',6)
166
+ assert_equal "ABC", oo.cell('D',6)
167
+ assert_equal "ABC", oo.cell('E',6)
168
+ end
169
+ end
170
+
171
+ def test_multiple_sheets
172
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
173
+ 2.times do
174
+ oo.default_sheet = "Tabelle1"
175
+ assert_equal 1, oo.cell(1,1)
176
+ assert_equal 1, oo.cell(1,1,"Tabelle1")
177
+ assert_equal "I am sheet 2", oo.cell('C',5,"Name of Sheet 2")
178
+ sheetname = 'Sheet5'
179
+ assert_equal :date, oo.celltype('A',4,sheetname)
180
+ assert_equal :date, oo.celltype('B',4,sheetname)
181
+ assert_equal :date, oo.celltype('C',4,sheetname)
182
+ assert_equal :date, oo.celltype('D',4,sheetname)
183
+ assert_equal :date, oo.celltype('E',4,sheetname)
184
+ assert_equal Date.new(2007,11,21), oo.cell('A',4,sheetname)
185
+ assert_equal Date.new(2007,11,21), oo.cell('B',4,sheetname)
186
+ assert_equal Date.new(2007,11,21), oo.cell('C',4,sheetname)
187
+ assert_equal Date.new(2007,11,21), oo.cell('D',4,sheetname)
188
+ assert_equal Date.new(2007,11,21), oo.cell('E',4,sheetname)
189
+ assert_equal :float, oo.celltype('A',5,sheetname)
190
+ assert_equal :float, oo.celltype('B',5,sheetname)
191
+ assert_equal :float, oo.celltype('C',5,sheetname)
192
+ assert_equal :float, oo.celltype('D',5,sheetname)
193
+ assert_equal :float, oo.celltype('E',5,sheetname)
194
+ assert_equal 42, oo.cell('A',5,sheetname)
195
+ assert_equal 42, oo.cell('B',5,sheetname)
196
+ assert_equal 42, oo.cell('C',5,sheetname)
197
+ assert_equal 42, oo.cell('D',5,sheetname)
198
+ assert_equal 42, oo.cell('E',5,sheetname)
199
+ assert_equal :string, oo.celltype('A',6,sheetname)
200
+ assert_equal :string, oo.celltype('B',6,sheetname)
201
+ assert_equal :string, oo.celltype('C',6,sheetname)
202
+ assert_equal :string, oo.celltype('D',6,sheetname)
203
+ assert_equal :string, oo.celltype('E',6,sheetname)
204
+ assert_equal "ABC", oo.cell('A',6,sheetname)
205
+ assert_equal "ABC", oo.cell('B',6,sheetname)
206
+ assert_equal "ABC", oo.cell('C',6,sheetname)
207
+ assert_equal "ABC", oo.cell('D',6,sheetname)
208
+ assert_equal "ABC", oo.cell('E',6,sheetname)
209
+ oo.reload
210
+ end
211
+ end
212
+ end
213
+
214
+ # Tests for Specific Cell types (time, etc)
215
+
216
+ def test_bug_time_nil
217
+ with_each_spreadsheet(:name=>'time-test') do |oo|
218
+ assert_equal 12*3600+13*60+14, oo.cell('B',1) # 12:13:14 (secs since midnight)
219
+ assert_equal :time, oo.celltype('B',1)
220
+ assert_equal 15*3600+16*60, oo.cell('C',1) # 15:16 (secs since midnight)
221
+ assert_equal :time, oo.celltype('C',1)
222
+ assert_equal 23*3600, oo.cell('D',1) # 23:00 (secs since midnight)
223
+ assert_equal :time, oo.celltype('D',1)
224
+ end
225
+ end
226
+
227
+ def test_datetime
228
+ with_each_spreadsheet(:name=>'datetime') do |oo|
229
+ val = oo.cell('c',3)
230
+ assert_equal :datetime, oo.celltype('c',3)
231
+ assert_equal DateTime.new(1961,11,21,12,17,18), val
232
+ assert_kind_of DateTime, val
233
+ val = oo.cell('a',1)
234
+ assert_equal :date, oo.celltype('a',1)
235
+ assert_kind_of Date, val
236
+ assert_equal Date.new(1961,11,21), val
237
+ assert_equal Date.new(1961,11,21), oo.cell('a',1)
238
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('a',3)
239
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('b',3)
240
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('c',3)
241
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('a',4)
242
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('b',4)
243
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('c',4)
244
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('a',5)
245
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('b',5)
246
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('c',5)
247
+ assert_equal Date.new(1961,11,21), oo.cell('a',6)
248
+ assert_equal Date.new(1961,11,21), oo.cell('b',6)
249
+ assert_equal Date.new(1961,11,21), oo.cell('c',6)
250
+ assert_equal Date.new(1961,11,21), oo.cell('a',7)
251
+ assert_equal Date.new(1961,11,21), oo.cell('b',7)
252
+ assert_equal Date.new(1961,11,21), oo.cell('c',7)
253
+ assert_equal DateTime.new(2013,11,5,11,45,00), oo.cell('a',8)
254
+ assert_equal DateTime.new(2013,11,5,11,45,00), oo.cell('b',8)
255
+ assert_equal DateTime.new(2013,11,5,11,45,00), oo.cell('c',8)
256
+ end
257
+ end
258
+
259
+ def test_cell_boolean
260
+ with_each_spreadsheet(:name=>'boolean', :format=>[:openoffice, :excelx]) do |oo|
261
+ if oo.class == Roo::Excelx
262
+ assert_equal true, oo.cell(1, 1), "failure in #{oo.class}"
263
+ assert_equal false, oo.cell(2, 1), "failure in #{oo.class}"
264
+
265
+ cell = oo.sheet_for(oo.default_sheet).cells[[1, 1,]]
266
+ assert_equal 'TRUE', cell.formatted_value
267
+
268
+ cell = oo.sheet_for(oo.default_sheet).cells[[2, 1,]]
269
+ assert_equal 'FALSE', cell.formatted_value
270
+ else
271
+ assert_equal "true", oo.cell(1,1), "failure in "+oo.class.to_s
272
+ assert_equal "false", oo.cell(2,1), "failure in "+oo.class.to_s
273
+ end
274
+ end
275
+ end
276
+
277
+ def test_cell_boolean_from_google_sheets
278
+ with_each_spreadsheet(:name=>'boolean-from-google-sheets', :format=>[:openoffice, :excelx]) do |oo|
279
+ if oo.class == Roo::Excelx
280
+ assert_equal true, oo.cell(1, 1), "failure in #{oo.class}"
281
+ assert_equal false, oo.cell(2, 1), "failure in #{oo.class}"
282
+
283
+ cell = oo.sheet_for(oo.default_sheet).cells[[1, 1,]]
284
+ assert_equal 'TRUE', cell.formatted_value
285
+
286
+ cell = oo.sheet_for(oo.default_sheet).cells[[2, 1,]]
287
+ assert_equal 'FALSE', cell.formatted_value
288
+ else
289
+ assert_equal "true", oo.cell(1,1), "failure in #{oo.class}"
290
+ assert_equal "false", oo.cell(2,1), "failure in #{oo.class}"
291
+ end
292
+ end
293
+ end
294
+
295
+ def test_cell_multiline
296
+ with_each_spreadsheet(:name=>'paragraph', :format=>[:openoffice, :excelx]) do |oo|
297
+ assert_equal "This is a test\nof a multiline\nCell", oo.cell(1,1)
298
+ assert_equal "This is a test\n¶\nof a multiline\n\nCell", oo.cell(1,2)
299
+ assert_equal "first p\n\nsecond p\n\nlast p", oo.cell(2,1)
300
+ end
301
+ end
302
+
303
+ def test_apostrophe_replacement
304
+ with_each_spreadsheet(:name=>'apostrophe', :format=>[:openoffice]) do |oo|
305
+ assert_equal "'", oo.cell(1,1)
306
+ end
307
+ end
308
+
309
+ def test_frozen_string_usage
310
+ with_each_spreadsheet(:name=>'frozen_string', :format=>[:openoffice]) do |oo|
311
+ assert_equal "", oo.cell(1,1)
312
+ end
313
+ end
314
+
315
+ def test_row_whitespace
316
+ # auf dieses Dokument habe ich keinen Zugriff TODO:
317
+ # TODO: No access to document whitespace?
318
+ with_each_spreadsheet(:name=>'whitespace') do |oo|
319
+ oo.default_sheet = "Sheet1"
320
+ assert_equal [nil, nil, nil, nil, nil, nil], oo.row(1)
321
+ assert_equal [nil, nil, nil, nil, nil, nil], oo.row(2)
322
+ assert_equal ["Date", "Start time", "End time", "Pause", "Sum", "Comment"], oo.row(3)
323
+ assert_equal [Date.new(2007,5,7), 9.25, 10.25, 0.0, 1.0, "Task 1"], oo.row(4)
324
+ assert_equal [nil, nil, nil, nil, nil, nil], oo.row(5)
325
+ assert_equal [Date.new(2007,5,7), 10.75, 10.75, 0.0, 0.0, "Task 1"], oo.row(6)
326
+ oo.default_sheet = "Sheet2"
327
+ assert_equal ["Date", nil, "Start time"], oo.row(1)
328
+ assert_equal [Date.new(2007,5,7), nil, 9.25], oo.row(2)
329
+ assert_equal [Date.new(2007,5,7), nil, 10.75], oo.row(3)
330
+ end
331
+ end
332
+
333
+ def test_col_whitespace
334
+ #TODO:
335
+ # kein Zugriff auf Dokument whitespace
336
+ with_each_spreadsheet(:name=>'whitespace') do |oo|
337
+ oo.default_sheet = "Sheet1"
338
+ assert_equal ["Date", Date.new(2007,5,7), nil, Date.new(2007,5,7)], oo.column(1)
339
+ assert_equal ["Start time", 9.25, nil, 10.75], oo.column(2)
340
+ assert_equal ["End time", 10.25, nil, 10.75], oo.column(3)
341
+ assert_equal ["Pause", 0.0, nil, 0.0], oo.column(4)
342
+ assert_equal ["Sum", 1.0, nil, 0.0], oo.column(5)
343
+ assert_equal ["Comment","Task 1", nil, "Task 1"], oo.column(6)
344
+ oo.default_sheet = "Sheet2"
345
+ assert_equal [nil, nil, nil], oo.column(1)
346
+ assert_equal [nil, nil, nil], oo.column(2)
347
+ assert_equal ["Date", Date.new(2007,5,7), Date.new(2007,5,7)], oo.column(3)
348
+ assert_equal [nil, nil, nil], oo.column(4)
349
+ assert_equal [ "Start time", 9.25, 10.75], oo.column(5)
350
+ end
351
+ end
352
+
353
+ def test_cell_methods
354
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
355
+ assert_equal 10, oo.a4 # cell(4,'A')
356
+ assert_equal 11, oo.b4 # cell(4,'B')
357
+ assert_equal 12, oo.c4 # cell(4,'C')
358
+ assert_equal 13, oo.d4 # cell(4,'D')
359
+ assert_equal 14, oo.e4 # cell(4,'E')
360
+ assert_equal 'ABC', oo.c6('Sheet5')
361
+ assert_equal 41, oo.a12
362
+
363
+ assert_raises(NoMethodError) do
364
+ # a42a is not a valid cell name, should raise ArgumentError
365
+ assert_equal 9999, oo.a42a
366
+ end
367
+ end
368
+ end
369
+
370
+ # compare large spreadsheets
371
+ def test_compare_large_spreadsheets
372
+ skip_long_test
373
+ qq = Roo::OpenOffice.new(File.join('test', 'files', "Bibelbund.ods"))
374
+ with_each_spreadsheet(name: 'Bibelbund') do |oo|
375
+ oo.sheets.each do |sh|
376
+ oo.first_row.upto(oo.last_row) do |row|
377
+ oo.first_column.upto(oo.last_column) do |col|
378
+ c1 = qq.cell(row, col, sh)
379
+ c1.force_encoding("UTF-8") if c1.class == String
380
+ c2 = oo.cell(row,col,sh)
381
+ c2.force_encoding("UTF-8") if c2.class == String
382
+ next if c1.nil? && c2.nil?
383
+
384
+ assert_equal c1, c2, "diff in #{sh}/#{row}/#{col}}"
385
+ assert_equal qq.celltype(row, col, sh), oo.celltype(row, col, sh)
386
+ assert_equal qq.formula?(row, col, sh), oo.formula?(row, col, sh)
387
+ end
388
+ end
389
+ end
390
+ end
391
+ end
392
+ end