roo 1.10.1 → 1.10.2

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 (136) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +38 -0
  4. data/History.txt +4 -4
  5. data/License.txt +20 -0
  6. data/Manifest.txt +68 -0
  7. data/README.markdown +109 -0
  8. data/Rakefile +5 -4
  9. data/bin/roo +0 -0
  10. data/examples/roo_soap_client.rb +53 -0
  11. data/examples/roo_soap_server.rb +29 -0
  12. data/examples/write_me.rb +33 -0
  13. data/lib/roo.rb +20 -61
  14. data/lib/roo/csv.rb +13 -11
  15. data/lib/roo/excel.rb +108 -219
  16. data/lib/roo/excel2003xml.rb +312 -0
  17. data/lib/roo/excelx.rb +205 -341
  18. data/lib/roo/generic_spreadsheet.rb +371 -268
  19. data/lib/roo/google.rb +64 -54
  20. data/lib/roo/openoffice.rb +101 -156
  21. data/lib/roo/roo_rails_helper.rb +5 -5
  22. data/lib/roo/worksheet.rb +18 -0
  23. data/roo.gemspec +43 -0
  24. data/scripts/txt2html +67 -0
  25. data/test/all_ss.rb +8 -10
  26. data/test/{1900_base.xls → files/1900_base.xls} +0 -0
  27. data/test/{1904_base.xls → files/1904_base.xls} +0 -0
  28. data/test/{Bibelbund.csv → files/Bibelbund.csv} +0 -0
  29. data/test/{Bibelbund.ods → files/Bibelbund.ods} +0 -0
  30. data/test/{Bibelbund.xls → files/Bibelbund.xls} +0 -0
  31. data/test/{Bibelbund.xlsx → files/Bibelbund.xlsx} +0 -0
  32. data/test/files/Bibelbund.xml +62518 -0
  33. data/test/{Bibelbund1.ods → files/Bibelbund1.ods} +0 -0
  34. data/test/{Pfand_from_windows_phone.xlsx → files/Pfand_from_windows_phone.xlsx} +0 -0
  35. data/test/files/bad_excel_date.xls +0 -0
  36. data/test/{bbu.ods → files/bbu.ods} +0 -0
  37. data/test/{bbu.xls → files/bbu.xls} +0 -0
  38. data/test/{bbu.xlsx → files/bbu.xlsx} +0 -0
  39. data/test/files/bbu.xml +152 -0
  40. data/test/{bode-v1.ods.zip → files/bode-v1.ods.zip} +0 -0
  41. data/test/{bode-v1.xls.zip → files/bode-v1.xls.zip} +0 -0
  42. data/test/{boolean.ods → files/boolean.ods} +0 -0
  43. data/test/{boolean.xls → files/boolean.xls} +0 -0
  44. data/test/{boolean.xlsx → files/boolean.xlsx} +0 -0
  45. data/test/files/boolean.xml +112 -0
  46. data/test/{borders.ods → files/borders.ods} +0 -0
  47. data/test/{borders.xls → files/borders.xls} +0 -0
  48. data/test/{borders.xlsx → files/borders.xlsx} +0 -0
  49. data/test/files/borders.xml +144 -0
  50. data/test/{bug-row-column-fixnum-float.xls → files/bug-row-column-fixnum-float.xls} +0 -0
  51. data/test/files/bug-row-column-fixnum-float.xml +127 -0
  52. data/test/{comments.ods → files/comments.ods} +0 -0
  53. data/test/{comments.xls → files/comments.xls} +0 -0
  54. data/test/{comments.xlsx → files/comments.xlsx} +0 -0
  55. data/test/{csvtypes.csv → files/csvtypes.csv} +0 -0
  56. data/test/{datetime.ods → files/datetime.ods} +0 -0
  57. data/test/{datetime.xls → files/datetime.xls} +0 -0
  58. data/test/{datetime.xlsx → files/datetime.xlsx} +0 -0
  59. data/test/files/datetime.xml +142 -0
  60. data/test/{datetime_floatconv.xls → files/datetime_floatconv.xls} +0 -0
  61. data/test/files/datetime_floatconv.xml +148 -0
  62. data/test/{dreimalvier.ods → files/dreimalvier.ods} +0 -0
  63. data/test/{emptysheets.ods → files/emptysheets.ods} +0 -0
  64. data/test/{emptysheets.xls → files/emptysheets.xls} +0 -0
  65. data/test/{emptysheets.xlsx → files/emptysheets.xlsx} +0 -0
  66. data/test/files/emptysheets.xml +105 -0
  67. data/test/files/excel2003.xml +21140 -0
  68. data/test/{false_encoding.xls → files/false_encoding.xls} +0 -0
  69. data/test/files/false_encoding.xml +132 -0
  70. data/test/{formula.ods → files/formula.ods} +0 -0
  71. data/test/{formula.xls → files/formula.xls} +0 -0
  72. data/test/{formula.xlsx → files/formula.xlsx} +0 -0
  73. data/test/files/formula.xml +134 -0
  74. data/test/files/formula_parse_error.xls +0 -0
  75. data/test/files/formula_parse_error.xml +1833 -0
  76. data/test/{formula_string_error.xlsx → files/formula_string_error.xlsx} +0 -0
  77. data/test/{html-escape.ods → files/html-escape.ods} +0 -0
  78. data/test/{matrix.ods → files/matrix.ods} +0 -0
  79. data/test/{matrix.xls → files/matrix.xls} +0 -0
  80. data/test/{named_cells.ods → files/named_cells.ods} +0 -0
  81. data/test/{named_cells.xls → files/named_cells.xls} +0 -0
  82. data/test/{named_cells.xlsx → files/named_cells.xlsx} +0 -0
  83. data/test/{no_spreadsheet_file.txt → files/no_spreadsheet_file.txt} +0 -0
  84. data/test/{numbers1.csv → files/numbers1.csv} +0 -0
  85. data/test/{numbers1.ods → files/numbers1.ods} +0 -0
  86. data/test/{numbers1.xls → files/numbers1.xls} +0 -0
  87. data/test/{numbers1.xlsx → files/numbers1.xlsx} +0 -0
  88. data/test/files/numbers1.xml +312 -0
  89. data/test/{only_one_sheet.ods → files/only_one_sheet.ods} +0 -0
  90. data/test/{only_one_sheet.xls → files/only_one_sheet.xls} +0 -0
  91. data/test/{only_one_sheet.xlsx → files/only_one_sheet.xlsx} +0 -0
  92. data/test/files/only_one_sheet.xml +67 -0
  93. data/test/{paragraph.ods → files/paragraph.ods} +0 -0
  94. data/test/{paragraph.xls → files/paragraph.xls} +0 -0
  95. data/test/{paragraph.xlsx → files/paragraph.xlsx} +0 -0
  96. data/test/files/paragraph.xml +127 -0
  97. data/test/{prova.xls → files/prova.xls} +0 -0
  98. data/test/{ric.ods → files/ric.ods} +0 -0
  99. data/test/{simple_spreadsheet.ods → files/simple_spreadsheet.ods} +0 -0
  100. data/test/{simple_spreadsheet.xls → files/simple_spreadsheet.xls} +0 -0
  101. data/test/{simple_spreadsheet.xlsx → files/simple_spreadsheet.xlsx} +0 -0
  102. data/test/files/simple_spreadsheet.xml +225 -0
  103. data/test/{simple_spreadsheet_from_italo.ods → files/simple_spreadsheet_from_italo.ods} +0 -0
  104. data/test/{simple_spreadsheet_from_italo.xls → files/simple_spreadsheet_from_italo.xls} +0 -0
  105. data/test/files/simple_spreadsheet_from_italo.xml +242 -0
  106. data/test/{so_datetime.csv → files/so_datetime.csv} +0 -0
  107. data/test/{style.ods → files/style.ods} +0 -0
  108. data/test/{style.xls → files/style.xls} +0 -0
  109. data/test/{style.xlsx → files/style.xlsx} +0 -0
  110. data/test/files/style.xml +154 -0
  111. data/test/{time-test.csv → files/time-test.csv} +0 -0
  112. data/test/{time-test.ods → files/time-test.ods} +0 -0
  113. data/test/{time-test.xls → files/time-test.xls} +0 -0
  114. data/test/{time-test.xlsx → files/time-test.xlsx} +0 -0
  115. data/test/files/time-test.xml +131 -0
  116. data/test/{type_excel.ods → files/type_excel.ods} +0 -0
  117. data/test/{type_excel.xlsx → files/type_excel.xlsx} +0 -0
  118. data/test/{type_excelx.ods → files/type_excelx.ods} +0 -0
  119. data/test/{type_excelx.xls → files/type_excelx.xls} +0 -0
  120. data/test/{type_openoffice.xls → files/type_openoffice.xls} +0 -0
  121. data/test/{type_openoffice.xlsx → files/type_openoffice.xlsx} +0 -0
  122. data/test/{whitespace.ods → files/whitespace.ods} +0 -0
  123. data/test/{whitespace.xls → files/whitespace.xls} +0 -0
  124. data/test/{whitespace.xlsx → files/whitespace.xlsx} +0 -0
  125. data/test/files/whitespace.xml +184 -0
  126. data/test/test_generic_spreadsheet.rb +257 -0
  127. data/test/test_helper.rb +167 -27
  128. data/test/test_roo.rb +1178 -930
  129. data/website/index.html +385 -0
  130. data/website/index.txt +423 -0
  131. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  132. data/website/stylesheets/screen.css +130 -0
  133. data/website/template.rhtml +48 -0
  134. metadata +151 -121
  135. data/README.txt +0 -110
  136. data/lib/roo/.csv.rb.swp +0 -0
data/test/test_roo.rb CHANGED
@@ -9,216 +9,75 @@
9
9
  # (like 'diff') must be changed (or commented out ;-)) if you want to run
10
10
  # the tests under another OS
11
11
  #
12
- require 'rubygems'
13
- require 'todonotes'
14
- require 'tmpdir'
15
- require './lib/roo'
12
+
16
13
  #TODO
17
14
  # Look at formulas in excel - does not work with date/time
18
15
 
19
- class Csv
20
- def cell_postprocessing(row,col,value)
21
- if row==1 and col==1
22
- return value.to_f
23
- end
24
- if row==1 and col==2
25
- return value.to_s
26
- end
27
- return value
28
- end
29
- end
30
-
31
16
  # Dump warnings that come from the test to open files
32
17
  # with the wrong spreadsheet class
33
18
  #STDERR.reopen "/dev/null","w"
34
19
 
35
- TESTDIR = File.dirname(__FILE__)
36
- TMP_PREFIX = 'oo_*'
37
- # require './' + TESTDIR + '/test_helper.rb'
38
- require TESTDIR + '/test_helper.rb'
39
-
40
- require 'fileutils'
41
- require 'timeout'
42
- require 'logger'
43
- $log = Logger.new(File.join(ENV['HOME'],"roo.log"))
44
- #$log.level = Logger::WARN
45
- $log.level = Logger::DEBUG
46
-
47
- DISPLAY_LOG = false
48
- DB_LOG = false
49
-
50
- if DB_LOG
51
- require 'activerecord'
52
- end
53
-
54
- include FileUtils
55
-
56
- def running_windows?
57
- # to do
58
- # "besser loesen"
59
- # end
60
- File.exists? "C:\\"
61
- end
62
-
63
- if DB_LOG
64
- def activerecord_connect
65
- ActiveRecord::Base.establish_connection(:adapter => "mysql",
66
- :database => "test_runs",
67
- :host => "localhost",
68
- :username => "root",
69
- :socket => "/var/run/mysqld/mysqld.sock")
70
- end
71
-
72
- class Testrun < ActiveRecord::Base
73
- end
74
- end
75
-
76
- class Test::Unit::TestCase
77
- def key_of(spreadsheetname)
78
- begin
79
-
80
- return {
81
- #'formula' => 'rt4Pw1WmjxFtyfrqqy94wPw',
82
- 'formula' => 'o10837434939102457526.3022866619437760118',
83
- #"write.me" => 'r6m7HFlUOwst0RTUTuhQ0Ow',
84
- "write.me" => '0AkCuGANLc3jFcHR1NmJiYWhOWnBZME4wUnJ4UWJXZHc',
85
- #'numbers1' => "rYraCzjxTtkxw1NxHJgDU8Q",
86
- 'numbers1' => 'o10837434939102457526.4784396906364855777',
87
- #'borders' => "r_nLYMft6uWg_PT9Rc2urXw",
88
- 'borders' => "o10837434939102457526.664868920231926255",
89
- #'simple_spreadsheet' => "r3aMMCBCA153TmU_wyIaxfw",
90
- 'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
91
- 'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
92
- #"only_one_sheet" => "rqRtkcPJ97nhQ0m9ksDw2rA",
93
- "only_one_sheet" => "o10837434939102457526.762705759906130135",
94
- #'time-test' => 'r2XfDBJMrLPjmuLrPQQrEYw',
95
- 'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
96
- #'datetime' => "r2kQpXWr6xOSUpw9MyXavYg",
97
- 'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
98
- 'whitespace' => "rZyQaoFebVGeHKzjG6e9gRQ",
99
- 'matrix' => '0AkCuGANLc3jFdHY3cWtYUkM4bVdadjZ5VGpfTzFEUEE',
100
- }[spreadsheetname]
101
- # 'numbers1' => "o10837434939102457526.4784396906364855777",
102
- # 'borders' => "o10837434939102457526.664868920231926255",
103
- # 'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
104
- # 'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
105
- # "only_one_sheet" => "o10837434939102457526.762705759906130135",
106
- # "write.me" => 'ptu6bbahNZpY0N0RrxQbWdw&hl',
107
- # 'formula' => 'o10837434939102457526.3022866619437760118',
108
- # 'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
109
- # 'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
110
- rescue
111
- raise "unknown spreadsheetname: #{spreadsheetname}"
112
- end
113
- end
114
-
115
- if DB_LOG
116
- if ! (defined?(@connected) and @connected)
117
- activerecord_connect
118
- else
119
- @connected = true
120
- end
121
- end
122
- alias unlogged_run run
123
- def run(result, &block)
124
- t1 = Time.now
125
- #RAILS_DEFAULT_LOGGER.debug "RUNNING #{self.class} #{@method_name} \t#{Time.now.to_s}"
126
- if DISPLAY_LOG
127
- v1,v2,v3 = RUBY_VERSION.split('.')
128
- if v1.to_i > 1 or
129
- (v1.to_i == 1 and v2.to_i > 8)
130
- # Ruby 1.9.x
131
- print "RUNNING #{self.class} #{self.__name__} \t#{Time.now.to_s}"
132
- else
133
- # Ruby < 1.9.x
134
- print "RUNNING #{self.class} #{@method_name} \t#{Time.now.to_s}"
135
- end
136
- STDOUT.flush
137
- end
138
- unlogged_run result, &block
139
- t2 = Time.now
140
- if DISPLAY_LOG
141
- puts "\t#{t2-t1} seconds"
142
- end
143
- if DB_LOG
144
- domain = Testrun.create(
145
- :class_name => self.class.to_s,
146
- :test_name => @method_name,
147
- :start => t1,
148
- :duration => t2-t1
149
- )
150
- end
151
- # TODO
152
- #if Dir.glob("oo_*") != []
153
- # puts "nicht alle temp. Dateien geloescht"
154
- # puts Dir.glob("oo_*")
155
- # print "? "
156
- # STDOUT.flush
157
- # a = gets
158
- # end
159
- end
160
- end
161
-
162
- class File
163
- def File.delete_if_exist(filename)
164
- if File.exist?(filename)
165
- File.delete(filename)
166
- end
167
- end
168
- end
169
-
170
- # :nodoc
171
- class Fixnum
172
- def minutes
173
- self * 60
174
- end
175
- end
20
+ require File.dirname(__FILE__) + '/test_helper'
176
21
 
177
22
  class TestRoo < Test::Unit::TestCase
178
23
 
179
- OPENOFFICE = true # do Openoffice-Spreadsheet Tests? (.ods files)
24
+ OPENOFFICE = false # do Openoffice-Spreadsheet Tests? (.ods files)
180
25
  EXCEL = true # do Excel Tests? (.xls files)
181
26
  GOOGLE = false # do Google-Spreadsheet Tests?
182
27
  EXCELX = true # do Excelx Tests? (.xlsx files)
183
28
  LIBREOFFICE = true # do Libreoffice tests? (.ods files)
184
29
  CSV = true # do CSV tests? (.csv files)
185
30
 
186
- ONLINE = false
187
- LONG_RUN = true
188
- GLOBAL_TIMEOUT = 48.minutes
31
+ FORMATS = {
32
+ excel: EXCEL,
33
+ excelx: EXCELX,
34
+ openoffice: OPENOFFICE,
35
+ google: GOOGLE,
36
+ libreoffice: LIBREOFFICE
37
+ }
189
38
 
190
- def setup
191
- #if DISPLAY_LOG
192
- # puts " GLOBAL_TIMEOUT = #{GLOBAL_TIMEOUT}"
193
- #end
194
- end
39
+ ONLINE = false
40
+ LONG_RUN = false
195
41
 
196
42
  def test_internal_minutes
197
43
  assert_equal 42*60, 42.minutes
198
44
  end
199
-
200
- # call a block of code for each spreadsheet type
45
+
46
+ def fixture_filename(name, format)
47
+ case format
48
+ when :excel
49
+ "#{name}.xls"
50
+ when :excelx
51
+ "#{name}.xlsx"
52
+ when :openoffice, :libreoffice
53
+ "#{name}.ods"
54
+ when :google
55
+ key_of(name) || name
56
+ end
57
+ end
58
+
59
+ # call a block of code for each spreadsheet type
201
60
  # and yield a reference to the roo object
202
61
  def with_each_spreadsheet(options)
203
- # test if the spreadsheet type is valid :nodoc
204
62
  if options[:format]
205
- if options[:format].is_a? Symbol
206
- options[:format] = [options[:format]]
63
+ options[:format] = Array(options[:format])
64
+ invalid_formats = options[:format] - FORMATS.keys
65
+ unless invalid_formats.empty?
66
+ raise "invalid spreadsheet types: #{invalid_formats.join(', ')}"
207
67
  end
208
- options[:format].each do |formatname|
209
- unless [:openoffice,:excel,:excelx,:google,:libreoffice].include?(formatname)
210
- raise "invalid spreadsheet type #{formatname}"
68
+ else
69
+ options[:format] = FORMATS.keys
70
+ end
71
+ options[:format].each do |format|
72
+ begin
73
+ if FORMATS[format]
74
+ yield Roo::Spreadsheet.open(File.join(TESTDIR,
75
+ fixture_filename(options[:name], format)))
211
76
  end
77
+ rescue => e
78
+ raise e, "#{e.message} for #{format}", e.backtrace
212
79
  end
213
80
  end
214
- # end test spreadsheet type :nodoc
215
- options[:format] ||= [:excel, :excelx, :openoffice, :google, :libreoffice]
216
- options[:format] = [options[:format]] if options[:format].class == Symbol
217
- yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xls')) if EXCEL && options[:format].include?(:excel)
218
- yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xlsx')) if EXCELX && options[:format].include?(:excelx)
219
- yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.ods')) if OPENOFFICE && options[:format].include?(:openoffice)
220
- yield Roo::Spreadsheet.open(key_of(options[:name]) || options[:name]) if GOOGLE && options[:format].include?(:google)
221
- yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.ods')) if LIBREOFFICE && options[:format].include?(:libreoffice)
222
81
  end
223
82
 
224
83
  # Using Date.strptime so check that it's using the method
@@ -239,45 +98,34 @@ class TestRoo < Test::Unit::TestCase
239
98
 
240
99
  def test_classes
241
100
  if OPENOFFICE
242
- oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
243
- assert_kind_of Openoffice, oo
101
+ oo = Roo::Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
102
+ assert_kind_of Roo::Openoffice, oo
244
103
  end
245
104
  if EXCEL
246
- oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
247
- assert_kind_of Excel, oo
105
+ oo = Roo::Excel.new(File.join(TESTDIR,"numbers1.xls"))
106
+ assert_kind_of Roo::Excel, oo
248
107
  end
249
108
  if GOOGLE
250
- oo = Google.new(key_of("numbers1"))
251
- assert_kind_of Google, oo
109
+ oo = Roo::Google.new(key_of("numbers1"))
110
+ assert_kind_of Roo::Google, oo
252
111
  end
253
112
  if EXCELX
254
- oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
255
- assert_kind_of Excelx, oo
113
+ oo = Roo::Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
114
+ assert_kind_of Roo::Excelx, oo
256
115
  end
257
116
  if LIBREOFFICE
258
- oo = Libreoffice.new(File.join(TESTDIR,"numbers1.ods"))
259
- assert_kind_of Libreoffice, oo
117
+ oo = Roo::Libreoffice.new(File.join(TESTDIR,"numbers1.ods"))
118
+ assert_kind_of Roo::Libreoffice, oo
260
119
  end
261
120
  if CSV
262
- oo = Csv.new(File.join(TESTDIR,"numbers1.csv"))
263
- assert_kind_of Csv, oo
121
+ oo = Roo::Csv.new(File.join(TESTDIR,"numbers1.csv"))
122
+ assert_kind_of Roo::Csv, oo
264
123
  end
265
124
  end
266
125
 
267
- def test_letters
268
- assert_equal 1, GenericSpreadsheet.letter_to_number('A')
269
- assert_equal 1, GenericSpreadsheet.letter_to_number('a')
270
- assert_equal 2, GenericSpreadsheet.letter_to_number('B')
271
- assert_equal 26, GenericSpreadsheet.letter_to_number('Z')
272
- assert_equal 27, GenericSpreadsheet.letter_to_number('AA')
273
- assert_equal 27, GenericSpreadsheet.letter_to_number('aA')
274
- assert_equal 27, GenericSpreadsheet.letter_to_number('Aa')
275
- assert_equal 27, GenericSpreadsheet.letter_to_number('aa')
276
- end
277
-
278
126
  def test_sheets_csv
279
127
  if CSV
280
- oo = Csv.new(File.join(TESTDIR,'numbers1.csv'))
128
+ oo = Roo::Csv.new(File.join(TESTDIR,'numbers1.csv'))
281
129
  assert_equal ["default"], oo.sheets
282
130
  assert_raise(RangeError) { oo.default_sheet = "no_sheet" }
283
131
  assert_raise(TypeError) { oo.default_sheet = [1,2,3] }
@@ -317,7 +165,7 @@ class TestRoo < Test::Unit::TestCase
317
165
  assert_equal "test", oo.cell(2,6)
318
166
  assert_equal :string, oo.celltype(2,6)
319
167
  assert_equal 11, oo.cell(2,7)
320
- unless oo.kind_of? Csv
168
+ unless oo.kind_of? Roo::Csv
321
169
  assert_equal :float, oo.celltype(2,7)
322
170
  end
323
171
  assert_equal 10, oo.cell(4,1)
@@ -330,14 +178,14 @@ class TestRoo < Test::Unit::TestCase
330
178
  assert_equal 12, oo.cell(4,'C')
331
179
  assert_equal 13, oo.cell(4,'D')
332
180
  assert_equal 14, oo.cell(4,'E')
333
- unless oo.kind_of? Csv
181
+ unless oo.kind_of? Roo::Csv
334
182
  assert_equal :date, oo.celltype(5,1)
335
183
  assert_equal Date.new(1961,11,21), oo.cell(5,1)
336
184
  assert_equal "1961-11-21", oo.cell(5,1).to_s
337
185
  end
338
186
  end
339
187
  end
340
-
188
+
341
189
  def test_celltype
342
190
  with_each_spreadsheet(:name=>'numbers1') do |oo|
343
191
  assert_equal :string, oo.celltype(2,6)
@@ -371,118 +219,35 @@ class TestRoo < Test::Unit::TestCase
371
219
 
372
220
  def test_libre_office
373
221
  if LIBREOFFICE
374
- oo = Libreoffice.new("test/numbers1.ods")
222
+ oo = Roo::Libreoffice.new(File.join(TESTDIR, "numbers1.ods"))
375
223
  oo.default_sheet = oo.sheets.first
376
224
  assert_equal 41, oo.cell('a',12)
377
225
  end
378
226
  end
379
227
 
380
- #TODO: inkonsequente Lieferung Fixnum/Float
381
- def test_rows
382
- with_each_spreadsheet(:name=>'numbers1') do |oo|
383
- oo.default_sheet = oo.sheets.first
384
- assert_equal 41, oo.cell('a',12)
385
- assert_equal 42, oo.cell('b',12)
386
- assert_equal 43, oo.cell('c',12)
387
- assert_equal 44, oo.cell('d',12)
388
- assert_equal 45, oo.cell('e',12)
389
- assert_equal [41.0,42.0,43.0,44.0,45.0, nil, nil], oo.row(12)
390
- assert_equal "einundvierzig", oo.cell('a',16)
391
- assert_equal "zweiundvierzig", oo.cell('b',16)
392
- assert_equal "dreiundvierzig", oo.cell('c',16)
393
- assert_equal "vierundvierzig", oo.cell('d',16)
394
- assert_equal "fuenfundvierzig", oo.cell('e',16)
395
- assert_equal ["einundvierzig", "zweiundvierzig", "dreiundvierzig", "vierundvierzig", "fuenfundvierzig", nil, nil], oo.row(16)
396
- end
397
- end
398
-
399
- def test_last_row
400
- with_each_spreadsheet(:name=>'numbers1') do |oo|
401
- oo.default_sheet = oo.sheets.first
402
- assert_equal 18, oo.last_row
403
- end
404
- end
405
-
406
- def test_last_column
407
- with_each_spreadsheet(:name=>'numbers1') do |oo|
408
- oo.default_sheet = oo.sheets.first
409
- assert_equal 7, oo.last_column
410
- end
411
- end
412
-
413
- def test_last_column_as_letter
414
- with_each_spreadsheet(:name=>'numbers1') do |oo|
415
- oo.default_sheet = oo.sheets.first
416
- assert_equal 'G', oo.last_column_as_letter
417
- end
418
- end
419
-
420
- def test_first_row
421
- with_each_spreadsheet(:name=>'numbers1') do |oo|
422
- oo.default_sheet = oo.sheets.first
423
- assert_equal 1, oo.first_row
424
- end
425
- end
426
-
427
- def test_first_column
428
- with_each_spreadsheet(:name=>'numbers1') do |oo|
429
- oo.default_sheet = oo.sheets.first
430
- assert_equal 1, oo.first_column
431
- end
432
- end
433
-
434
- def test_first_column_as_letter
435
- with_each_spreadsheet(:name=>'numbers1') do |oo|
436
- oo.default_sheet = oo.sheets.first
437
- assert_equal 'A', oo.first_column_as_letter
438
- end
439
- end
440
-
441
228
  def test_sheetname
442
229
  with_each_spreadsheet(:name=>'numbers1') do |oo|
443
230
  oo.default_sheet = "Name of Sheet 2"
444
231
  assert_equal 'I am sheet 2', oo.cell('C',5)
445
232
  assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
446
233
  assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
447
- assert_raise(RangeError) { dummy = oo.cell('C',5,"non existing sheet name")}
448
- assert_raise(RangeError) { dummy = oo.celltype('C',5,"non existing sheet name")}
449
- assert_raise(RangeError) { dummy = oo.empty?('C',5,"non existing sheet name")}
450
- if oo.class == Excel
451
- assert_raise(RuntimeError) { dummy = oo.formula?('C',5,"non existing sheet name")}
452
- assert_raise(RuntimeError) { dummy = oo.formula('C',5,"non existing sheet name")}
234
+ assert_raise(RangeError) { oo.cell('C',5,"non existing sheet name")}
235
+ assert_raise(RangeError) { oo.celltype('C',5,"non existing sheet name")}
236
+ assert_raise(RangeError) { oo.empty?('C',5,"non existing sheet name")}
237
+ if oo.class == Roo::Excel
238
+ assert_raise(RuntimeError) { oo.formula?('C',5,"non existing sheet name")}
239
+ assert_raise(RuntimeError) { oo.formula('C',5,"non existing sheet name")}
453
240
  else
454
- assert_raise(RangeError) { dummy = oo.formula?('C',5,"non existing sheet name")}
455
- assert_raise(RangeError) { dummy = oo.formula('C',5,"non existing sheet name")}
241
+ assert_raise(RangeError) { oo.formula?('C',5,"non existing sheet name")}
242
+ assert_raise(RangeError) { oo.formula('C',5,"non existing sheet name")}
456
243
  begin
457
- assert_raise(RangeError) { dummy = oo.set('C',5,42,"non existing sheet name")} unless oo.class == Google
244
+ assert_raise(RangeError) { oo.set('C',5,42,"non existing sheet name")}
458
245
  rescue NameError
459
246
  #
460
247
  end
461
- assert_raise(RangeError) { dummy = oo.formulas("non existing sheet name")}
248
+ assert_raise(RangeError) { oo.formulas("non existing sheet name")}
462
249
  end
463
- assert_raise(RangeError) { dummy = oo.to_yaml({},1,1,1,1,"non existing sheet name")}
464
- end
465
- end
466
-
467
- def test_boundaries
468
- with_each_spreadsheet(:name=>'numbers1') do |oo|
469
- oo.default_sheet = "Name of Sheet 2"
470
- assert_equal 2, oo.first_column
471
- assert_equal 'B', oo.first_column_as_letter
472
- assert_equal 5, oo.first_row
473
- assert_equal 'E', oo.last_column_as_letter
474
- assert_equal 14, oo.last_row
475
- end
476
- end
477
-
478
- def test_multiple_letters
479
- with_each_spreadsheet(:name=>'numbers1') do |oo|
480
- oo.default_sheet = "Sheet3"
481
- assert_equal "i am AA", oo.cell('AA',1)
482
- assert_equal "i am AB", oo.cell('AB',1)
483
- assert_equal "i am BA", oo.cell('BA',1)
484
- assert_equal 'BA', oo.last_column_as_letter
485
- assert_equal "i am BA", oo.cell(1,'BA')
250
+ assert_raise(RangeError) { oo.to_yaml({},1,1,1,1,"non existing sheet name")}
486
251
  end
487
252
  end
488
253
 
@@ -492,23 +257,6 @@ class TestRoo < Test::Unit::TestCase
492
257
  end
493
258
  end
494
259
 
495
- def test_empty_eh
496
- with_each_spreadsheet(:name=>'numbers1') do |oo|
497
- assert oo.empty?('a',14)
498
- assert ! oo.empty?('a',15)
499
- assert oo.empty?('a',20)
500
- end
501
- end
502
-
503
- def test_reload
504
- with_each_spreadsheet(:name=>'numbers1') do |oo|
505
- oo.default_sheet = oo.sheets.first
506
- assert_equal 1, oo.cell(1,1)
507
- oo.reload
508
- assert_equal 1, oo.cell(1,1)
509
- end
510
- end
511
-
512
260
  def test_bug_contiguous_cells
513
261
  with_each_spreadsheet(:name=>'numbers1', :format=>:openoffice) do |oo|
514
262
  oo.default_sheet = "Sheet4"
@@ -571,7 +319,7 @@ class TestRoo < Test::Unit::TestCase
571
319
  assert_equal "A:string",oo.cell(4, 3)+":"+oo.celltype(4, 3).to_s
572
320
 
573
321
  # Cells values in row 5:
574
- if oo.class == Openoffice
322
+ if oo.class == Roo::Openoffice
575
323
  assert_equal "0.01:percentage",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
576
324
  assert_equal "0.01:percentage",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
577
325
  assert_equal "0.01:percentage",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
@@ -683,7 +431,7 @@ class TestRoo < Test::Unit::TestCase
683
431
  assert_equal 42.5, oo.cell('A',17)
684
432
  end
685
433
  end
686
-
434
+
687
435
  # Excel can only read the cell's value
688
436
  def test_formula_excel
689
437
  with_each_spreadsheet(:name=>'formula', :format=>:excel) do |oo|
@@ -692,7 +440,6 @@ class TestRoo < Test::Unit::TestCase
692
440
  end
693
441
  end
694
442
 
695
-
696
443
  def test_borders_sheets
697
444
  with_each_spreadsheet(:name=>'borders') do |oo|
698
445
  oo.default_sheet = oo.sheets[1]
@@ -715,33 +462,6 @@ class TestRoo < Test::Unit::TestCase
715
462
  end
716
463
  end
717
464
 
718
- def yaml_entry(row,col,type,value)
719
- "cell_#{row}_#{col}: \n row: #{row} \n col: #{col} \n celltype: #{type} \n value: #{value} \n"
720
- end
721
-
722
- def test_to_yaml
723
- with_each_spreadsheet(:name=>'numbers1') do |oo|
724
- oo.default_sheet = oo.sheets.first
725
- assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), oo.to_yaml({}, 5,1,5,1)
726
- assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3)
727
- assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3)
728
- assert_equal \
729
- "--- \n"+yaml_entry(12,3,"float",43.0) +
730
- yaml_entry(12,4,"float",44.0) +
731
- yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12)
732
- assert_equal \
733
- "--- \n"+yaml_entry(12,3,"float",43.0)+
734
- yaml_entry(12,4,"float",44.0)+
735
- yaml_entry(12,5,"float",45.0)+
736
- yaml_entry(15,3,"float",43.0)+
737
- yaml_entry(15,4,"float",44.0)+
738
- yaml_entry(15,5,"float",45.0)+
739
- yaml_entry(16,3,"string","dreiundvierzig")+
740
- yaml_entry(16,4,"string","vierundvierzig")+
741
- yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3)
742
- end
743
- end
744
-
745
465
  def test_only_one_sheet
746
466
  with_each_spreadsheet(:name=>'only_one_sheet') do |oo|
747
467
  assert_equal 42, oo.cell('B',4)
@@ -757,12 +477,10 @@ class TestRoo < Test::Unit::TestCase
757
477
  def test_excel_open_from_uri_and_zipped
758
478
  if EXCEL
759
479
  if ONLINE
760
- begin
761
- url = 'http://stiny-leonhard.de/bode-v1.xls.zip'
762
- excel = Excel.new(url, :zip)
763
- excel.default_sheet = excel.sheets.first
764
- assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
765
- end
480
+ url = 'http://stiny-leonhard.de/bode-v1.xls.zip'
481
+ excel = Roo::Excel.new(url, :zip)
482
+ excel.default_sheet = excel.sheets.first
483
+ assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
766
484
  end
767
485
  end
768
486
  end
@@ -770,38 +488,26 @@ class TestRoo < Test::Unit::TestCase
770
488
  def test_openoffice_open_from_uri_and_zipped
771
489
  if OPENOFFICE
772
490
  if ONLINE
773
- begin
774
- url = 'http://spazioinwind.libero.it/s2/rata.ods.zip'
775
- sheet = Openoffice.new(url, :zip)
776
- #has been changed: assert_equal 'ist "e" im Nenner von H(s)', sheet.cell('b', 5)
777
- assert_in_delta 0.001, 505.14, sheet.cell('c', 33).to_f
778
- end
491
+ url = 'http://spazioinwind.libero.it/s2/rata.ods.zip'
492
+ sheet = Roo::Openoffice.new(url, :zip)
493
+ #has been changed: assert_equal 'ist "e" im Nenner von H(s)', sheet.cell('b', 5)
494
+ assert_in_delta 0.001, 505.14, sheet.cell('c', 33).to_f
779
495
  end
780
496
  end
781
497
  end
782
498
 
783
499
  def test_excel_zipped
784
- after Date.new(2011,12,7) do
785
- to do
786
- 'hier wieder das Problem, dass ausgepacktes xls File
787
- unter Windows nicht geloescht werden kann, weil
788
- das spreadsheet gem die Datei nicht schliesst.
789
- Fehler von spreadsheet gem'
790
- end
791
- if EXCEL
792
- begin
793
- oo = Excel.new(File.join(TESTDIR,"bode-v1.xls.zip"), :zip)
794
- assert oo
795
- assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
796
- end
797
- end
500
+ if EXCEL
501
+ oo = Roo::Excel.new(File.join(TESTDIR,"bode-v1.xls.zip"), :zip)
502
+ assert oo
503
+ assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
798
504
  end
799
505
  end
800
506
 
801
507
  def test_openoffice_zipped
802
508
  if OPENOFFICE
803
509
  begin
804
- oo = Openoffice.new(File.join(TESTDIR,"bode-v1.ods.zip"), :zip)
510
+ oo = Roo::Openoffice.new(File.join(TESTDIR,"bode-v1.ods.zip"), :zip)
805
511
  assert oo
806
512
  assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
807
513
  end
@@ -859,52 +565,38 @@ class TestRoo < Test::Unit::TestCase
859
565
  end
860
566
  #if EXCELX
861
567
  # #Datei gibt es noch nicht
862
- # oo = Excelx.new(File.join(TESTDIR,"Bibelbund1.xlsx"))
568
+ # oo = Roo::Excelx.new(File.join(TESTDIR,"Bibelbund1.xlsx"))
863
569
  # oo.default_sheet = oo.sheets.first
864
570
  # assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
865
571
  #end
866
572
  end
867
-
868
- def tempdir
869
- Dir::tmpdir
870
- end
871
573
 
872
574
  # "/tmp/xxxx" darf man unter Windows nicht verwenden, weil das nicht erkannt
873
575
  # wird.
874
576
  # Besser: Methode um temporaeres Dir. portabel zu bestimmen
875
577
  def test_huge_document_to_csv
876
578
  if LONG_RUN
877
- with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
878
- :excel,
879
- :excelx
880
- # Google hier nicht, weil Google-Spreadsheets nicht so gross werden
881
- # duerfen
882
- ]) do |oo|
883
- assert_nothing_raised(Timeout::Error) {
884
- Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
885
- File.delete_if_exist(File.join(tempdir,"Bibelbund.csv"))
886
- assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
887
- assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", oo.cell(46,'A')
888
- assert_equal "Tagebuch aus Chile Juli 1977", oo.cell(55,'A')
889
- assert oo.to_csv(File.join(tempdir,"Bibelbund.csv"))
890
- assert File.exists?(File.join(tempdir,"Bibelbund.csv"))
891
- #if running_windows?
892
- # to do
893
- # "diff is not available under windows"
894
- # end
895
- #else
896
- # assert_equal "", `diff test/Bibelbund.csv /tmp/Bibelbund.csv`, "error in class #{oo.class}"
897
- # assert_equal "", `diff test/Bibelbund.csv #{File.join(tempdir,"Bibelbund.csv")}`, "error in class #{oo.class}"
898
- assert_equal "",
899
- diff("test/Bibelbund.csv","#{File.join(tempdir,"Bibelbund.csv")}"),
579
+ with_each_spreadsheet(:name=>'Bibelbund', :format=>[
580
+ :openoffice,
581
+ :excel,
582
+ :excelx
583
+ # Google hier nicht, weil Google-Spreadsheets nicht so gross werden
584
+ # duerfen
585
+ ]) do |oo|
586
+ Dir.mktmpdir do |tempdir|
587
+ assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
588
+ assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", oo.cell(46,'A')
589
+ assert_equal "Tagebuch aus Chile Juli 1977", oo.cell(55,'A')
590
+ assert oo.to_csv(File.join(tempdir,"Bibelbund.csv"))
591
+ assert File.exists?(File.join(tempdir,"Bibelbund.csv"))
592
+ assert_equal "", file_diff(File.join(TESTDIR, "Bibelbund.csv"), File.join(tempdir,"Bibelbund.csv")),
900
593
  "error in class #{oo.class}"
901
- #end
902
- end
903
- }
594
+ #end
595
+ end
904
596
  end
905
597
  end
906
598
  end
907
-
599
+
908
600
  def test_bug_quotes_excelx
909
601
  if LONG_RUN
910
602
  with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
@@ -913,7 +605,7 @@ class TestRoo < Test::Unit::TestCase
913
605
  oo.default_sheet = oo.sheets.first
914
606
  assert_equal 'Einflüsse der neuen Theologie in "de gereformeerde Kerken van Nederland"',
915
607
  oo.cell('a',76)
916
- dummy = oo.to_csv("csv#{$$}")
608
+ oo.to_csv("csv#{$$}")
917
609
  assert_equal 'Einflüsse der neuen Theologie in "de gereformeerde Kerken van Nederland"',
918
610
  oo.cell('a',78)
919
611
  File.delete_if_exist("csv#{$$}")
@@ -921,23 +613,6 @@ class TestRoo < Test::Unit::TestCase
921
613
  end
922
614
  end
923
615
 
924
- def test_to_csv
925
- with_each_spreadsheet(:name=>'numbers1') do |oo|
926
- master = "#{TESTDIR}/numbers1.csv"
927
- File.delete_if_exist(File.join(tempdir,"numbers1.csv"))
928
- assert oo.to_csv(File.join(tempdir,"numbers1.csv"),oo.sheets.first)
929
- assert(File.exists?(File.join(tempdir,"numbers1.csv")), "Datei #{tempdir}/numbers1.csv existiert nicht")
930
- if running_windows?
931
- warn "no 'diff' in windows"
932
- else
933
- assert_equal "", `diff #{master} #{File.join(tempdir,"numbers1.csv")}`
934
- assert oo.to_csv(File.join(tempdir,"numbers1.csv"))
935
- assert File.exists?(File.join(tempdir,"numbers1.csv"))
936
- assert_equal "", `diff #{master} #{File.join(tempdir,"numbers1.csv")}`
937
- end
938
- end
939
- end
940
-
941
616
  def test_bug_mehrere_datum
942
617
  with_each_spreadsheet(:name=>'numbers1') do |oo|
943
618
  oo.default_sheet = 'Sheet5'
@@ -1021,8 +696,10 @@ class TestRoo < Test::Unit::TestCase
1021
696
  def test_bug_empty_sheet
1022
697
  with_each_spreadsheet(:name=>'formula', :format=>[:openoffice, :excelx]) do |oo|
1023
698
  oo.default_sheet = 'Sheet3' # is an empty sheet
1024
- assert_nothing_raised() { oo.to_csv(File.join(tempdir,"emptysheet.csv")) }
1025
- assert_equal "", `cat #{File.join(tempdir,"emptysheet.csv")}`
699
+ Dir.mktmpdir do |tempdir|
700
+ assert_nothing_raised() { oo.to_csv(File.join(tempdir,"emptysheet.csv")) }
701
+ assert_equal "", `cat #{File.join(tempdir,"emptysheet.csv")}`
702
+ end
1026
703
  end
1027
704
  end
1028
705
 
@@ -1031,18 +708,16 @@ class TestRoo < Test::Unit::TestCase
1031
708
  with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
1032
709
  :excel,
1033
710
  :excelx]) do |oo|
1034
- Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1035
- oo.default_sheet = oo.sheets.first
1036
- rec = oo.find 20
1037
- assert rec
1038
- # assert_equal "Brief aus dem Sekretariat", rec[0]
1039
- #p rec
1040
- assert_equal "Brief aus dem Sekretariat", rec[0]['TITEL']
1041
- rec = oo.find 22
1042
- assert rec
1043
- # assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]
1044
- assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]['TITEL']
1045
- end
711
+ oo.default_sheet = oo.sheets.first
712
+ rec = oo.find 20
713
+ assert rec
714
+ # assert_equal "Brief aus dem Sekretariat", rec[0]
715
+ #p rec
716
+ assert_equal "Brief aus dem Sekretariat", rec[0]['TITEL']
717
+ rec = oo.find 22
718
+ assert rec
719
+ # assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]
720
+ assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]['TITEL']
1046
721
  end
1047
722
  end
1048
723
  end
@@ -1067,90 +742,86 @@ class TestRoo < Test::Unit::TestCase
1067
742
  with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
1068
743
  :excel,
1069
744
  :excelx]) do |oo|
1070
- assert_nothing_raised(Timeout::Error) {
1071
- Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1072
- #-----------------------------------------------------------------
1073
- zeilen = oo.find(:all, :conditions => {
1074
- 'TITEL' => 'Brief aus dem Sekretariat'
1075
- }
1076
- )
1077
- assert_equal 2, zeilen.size
1078
- assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
1079
- "INTERNET"=>nil,
1080
- "SEITE"=>316.0,
1081
- "KENNUNG"=>"Aus dem Bibelbund",
1082
- "OBJEKT"=>"Bibel+Gem",
1083
- "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1084
- "NUMMER"=>"1982-3",
1085
- "TITEL"=>"Brief aus dem Sekretariat"},
1086
- {"VERFASSER"=>"Almassy, Annelene von",
1087
- "INTERNET"=>nil,
1088
- "SEITE"=>222.0,
1089
- "KENNUNG"=>"Aus dem Bibelbund",
1090
- "OBJEKT"=>"Bibel+Gem",
1091
- "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1092
- "NUMMER"=>"1983-2",
1093
- "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
1094
-
1095
- #----------------------------------------------------------
1096
- zeilen = oo.find(:all,
1097
- :conditions => { 'VERFASSER' => 'Almassy, Annelene von' }
1098
- )
1099
- assert_equal 13, zeilen.size
1100
- #----------------------------------------------------------
1101
- zeilen = oo.find(:all, :conditions => {
1102
- 'TITEL' => 'Brief aus dem Sekretariat',
1103
- 'VERFASSER' => 'Almassy, Annelene von',
1104
- }
1105
- )
1106
- assert_equal 2, zeilen.size
1107
- assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
1108
- "INTERNET"=>nil,
1109
- "SEITE"=>316.0,
1110
- "KENNUNG"=>"Aus dem Bibelbund",
1111
- "OBJEKT"=>"Bibel+Gem",
1112
- "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1113
- "NUMMER"=>"1982-3",
1114
- "TITEL"=>"Brief aus dem Sekretariat"},
1115
- {"VERFASSER"=>"Almassy, Annelene von",
1116
- "INTERNET"=>nil,
1117
- "SEITE"=>222.0,
1118
- "KENNUNG"=>"Aus dem Bibelbund",
1119
- "OBJEKT"=>"Bibel+Gem",
1120
- "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1121
- "NUMMER"=>"1983-2",
1122
- "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
1123
-
1124
- # Result as an array
1125
- zeilen = oo.find(:all,
1126
- :conditions => {
1127
- 'TITEL' => 'Brief aus dem Sekretariat',
1128
- 'VERFASSER' => 'Almassy, Annelene von',
1129
- }, :array => true)
1130
- assert_equal 2, zeilen.size
1131
- assert_equal [
1132
- [
1133
- "Brief aus dem Sekretariat",
1134
- "Almassy, Annelene von",
1135
- "Bibel+Gem",
1136
- "1982-3",
1137
- 316.0,
1138
- nil,
1139
- "#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1140
- "Aus dem Bibelbund",
1141
- ],
1142
- [
1143
- "Brief aus dem Sekretariat",
1144
- "Almassy, Annelene von",
1145
- "Bibel+Gem",
1146
- "1983-2",
1147
- 222.0,
1148
- nil,
1149
- "#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1150
- "Aus dem Bibelbund",
1151
- ]] , zeilen
1152
- end # Timeout
1153
- } # nothing_raised
745
+ #-----------------------------------------------------------------
746
+ zeilen = oo.find(:all, :conditions => {
747
+ 'TITEL' => 'Brief aus dem Sekretariat'
748
+ }
749
+ )
750
+ assert_equal 2, zeilen.size
751
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
752
+ "INTERNET"=>nil,
753
+ "SEITE"=>316.0,
754
+ "KENNUNG"=>"Aus dem Bibelbund",
755
+ "OBJEKT"=>"Bibel+Gem",
756
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
757
+ "NUMMER"=>"1982-3",
758
+ "TITEL"=>"Brief aus dem Sekretariat"},
759
+ {"VERFASSER"=>"Almassy, Annelene von",
760
+ "INTERNET"=>nil,
761
+ "SEITE"=>222.0,
762
+ "KENNUNG"=>"Aus dem Bibelbund",
763
+ "OBJEKT"=>"Bibel+Gem",
764
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
765
+ "NUMMER"=>"1983-2",
766
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
767
+
768
+ #----------------------------------------------------------
769
+ zeilen = oo.find(:all,
770
+ :conditions => { 'VERFASSER' => 'Almassy, Annelene von' }
771
+ )
772
+ assert_equal 13, zeilen.size
773
+ #----------------------------------------------------------
774
+ zeilen = oo.find(:all, :conditions => {
775
+ 'TITEL' => 'Brief aus dem Sekretariat',
776
+ 'VERFASSER' => 'Almassy, Annelene von',
777
+ }
778
+ )
779
+ assert_equal 2, zeilen.size
780
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
781
+ "INTERNET"=>nil,
782
+ "SEITE"=>316.0,
783
+ "KENNUNG"=>"Aus dem Bibelbund",
784
+ "OBJEKT"=>"Bibel+Gem",
785
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
786
+ "NUMMER"=>"1982-3",
787
+ "TITEL"=>"Brief aus dem Sekretariat"},
788
+ {"VERFASSER"=>"Almassy, Annelene von",
789
+ "INTERNET"=>nil,
790
+ "SEITE"=>222.0,
791
+ "KENNUNG"=>"Aus dem Bibelbund",
792
+ "OBJEKT"=>"Bibel+Gem",
793
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
794
+ "NUMMER"=>"1983-2",
795
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
796
+
797
+ # Result as an array
798
+ zeilen = oo.find(:all,
799
+ :conditions => {
800
+ 'TITEL' => 'Brief aus dem Sekretariat',
801
+ 'VERFASSER' => 'Almassy, Annelene von',
802
+ }, :array => true)
803
+ assert_equal 2, zeilen.size
804
+ assert_equal [
805
+ [
806
+ "Brief aus dem Sekretariat",
807
+ "Almassy, Annelene von",
808
+ "Bibel+Gem",
809
+ "1982-3",
810
+ 316.0,
811
+ nil,
812
+ "#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
813
+ "Aus dem Bibelbund",
814
+ ],
815
+ [
816
+ "Brief aus dem Sekretariat",
817
+ "Almassy, Annelene von",
818
+ "Bibel+Gem",
819
+ "1983-2",
820
+ 222.0,
821
+ nil,
822
+ "#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
823
+ "Aus dem Bibelbund",
824
+ ]] , zeilen
1154
825
  end
1155
826
  end
1156
827
  end
@@ -1183,13 +854,9 @@ class TestRoo < Test::Unit::TestCase
1183
854
  with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
1184
855
  :excel,
1185
856
  :excelx]) do |oo|
1186
- assert_nothing_raised(Timeout::Error) {
1187
- Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1188
- oo.default_sheet = oo.sheets.first
1189
- assert_equal 3735, oo.column('a').size
1190
- #assert_equal 499, oo.column('a').size
1191
- end
1192
- }
857
+ oo.default_sheet = oo.sheets.first
858
+ assert_equal 3735, oo.column('a').size
859
+ #assert_equal 499, oo.column('a').size
1193
860
  end
1194
861
  end
1195
862
  end
@@ -1203,11 +870,11 @@ class TestRoo < Test::Unit::TestCase
1203
870
  assert_equal 10.75 , erg[1]['Start time']
1204
871
  assert_equal 12.50 , erg[1]['End time']
1205
872
  assert_equal 0 , erg[1]['Pause']
1206
- assert_equal 1.75 , erg[1]['Sum'] unless oo.class == Excel
873
+ assert_equal 1.75 , erg[1]['Sum'] unless oo.class == Roo::Excel
1207
874
  assert_equal "Task 1" , erg[1]['Comment']
1208
875
  end
1209
876
  end
1210
-
877
+
1211
878
  # Ruby-spreadsheet now allows us to at least give the current value
1212
879
  # from a cell with a formula (no possible with parseexcel)
1213
880
  def test_bug_false_borders_with_formulas
@@ -1248,25 +915,25 @@ class TestRoo < Test::Unit::TestCase
1248
915
 
1249
916
  def test_excel_does_not_support_formulas
1250
917
  with_each_spreadsheet(:name=>'false_encoding', :format=>:excel) do |oo|
1251
- assert_raise(RuntimeError) { void = oo.formula('a',1) }
1252
- assert_raise(RuntimeError) { void = oo.formula?('a',1) }
1253
- assert_raise(RuntimeError) { void = oo.formulas(oo.sheets.first) }
918
+ assert_raise(RuntimeError) { oo.formula('a',1) }
919
+ assert_raise(RuntimeError) { oo.formula?('a',1) }
920
+ assert_raise(RuntimeError) { oo.formulas(oo.sheets.first) }
1254
921
  end
1255
922
  end
1256
923
 
1257
924
  def get_extension(oo)
1258
925
  case oo
1259
- when Openoffice
926
+ when Roo::Openoffice
1260
927
  ".ods"
1261
- when Excel
928
+ when Roo::Excel
1262
929
  ".xls"
1263
- when Excelx
930
+ when Roo::Excelx
1264
931
  ".xlsx"
1265
- when Google
932
+ when Roo::Google
1266
933
  ""
1267
934
  end
1268
935
  end
1269
-
936
+
1270
937
  def test_info
1271
938
  expected_templ = "File: numbers1%s\n"+
1272
939
  "Number of sheets: 5\n"+
@@ -1316,100 +983,98 @@ class TestRoo < Test::Unit::TestCase
1316
983
  oo.default_sheet = "Tabelle1"
1317
984
  assert_equal 1, oo.first_row
1318
985
  assert_equal 18, oo.last_row
1319
- assert_equal Openoffice.letter_to_number('A'), oo.first_column
1320
- assert_equal Openoffice.letter_to_number('G'), oo.last_column
986
+ assert_equal Roo::Openoffice.letter_to_number('A'), oo.first_column
987
+ assert_equal Roo::Openoffice.letter_to_number('G'), oo.last_column
1321
988
  oo.default_sheet = "Name of Sheet 2"
1322
989
  assert_equal 5, oo.first_row
1323
990
  assert_equal 14, oo.last_row
1324
- assert_equal Openoffice.letter_to_number('B'), oo.first_column
1325
- assert_equal Openoffice.letter_to_number('E'), oo.last_column
991
+ assert_equal Roo::Openoffice.letter_to_number('B'), oo.first_column
992
+ assert_equal Roo::Openoffice.letter_to_number('E'), oo.last_column
1326
993
  oo.default_sheet = "Sheet3"
1327
994
  assert_equal 1, oo.first_row
1328
995
  assert_equal 1, oo.last_row
1329
- assert_equal Openoffice.letter_to_number('A'), oo.first_column
1330
- assert_equal Openoffice.letter_to_number('BA'), oo.last_column
996
+ assert_equal Roo::Openoffice.letter_to_number('A'), oo.first_column
997
+ assert_equal Roo::Openoffice.letter_to_number('BA'), oo.last_column
1331
998
  oo.default_sheet = "Sheet4"
1332
999
  assert_equal 1, oo.first_row
1333
1000
  assert_equal 1, oo.last_row
1334
- assert_equal Openoffice.letter_to_number('A'), oo.first_column
1335
- assert_equal Openoffice.letter_to_number('E'), oo.last_column
1001
+ assert_equal Roo::Openoffice.letter_to_number('A'), oo.first_column
1002
+ assert_equal Roo::Openoffice.letter_to_number('E'), oo.last_column
1336
1003
  oo.default_sheet = "Sheet5"
1337
1004
  assert_equal 1, oo.first_row
1338
1005
  assert_equal 6, oo.last_row
1339
- assert_equal Openoffice.letter_to_number('A'), oo.first_column
1340
- assert_equal Openoffice.letter_to_number('E'), oo.last_column
1006
+ assert_equal Roo::Openoffice.letter_to_number('A'), oo.first_column
1007
+ assert_equal Roo::Openoffice.letter_to_number('E'), oo.last_column
1341
1008
  end
1342
1009
  end
1343
1010
 
1344
1011
  def test_should_raise_file_not_found_error
1345
1012
  if OPENOFFICE
1346
1013
  assert_raise(IOError) {
1347
- oo = Openoffice.new(File.join('testnichtvorhanden','Bibelbund.ods'))
1014
+ Roo::Openoffice.new(File.join('testnichtvorhanden','Bibelbund.ods'))
1348
1015
  }
1349
1016
  end
1350
1017
  if EXCEL
1351
1018
  assert_raise(IOError) {
1352
- oo = Excel.new(File.join('testnichtvorhanden','Bibelbund.xls'))
1019
+ Roo::Excel.new(File.join('testnichtvorhanden','Bibelbund.xls'))
1353
1020
  }
1354
1021
  end
1355
1022
  if EXCELX
1356
1023
  assert_raise(IOError) {
1357
- oo = Excelx.new(File.join('testnichtvorhanden','Bibelbund.xlsx'))
1024
+ Roo::Excelx.new(File.join('testnichtvorhanden','Bibelbund.xlsx'))
1358
1025
  }
1359
1026
  end
1360
1027
  if GOOGLE
1361
- # assert_raise(Net::HTTPServerException) {
1362
- # oo = Google.new(key_of('testnichtvorhanden'+'Bibelbund.ods'))
1363
- # oo = Google.new('testnichtvorhanden')
1364
- # }
1028
+ # assert_raise(Net::HTTPServerException) {
1029
+ # Google.new(key_of('testnichtvorhanden'+'Bibelbund.ods'))
1030
+ # Google.new('testnichtvorhanden')
1031
+ # }
1365
1032
  end
1366
1033
  end
1367
-
1034
+
1368
1035
  def test_write_google
1369
1036
  # write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB
1370
1037
  with_each_spreadsheet(:name=>'write.me', :format=>:google) do |oo|
1371
1038
  oo.default_sheet = oo.sheets.first
1372
- oo.set_value(1,1,"hello from the tests")
1039
+ oo.set(1,1,"hello from the tests")
1373
1040
  assert_equal "hello from the tests", oo.cell(1,1)
1374
- oo.set_value(1,1, 1.0)
1041
+ oo.set(1,1, 1.0)
1375
1042
  assert_equal 1.0, oo.cell(1,1)
1376
1043
  end
1377
1044
  end
1378
1045
 
1379
- def test_bug_set_value_with_more_than_one_sheet_google
1046
+ def test_bug_set_with_more_than_one_sheet_google
1380
1047
  # write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB
1381
- after Date.new(2011,6,19) do
1382
- with_each_spreadsheet(:name=>'write.me', :format=>:google) do |oo|
1383
- content1 = 'AAA'
1384
- content2 = 'BBB'
1385
- oo.default_sheet = oo.sheets.first
1386
- oo.set_value(1,1,content1)
1387
- oo.default_sheet = oo.sheets[1]
1388
- oo.set_value(1,1,content2) # in the second sheet
1389
- oo.default_sheet = oo.sheets.first
1390
- assert_equal content1, oo.cell(1,1)
1391
- oo.default_sheet = oo.sheets[1]
1392
- assert_equal content2, oo.cell(1,1)
1393
- end
1048
+ with_each_spreadsheet(:name=>'write.me', :format=>:google) do |oo|
1049
+ content1 = 'AAA'
1050
+ content2 = 'BBB'
1051
+ oo.default_sheet = oo.sheets.first
1052
+ oo.set(1,1,content1)
1053
+ oo.default_sheet = oo.sheets[1]
1054
+ oo.set(1,1,content2) # in the second sheet
1055
+ oo.default_sheet = oo.sheets.first
1056
+ assert_equal content1, oo.cell(1,1)
1057
+ oo.default_sheet = oo.sheets[1]
1058
+ assert_equal content2, oo.cell(1,1)
1394
1059
  end
1395
1060
  end
1396
1061
 
1397
- def test_set_value_with_sheet_argument_google
1062
+ def test_set_with_sheet_argument_google
1398
1063
  with_each_spreadsheet(:name=>'write.me', :format=>:google) do |oo|
1399
1064
  random_row = rand(10)+1
1400
1065
  random_column = rand(10)+1
1401
1066
  content1 = 'ABC'
1402
1067
  content2 = 'DEF'
1403
- oo.set_value(random_row,random_column,content1,oo.sheets.first)
1404
- oo.set_value(random_row,random_column,content2,oo.sheets[1])
1068
+ oo.set(random_row,random_column,content1,oo.sheets.first)
1069
+ oo.set(random_row,random_column,content2,oo.sheets[1])
1405
1070
  assert_equal content1, oo.cell(random_row,random_column,oo.sheets.first)
1406
1071
  assert_equal content2, oo.cell(random_row,random_column,oo.sheets[1])
1407
1072
  end
1408
1073
  end
1409
1074
 
1410
- def test_set_value_for_non_existing_sheet_google
1075
+ def test_set_for_non_existing_sheet_google
1411
1076
  with_each_spreadsheet(:name=>'ptu6bbahNZpY0N0RrxQbWdw', :format=>:google) do |oo|
1412
- assert_raise(RangeError) { oo.set_value(1,1,"dummy","no_sheet") }
1077
+ assert_raise(RangeError) { oo.set(1,1,"dummy","no_sheet") }
1413
1078
  end
1414
1079
  end
1415
1080
 
@@ -1452,15 +1117,13 @@ Sheet 3:
1452
1117
 
1453
1118
  def test_date_time_to_csv
1454
1119
  with_each_spreadsheet(:name=>'time-test') do |oo|
1455
- begin
1120
+ Dir.mktmpdir do |tempdir|
1456
1121
  csv_output = File.join(tempdir,'time_test.csv')
1457
1122
  assert oo.to_csv(csv_output)
1458
1123
  assert File.exists?(csv_output)
1459
1124
  assert_equal "", `diff --strip-trailing-cr #{TESTDIR}/time-test.csv #{csv_output}`
1460
1125
  # --strip-trailing-cr is needed because the test-file use 0A and
1461
1126
  # the test on an windows box generates 0D 0A as line endings
1462
- ensure
1463
- File.delete_if_exist(csv_output)
1464
1127
  end
1465
1128
  end
1466
1129
  end
@@ -1473,81 +1136,6 @@ Sheet 3:
1473
1136
  end
1474
1137
  end
1475
1138
 
1476
- def test_no_remaining_tmp_files_openoffice
1477
- after Date.new(2011,12,7) do
1478
- # alles noch mal ueberarbeiten
1479
- # temp. Directories sollten in diesem Fall ueberhaupt nicht
1480
- # angelegt werden
1481
- if OPENOFFICE
1482
- assert_raise(Zip::ZipError) { #TODO: besseres Fehlerkriterium bei
1483
- # oo = Openoffice.new(File.join(TESTDIR,"no_spreadsheet_file.txt"))
1484
- # es soll absichtlich ein Abbruch provoziert werden, deshalb :ignore
1485
- begin
1486
- oo = Openoffice.new(File.join(TESTDIR,"no_spreadsheet_file.txt"),
1487
- false,
1488
- :ignore)
1489
- rescue Zip::ZipError
1490
- @tmp = Dir.glob(oo.tmpdir)
1491
- raise
1492
- end
1493
- }
1494
- assert @tmp.empty?, "temporay directory was not deleted"
1495
- end
1496
- end
1497
- end
1498
-
1499
- def test_no_remaining_tmp_files_excel
1500
- after Date.new(2011,12,7) do
1501
- # alles noch mal ueberarbeiten
1502
- # temp. Directories sollten in diesem Fall ueberhaupt nicht
1503
- # angelegt werden
1504
- if EXCEL
1505
- prev = Dir.glob(TMP_PREFIX)
1506
- assert_raise(Ole::Storage::FormatError) {
1507
- oo = Excel.new(File.join(TESTDIR,"no_spreadsheet_file.txt"),
1508
- false,
1509
- :ignore)
1510
- }
1511
- now = Dir.glob(TMP_PREFIX)
1512
- assert (now-prev).empty?, "temporary directory not removed"
1513
- end
1514
- end
1515
- end
1516
-
1517
- def test_no_remaining_tmp_files_excelx
1518
- after Date.new(2011,12,7) do
1519
- # alles noch mal ueberarbeiten
1520
- # temp. Directories sollten in diesem Fall ueberhaupt nicht
1521
- # angelegt werden
1522
- if EXCELX
1523
- prev = Dir.glob(TMP_PREFIX)
1524
- assert_raise(Zip::ZipError) { #TODO: besseres Fehlerkriterium bei
1525
- # oo = Excelx.new(File.join(TESTDIR,"no_spreadsheet_file.txt"))
1526
- # es soll absichtlich ein Abbruch provoziert werden, deshalb :ignore
1527
- oo = Excelx.new(File.join(TESTDIR,"no_spreadsheet_file.txt"),
1528
- false,
1529
- :ignore)
1530
- }
1531
- now = Dir.glob(TMP_PREFIX)
1532
- assert (now-prev).empty?
1533
- end
1534
- end
1535
- end
1536
-
1537
- def test_no_remaining_tmp_files_google
1538
- # Exception ist irgendwie anders, nochmal ansehen TODO:
1539
- after Date.new(2011,6,19) do
1540
- if GOOGLE
1541
- prev = Dir.glob(TMP_PREFIX)
1542
- assert_nothing_raised() {
1543
- oo = Google.new(key_of("no_spreadsheet_file.txt"))
1544
- }
1545
- now = Dir.glob(TMP_PREFIX)
1546
- assert (now-prev).empty?
1547
- end
1548
- end
1549
- end
1550
-
1551
1139
  # Erstellt eine Liste aller Zellen im Spreadsheet. Dies ist nötig, weil ein einfacher
1552
1140
  # Textvergleich des XML-Outputs nicht funktioniert, da xml-builder die Attribute
1553
1141
  # nicht immer in der gleichen Reihenfolge erzeugt.
@@ -1601,7 +1189,7 @@ Sheet 3:
1601
1189
  sheetname = oo.sheets[oo.sheets.index(sheetname)+1]
1602
1190
  }
1603
1191
  end
1604
- end
1192
+ end
1605
1193
 
1606
1194
  def test_bug_row_column_fixnum_float
1607
1195
  with_each_spreadsheet(:name=>'bug-row-column-fixnum-float', :format=>:excel) do |oo|
@@ -1614,107 +1202,72 @@ Sheet 3:
1614
1202
 
1615
1203
  def test_file_warning_default
1616
1204
  if OPENOFFICE
1617
- prev = Dir.glob(TMP_PREFIX)
1618
- assert_raises(TypeError, "test/numbers1.xls is not an openoffice spreadsheet") { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls")) }
1619
- assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx")) }
1620
- now = Dir.glob(TMP_PREFIX)
1621
- assert (now-prev).empty?
1205
+ assert_raises(TypeError, "test/files/numbers1.xls is not an openoffice spreadsheet") {
1206
+ Roo::Openoffice.new(File.join(TESTDIR,"numbers1.xls"))
1207
+ }
1208
+ assert_raises(TypeError) { Roo::Openoffice.new(File.join(TESTDIR,"numbers1.xlsx")) }
1622
1209
  end
1623
1210
  if EXCEL
1624
- prev = Dir.glob(TMP_PREFIX)
1625
- assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.ods")) }
1626
- assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx")) }
1627
- now = Dir.glob(TMP_PREFIX)
1628
- assert (now-prev).empty?, "temporary directory was not removed"
1211
+ assert_raises(TypeError) { Roo::Excel.new(File.join(TESTDIR,"numbers1.ods")) }
1212
+ assert_raises(TypeError) { Roo::Excel.new(File.join(TESTDIR,"numbers1.xlsx")) }
1629
1213
  end
1630
1214
  if EXCELX
1631
- prev = Dir.glob(TMP_PREFIX)
1632
- assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.ods")) }
1633
- assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.xls")) }
1634
- now = Dir.glob(TMP_PREFIX)
1635
- assert (now-prev).empty?
1215
+ assert_raises(TypeError) { Roo::Excelx.new(File.join(TESTDIR,"numbers1.ods")) }
1216
+ assert_raises(TypeError) { Roo::Excelx.new(File.join(TESTDIR,"numbers1.xls")) }
1636
1217
  end
1637
1218
  end
1638
1219
 
1639
1220
  def test_file_warning_error
1640
1221
  if OPENOFFICE
1641
- prev = Dir.glob(TMP_PREFIX)
1642
- assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls"),false,:error) }
1643
- now = Dir.glob(TMP_PREFIX)
1644
- assert (now-prev).empty?
1645
-
1646
- prev = Dir.glob(TMP_PREFIX)
1647
- assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) }
1648
- now = Dir.glob(TMP_PREFIX)
1649
- assert (now-prev).empty?
1222
+ assert_raises(TypeError) { Roo::Openoffice.new(File.join(TESTDIR,"numbers1.xls"),false,:error) }
1223
+ assert_raises(TypeError) { Roo::Openoffice.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) }
1650
1224
  end
1651
1225
  if EXCEL
1652
- prev = Dir.glob(TMP_PREFIX)
1653
- assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.ods"),false,:error) }
1654
- now = Dir.glob(TMP_PREFIX)
1655
- assert (now-prev).empty?, "temporary directory was not deleted"
1656
-
1657
- prev = Dir.glob(TMP_PREFIX)
1658
- assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) }
1659
- now = Dir.glob(TMP_PREFIX)
1660
- assert (now-prev).empty?, "temporary directory was not deleted"
1226
+ assert_raises(TypeError) { Roo::Excel.new(File.join(TESTDIR,"numbers1.ods"),false,:error) }
1227
+ assert_raises(TypeError) { Roo::Excel.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) }
1661
1228
  end
1662
1229
  if EXCELX
1663
- prev = Dir.glob(TMP_PREFIX)
1664
- assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.ods"),false,:error) }
1665
- now = Dir.glob(TMP_PREFIX)
1666
- assert (now-prev).empty?, "temporary directory was not deleted"
1667
-
1668
- prev = Dir.glob(TMP_PREFIX)
1669
- assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.xls"),false,:error) }
1670
- now = Dir.glob(TMP_PREFIX)
1671
- assert (now-prev).empty?, "temporary directory was not deleted"
1230
+ assert_raises(TypeError) { Roo::Excelx.new(File.join(TESTDIR,"numbers1.ods"),false,:error) }
1231
+ assert_raises(TypeError) { Roo::Excelx.new(File.join(TESTDIR,"numbers1.xls"),false,:error) }
1672
1232
  end
1673
1233
  end
1674
1234
 
1675
1235
  def test_file_warning_warning
1676
- after Date.new(2011,12,7) do
1677
- if OPENOFFICE
1678
- assert_nothing_raised(TypeError) {
1679
- assert_raises(Zip::ZipError) {
1680
- oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls"),false, :warning)
1681
- }
1236
+ if OPENOFFICE
1237
+ assert_nothing_raised(TypeError) {
1238
+ assert_raises(Zip::ZipError) {
1239
+ Roo::Openoffice.new(File.join(TESTDIR,"numbers1.xls"),false, :warning)
1682
1240
  }
1683
- prev = Dir.glob(TMP_PREFIX)
1684
- assert_nothing_raised(TypeError) {
1685
- assert_raises(Errno::ENOENT) {
1686
- oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx"),false, :warning)
1687
- }
1241
+ }
1242
+ assert_nothing_raised(TypeError) {
1243
+ assert_raises(Errno::ENOENT) {
1244
+ Roo::Openoffice.new(File.join(TESTDIR,"numbers1.xlsx"),false, :warning)
1688
1245
  }
1689
- now = Dir.glob(TMP_PREFIX)
1690
- assert (now-prev).empty?
1691
- end
1692
- if EXCEL
1693
- prev = Dir.glob(TMP_PREFIX)
1694
- assert_nothing_raised(TypeError) {
1695
- assert_raises(Ole::Storage::FormatError) {
1696
- oo = Excel.new(File.join(TESTDIR,"numbers1.ods"),false, :warning) }
1246
+ }
1247
+ end
1248
+ if EXCEL
1249
+ assert_nothing_raised(TypeError) {
1250
+ assert_raises(Ole::Storage::FormatError) {
1251
+ Roo::Excel.new(File.join(TESTDIR,"numbers1.ods"),false, :warning)
1697
1252
  }
1698
- assert_nothing_raised(TypeError) {
1699
- assert_raises(Ole::Storage::FormatError) {
1700
- oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx"),false, :warning) }
1253
+ }
1254
+ assert_nothing_raised(TypeError) {
1255
+ assert_raises(Ole::Storage::FormatError) {
1256
+ Roo::Excel.new(File.join(TESTDIR,"numbers1.xlsx"),false, :warning)
1701
1257
  }
1702
- now = Dir.glob(TMP_PREFIX)
1703
- assert (now-prev).empty?, "temporary directory was not removed"
1704
- end
1705
- if EXCELX
1706
- prev = Dir.glob(TMP_PREFIX)
1707
- assert_nothing_raised(TypeError) {
1708
- assert_raises(Errno::ENOENT) {
1709
- oo = Excelx.new(File.join(TESTDIR,"numbers1.ods"),false, :warning) }
1258
+ }
1259
+ end
1260
+ if EXCELX
1261
+ assert_nothing_raised(TypeError) {
1262
+ assert_raises(Errno::ENOENT) {
1263
+ Roo::Excelx.new(File.join(TESTDIR,"numbers1.ods"),false, :warning)
1710
1264
  }
1711
- assert_nothing_raised(TypeError) {
1712
- assert_raises(Zip::ZipError) {
1713
- oo = Excelx.new(File.join(TESTDIR,"numbers1.xls"),false, :warning) }
1265
+ }
1266
+ assert_nothing_raised(TypeError) {
1267
+ assert_raises(Zip::ZipError) {
1268
+ Roo::Excelx.new(File.join(TESTDIR,"numbers1.xls"),false, :warning)
1714
1269
  }
1715
- now = Dir.glob(TMP_PREFIX)
1716
- assert (now-prev).empty?
1717
- end
1270
+ }
1718
1271
  end
1719
1272
  end
1720
1273
 
@@ -1727,64 +1280,29 @@ Sheet 3:
1727
1280
 
1728
1281
  # xls
1729
1282
  assert_nothing_raised() {
1730
- oo = Openoffice.new(File.join(TESTDIR,"type_openoffice.xls"),false, :ignore)
1283
+ Roo::Openoffice.new(File.join(TESTDIR,"type_openoffice.xls"),false, :ignore)
1731
1284
  }
1732
1285
  # xlsx
1733
1286
  assert_nothing_raised() {
1734
- oo = Openoffice.new(File.join(TESTDIR,"type_openoffice.xlsx"),false, :ignore)
1287
+ Roo::Openoffice.new(File.join(TESTDIR,"type_openoffice.xlsx"),false, :ignore)
1735
1288
  }
1736
1289
  end
1737
1290
  if EXCEL
1738
1291
  assert_nothing_raised() {
1739
- oo = Excel.new(File.join(TESTDIR,"type_excel.ods"),false, :ignore)
1292
+ Roo::Excel.new(File.join(TESTDIR,"type_excel.ods"),false, :ignore)
1740
1293
  }
1741
1294
  assert_nothing_raised() {
1742
- oo = Excel.new(File.join(TESTDIR,"type_excel.xlsx"),false, :ignore)
1295
+ Roo::Excel.new(File.join(TESTDIR,"type_excel.xlsx"),false, :ignore)
1743
1296
  }
1744
1297
  end
1745
1298
  if EXCELX
1746
1299
  assert_nothing_raised() {
1747
- oo = Excelx.new(File.join(TESTDIR,"type_excelx.ods"),false, :ignore)
1300
+ Roo::Excelx.new(File.join(TESTDIR,"type_excelx.ods"),false, :ignore)
1748
1301
  }
1749
1302
  assert_nothing_raised() {
1750
- oo = Excelx.new(File.join(TESTDIR,"type_excelx.xls"),false, :ignore)
1303
+ Roo::Excelx.new(File.join(TESTDIR,"type_excelx.xls"),false, :ignore)
1751
1304
  }
1752
1305
  end
1753
- =begin
1754
- if OPENOFFICE
1755
- assert_nothing_raised() {
1756
- assert_raises(Zip::ZipError) {
1757
- oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls"),false, :ignore) }
1758
- }
1759
- assert_nothing_raised() {
1760
- assert_raises(Errno::ENOENT) {
1761
- oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx"),false, :ignore) }
1762
- }
1763
- assert Dir.glob(TMP_PREFIX).empty?
1764
- end
1765
- if EXCEL
1766
- assert_nothing_raised(TypeError) {
1767
- assert_raises(Ole::Storage::FormatError) {
1768
- oo = Excel.new(File.join(TESTDIR,"numbers1.ods"),false, :ignore) }
1769
- }
1770
- assert_nothing_raised(TypeError) {
1771
- assert_raises(Ole::Storage::FormatError) {oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx"),false, :ignore) }}
1772
- assert Dir.glob(TMP_PREFIX).empty?
1773
- end
1774
- if EXCELX
1775
- assert_nothing_raised(TypeError) {
1776
- assert_raises(Errno::ENOENT) {
1777
- oo = Excelx.new(File.join(TESTDIR,"numbers1.ods"),false, :ignore)
1778
- }
1779
- }
1780
- assert_nothing_raised(TypeError) {
1781
- assert_raises(Zip::ZipError) {
1782
- oo = Excelx.new(File.join(TESTDIR,"numbers1.xls"),false, :ignore)
1783
- }
1784
- }
1785
- assert Dir.glob(TMP_PREFIX).empty?
1786
- end
1787
- =end
1788
1306
  end
1789
1307
 
1790
1308
  def test_bug_last_row_excel
@@ -1805,7 +1323,7 @@ Sheet 3:
1805
1323
  assert_equal nil, oo.first_column(sheet), "first_column not nil in sheet #{sheet}"
1806
1324
  assert_equal nil, oo.last_column(sheet), "last_column not nil in sheet #{sheet}"
1807
1325
  }
1808
- assert_nothing_raised() { result = oo.to_xml }
1326
+ assert_nothing_raised() { oo.to_xml }
1809
1327
  end
1810
1328
  end
1811
1329
 
@@ -1885,7 +1403,7 @@ Sheet 3:
1885
1403
  assert_equal Date.new(1961,11,21), oo.cell('c',7)
1886
1404
  end
1887
1405
  end
1888
-
1406
+
1889
1407
  def test_cell_openoffice_html_escape
1890
1408
  with_each_spreadsheet(:name=>'html-escape', :format=>:openoffice) do |oo|
1891
1409
  assert_equal "'", oo.cell(1,1)
@@ -1896,10 +1414,10 @@ Sheet 3:
1896
1414
  # test_openoffice_zipped will catch issues with &quot;
1897
1415
  end
1898
1416
  end
1899
-
1417
+
1900
1418
  def test_cell_boolean
1901
1419
  with_each_spreadsheet(:name=>'boolean', :format=>[:openoffice, :excel, :excelx]) do |oo|
1902
- if oo.class == Excelx
1420
+ if oo.class == Roo::Excelx
1903
1421
  assert_equal "TRUE", oo.cell(1,1), "failure in "+oo.class.to_s
1904
1422
  assert_equal "FALSE", oo.cell(2,1), "failure in "+oo.class.to_s
1905
1423
  else
@@ -1908,7 +1426,7 @@ Sheet 3:
1908
1426
  end
1909
1427
  end
1910
1428
  end
1911
-
1429
+
1912
1430
  def test_cell_multiline
1913
1431
  with_each_spreadsheet(:name=>'paragraph', :format=>[:openoffice, :excel, :excelx]) do |oo|
1914
1432
  assert_equal "This is a test\nof a multiline\nCell", oo.cell(1,1)
@@ -1916,7 +1434,7 @@ Sheet 3:
1916
1434
  assert_equal "first p\n\nsecond p\n\nlast p", oo.cell(2,1)
1917
1435
  end
1918
1436
  end
1919
-
1437
+
1920
1438
  def test_cell_styles
1921
1439
  # styles only valid in excel spreadsheets?
1922
1440
  # TODO: what todo with other spreadsheet types
@@ -1928,7 +1446,7 @@ Sheet 3:
1928
1446
  assert_equal true, oo.font(1,1).bold?
1929
1447
  assert_equal false, oo.font(1,1).italic?
1930
1448
  assert_equal false, oo.font(1,1).underline?
1931
-
1449
+
1932
1450
  # italic
1933
1451
  assert_equal false, oo.font(2,1).bold?
1934
1452
  assert_equal true, oo.font(2,1).italic?
@@ -1980,7 +1498,7 @@ Sheet 3:
1980
1498
  assert_equal false, oo.font(11,4).underline?
1981
1499
  end
1982
1500
  end
1983
-
1501
+
1984
1502
  # If a cell has a date-like string but is preceeded by a '
1985
1503
  # to force that date to be treated like a string, we were getting an exception.
1986
1504
  # This test just checks for that exception to make sure it's not raised in this case
@@ -2010,7 +1528,7 @@ Sheet 3:
2010
1528
  assert_equal [Date.new(2007,5,7), nil, 10.75], oo.row(3)
2011
1529
  end
2012
1530
  end
2013
-
1531
+
2014
1532
  def test_col_whitespace
2015
1533
  #TODO:
2016
1534
  # kein Zugriff auf Dokument whitespace
@@ -2030,7 +1548,14 @@ Sheet 3:
2030
1548
  assert_equal [ "Start time", 9.25, 10.75], oo.column(5)
2031
1549
  end
2032
1550
  end
2033
-
1551
+
1552
+ def test_ruby_spreadsheet_formula_bug
1553
+ with_each_spreadsheet(:name=>'formula_parse_error', :format=>:excel) do |oo|
1554
+ assert_equal '5026', oo.cell(2,3)
1555
+ assert_equal '5026', oo.cell(3,3)
1556
+ end
1557
+ end
1558
+
2034
1559
  # Excel has two base date formats one from 1900 and the other from 1904.
2035
1560
  # There's a MS bug that 1900 base dates include an extra day due to erroneously
2036
1561
  # including 1900 as a leap yar.
@@ -2050,13 +1575,21 @@ Sheet 3:
2050
1575
  assert_equal :date, oo.celltype(1,1)
2051
1576
  end
2052
1577
  end
2053
-
1578
+
2054
1579
  def test_bad_date
2055
1580
  with_each_spreadsheet(:name=>'prova', :format=>:excel) do |oo|
2056
1581
  assert_nothing_raised(ArgumentError) {
2057
1582
  assert_equal DateTime.new(2006,2,2,10,0,0), oo.cell('a',1)
2058
1583
  }
2059
- end # each
1584
+ end
1585
+ end
1586
+
1587
+ def test_bad_excel_date
1588
+ with_each_spreadsheet(:name=>'bad_excel_date', :format=>:excel) do |oo|
1589
+ assert_nothing_raised(ArgumentError) {
1590
+ assert_equal DateTime.new(2006,2,2,10,0,0), oo.cell('a',1)
1591
+ }
1592
+ end
2060
1593
  end
2061
1594
 
2062
1595
  def test_cell_methods
@@ -2081,7 +1614,7 @@ Sheet 3:
2081
1614
  def test_compare_large_spreadsheets
2082
1615
  # problematisch, weil Formeln in Excel nicht unterstützt werden
2083
1616
  if LONG_RUN
2084
- qq = Openoffice.new(File.join('test',"Bibelbund.ods"))
1617
+ qq = Roo::Openoffice.new(File.join('test',"Bibelbund.ods"))
2085
1618
  with_each_spreadsheet(:name=>'Bibelbund') do |oo|
2086
1619
  # p "comparing Bibelbund.ods with #{oo.class}"
2087
1620
  oo.sheets.each do |sh|
@@ -2093,7 +1626,7 @@ Sheet 3:
2093
1626
  c2.force_encoding("UTF-8") if c2.class == String
2094
1627
  assert_equal c1, c2, "diff in #{sh}/#{row}/#{col}}"
2095
1628
  assert_equal qq.celltype(row,col,sh), oo.celltype(row,col,sh)
2096
- assert_equal qq.formula?(row,col,sh), oo.formula?(row,col,sh) if oo.class != Excel
1629
+ assert_equal qq.formula?(row,col,sh), oo.formula?(row,col,sh) if oo.class != Roo::Excel
2097
1630
  end
2098
1631
  end
2099
1632
  end
@@ -2138,7 +1671,7 @@ Sheet 3:
2138
1671
  # oo.default_sheet = oo.sheets.first
2139
1672
  assert_equal "Anton", oo.anton
2140
1673
  assert_raises(NoMethodError) {
2141
- row,col = oo.never
1674
+ oo.never
2142
1675
  }
2143
1676
  end
2144
1677
  end
@@ -2154,63 +1687,55 @@ Sheet 3:
2154
1687
  end
2155
1688
  end
2156
1689
 
2157
- # def test_labeled_cells
2158
- # to do
2159
- # "more spreadsheet types"
2160
- # end
2161
- # with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo|
2162
- # oo.default_sheet = oo.sheets.first
2163
- # begin
2164
- # row,col = oo.label('anton')
2165
- # rescue ArgumentError
2166
- # puts "labels error at #{oo.class}"
2167
- # raise
2168
- # end
2169
- # assert_equal 5, row
2170
- # assert_equal 3, col
2171
- #
2172
- # row,col = oo.label('anton')
2173
- # assert_equal 'Anton', oo.cell(row,col)
2174
- #
2175
- # row,col = oo.label('berta')
2176
- # assert_equal 'Bertha', oo.cell(row,col)
2177
- #
2178
- # row,col = oo.label('caesar')
2179
- # assert_equal 'Cäsar', oo.cell(row,col)
2180
- #
2181
- # row,col = oo.label('never')
2182
- # assert_nil row
2183
- # assert_nil col
2184
- #
2185
- # row,col,sheet = oo.label('anton')
2186
- # assert_equal 5, row
2187
- # assert_equal 3, col
2188
- # assert_equal "Sheet1", sheet
2189
- #
2190
- # assert_equal "Anton", oo.anton
2191
- # assert_raises(NoMethodError) {
2192
- # row,col = oo.never
2193
- # }
2194
- #
2195
- # #assert_equal [
2196
- ## ['anton',['Sheet1',5,3]],
2197
- ## ['berta',['Sheet1',4,2]],
2198
- ## ['caesar',['Sheet1',7,2]],
2199
- ## ], oo.labels, "error with labels array in class #{oo.class}"
2200
- ## Reihenfolge row,col,sheet analog zu #label
2201
- # assert_equal [
2202
- # ['anton',[5,3,'Sheet1']],
2203
- # ['berta',[4,2,'Sheet1']],
2204
- # ['caesar',[7,2,'Sheet1']],
2205
- # ], oo.labels, "error with labels array in class #{oo.class}"
2206
- # end
2207
- # end
1690
+ def test_labeled_cells
1691
+ with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo|
1692
+ oo.default_sheet = oo.sheets.first
1693
+ begin
1694
+ row,col = oo.label('anton')
1695
+ rescue ArgumentError
1696
+ puts "labels error at #{oo.class}"
1697
+ raise
1698
+ end
1699
+ assert_equal 5, row
1700
+ assert_equal 3, col
1701
+
1702
+ row,col = oo.label('anton')
1703
+ assert_equal 'Anton', oo.cell(row,col)
1704
+
1705
+ row,col = oo.label('berta')
1706
+ assert_equal 'Bertha', oo.cell(row,col)
1707
+
1708
+ row,col = oo.label('caesar')
1709
+ assert_equal 'Cäsar', oo.cell(row,col)
1710
+
1711
+ row,col = oo.label('never')
1712
+ assert_nil row
1713
+ assert_nil col
1714
+
1715
+ row,col,sheet = oo.label('anton')
1716
+ assert_equal 5, row
1717
+ assert_equal 3, col
1718
+ assert_equal "Sheet1", sheet
1719
+
1720
+ assert_equal "Anton", oo.anton
1721
+ assert_raises(NoMethodError) {
1722
+ row,col = oo.never
1723
+ }
1724
+
1725
+ # Reihenfolge row,col,sheet analog zu #label
1726
+ assert_equal [
1727
+ ['anton',[5,3,'Sheet1']],
1728
+ ['berta',[4,2,'Sheet1']],
1729
+ ['caesar',[7,2,'Sheet1']],
1730
+ ], oo.labels, "error with labels array in class #{oo.class}"
1731
+ end
1732
+ end
2208
1733
 
2209
1734
 
2210
1735
  def test_bug_excel_last_row_255
2211
1736
  if LONG_RUN
2212
1737
  local_only do
2213
- oo = Excel.new(File.join('..','confidential','ScienceStaff.xls'))
1738
+ oo = Roo::Excel.new(File.join('..','confidential','ScienceStaff.xls'))
2214
1739
  oo.default_sheet = oo.sheets.first
2215
1740
  assert_equal "COMSCI", oo.cell(255,1)
2216
1741
  assert_equal "lala", oo.cell(256,1)
@@ -2221,7 +1746,7 @@ Sheet 3:
2221
1746
 
2222
1747
  def test_bug_excel_last_row_255_modified
2223
1748
  local_only do
2224
- oo = Excel.new(File.join('..','confidential','ScienceStaff_modified.xls'))
1749
+ oo = Roo::Excel.new(File.join('..','confidential','ScienceStaff_modified.xls'))
2225
1750
  oo.default_sheet = oo.sheets.first
2226
1751
  assert_equal 1537, oo.last_row
2227
1752
  end
@@ -2265,15 +1790,12 @@ Sheet 3:
2265
1790
  [1.0, nil, 3.0],
2266
1791
  [4.0, 5.0, 6.0],
2267
1792
  [7.0, 8.0, nil] ], oo.to_matrix(1,1,3,3)
2268
- end end
1793
+ end
1794
+ end
2269
1795
 
2270
1796
  def test_bug_date_mileszs
2271
- after Date.new(2011,12,7) do
2272
- # to do
2273
- # "An richtige Stelle kopieren. Ist das Dokument vertraulich?"
2274
- # 'ist auf dem Netbook nicht vorhanden'
2275
- # end
2276
- oo = Excel.new "/home/tp/Documents/feb-sales-analysis.xls"
1797
+ local_only do
1798
+ oo = Roo::Excel.new "/home/tp/Documents/feb-sales-analysis.xls"
2277
1799
  oo.default_sheet = oo.sheets.first
2278
1800
  # 2/1/2010 A2-A6 mm/dd/yyyy
2279
1801
  2.upto(6) do |i|
@@ -2282,25 +1804,15 @@ Sheet 3:
2282
1804
  end
2283
1805
  end
2284
1806
 
2285
- #def test_no_generic_new
2286
- #oo = GenericSpreadsheet.new
2287
- #assert_equal GenericSpreadsheet, oo.class
2288
- #end
2289
-
2290
1807
  # unter Windows soll es laut Bug-Reports nicht moeglich sein, eine Excel-Datei, die
2291
1808
  # mit Excel.new geoeffnet wurde nach dem Processing anschliessend zu loeschen.
2292
1809
  # Anmerkung: Das Spreadsheet-Gem erlaubt kein explizites Close von Spreadsheet-Dateien,
2293
1810
  # was verhindern koennte, das die Datei geloescht werden kann.
2294
- def test_bug_cannot_delete_opened_excel_sheet
2295
- # with_each_spreadsheet(:name=>'simple_spreadsheet') do |oo|
2296
- after Date.new(2011,7,17) do
2297
- # to do
2298
- # 'kopiere nach temporaere Datei
2299
- # und versuche diese zu oeffnen und zu loeschen'
2300
- # end
2301
- end
2302
- #end
2303
- end
1811
+ # def test_bug_cannot_delete_opened_excel_sheet
1812
+ # with_each_spreadsheet(:name=>'simple_spreadsheet') do |oo|
1813
+ # 'kopiere nach temporaere Datei und versuche diese zu oeffnen und zu loeschen'
1814
+ # end
1815
+ # end
2304
1816
 
2305
1817
  def test_bug_xlsx_reference_cell
2306
1818
 
@@ -2310,7 +1822,7 @@ Sheet 3:
2310
1822
  "0.0" instead of the value of cell A.
2311
1823
 
2312
1824
  With the attached test case, I ran the following code:
2313
- spreadsheet = Excelx.new('formula_string_error.xlsx')
1825
+ spreadsheet = Roo::Excelx.new('formula_string_error.xlsx')
2314
1826
  spreadsheet.default_sheet = 'sheet1'
2315
1827
  p "A: #{spreadsheet.cell(1, 1)}"
2316
1828
  p "B: #{spreadsheet.cell(2, 1)}"
@@ -2323,16 +1835,16 @@ where the expected result is
2323
1835
  "A: TestString"
2324
1836
  "B: TestString"
2325
1837
  =end
2326
- xlsx = Excelx.new(File.join('test', "formula_string_error.xlsx"))
1838
+ xlsx = Roo::Excelx.new(File.join(TESTDIR, "formula_string_error.xlsx"))
2327
1839
  xlsx.default_sheet = xlsx.sheets.first
2328
1840
  assert_equal 'Teststring', xlsx.cell('a',1)
2329
1841
  assert_equal 'Teststring', xlsx.cell('a',2)
2330
1842
  end
2331
1843
  end
2332
-
1844
+
2333
1845
  def test_bug_guest_list_2011_05_05
2334
- after Date.new(2011,12,7) do
2335
- oo = Excel.new(File.join("..","confidential","guest_list_addresses.xls"))
1846
+ local_only do
1847
+ oo = Roo::Excel.new(File.join("..","confidential","guest_list_addresses.xls"))
2336
1848
  oo.default_sheet = oo.sheets.first
2337
1849
  assert_equal "lalala", oo.cell('a',1) # anderer Inhalt im Spreadsheet
2338
1850
  assert_equal :string, oo.celltype('a',1)
@@ -2340,37 +1852,34 @@ where the expected result is
2340
1852
  end
2341
1853
 
2342
1854
  def test_bug_guest_list_2011_05_05_spreadsheet
2343
- # to do
2344
- # 'wieder entfernen'
2345
- # end
2346
- require 'spreadsheet'
2347
- book = Spreadsheet.open File.join('..','confidential','guest_list_addresses.xls')
2348
- sheet1 = book.worksheet 0
2349
- sheet1.each do |row|
2350
- p row[0]
2351
-
2352
- end
1855
+ local_only do
1856
+ require 'spreadsheet'
1857
+ book = Spreadsheet.open File.join('..','confidential','guest_list_addresses.xls')
1858
+ sheet1 = book.worksheet 0
1859
+ sheet1.each do |row|
1860
+ p row[0]
1861
+ end
1862
+ end
2353
1863
  end
2354
1864
 
2355
1865
  # don't test it with other spreadsheet types! this was only a problem
2356
1866
  # with .xlsx files
2357
1867
  def test_bug_date_not_recognized_2011_05_21
2358
1868
  if EXCELX
2359
- oo = Excelx.new(File.join('..','confidential','2011-05-21_sample_date_problem.xlsx'))
2360
- oo.default_sheet = oo.sheets.first
2361
- assert_equal Date.new(2011,3,24), oo.b4
2362
- assert_equal Date.new(2011,3,25), oo.b5
2363
- assert_equal Date.new(2011,5,5), oo.b6
2364
- assert_equal Date.new(2012,3,23), oo.b7
1869
+ local_only do
1870
+ oo = Roo::Excelx.new(File.join('..','confidential','2011-05-21_sample_date_problem.xlsx'))
1871
+ oo.default_sheet = oo.sheets.first
1872
+ assert_equal Date.new(2011,3,24), oo.b4
1873
+ assert_equal Date.new(2011,3,25), oo.b5
1874
+ assert_equal Date.new(2011,5,5), oo.b6
1875
+ assert_equal Date.new(2012,3,23), oo.b7
1876
+ end
2365
1877
  end
2366
1878
  end
2367
1879
 
2368
1880
  def test_bug_string_as_a_date_2011_05_21_spreadsheet_only
2369
- after Date.new(2011,12,28) do
2370
- if EXCEL
2371
- # to do
2372
- # 'wieder entfernen'
2373
- # end
1881
+ if EXCEL
1882
+ local_only do
2374
1883
  require 'spreadsheet'
2375
1884
  book = Spreadsheet.open File.join('..','confidential','2011-05-21_sample_type_problem.xls')
2376
1885
  sheet1 = book.worksheet 0
@@ -2385,9 +1894,23 @@ where the expected result is
2385
1894
  end
2386
1895
 
2387
1896
  def test_bug_string_as_a_date_2011_05_21
2388
- after Date.new(2011,12,7) do
2389
- #oo = Excel.new(File.join(TESTDIR,'2011-05-21_sample_type_problem.xls'))
2390
- oo = Excel.new(File.join('..','confidential','2011-05-21_sample_type_problem.xls'))
1897
+ if EXCEL
1898
+ local_only do
1899
+ oo = Roo::Excel.new(File.join('..','confidential','2011-05-21_sample_type_problem.xls'))
1900
+ oo.default_sheet = oo.sheets.first
1901
+ assert_equal 68, oo.g2
1902
+ assert_equal 72, oo.g3
1903
+ assert_equal 75, oo.g4
1904
+ assert_equal 76, oo.g5
1905
+ assert_equal 77, oo.g6
1906
+ assert_equal 78, oo.g7
1907
+ end
1908
+ end
1909
+ end
1910
+
1911
+ def test_bug_string_as_a_date_2011_05_21_saved_as_ods
1912
+ local_only do
1913
+ oo = Roo::Openoffice.new(File.join('..','confidential','2011-05-21_sample_type_problem.ods'))
2391
1914
  oo.default_sheet = oo.sheets.first
2392
1915
  assert_equal 68, oo.g2
2393
1916
  assert_equal 72, oo.g3
@@ -2398,18 +1921,6 @@ where the expected result is
2398
1921
  end
2399
1922
  end
2400
1923
 
2401
- def test_bug_string_as_a_date_2011_05_21_saved_as_ods
2402
- #oo = Openoffice.new(File.join(TESTDIR,'2011-05-21_sample_type_problem.ods'))
2403
- oo = Openoffice.new(File.join('..','confidential','2011-05-21_sample_type_problem.ods'))
2404
- oo.default_sheet = oo.sheets.first
2405
- assert_equal 68, oo.g2
2406
- assert_equal 72, oo.g3
2407
- assert_equal 75, oo.g4
2408
- assert_equal 76, oo.g5
2409
- assert_equal 77, oo.g6
2410
- assert_equal 78, oo.g7
2411
- end
2412
-
2413
1924
  # #formulas of an empty sheet should return an empty array and not result in
2414
1925
  # an error message
2415
1926
  # 2011-06-24
@@ -2418,7 +1929,7 @@ where the expected result is
2418
1929
  :format=>[:openoffice,:excelx,:google]) do |oo|
2419
1930
  assert_nothing_raised(NoMethodError) {
2420
1931
  oo.default_sheet = oo.sheets.first
2421
- result = oo.formulas
1932
+ oo.formulas
2422
1933
  }
2423
1934
  assert_equal([], oo.formulas)
2424
1935
  end
@@ -2432,7 +1943,7 @@ where the expected result is
2432
1943
  :format=>[:openoffice,:excelx,:google]) do |oo|
2433
1944
  assert_nothing_raised(NoMethodError) {
2434
1945
  oo.default_sheet = oo.sheets.first
2435
- result = oo.to_yaml
1946
+ oo.to_yaml
2436
1947
  }
2437
1948
  assert_equal('', oo.to_yaml)
2438
1949
  end
@@ -2446,7 +1957,7 @@ where the expected result is
2446
1957
  :format=>[:openoffice,:excelx,:google]) do |oo|
2447
1958
  assert_nothing_raised(NoMethodError) {
2448
1959
  oo.default_sheet = oo.sheets.first
2449
- result = oo.to_matrix
1960
+ oo.to_matrix
2450
1961
  }
2451
1962
  assert_equal(Matrix.empty(0,0), oo.to_matrix)
2452
1963
  end
@@ -2455,9 +1966,13 @@ where the expected result is
2455
1966
  # 2011-08-03
2456
1967
  def test_bug_datetime_to_csv
2457
1968
  with_each_spreadsheet(:name=>'datetime') do |oo|
2458
- assert oo.to_csv("datetime.csv")
2459
- assert File.exists?("datetime.csv")
2460
- assert_equal "", `diff test/so_datetime.csv datetime.csv`
1969
+ Dir.mktmpdir do |tempdir|
1970
+ datetime_csv_file = File.join(tempdir,"datetime.csv")
1971
+
1972
+ assert oo.to_csv(datetime_csv_file)
1973
+ assert File.exists?(datetime_csv_file)
1974
+ assert_equal "", file_diff('test/files/so_datetime.csv', datetime_csv_file)
1975
+ end
2461
1976
  end
2462
1977
  end
2463
1978
 
@@ -2471,12 +1986,12 @@ where the expected result is
2471
1986
  # Bei den Openoffice-Dateien ist in diesem Feld in der XML-
2472
1987
  # Datei of: als Prefix enthalten, waehrend in dieser Datei
2473
1988
  # irgendetwas mit oooc: als Prefix verwendet wird.
2474
- oo = Openoffice.new(File.join(TESTDIR,'dreimalvier.ods'))
1989
+ oo = Roo::Openoffice.new(File.join(TESTDIR,'dreimalvier.ods'))
2475
1990
  oo.default_sheet = oo.sheets.first
2476
1991
  assert_equal '=SUM([.A1:.D1])', oo.formula('e',1)
2477
1992
  assert_equal '=SUM([.A2:.D2])', oo.formula('e',2)
2478
1993
  assert_equal '=SUM([.A3:.D3])', oo.formula('e',3)
2479
- assert_equal [
1994
+ assert_equal [
2480
1995
  [1,5,'=SUM([.A1:.D1])'],
2481
1996
  [2,5,'=SUM([.A2:.D2])'],
2482
1997
  [3,5,'=SUM([.A3:.D3])'],
@@ -2526,17 +2041,12 @@ where the expected result is
2526
2041
  =end
2527
2042
 
2528
2043
  def test_nil_rows_and_lines_csv
2529
- to do
2530
- 'wieder aktivieren'
2531
- end
2532
- =begin
2533
- x_123
2044
+ # x_123
2534
2045
  if CSV
2535
- oo = Csv.new(File.join(TESTDIR,'Bibelbund.csv'))
2046
+ oo = Roo::Csv.new(File.join(TESTDIR,'Bibelbund.csv'))
2536
2047
  oo.default_sheet = oo.sheets.first
2537
- assert_equal 3, oo.first_row
2048
+ assert_equal 1, oo.first_row
2538
2049
  end
2539
- =end
2540
2050
  end
2541
2051
 
2542
2052
  def test_bug_pfand_from_windows_phone_xlsx
@@ -2557,9 +2067,6 @@ where the expected result is
2557
2067
  end
2558
2068
 
2559
2069
  def test_comment
2560
- to do
2561
- "more spreadsheet types"
2562
- end
2563
2070
  with_each_spreadsheet(:name=>'comments', :format=>[:openoffice,:libreoffice,
2564
2071
  :excelx]) do |oo|
2565
2072
  oo.default_sheet = oo.sheets.first
@@ -2595,4 +2102,745 @@ where the expected result is
2595
2102
  end
2596
2103
  end
2597
2104
 
2105
+ ## PREVIOUSLY SKIPPED
2106
+
2107
+ # don't have these test files so removing. We can easily add in
2108
+ # by modifying with_each_spreadsheet
2109
+ GNUMERIC_ODS = false # do gnumeric with ods files Tests?
2110
+ OPENOFFICEWRITE = false # experimental: write access with OO-Documents
2111
+
2112
+ def test_writeopenoffice
2113
+ if OPENOFFICEWRITE
2114
+ File.cp(File.join(TESTDIR,"numbers1.ods"),
2115
+ File.join(TESTDIR,"numbers2.ods"))
2116
+ File.cp(File.join(TESTDIR,"numbers2.ods"),
2117
+ File.join(TESTDIR,"bak_numbers2.ods"))
2118
+ oo = Openoffice.new(File.join(TESTDIR,"numbers2.ods"))
2119
+ oo.default_sheet = oo.sheets.first
2120
+ oo.first_row.upto(oo.last_row) {|y|
2121
+ oo.first_column.upto(oo.last_column) {|x|
2122
+ unless oo.empty?(y,x)
2123
+ # oo.set(y, x, oo.cell(y,x) + 7) if oo.celltype(y,x) == "float"
2124
+ oo.set(y, x, oo.cell(y,x) + 7) if oo.celltype(y,x) == :float
2125
+ end
2126
+ }
2127
+ }
2128
+ oo.save
2129
+
2130
+ oo1 = Roo::Openoffice.new(File.join(TESTDIR,"numbers2.ods"))
2131
+ oo2 = Roo::Openoffice.new(File.join(TESTDIR,"bak_numbers2.ods"))
2132
+ #p oo2.to_s
2133
+ assert_equal 999, oo2.cell('a',1), oo2.cell('a',1)
2134
+ assert_equal oo2.cell('a',1) + 7, oo1.cell('a',1)
2135
+ assert_equal oo2.cell('b',1)+7, oo1.cell('b',1)
2136
+ assert_equal oo2.cell('c',1)+7, oo1.cell('c',1)
2137
+ assert_equal oo2.cell('d',1)+7, oo1.cell('d',1)
2138
+ assert_equal oo2.cell('a',2)+7, oo1.cell('a',2)
2139
+ assert_equal oo2.cell('b',2)+7, oo1.cell('b',2)
2140
+ assert_equal oo2.cell('c',2)+7, oo1.cell('c',2)
2141
+ assert_equal oo2.cell('d',2)+7, oo1.cell('d',2)
2142
+ assert_equal oo2.cell('e',2)+7, oo1.cell('e',2)
2143
+
2144
+ File.cp(File.join(TESTDIR,"bak_numbers2.ods"),
2145
+ File.join(TESTDIR,"numbers2.ods"))
2146
+ end
2147
+ end
2148
+
2149
+ def test_possible_bug_snowboard_borders #no test file
2150
+ local_only do
2151
+ if EXCEL
2152
+ ex = Excel.new(File.join(TESTDIR,'problem.xls'))
2153
+ ex.default_sheet = ex.sheets.first
2154
+ assert_equal 2, ex.first_row
2155
+ assert_equal 30, ex.last_row
2156
+ assert_equal 'A', ex.first_column_as_letter
2157
+ assert_equal 'J', ex.last_column_as_letter
2158
+ end
2159
+ if EXCELX
2160
+ ex = Excelx.new(File.join(TESTDIR,'problem.xlsx'))
2161
+ ex.default_sheet = ex.sheets.first
2162
+ assert_equal 2, ex.first_row
2163
+ assert_equal 30, ex.last_row
2164
+ assert_equal 'A', ex.first_column_as_letter
2165
+ assert_equal 'J', ex.last_column_as_letter
2166
+ end
2167
+ end
2168
+ end
2169
+
2170
+ def common_possible_bug_snowboard_cells(ss)
2171
+ assert_equal "A.", ss.cell(13,'A'), ss.class
2172
+ assert_equal 147, ss.cell(13,'f'), ss.class
2173
+ assert_equal 152, ss.cell(13,'g'), ss.class
2174
+ assert_equal 156, ss.cell(13,'h'), ss.class
2175
+ assert_equal 158, ss.cell(13,'i'), ss.class
2176
+ assert_equal 160, ss.cell(13,'j'), ss.class
2177
+ assert_equal 164, ss.cell(13,'k'), ss.class
2178
+ assert_equal 168, ss.cell(13,'l'), ss.class
2179
+ assert_equal :string, ss.celltype(13,'m'), ss.class
2180
+ assert_equal "159W", ss.cell(13,'m'), ss.class
2181
+ assert_equal "164W", ss.cell(13,'n'), ss.class
2182
+ assert_equal "168W", ss.cell(13,'o'), ss.class
2183
+ end
2184
+
2185
+ def test_possible_bug_snowboard_cells # no test file
2186
+ local_only do
2187
+ # warten auf Bugfix in parseexcel
2188
+ if EXCEL
2189
+ ex = Roo::Excel.new(File.join(TESTDIR,'problem.xls'))
2190
+ ex.default_sheet = 'Custom X'
2191
+ common_possible_bug_snowboard_cells(ex)
2192
+ end
2193
+ if EXCELX
2194
+ ex = Roo::Excelx.new(File.join(TESTDIR,'problem.xlsx'))
2195
+ ex.default_sheet = 'Custom X'
2196
+ common_possible_bug_snowboard_cells(ex)
2197
+ end
2198
+ end
2199
+ end
2200
+
2201
+ if EXCELX
2202
+ def test_possible_bug_2008_09_13
2203
+ local_only do
2204
+ # war nur in der 1.0.0 Release ein Fehler und sollte mit aktueller
2205
+ # Release nicht mehr auftreten.
2206
+ =begin
2207
+
2208
+ <sst count="46" uniqueCount="39">
2209
+
2210
+ 0<si>
2211
+ <t>Bond</t>
2212
+ <phoneticPr fontId="1" type="noConversion"/>
2213
+ </si>
2214
+
2215
+ 1<si>
2216
+ <t>James</t>
2217
+ <phoneticPr fontId="1" type="noConversion"/>
2218
+ </si>
2219
+
2220
+ 2<si>
2221
+ <t>8659</t>
2222
+ <phoneticPr fontId="1" type="noConversion"/>
2223
+ </si>
2224
+
2225
+ 3<si>
2226
+ <t>12B</t>
2227
+ <phoneticPr fontId="1" type="noConversion"/>
2228
+ </si>
2229
+
2230
+ 4<si>
2231
+ <t>087692</t>
2232
+ <phoneticPr fontId="1" type="noConversion"/>
2233
+ </si>
2234
+
2235
+ 5<si>
2236
+ <t>Rowe</t>
2237
+ <phoneticPr fontId="1" type="noConversion"/>
2238
+ </si>
2239
+
2240
+ 6<si>
2241
+ <t>Karl</t>
2242
+ <phoneticPr fontId="1" type="noConversion"/>
2243
+ </si>
2244
+
2245
+ 7<si>
2246
+ <t>9128</t>
2247
+ <phoneticPr fontId="1" type="noConversion"/>
2248
+ </si>
2249
+
2250
+ 8<si>
2251
+ <t>79A</t>
2252
+ <phoneticPr fontId="1" type="noConversion"/>
2253
+ </si>
2254
+
2255
+ 9<si>
2256
+ <t>Benson</t>
2257
+ <phoneticPr fontId="1" type="noConversion"/>
2258
+ </si>
2259
+
2260
+ 10<si>
2261
+ <t>Cedric</t>
2262
+ <phoneticPr fontId="1" type="noConversion"/>
2263
+ </si>
2264
+
2265
+ 11<si>
2266
+ <t>Greenstreet</t>
2267
+ <phoneticPr fontId="1" type="noConversion"/>
2268
+ </si>
2269
+
2270
+ 12<si>
2271
+ <t>Jenny</t>
2272
+ <phoneticPr fontId="1" type="noConversion"/>
2273
+ </si>
2274
+
2275
+ 13<si>
2276
+ <t>Smith</t>
2277
+ <phoneticPr fontId="1" type="noConversion"/>
2278
+ </si>
2279
+
2280
+ 14<si>
2281
+ <t>Greame</t>
2282
+ <phoneticPr fontId="1" type="noConversion"/>
2283
+ </si>
2284
+
2285
+ 15<si>
2286
+ <t>Lucas</t>
2287
+ <phoneticPr fontId="1" type="noConversion"/>
2288
+ </si>
2289
+
2290
+ 16<si>
2291
+ <t>Ward</t>
2292
+ <phoneticPr fontId="1" type="noConversion"/>
2293
+ </si>
2294
+
2295
+ 17<si>
2296
+ <t>Lee</t>
2297
+ <phoneticPr fontId="1" type="noConversion"/>
2298
+ </si>
2299
+
2300
+ 18<si>
2301
+ <t>Bret</t>
2302
+ <phoneticPr fontId="1" type="noConversion"/>
2303
+ </si>
2304
+
2305
+ 19<si>
2306
+ <t>Warne</t>
2307
+ <phoneticPr fontId="1" type="noConversion"/>
2308
+ </si>
2309
+
2310
+ 20<si>
2311
+ <t>Shane</t>
2312
+ <phoneticPr fontId="1" type="noConversion"/>
2313
+ </si>
2314
+
2315
+ 21<si>
2316
+ <t>782</t>
2317
+ <phoneticPr fontId="1" type="noConversion"/>
2318
+ </si>
2319
+
2320
+ 22<si>
2321
+ <t>876</t>
2322
+ <phoneticPr fontId="1" type="noConversion"/>
2323
+ </si>
2324
+
2325
+ 23<si>
2326
+ <t>9901</t>
2327
+ <phoneticPr fontId="1" type="noConversion"/>
2328
+ </si>
2329
+
2330
+ 24<si>
2331
+ <t>1235</t>
2332
+ <phoneticPr fontId="1" type="noConversion"/>
2333
+ </si>
2334
+
2335
+ 25<si>
2336
+ <t>16547</t>
2337
+ <phoneticPr fontId="1" type="noConversion"/>
2338
+ </si>
2339
+
2340
+ 26<si>
2341
+ <t>7789</t>
2342
+ <phoneticPr fontId="1" type="noConversion"/>
2343
+ </si>
2344
+
2345
+ 27<si>
2346
+ <t>89</t>
2347
+ <phoneticPr fontId="1" type="noConversion"/>
2348
+ </si>
2349
+
2350
+ 28<si>
2351
+ <t>12A</t>
2352
+ <phoneticPr fontId="1" type="noConversion"/>
2353
+ </si>
2354
+
2355
+ 29<si>
2356
+ <t>19A</t>
2357
+ <phoneticPr fontId="1" type="noConversion"/>
2358
+ </si>
2359
+
2360
+ 30<si>
2361
+ <t>256</t>
2362
+ <phoneticPr fontId="1" type="noConversion"/>
2363
+ </si>
2364
+
2365
+ 31<si>
2366
+ <t>129B</t>
2367
+ <phoneticPr fontId="1" type="noConversion"/>
2368
+ </si>
2369
+
2370
+ 32<si>
2371
+ <t>11</t>
2372
+ <phoneticPr fontId="1" type="noConversion"/>
2373
+ </si>
2374
+
2375
+ 33<si>
2376
+ <t>Last Name</t>
2377
+ </si>
2378
+
2379
+ 34<si>
2380
+ <t>First Name</t>
2381
+ </si>
2382
+
2383
+ 35 <si>
2384
+ <t>Middle Name</t>
2385
+ </si>
2386
+
2387
+ 36<si>
2388
+ <t>Resident ID</t>
2389
+ </si>
2390
+
2391
+ 37<si>
2392
+ <t>Room Number</t>
2393
+ </si>
2394
+
2395
+ 38<si>
2396
+ <t>Provider ID #</t>
2397
+ </si>
2398
+ </sst>
2399
+ Hello Thomas,
2400
+ How are you doing ? I am running into this strange issue with roo plugin (1.0.0). The attached
2401
+ spreadsheet has all the cells formatted as "text", when I view in the Excel spreadsheet. But when it
2402
+ get's into roo plugin (set_cell_values method - line 299), the values for the cells 1,1, 1,2, 1,3...1,6
2403
+ show as 'date' instead of 'string'.
2404
+ Because of this my parser is failing to get the proper values from the spreadsheet. Any ideas why
2405
+ the formatting is getting set to the wrong value ?
2406
+ Even stranger is if I save this file as ".XLS" and parse it the cells parse out fine as they are treated as
2407
+ 'string' instead of 'date'.
2408
+ This attached file is the newer format of Microsoft Excel (.xlsx).
2409
+
2410
+ =end
2411
+ xx = Roo::Excelx.new(File.join(TESTDIR,'sample_file_2008-09-13.xlsx'))
2412
+ assert_equal 1, xx.sheets.size
2413
+
2414
+ assert_equal 1, xx.first_row
2415
+ assert_equal 9, xx.last_row # 9 ist richtig. Es sind zwar 44 Zeilen definiert, aber der Rest hat keinen Inhalt
2416
+ assert_equal 1, xx.first_column
2417
+ assert_equal 6, xx.last_column
2418
+ assert_equal 'A', xx.first_column_as_letter
2419
+ assert_equal 'F', xx.last_column_as_letter
2420
+
2421
+ assert_nothing_raised() {
2422
+ puts xx.info
2423
+ }
2424
+ p xx.cell(1,1)
2425
+ p xx.cell(1,2)
2426
+ p xx.cell(1,3)
2427
+ p xx.cell(1,4)
2428
+ p xx.cell(1,5)
2429
+ p xx.cell(1,6)
2430
+ xx.default_sheet = xx.sheets.first
2431
+
2432
+ assert_equal 'Last Name', xx.cell('A',1)
2433
+
2434
+ 1.upto(6) do |col|
2435
+ assert_equal :string, xx.celltype(1,col)
2436
+ end
2437
+ #for col in (1..6)
2438
+ # assert_equal "1234", xx.cell(1,col)
2439
+ #end
2440
+ end
2441
+ end
2442
+ end
2443
+
2444
+ #-- bei diesen Test bekomme ich seltsamerweise einen Fehler can't allocate
2445
+ #-- memory innerhalb der zip-Routinen => erstmal deaktiviert
2446
+ def test_huge_table_timing_10_000_openoffice #no test file
2447
+ local_only do
2448
+ with_each_spreadsheet(:name=>'/home/tp/ruby-test/too-testing/speedtest_10000') do |oo|
2449
+ if LONG_RUN
2450
+ assert_nothing_raised(Timeout::Error) {
2451
+ Timeout::timeout(3.minutes) do |timeout_length|
2452
+ # process every cell
2453
+ sum = 0
2454
+ oo.sheets.each {|sheet|
2455
+ oo.default_sheet = sheet
2456
+ for row in oo.first_row..oo.last_row do
2457
+ for col in oo.first_column..oo.last_column do
2458
+ c = oo.cell(row,col)
2459
+ sum += c.length if c
2460
+ end
2461
+ end
2462
+ p sum
2463
+ assert sum > 0
2464
+ }
2465
+ end
2466
+ }
2467
+ end
2468
+ end
2469
+ end
2470
+ end
2471
+
2472
+ def test_bug_encoding_exported_from_google
2473
+ if EXCEL
2474
+ local_only do
2475
+ xl = Roo::Excel.new(File.join(TESTDIR,"numbers1_from_google.xls"))
2476
+ xl.default_sheet = xl.sheets.first
2477
+ assert_equal 'test', xl.cell(2,'F')
2478
+ end
2479
+ end
2480
+ end
2481
+
2482
+ def test_invalid_iconv_from_ms
2483
+ local_only do
2484
+ #TODO: does only run within a darwin-environment
2485
+ if RUBY_PLATFORM.downcase =~ /darwin/
2486
+ assert_nothing_raised() {
2487
+ Roo::Excel.new(File.join(TESTDIR,"ms.xls"))
2488
+ }
2489
+ end
2490
+ end
2491
+ end
2492
+
2493
+ # def test_false_encoding
2494
+ # ex = Roo::Excel.new(File.join(TESTDIR,'false_encoding.xls'))
2495
+ # ex.default_sheet = ex.sheets.first
2496
+ # assert_equal "Sheet1", ex.sheets.first
2497
+ # ex.first_row.upto(ex.last_row) do |row|
2498
+ # ex.first_column.upto(ex.last_column) do |col|
2499
+ # content = ex.cell(row,col)
2500
+ # puts "#{row}/#{col}"
2501
+ # #puts content if ! ex.empty?(row,col) or ex.formula?(row,col)
2502
+ # if ex.formula?(row,col)
2503
+ # #! ex.empty?(row,col)
2504
+ # puts content
2505
+ # end
2506
+ # end
2507
+ # end
2508
+ # end
2509
+
2510
+ def test_simple_google
2511
+ if GOOGLE
2512
+ go = Roo::Google.new("egal")
2513
+ assert_equal "42", go.cell(1,1)
2514
+ end
2515
+ end
2516
+ def test_bug_c2 # no test file
2517
+ local_only do
2518
+ with_each_spreadsheet(:name=>'problem', :foramt=>:excel) do |oo|
2519
+ expected = ['Supermodel X','T6','Shaun White','Jeremy','Custom',
2520
+ 'Warhol','Twin','Malolo','Supermodel','Air','Elite',
2521
+ 'King','Dominant','Dominant Slick','Blunt','Clash',
2522
+ 'Bullet','Tadashi Fuse','Jussi','Royale','S-Series',
2523
+ 'Fish','Love','Feelgood ES','Feelgood','GTwin','Troop',
2524
+ 'Lux','Stigma','Feather','Stria','Alpha','Feelgood ICS']
2525
+ result = oo.sheets[2..oo.sheets.length].map do |s|
2526
+ #(13..13).each do |s|
2527
+ #puts "#{name} (sheet: #{s})"
2528
+ #assert_equal "whatever (sheet: 13)", "#{name} (sheet: #{s})"
2529
+ oo.default_sheet = s
2530
+ oo.cell(2,'C')
2531
+ end
2532
+ assert_equal expected, result
2533
+ end
2534
+ end
2535
+ end
2536
+
2537
+ def test_bug_c2_parseexcel #no test file
2538
+ local_only do
2539
+ #-- this is OK
2540
+ @workbook = Spreadsheet::ParseExcel.parse(File.join(TESTDIR,"problem.xls"))
2541
+ worksheet = @workbook.worksheet(11)
2542
+ skip = 0
2543
+ line = 1
2544
+ row = 2
2545
+ col = 3
2546
+ worksheet.each(skip) { |row_par|
2547
+ if line == row
2548
+ if row_par == nil
2549
+ raise "nil"
2550
+ end
2551
+ cell = row_par.at(col-1)
2552
+ assert cell, "cell should not be nil"
2553
+ assert_equal "Air", cell.to_s('utf-8')
2554
+ end
2555
+ line += 1
2556
+ }
2557
+ #-- worksheet 12 does not work
2558
+ @workbook = Spreadsheet::ParseExcel.parse(File.join(TESTDIR,"problem.xls"))
2559
+ worksheet = @workbook.worksheet(12)
2560
+ skip = 0
2561
+ line = 1
2562
+ row = 2
2563
+ col = 3
2564
+ worksheet.each(skip) { |row_par|
2565
+ if line == row
2566
+ if row_par == nil
2567
+ raise "nil"
2568
+ end
2569
+ cell = row_par.at(col-1)
2570
+ assert cell, "cell should not be nil"
2571
+ assert_equal "Elite", cell.to_s('utf-8')
2572
+ end
2573
+ line += 1
2574
+ }
2575
+ end
2576
+ end
2577
+
2578
+ def test_bug_c2_excelx #no test file
2579
+ local_only do
2580
+ expected = ['Supermodel X','T6','Shaun White','Jeremy','Custom',
2581
+ 'Warhol','Twin','Malolo','Supermodel','Air','Elite',
2582
+ 'King','Dominant','Dominant Slick','Blunt','Clash',
2583
+ 'Bullet','Tadashi Fuse','Jussi','Royale','S-Series',
2584
+ 'Fish','Love','Feelgood ES','Feelgood','GTwin','Troop',
2585
+ 'Lux','Stigma','Feather','Stria','Alpha','Feelgood ICS']
2586
+ @e = Roo::Excelx.new(File.join(TESTDIR,"problem.xlsx"))
2587
+ result = @e.sheets[2..@e.sheets.length].map do |s|
2588
+ @e.default_sheet = s
2589
+ # assert_equal "A.",@e.cell('a',13)
2590
+ #puts "#{name} (sheet: #{s})"
2591
+ #assert_equal :string, @e.celltype('c',2)
2592
+ #assert_equal "Vapor (sheet: Vapor)", "#{name} (sheet: #{@e.sheets.first})"
2593
+ assert @e.cell(2,'c')
2594
+ @e.cell(2,'C')
2595
+ end
2596
+ assert_equal expected, result
2597
+
2598
+ @e = Roo::Excelx.new(File.join(TESTDIR,"problem.xlsx"))
2599
+ #@e.sheets[2..@e.sheets.length].each do |s|
2600
+ (13..13).each do |s|
2601
+ @e.default_sheet = s
2602
+ name = @e.cell(2,'C')
2603
+ #puts "#{name} (sheet: #{s})"
2604
+ assert_equal "Elite (sheet: 13)", "#{name} (sheet: #{s})"
2605
+ end
2606
+ end
2607
+ end
2608
+
2609
+ def test_compare_csv_excelx_excel #no test file
2610
+ if EXCELX
2611
+ # parseexcel bug
2612
+ local_only do
2613
+ s1 = Roo::Excel.new(File.join(TESTDIR,"problem.xls"))
2614
+ s2 = Roo::Excelx.new(File.join(TESTDIR,"problem.xlsx"))
2615
+ s1.sheets.each {|sh| #TODO:
2616
+ s1.default_sheet = sh
2617
+ s2.default_sheet = sh
2618
+ File.delete_if_exist("/tmp/problem.csv")
2619
+ File.delete_if_exist("/tmp/problemx.csv")
2620
+ assert s1.to_csv("/tmp/problem.csv")
2621
+ assert s2.to_csv("/tmp/problemx.csv")
2622
+ assert File.exists?("/tmp/problem.csv")
2623
+ assert File.exists?("/tmp/problemx.csv")
2624
+ assert_equal "", `diff /tmp/problem.csv /tmp/problemx.csv`, "Unterschied in Sheet #{sh} #{s1.sheets.index(sh)}"
2625
+ }
2626
+ end
2627
+ end
2628
+ end
2629
+
2630
+ def test_problemx_csv_imported #no test file
2631
+ if EXCEL
2632
+ local_only do
2633
+ # wieder eingelesene CSV-Datei aus obigem Test
2634
+ # muss identisch mit problem.xls sein
2635
+ # Importieren aus csv-Datei muss manuell gemacht werden
2636
+ ex = Roo::Excel.new(File.join(TESTDIR,"problem.xls"))
2637
+ cs = Roo::Excel.new(File.join(TESTDIR,"problemx_csv_imported.xls"))
2638
+ # nur das erste sheet betrachten
2639
+ ex.default_sheet = ex.sheets.first
2640
+ cs.default_sheet = cs.sheets.first
2641
+ ex.first_row.upto(ex.last_row) do |row|
2642
+ ex.first_column.upto(ex.last_column) do |col|
2643
+ assert_equal ex.cell(row,col), cs.cell(row,col), "cell #{row}/#{col} does not match '#{ex.cell(row,col)}' '#{cs.cell(row,col)}'"
2644
+ assert_equal ex.celltype(row,col), cs.celltype(row,col), "celltype #{row}/#{col} does not match"
2645
+ assert_equal ex.empty?(row,col), cs.empty?(row,col), "empty? #{row}/#{col} does not match"
2646
+ if defined? excel_supports_formulas
2647
+ assert_equal ex.formula?(row,col), cs.formula?(row,col), "formula? #{row}/#{col} does not match"
2648
+ assert_equal ex.formula(row,col), cs.formula(row,col), "formula #{row}/#{col} does not match"
2649
+ end
2650
+ end
2651
+ end
2652
+ cs.first_row.upto(cs.last_row) do |row|
2653
+ cs.first_column.upto(cs.last_column) do |col|
2654
+ assert_equal ex.cell(row,col), cs.cell(row,col), "cell #{row}/#{col} does not match '#{ex.cell(row,col)}' '#{cs.cell(row,col)}'"
2655
+ assert_equal ex.celltype(row,col), cs.celltype(row,col), "celltype #{row}/#{col} does not match"
2656
+ assert_equal ex.empty?(row,col), cs.empty?(row,col), "empty? #{row}/#{col} does not match"
2657
+ if defined? excel_supports_formulas
2658
+ assert_equal ex.formula?(row,col), cs.formula?(row,col), "formula? #{row}/#{col} does not match"
2659
+ assert_equal ex.formula(row,col), cs.formula(row,col), "formula #{row}/#{col} does not match"
2660
+ end
2661
+ end
2662
+ end
2663
+ end
2664
+ end
2665
+ end
2666
+
2667
+ def test_open_from_uri
2668
+ if ONLINE
2669
+ if OPENOFFICE
2670
+ assert_raises(RuntimeError) {
2671
+ Roo::Openoffice.new("http://gibbsnichtdomainxxxxx.com/file.ods")
2672
+ }
2673
+ end
2674
+ if EXCEL
2675
+ assert_raises(RuntimeError) {
2676
+ Roo::Excel.new("http://gibbsnichtdomainxxxxx.com/file.xls")
2677
+ }
2678
+ end
2679
+ if EXCELX
2680
+ assert_raises(RuntimeError) {
2681
+ Roo::Excelx.new("http://gibbsnichtdomainxxxxx.com/file.xlsx")
2682
+ }
2683
+ end
2684
+ end
2685
+ end
2686
+
2687
+ def test_to_ascii_openoffice #file does not exist
2688
+ local_only do
2689
+ with_each_spreadsheet(:name=>'verysimple_spreadsheet', :format=>:openoffice) do |oo|
2690
+ oo.default_sheet = oo.sheets.first
2691
+ expected="
2692
+ A | B | C |
2693
+ -------+-------+------|
2694
+ 7| 8| 9|
2695
+ -------+-------+------|
2696
+ 4| 5| 6|
2697
+ -------+-------+------|
2698
+ 1| 2| 3|
2699
+ ----------------------/
2700
+ "
2701
+ assert_equal expected, oo.to_ascii
2702
+ end
2703
+ end
2704
+ end
2705
+
2706
+ # def test_soap_server
2707
+ # #threads = []
2708
+ # #threads << Thread.new("serverthread") do
2709
+ # fork do
2710
+ # p "serverthread started"
2711
+ # puts "in child, pid = #$$"
2712
+ # puts `/usr/bin/ruby rooserver.rb`
2713
+ # p "serverthread finished"
2714
+ # end
2715
+ # #threads << Thread.new("clientthread") do
2716
+ # p "clientthread started"
2717
+ # sleep 10
2718
+ # proxy = SOAP::RPC::Driver.new("http://localhost:12321","spreadsheetserver")
2719
+ # proxy.add_method('cell','row','col')
2720
+ # proxy.add_method('officeversion')
2721
+ # proxy.add_method('last_row')
2722
+ # proxy.add_method('last_column')
2723
+ # proxy.add_method('first_row')
2724
+ # proxy.add_method('first_column')
2725
+ # proxy.add_method('sheets')
2726
+ # proxy.add_method('set_default_sheet','s')
2727
+ # proxy.add_method('ferien_fuer_region', 'region')
2728
+
2729
+ # sheets = proxy.sheets
2730
+ # p sheets
2731
+ # proxy.set_default_sheet(sheets.first)
2732
+
2733
+ # assert_equal 1, proxy.first_row
2734
+ # assert_equal 1, proxy.first_column
2735
+ # assert_equal 187, proxy.last_row
2736
+ # assert_equal 7, proxy.last_column
2737
+ # assert_equal 42, proxy.cell('C',8)
2738
+ # assert_equal 43, proxy.cell('F',12)
2739
+ # assert_equal "1.0", proxy.officeversion
2740
+ # p "clientthread finished"
2741
+ # #end
2742
+ # #threads.each {|t| t.join }
2743
+ # puts "fertig"
2744
+ # Process.kill("INT",pid)
2745
+ # pid = Process.wait
2746
+ # puts "child terminated, pid= #{pid}, status= #{$?.exitstatus}"
2747
+ # end
2748
+
2749
+ def split_coord(s)
2750
+ letter = ""
2751
+ number = 0
2752
+ i = 0
2753
+ while i<s.length and "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".include?(s[i,1])
2754
+ letter += s[i,1]
2755
+ i+=1
2756
+ end
2757
+ while i<s.length and "01234567890".include?(s[i,1])
2758
+ number = number*10 + s[i,1].to_i
2759
+ i+=1
2760
+ end
2761
+ if letter=="" or number==0
2762
+ raise ArgumentError
2763
+ end
2764
+ return letter,number
2765
+ end
2766
+
2767
+ #def sum(s,expression)
2768
+ # arg = expression.split(':')
2769
+ # b,z = split_coord(arg[0])
2770
+ # first_row = z
2771
+ # first_col = Openoffice.letter_to_number(b)
2772
+ # b,z = split_coord(arg[1])
2773
+ # last_row = z
2774
+ # last_col = Openoffice.letter_to_number(b)
2775
+ # result = 0
2776
+ # first_row.upto(last_row) {|row|
2777
+ # first_col.upto(last_col) {|col|
2778
+ # result = result + s.cell(row,col)
2779
+ # }
2780
+ # }
2781
+ # result
2782
+ #end
2783
+
2784
+ #def test_dsl
2785
+ # s = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
2786
+ # s.default_sheet = s.sheets.first
2787
+ #
2788
+ # s.set 'a',1, 5
2789
+ # s.set 'b',1, 3
2790
+ # s.set 'c',1, 7
2791
+ # s.set('a',2, s.cell('a',1)+s.cell('b',1))
2792
+ # assert_equal 8, s.cell('a',2)
2793
+ #
2794
+ # assert_equal 15, sum(s,'A1:C1')
2795
+ # end
2796
+
2797
+ #def test_create_spreadsheet1
2798
+ # name = File.join(TESTDIR,'createdspreadsheet.ods')
2799
+ # rm(name) if File.exists?(File.join(TESTDIR,'createdspreadsheet.ods'))
2800
+ # # anlegen, falls noch nicht existierend
2801
+ # s = Openoffice.new(name,true)
2802
+ # assert File.exists?(name)
2803
+ #end
2804
+
2805
+ #def test_create_spreadsheet2
2806
+ # # anlegen, falls noch nicht existierend
2807
+ # s = Openoffice.new(File.join(TESTDIR,"createdspreadsheet.ods"),true)
2808
+ # s.set 'a',1,42
2809
+ # s.set 'b',1,43
2810
+ # s.set 'c',1,44
2811
+ # s.save
2812
+ #
2813
+ # t = Openoffice.new(File.join(TESTDIR,"createdspreadsheet.ods"))
2814
+ # assert_equal 42, t.cell(1,'a')
2815
+ # assert_equal 43, t.cell('b',1)
2816
+ # assert_equal 44, t.cell('c',3)
2817
+ #end
2818
+
2819
+ # We don't have the bode-v1.xlsx test file
2820
+ # #TODO: xlsx-Datei anpassen!
2821
+ # def test_excelx_open_from_uri_and_zipped
2822
+ # #TODO: gezippte xlsx Datei online zum Testen suchen
2823
+ # if EXCELX
2824
+ # if ONLINE
2825
+ # url = 'http://stiny-leonhard.de/bode-v1.xlsx.zip'
2826
+ # excel = Roo::Excelx.new(url, :zip)
2827
+ # assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
2828
+ # end
2829
+ # end
2830
+ # end
2831
+
2832
+ # def test_excelx_zipped
2833
+ # # TODO: bode...xls bei Gelegenheit nach .xlsx konverieren lassen und zippen!
2834
+ # if EXCELX
2835
+ # # diese Datei gibt es noch nicht gezippt
2836
+ # excel = Roo::Excelx.new(File.join(TESTDIR,"bode-v1.xlsx.zip"), :zip)
2837
+ # assert excel
2838
+ # assert_raises(ArgumentError) {
2839
+ # assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
2840
+ # }
2841
+ # excel.default_sheet = excel.sheets.first
2842
+ # assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
2843
+ # end
2844
+ # end
2845
+
2598
2846
  end # class