roo 1.9.7 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +13 -1
- data/README.txt +2 -0
- data/bin/roo +1 -2
- data/lib/roo.rb +4 -1
- data/lib/roo/.csv.rb.swp +0 -0
- data/lib/roo/csv.rb +117 -0
- data/lib/roo/excel.rb +14 -5
- data/lib/roo/excelx.rb +235 -37
- data/lib/roo/generic_spreadsheet.rb +23 -4
- data/lib/roo/openoffice.rb +145 -41
- data/test/Pfand_from_windows_phone.xlsx +0 -0
- data/test/comments.ods +0 -0
- data/test/comments.xls +0 -0
- data/test/comments.xlsx +0 -0
- data/test/csvtypes.csv +1 -0
- data/test/named_cells.xls +0 -0
- data/test/named_cells.xlsx +0 -0
- data/test/numbers1.csv +18 -0
- data/test/test_roo.rb +444 -223
- metadata +31 -22
- data/PostInstall.txt +0 -1
- data/a.xls +0 -0
- data/csv8532 +0 -862
- data/test/benchmark1.rb +0 -43
- data/tmp.xls +0 -0
@@ -32,6 +32,23 @@ class GenericSpreadsheet
|
|
32
32
|
tmpdir
|
33
33
|
end
|
34
34
|
|
35
|
+
def self.split_coordinate(str)
|
36
|
+
letter,number = GenericSpreadsheet.split_coord(str)
|
37
|
+
x = letter_to_number(letter)
|
38
|
+
y = number
|
39
|
+
return y, x
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.split_coord(s)
|
43
|
+
if s =~ /([a-zA-Z]+)([0-9]+)/
|
44
|
+
letter = $1
|
45
|
+
number = $2.to_i
|
46
|
+
else
|
47
|
+
raise ArgumentError
|
48
|
+
end
|
49
|
+
return letter, number
|
50
|
+
end
|
51
|
+
|
35
52
|
|
36
53
|
public
|
37
54
|
|
@@ -332,9 +349,6 @@ class GenericSpreadsheet
|
|
332
349
|
initialize(@spreadsheetkey,@user,@password)
|
333
350
|
else
|
334
351
|
initialize(@filename)
|
335
|
-
to do
|
336
|
-
'was ist mit weiteren Parametern bei initialize'
|
337
|
-
end
|
338
352
|
end
|
339
353
|
self.default_sheet = ds
|
340
354
|
#@first_row = @last_row = @first_column = @last_column = nil
|
@@ -428,6 +442,8 @@ class GenericSpreadsheet
|
|
428
442
|
end
|
429
443
|
end
|
430
444
|
|
445
|
+
=begin
|
446
|
+
#TODO: hier entfernen
|
431
447
|
# returns each formula in the selected sheet as an array of elements
|
432
448
|
# [row, col, formula]
|
433
449
|
def formulas(sheet=nil)
|
@@ -445,6 +461,7 @@ class GenericSpreadsheet
|
|
445
461
|
}
|
446
462
|
theformulas
|
447
463
|
end
|
464
|
+
=end
|
448
465
|
|
449
466
|
protected
|
450
467
|
|
@@ -453,6 +470,7 @@ class GenericSpreadsheet
|
|
453
470
|
'.ods' => 'Openoffice.new',
|
454
471
|
'.xls' => 'Excel.new',
|
455
472
|
'.xlsx' => 'Excelx.new',
|
473
|
+
'.csv' => 'Csv.new',
|
456
474
|
}
|
457
475
|
if packed == :zip
|
458
476
|
# lalala.ods.zip => lalala.ods
|
@@ -461,7 +479,7 @@ class GenericSpreadsheet
|
|
461
479
|
filename = File.basename(filename,File.extname(filename))
|
462
480
|
end
|
463
481
|
case ext
|
464
|
-
when '.ods', '.xls', '.xlsx'
|
482
|
+
when '.ods', '.xls', '.xlsx', '.csv'
|
465
483
|
correct_class = "use #{new_expression[ext]} to handle #{ext} spreadsheet files"
|
466
484
|
else
|
467
485
|
raise "unknown file type: #{ext}"
|
@@ -678,4 +696,5 @@ class GenericSpreadsheet
|
|
678
696
|
s = content
|
679
697
|
sprintf("%02d:%02d:%02d",h,m,s)
|
680
698
|
end
|
699
|
+
|
681
700
|
end
|
data/lib/roo/openoffice.rb
CHANGED
@@ -4,7 +4,7 @@ require 'zip/zipfilesystem'
|
|
4
4
|
require 'date'
|
5
5
|
require 'nokogiri'
|
6
6
|
require 'cgi'
|
7
|
-
|
7
|
+
require 'pp' #TODO
|
8
8
|
class Openoffice < GenericSpreadsheet
|
9
9
|
|
10
10
|
@@nr = 0
|
@@ -49,13 +49,17 @@ class Openoffice < GenericSpreadsheet
|
|
49
49
|
@style_defaults = Hash.new { |h,k| h[k] = [] }
|
50
50
|
@style_definitions = Hash.new
|
51
51
|
@header_line = 1
|
52
|
-
@
|
52
|
+
@label = Hash.new
|
53
|
+
@labels_read = false
|
54
|
+
@comment = Hash.new
|
55
|
+
@comments_read = Hash.new
|
53
56
|
end
|
54
57
|
|
55
58
|
def method_missing(m,*args)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
+
read_labels unless @labels_read
|
60
|
+
# is method name a label name
|
61
|
+
if @label.has_key?(m.to_s)
|
62
|
+
row,col = label(m.to_s)
|
59
63
|
cell(row,col)
|
60
64
|
else
|
61
65
|
# call super for methods like #a1
|
@@ -89,12 +93,14 @@ class Openoffice < GenericSpreadsheet
|
|
89
93
|
return nil
|
90
94
|
else
|
91
95
|
# return @formula[sheet][[row,col]]["oooc:".length..-1]
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
96
|
+
# TODO:
|
97
|
+
#str = @formula[sheet][[row,col]]
|
98
|
+
#if str.include? ':'
|
99
|
+
#return str[str.index(':')+1..-1]
|
100
|
+
#else
|
101
|
+
#return str
|
102
|
+
#end
|
103
|
+
@formula[sheet][[row,col]]
|
98
104
|
end
|
99
105
|
end
|
100
106
|
|
@@ -105,7 +111,21 @@ class Openoffice < GenericSpreadsheet
|
|
105
111
|
row,col = normalize(row,col)
|
106
112
|
formula(row,col) != nil
|
107
113
|
end
|
108
|
-
|
114
|
+
|
115
|
+
# returns each formula in the selected sheet as an array of elements
|
116
|
+
# [row, col, formula]
|
117
|
+
def formulas(sheet=nil)
|
118
|
+
sheet = @default_sheet unless sheet
|
119
|
+
read_cells(sheet) unless @cells_read[sheet]
|
120
|
+
if @formula[sheet]
|
121
|
+
@formula[sheet].each.collect do |elem|
|
122
|
+
[elem[0][0], elem[0][1], elem[1]]
|
123
|
+
end
|
124
|
+
else
|
125
|
+
[]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
109
129
|
class Font
|
110
130
|
attr_accessor :bold, :italic, :underline
|
111
131
|
|
@@ -193,17 +213,65 @@ class Openoffice < GenericSpreadsheet
|
|
193
213
|
|
194
214
|
# returns the row,col values of the labelled cell
|
195
215
|
# (nil,nil) if label is not defined
|
196
|
-
|
197
|
-
|
198
|
-
|
216
|
+
def label(labelname)
|
217
|
+
read_labels unless @labels_read
|
218
|
+
unless @label.size > 0
|
219
|
+
return nil,nil,nil
|
220
|
+
end
|
221
|
+
if @label.has_key? labelname
|
222
|
+
return @label[labelname][1].to_i,
|
223
|
+
GenericSpreadsheet.letter_to_number(@label[labelname][2]),
|
224
|
+
@label[labelname][0]
|
225
|
+
else
|
226
|
+
return nil,nil,nil
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
# Returns an array which all labels. Each element is an array with
|
231
|
+
# [labelname, [sheetname,row,col]]
|
232
|
+
def labels(sheet=nil)
|
233
|
+
read_labels unless @labels_read
|
234
|
+
result = []
|
235
|
+
@label.each do |label|
|
236
|
+
result << [ label[0], # name
|
237
|
+
[ label[1][1].to_i, # row
|
238
|
+
GenericSpreadsheet.letter_to_number(label[1][2]), # column
|
239
|
+
label[1][0], # sheet
|
240
|
+
] ]
|
241
|
+
end
|
242
|
+
result
|
243
|
+
end
|
244
|
+
|
245
|
+
# returns the comment at (row/col)
|
246
|
+
# nil if there is no comment
|
247
|
+
def comment(row,col,sheet=nil)
|
199
248
|
sheet = @default_sheet unless sheet
|
200
249
|
read_cells(sheet) unless @cells_read[sheet]
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
250
|
+
row,col = normalize(row,col)
|
251
|
+
return nil unless @comment[sheet]
|
252
|
+
@comment[sheet][[row,col]]
|
253
|
+
end
|
254
|
+
|
255
|
+
# true, if there is a comment
|
256
|
+
def comment?(row,col,sheet=nil)
|
257
|
+
sheet = @default_sheet unless sheet
|
258
|
+
read_cells(sheet) unless @cells_read[sheet]
|
259
|
+
row,col = normalize(row,col)
|
260
|
+
comment(row,col) != nil
|
261
|
+
end
|
262
|
+
|
263
|
+
|
264
|
+
# returns each comment in the selected sheet as an array of elements
|
265
|
+
# [row, col, comment]
|
266
|
+
def comments(sheet=nil)
|
267
|
+
sheet = @default_sheet unless sheet
|
268
|
+
read_comments(sheet) unless @comments_read[sheet]
|
269
|
+
if @comment[sheet]
|
270
|
+
@comment[sheet].each.collect do |elem|
|
271
|
+
[elem[0][0],elem[0][1],elem[1]]
|
272
|
+
end
|
205
273
|
else
|
206
|
-
|
274
|
+
[]
|
207
275
|
end
|
208
276
|
end
|
209
277
|
|
@@ -222,8 +290,15 @@ class Openoffice < GenericSpreadsheet
|
|
222
290
|
@cell_type[sheet] = {} unless @cell_type[sheet]
|
223
291
|
@cell_type[sheet][key] = Openoffice.oo_type_2_roo_type(vt)
|
224
292
|
@formula[sheet] = {} unless @formula[sheet]
|
225
|
-
|
226
|
-
|
293
|
+
if formula
|
294
|
+
['of:', 'oooc:'].each do |prefix|
|
295
|
+
if formula[0,prefix.length] == prefix
|
296
|
+
formula = formula[prefix.length..-1]
|
297
|
+
end
|
298
|
+
end
|
299
|
+
@formula[sheet][key] = formula
|
300
|
+
end
|
301
|
+
@cell[sheet] = {} unless @cell[sheet]
|
227
302
|
@style[sheet] = {} unless @style[sheet]
|
228
303
|
@style[sheet][key] = style_name
|
229
304
|
case @cell_type[sheet][key]
|
@@ -262,23 +337,6 @@ class Openoffice < GenericSpreadsheet
|
|
262
337
|
raise ArgumentError, "Error: sheet '#{sheet||'nil'}' not valid" if @default_sheet == nil and sheet==nil
|
263
338
|
raise RangeError unless self.sheets.include? sheet
|
264
339
|
|
265
|
-
#-
|
266
|
-
# Labels
|
267
|
-
# should be factored out in separate method because labels are global
|
268
|
-
# to the whole spreadsheet file (and not to specific sheet)
|
269
|
-
#+
|
270
|
-
@doc.xpath("//table:named-range").each do |ne|
|
271
|
-
#-
|
272
|
-
# $Sheet1.$C$5
|
273
|
-
#+
|
274
|
-
name = ne.attribute('name').to_s
|
275
|
-
sheetname,coords = ne.attribute('cell-range-address').to_s.split('.')
|
276
|
-
col = coords.split('$')[1]
|
277
|
-
row = coords.split('$')[2]
|
278
|
-
sheetname = sheetname[1..-1] if sheetname[0,1] == '$'
|
279
|
-
@labels[name] = [sheetname,row,col]
|
280
|
-
end
|
281
|
-
|
282
340
|
@doc.xpath("//*[local-name()='table']").each do |ws|
|
283
341
|
if sheet == ws['name']
|
284
342
|
sheet_found = true
|
@@ -304,6 +362,30 @@ class Openoffice < GenericSpreadsheet
|
|
304
362
|
# insert \n if there is more than one paragraph
|
305
363
|
para_count = 0
|
306
364
|
cell.children.each do |str|
|
365
|
+
# begin comments
|
366
|
+
=begin
|
367
|
+
- <table:table-cell office:value-type="string">
|
368
|
+
- <office:annotation office:display="true" draw:style-name="gr1" draw:text-style-name="P1" svg:width="1.1413in" svg:height="0.3902in" svg:x="2.0142in" svg:y="0in" draw:caption-point-x="-0.2402in" draw:caption-point-y="0.5661in">
|
369
|
+
<dc:date>2011-09-20T00:00:00</dc:date>
|
370
|
+
<text:p text:style-name="P1">Kommentar fuer B4</text:p>
|
371
|
+
</office:annotation>
|
372
|
+
<text:p>B4 (mit Kommentar)</text:p>
|
373
|
+
</table:table-cell>
|
374
|
+
=end
|
375
|
+
if str.name == 'annotation'
|
376
|
+
str.children.each do |annotation|
|
377
|
+
if annotation.name == 'p'
|
378
|
+
# @comment ist ein Hash mit Sheet als Key (wie bei @cell)
|
379
|
+
# innerhalb eines Elements besteht ein Eintrag aus einem
|
380
|
+
# weiteren Hash mit Key [row,col] und dem eigentlichen
|
381
|
+
# Kommentartext als Inhalt
|
382
|
+
@comment[sheet] = Hash.new unless @comment[sheet]
|
383
|
+
key = [row,col]
|
384
|
+
@comment[sheet][key] = annotation.text
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|
388
|
+
# end comments
|
307
389
|
if str.name == 'p'
|
308
390
|
v = str.content
|
309
391
|
str_v += "\n" if para_count > 0
|
@@ -348,7 +430,7 @@ class Openoffice < GenericSpreadsheet
|
|
348
430
|
end # if skip
|
349
431
|
set_cell_values(sheet,col,row,0,v,vt,formula,cell,str_v,style_name)
|
350
432
|
col += 1
|
351
|
-
end
|
433
|
+
end
|
352
434
|
row += 1
|
353
435
|
col = 1
|
354
436
|
end
|
@@ -362,8 +444,30 @@ class Openoffice < GenericSpreadsheet
|
|
362
444
|
raise RangeError
|
363
445
|
end
|
364
446
|
@cells_read[sheet] = true
|
447
|
+
@comments_read[sheet] = true
|
365
448
|
end
|
366
449
|
|
450
|
+
# Only calls read_cells because GenericSpreadsheet calls read_comments
|
451
|
+
# whereas the reading of comments is done in read_cells for Openoffice-objects
|
452
|
+
def read_comments(sheet=nil)
|
453
|
+
read_cells(sheet)
|
454
|
+
end
|
455
|
+
|
456
|
+
def read_labels
|
457
|
+
@doc.xpath("//table:named-range").each do |ne|
|
458
|
+
#-
|
459
|
+
# $Sheet1.$C$5
|
460
|
+
#+
|
461
|
+
name = ne.attribute('name').to_s
|
462
|
+
sheetname,coords = ne.attribute('cell-range-address').to_s.split('.')
|
463
|
+
col = coords.split('$')[1]
|
464
|
+
row = coords.split('$')[2]
|
465
|
+
sheetname = sheetname[1..-1] if sheetname[0,1] == '$'
|
466
|
+
@label[name] = [sheetname,row,col]
|
467
|
+
end
|
468
|
+
@labels_read = true
|
469
|
+
end
|
470
|
+
|
367
471
|
def read_styles(style_elements)
|
368
472
|
@style_definitions['Default'] = Openoffice::Font.new
|
369
473
|
style_elements.each do |style|
|
@@ -375,7 +479,7 @@ class Openoffice < GenericSpreadsheet
|
|
375
479
|
font.italic = properties.attributes['font-style']
|
376
480
|
font.underline = properties.attributes['text-underline-style']
|
377
481
|
@style_definitions[style_name] = font
|
378
|
-
end
|
482
|
+
end
|
379
483
|
end
|
380
484
|
end
|
381
485
|
|
Binary file
|
data/test/comments.ods
ADDED
Binary file
|
data/test/comments.xls
ADDED
Binary file
|
data/test/comments.xlsx
ADDED
Binary file
|
data/test/csvtypes.csv
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1,2,Mayer
|
Binary file
|
Binary file
|
data/test/numbers1.csv
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
1,2,3,4,10,,
|
2
|
+
5,6,7,8,9,"test",11
|
3
|
+
,,,,,,
|
4
|
+
10,11,12,13,14,,
|
5
|
+
11/21/61,,,,,,
|
6
|
+
"tata",,,,,,
|
7
|
+
,,,,,,
|
8
|
+
,,"thisisc8",,,,
|
9
|
+
,,,"thisisd9",,,
|
10
|
+
,,,,,,
|
11
|
+
"thisisa11",,,,,,
|
12
|
+
41,42,43,44,45,,
|
13
|
+
,,,,,,
|
14
|
+
,,,,,,
|
15
|
+
41,42,43,44,45,,
|
16
|
+
"einundvierzig","zweiundvierzig","dreiundvierzig","vierundvierzig","fuenfundvierzig",,
|
17
|
+
,,,,,,
|
18
|
+
05/31/07,"dies hier als Date-Objekt",,,,,
|
data/test/test_roo.rb
CHANGED
@@ -16,6 +16,17 @@ require './lib/roo'
|
|
16
16
|
#TODO
|
17
17
|
# Look at formulas in excel - does not work with date/time
|
18
18
|
|
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
|
19
30
|
|
20
31
|
# Dump warnings that come from the test to open files
|
21
32
|
# with the wrong spreadsheet class
|
@@ -26,7 +37,6 @@ TMP_PREFIX = 'oo_*'
|
|
26
37
|
# require './' + TESTDIR + '/test_helper.rb'
|
27
38
|
require TESTDIR + '/test_helper.rb'
|
28
39
|
|
29
|
-
#require 'soap/rpc/driver'
|
30
40
|
require 'fileutils'
|
31
41
|
require 'timeout'
|
32
42
|
require 'logger'
|
@@ -34,18 +44,20 @@ $log = Logger.new(File.join(ENV['HOME'],"roo.log"))
|
|
34
44
|
#$log.level = Logger::WARN
|
35
45
|
$log.level = Logger::DEBUG
|
36
46
|
|
37
|
-
DISPLAY_LOG =
|
47
|
+
DISPLAY_LOG = false
|
38
48
|
DB_LOG = false
|
49
|
+
|
39
50
|
if DB_LOG
|
40
51
|
require 'activerecord'
|
41
52
|
end
|
42
53
|
|
43
54
|
include FileUtils
|
55
|
+
|
44
56
|
def running_windows?
|
45
|
-
|
57
|
+
# to do
|
46
58
|
# "besser loesen"
|
47
|
-
|
48
|
-
|
59
|
+
# end
|
60
|
+
File.exists? "C:\\"
|
49
61
|
end
|
50
62
|
|
51
63
|
if DB_LOG
|
@@ -136,13 +148,14 @@ class Test::Unit::TestCase
|
|
136
148
|
:duration => t2-t1
|
137
149
|
)
|
138
150
|
end
|
139
|
-
|
140
|
-
|
141
|
-
puts
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
146
159
|
end
|
147
160
|
end
|
148
161
|
|
@@ -164,10 +177,11 @@ end
|
|
164
177
|
class TestRoo < Test::Unit::TestCase
|
165
178
|
|
166
179
|
OPENOFFICE = true # do Openoffice-Spreadsheet Tests? (.ods files)
|
167
|
-
EXCEL = true
|
180
|
+
EXCEL = true # do Excel Tests? (.xls files)
|
168
181
|
GOOGLE = false # do Google-Spreadsheet Tests?
|
169
182
|
EXCELX = true # do Excelx Tests? (.xlsx files)
|
170
|
-
LIBREOFFICE
|
183
|
+
LIBREOFFICE = true # do Libreoffice tests? (.ods files)
|
184
|
+
CSV = true # do CSV tests? (.csv files)
|
171
185
|
|
172
186
|
ONLINE = false
|
173
187
|
LONG_RUN = true
|
@@ -198,7 +212,7 @@ class TestRoo < Test::Unit::TestCase
|
|
198
212
|
end
|
199
213
|
end
|
200
214
|
# end test spreadsheet type :nodoc
|
201
|
-
options[:format] ||= [:excel, :excelx, :openoffice, :google]
|
215
|
+
options[:format] ||= [:excel, :excelx, :openoffice, :google, :libreoffice]
|
202
216
|
options[:format] = [options[:format]] if options[:format].class == Symbol
|
203
217
|
yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xls')) if EXCEL && options[:format].include?(:excel)
|
204
218
|
yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xlsx')) if EXCELX && options[:format].include?(:excelx)
|
@@ -206,6 +220,7 @@ class TestRoo < Test::Unit::TestCase
|
|
206
220
|
yield Roo::Spreadsheet.open(key_of(options[:name]) || options[:name]) if GOOGLE && options[:format].include?(:google)
|
207
221
|
yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.ods')) if LIBREOFFICE && options[:format].include?(:libreoffice)
|
208
222
|
end
|
223
|
+
|
209
224
|
# Using Date.strptime so check that it's using the method
|
210
225
|
# with the value set in date_format
|
211
226
|
def test_date
|
@@ -239,6 +254,14 @@ class TestRoo < Test::Unit::TestCase
|
|
239
254
|
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
|
240
255
|
assert_kind_of Excelx, oo
|
241
256
|
end
|
257
|
+
if LIBREOFFICE
|
258
|
+
oo = Libreoffice.new(File.join(TESTDIR,"numbers1.ods"))
|
259
|
+
assert_kind_of Libreoffice, oo
|
260
|
+
end
|
261
|
+
if CSV
|
262
|
+
oo = Csv.new(File.join(TESTDIR,"numbers1.csv"))
|
263
|
+
assert_kind_of Csv, oo
|
264
|
+
end
|
242
265
|
end
|
243
266
|
|
244
267
|
def test_letters
|
@@ -251,6 +274,20 @@ class TestRoo < Test::Unit::TestCase
|
|
251
274
|
assert_equal 27, GenericSpreadsheet.letter_to_number('Aa')
|
252
275
|
assert_equal 27, GenericSpreadsheet.letter_to_number('aa')
|
253
276
|
end
|
277
|
+
|
278
|
+
def test_sheets_csv
|
279
|
+
if CSV
|
280
|
+
oo = Csv.new(File.join(TESTDIR,'numbers1.csv'))
|
281
|
+
assert_equal ["default"], oo.sheets
|
282
|
+
assert_raise(RangeError) { oo.default_sheet = "no_sheet" }
|
283
|
+
assert_raise(TypeError) { oo.default_sheet = [1,2,3] }
|
284
|
+
oo.sheets.each { |sh|
|
285
|
+
oo.default_sheet = sh
|
286
|
+
assert_equal sh, oo.default_sheet
|
287
|
+
}
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
254
291
|
def test_sheets
|
255
292
|
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
256
293
|
assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets
|
@@ -280,7 +317,9 @@ class TestRoo < Test::Unit::TestCase
|
|
280
317
|
assert_equal "test", oo.cell(2,6)
|
281
318
|
assert_equal :string, oo.celltype(2,6)
|
282
319
|
assert_equal 11, oo.cell(2,7)
|
283
|
-
|
320
|
+
unless oo.kind_of? Csv
|
321
|
+
assert_equal :float, oo.celltype(2,7)
|
322
|
+
end
|
284
323
|
assert_equal 10, oo.cell(4,1)
|
285
324
|
assert_equal 11, oo.cell(4,2)
|
286
325
|
assert_equal 12, oo.cell(4,3)
|
@@ -291,12 +330,14 @@ class TestRoo < Test::Unit::TestCase
|
|
291
330
|
assert_equal 12, oo.cell(4,'C')
|
292
331
|
assert_equal 13, oo.cell(4,'D')
|
293
332
|
assert_equal 14, oo.cell(4,'E')
|
294
|
-
|
295
|
-
|
296
|
-
|
333
|
+
unless oo.kind_of? Csv
|
334
|
+
assert_equal :date, oo.celltype(5,1)
|
335
|
+
assert_equal Date.new(1961,11,21), oo.cell(5,1)
|
336
|
+
assert_equal "1961-11-21", oo.cell(5,1).to_s
|
337
|
+
end
|
297
338
|
end
|
298
339
|
end
|
299
|
-
|
340
|
+
|
300
341
|
def test_celltype
|
301
342
|
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
302
343
|
assert_equal :string, oo.celltype(2,6)
|
@@ -330,7 +371,7 @@ class TestRoo < Test::Unit::TestCase
|
|
330
371
|
|
331
372
|
def test_libre_office
|
332
373
|
if LIBREOFFICE
|
333
|
-
|
374
|
+
oo = Libreoffice.new("test/numbers1.ods")
|
334
375
|
oo.default_sheet = oo.sheets.first
|
335
376
|
assert_equal 41, oo.cell('a',12)
|
336
377
|
end
|
@@ -740,21 +781,21 @@ class TestRoo < Test::Unit::TestCase
|
|
740
781
|
end
|
741
782
|
|
742
783
|
def test_excel_zipped
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
784
|
+
after Date.new(2011,10,30) 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
|
755
797
|
end
|
756
798
|
end
|
757
|
-
end
|
758
799
|
end
|
759
800
|
|
760
801
|
def test_openoffice_zipped
|
@@ -1433,66 +1474,66 @@ Sheet 3:
|
|
1433
1474
|
end
|
1434
1475
|
|
1435
1476
|
def test_no_remaining_tmp_files_openoffice
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1477
|
+
after Date.new(2011,10,30) 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
|
1454
1496
|
end
|
1455
|
-
end
|
1456
1497
|
end
|
1457
1498
|
|
1458
1499
|
def test_no_remaining_tmp_files_excel
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1500
|
+
after Date.new(2011,9,30) 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
|
1472
1514
|
end
|
1473
|
-
end
|
1474
1515
|
end
|
1475
1516
|
|
1476
1517
|
def test_no_remaining_tmp_files_excelx
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1518
|
+
after Date.new(2011,11,1) 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
|
1484
1525
|
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1526
|
+
# oo = Excelx.new(File.join(TESTDIR,"no_spreadsheet_file.txt"))
|
1527
|
+
# es soll absichtlich ein Abbruch provoziert werden, deshalb :ignore
|
1528
|
+
oo = Excelx.new(File.join(TESTDIR,"no_spreadsheet_file.txt"),
|
1529
|
+
false,
|
1530
|
+
:ignore)
|
1490
1531
|
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1532
|
+
}
|
1533
|
+
now = Dir.glob(TMP_PREFIX)
|
1534
|
+
assert (now-prev).empty?
|
1535
|
+
end
|
1494
1536
|
end
|
1495
|
-
end
|
1496
1537
|
end
|
1497
1538
|
|
1498
1539
|
def test_no_remaining_tmp_files_google
|
@@ -1574,67 +1615,67 @@ Sheet 3:
|
|
1574
1615
|
end
|
1575
1616
|
|
1576
1617
|
def test_file_warning_default
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1618
|
+
if OPENOFFICE
|
1619
|
+
prev = Dir.glob(TMP_PREFIX)
|
1620
|
+
assert_raises(TypeError, "test/numbers1.xls is not an openoffice spreadsheet") { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls")) }
|
1621
|
+
assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx")) }
|
1622
|
+
now = Dir.glob(TMP_PREFIX)
|
1623
|
+
assert (now-prev).empty?
|
1624
|
+
end
|
1625
|
+
if EXCEL
|
1626
|
+
prev = Dir.glob(TMP_PREFIX)
|
1627
|
+
assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.ods")) }
|
1628
|
+
assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx")) }
|
1629
|
+
now = Dir.glob(TMP_PREFIX)
|
1630
|
+
assert (now-prev).empty?, "temporary directory was not removed"
|
1631
|
+
end
|
1632
|
+
if EXCELX
|
1633
|
+
prev = Dir.glob(TMP_PREFIX)
|
1634
|
+
assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.ods")) }
|
1635
|
+
assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.xls")) }
|
1636
|
+
now = Dir.glob(TMP_PREFIX)
|
1637
|
+
assert (now-prev).empty?
|
1638
|
+
end
|
1598
1639
|
end
|
1599
1640
|
|
1600
1641
|
def test_file_warning_error
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1642
|
+
if OPENOFFICE
|
1643
|
+
prev = Dir.glob(TMP_PREFIX)
|
1644
|
+
assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls"),false,:error) }
|
1645
|
+
now = Dir.glob(TMP_PREFIX)
|
1646
|
+
assert (now-prev).empty?
|
1606
1647
|
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1648
|
+
prev = Dir.glob(TMP_PREFIX)
|
1649
|
+
assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) }
|
1650
|
+
now = Dir.glob(TMP_PREFIX)
|
1651
|
+
assert (now-prev).empty?
|
1652
|
+
end
|
1653
|
+
if EXCEL
|
1654
|
+
prev = Dir.glob(TMP_PREFIX)
|
1655
|
+
assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.ods"),false,:error) }
|
1656
|
+
now = Dir.glob(TMP_PREFIX)
|
1657
|
+
assert (now-prev).empty?, "temporary directory was not deleted"
|
1658
|
+
|
1659
|
+
prev = Dir.glob(TMP_PREFIX)
|
1660
|
+
assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) }
|
1661
|
+
now = Dir.glob(TMP_PREFIX)
|
1662
|
+
assert (now-prev).empty?, "temporary directory was not deleted"
|
1663
|
+
end
|
1664
|
+
if EXCELX
|
1665
|
+
prev = Dir.glob(TMP_PREFIX)
|
1666
|
+
assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.ods"),false,:error) }
|
1667
|
+
now = Dir.glob(TMP_PREFIX)
|
1668
|
+
assert (now-prev).empty?, "temporary directory was not deleted"
|
1669
|
+
|
1670
|
+
prev = Dir.glob(TMP_PREFIX)
|
1671
|
+
assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.xls"),false,:error) }
|
1672
|
+
now = Dir.glob(TMP_PREFIX)
|
1673
|
+
assert (now-prev).empty?, "temporary directory was not deleted"
|
1674
|
+
end
|
1634
1675
|
end
|
1635
1676
|
|
1636
1677
|
def test_file_warning_warning
|
1637
|
-
after Date.new(2011,
|
1678
|
+
after Date.new(2011,10,14) do
|
1638
1679
|
if OPENOFFICE
|
1639
1680
|
assert_nothing_raised(TypeError) {
|
1640
1681
|
assert_raises(Zip::ZipError) {
|
@@ -1680,37 +1721,37 @@ Sheet 3:
|
|
1680
1721
|
end
|
1681
1722
|
|
1682
1723
|
def test_file_warning_ignore
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1724
|
+
if OPENOFFICE
|
1725
|
+
# Files, die eigentlich Openoffice-
|
1726
|
+
# Files sind, aber die falsche Endung haben.
|
1727
|
+
# Es soll ohne Fehlermeldung oder Warnung
|
1728
|
+
# oder Abbruch die Datei geoffnet werden
|
1688
1729
|
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1730
|
+
# xls
|
1731
|
+
assert_nothing_raised() {
|
1732
|
+
oo = Openoffice.new(File.join(TESTDIR,"type_openoffice.xls"),false, :ignore)
|
1733
|
+
}
|
1734
|
+
# xlsx
|
1735
|
+
assert_nothing_raised() {
|
1736
|
+
oo = Openoffice.new(File.join(TESTDIR,"type_openoffice.xlsx"),false, :ignore)
|
1737
|
+
}
|
1738
|
+
end
|
1739
|
+
if EXCEL
|
1740
|
+
assert_nothing_raised() {
|
1741
|
+
oo = Excel.new(File.join(TESTDIR,"type_excel.ods"),false, :ignore)
|
1742
|
+
}
|
1743
|
+
assert_nothing_raised() {
|
1744
|
+
oo = Excel.new(File.join(TESTDIR,"type_excel.xlsx"),false, :ignore)
|
1745
|
+
}
|
1746
|
+
end
|
1747
|
+
if EXCELX
|
1748
|
+
assert_nothing_raised() {
|
1749
|
+
oo = Excelx.new(File.join(TESTDIR,"type_excelx.ods"),false, :ignore)
|
1750
|
+
}
|
1751
|
+
assert_nothing_raised() {
|
1752
|
+
oo = Excelx.new(File.join(TESTDIR,"type_excelx.xls"),false, :ignore)
|
1753
|
+
}
|
1754
|
+
end
|
1714
1755
|
=begin
|
1715
1756
|
if OPENOFFICE
|
1716
1757
|
assert_nothing_raised() {
|
@@ -2062,29 +2103,26 @@ Sheet 3:
|
|
2062
2103
|
end # LONG_RUN
|
2063
2104
|
end
|
2064
2105
|
|
2065
|
-
def
|
2066
|
-
|
2067
|
-
|
2068
|
-
# end
|
2069
|
-
with_each_spreadsheet(:name=>'named_cells', :format=>:openoffice) do |oo|
|
2070
|
-
oo.default_sheet = oo.sheets.first
|
2106
|
+
def test_label
|
2107
|
+
with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo|
|
2108
|
+
# oo.default_sheet = oo.sheets.first
|
2071
2109
|
begin
|
2072
2110
|
row,col = oo.label('anton')
|
2073
2111
|
rescue ArgumentError
|
2074
2112
|
puts "labels error at #{oo.class}"
|
2075
2113
|
raise
|
2076
2114
|
end
|
2077
|
-
assert_equal 5, row
|
2078
|
-
assert_equal 3, col
|
2115
|
+
assert_equal 5, row, "error with label in class #{oo.class}"
|
2116
|
+
assert_equal 3, col, "error with label in class #{oo.class}"
|
2079
2117
|
|
2080
2118
|
row,col = oo.label('anton')
|
2081
|
-
assert_equal 'Anton', oo.cell(row,col)
|
2119
|
+
assert_equal 'Anton', oo.cell(row,col), "error with label in class #{oo.class}"
|
2082
2120
|
|
2083
2121
|
row,col = oo.label('berta')
|
2084
|
-
assert_equal 'Bertha', oo.cell(row,col)
|
2122
|
+
assert_equal 'Bertha', oo.cell(row,col), "error with label in class #{oo.class}"
|
2085
2123
|
|
2086
2124
|
row,col = oo.label('caesar')
|
2087
|
-
assert_equal 'Cäsar', oo.cell(row,col)
|
2125
|
+
assert_equal 'Cäsar', oo.cell(row,col),"error with label in class #{oo.class}"
|
2088
2126
|
|
2089
2127
|
row,col = oo.label('never')
|
2090
2128
|
assert_nil row
|
@@ -2094,7 +2132,12 @@ Sheet 3:
|
|
2094
2132
|
assert_equal 5, row
|
2095
2133
|
assert_equal 3, col
|
2096
2134
|
assert_equal "Sheet1", sheet
|
2135
|
+
end
|
2136
|
+
end
|
2097
2137
|
|
2138
|
+
def test_method_missing_anton
|
2139
|
+
with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo|
|
2140
|
+
# oo.default_sheet = oo.sheets.first
|
2098
2141
|
assert_equal "Anton", oo.anton
|
2099
2142
|
assert_raises(NoMethodError) {
|
2100
2143
|
row,col = oo.never
|
@@ -2102,6 +2145,69 @@ Sheet 3:
|
|
2102
2145
|
end
|
2103
2146
|
end
|
2104
2147
|
|
2148
|
+
def test_labels
|
2149
|
+
with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo|
|
2150
|
+
# oo.default_sheet = oo.sheets.first
|
2151
|
+
assert_equal [
|
2152
|
+
['anton',[5,3,'Sheet1']],
|
2153
|
+
['berta',[4,2,'Sheet1']],
|
2154
|
+
['caesar',[7,2,'Sheet1']],
|
2155
|
+
], oo.labels, "error with labels array in class #{oo.class}"
|
2156
|
+
end
|
2157
|
+
end
|
2158
|
+
|
2159
|
+
# def test_labeled_cells
|
2160
|
+
# to do
|
2161
|
+
# "more spreadsheet types"
|
2162
|
+
# end
|
2163
|
+
# with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo|
|
2164
|
+
# oo.default_sheet = oo.sheets.first
|
2165
|
+
# begin
|
2166
|
+
# row,col = oo.label('anton')
|
2167
|
+
# rescue ArgumentError
|
2168
|
+
# puts "labels error at #{oo.class}"
|
2169
|
+
# raise
|
2170
|
+
# end
|
2171
|
+
# assert_equal 5, row
|
2172
|
+
# assert_equal 3, col
|
2173
|
+
#
|
2174
|
+
# row,col = oo.label('anton')
|
2175
|
+
# assert_equal 'Anton', oo.cell(row,col)
|
2176
|
+
#
|
2177
|
+
# row,col = oo.label('berta')
|
2178
|
+
# assert_equal 'Bertha', oo.cell(row,col)
|
2179
|
+
#
|
2180
|
+
# row,col = oo.label('caesar')
|
2181
|
+
# assert_equal 'Cäsar', oo.cell(row,col)
|
2182
|
+
#
|
2183
|
+
# row,col = oo.label('never')
|
2184
|
+
# assert_nil row
|
2185
|
+
# assert_nil col
|
2186
|
+
#
|
2187
|
+
# row,col,sheet = oo.label('anton')
|
2188
|
+
# assert_equal 5, row
|
2189
|
+
# assert_equal 3, col
|
2190
|
+
# assert_equal "Sheet1", sheet
|
2191
|
+
#
|
2192
|
+
# assert_equal "Anton", oo.anton
|
2193
|
+
# assert_raises(NoMethodError) {
|
2194
|
+
# row,col = oo.never
|
2195
|
+
# }
|
2196
|
+
#
|
2197
|
+
# #assert_equal [
|
2198
|
+
## ['anton',['Sheet1',5,3]],
|
2199
|
+
## ['berta',['Sheet1',4,2]],
|
2200
|
+
## ['caesar',['Sheet1',7,2]],
|
2201
|
+
## ], oo.labels, "error with labels array in class #{oo.class}"
|
2202
|
+
## Reihenfolge row,col,sheet analog zu #label
|
2203
|
+
# assert_equal [
|
2204
|
+
# ['anton',[5,3,'Sheet1']],
|
2205
|
+
# ['berta',[4,2,'Sheet1']],
|
2206
|
+
# ['caesar',[7,2,'Sheet1']],
|
2207
|
+
# ], oo.labels, "error with labels array in class #{oo.class}"
|
2208
|
+
# end
|
2209
|
+
# end
|
2210
|
+
|
2105
2211
|
|
2106
2212
|
def test_bug_excel_last_row_255
|
2107
2213
|
if LONG_RUN
|
@@ -2164,7 +2270,7 @@ Sheet 3:
|
|
2164
2270
|
end end
|
2165
2271
|
|
2166
2272
|
def test_bug_date_mileszs
|
2167
|
-
after Date.new(2011,
|
2273
|
+
after Date.new(2011,11,1) do
|
2168
2274
|
# to do
|
2169
2275
|
# "An richtige Stelle kopieren. Ist das Dokument vertraulich?"
|
2170
2276
|
# 'ist auf dem Netbook nicht vorhanden'
|
@@ -2199,6 +2305,8 @@ Sheet 3:
|
|
2199
2305
|
end
|
2200
2306
|
|
2201
2307
|
def test_bug_xlsx_reference_cell
|
2308
|
+
|
2309
|
+
if EXCELX
|
2202
2310
|
=begin
|
2203
2311
|
If cell A contains a string and cell B references cell A. When reading the value of cell B, the result will be
|
2204
2312
|
"0.0" instead of the value of cell A.
|
@@ -2217,14 +2325,15 @@ where the expected result is
|
|
2217
2325
|
"A: TestString"
|
2218
2326
|
"B: TestString"
|
2219
2327
|
=end
|
2220
|
-
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2328
|
+
xlsx = Excelx.new(File.join('test', "formula_string_error.xlsx"))
|
2329
|
+
xlsx.default_sheet = xlsx.sheets.first
|
2330
|
+
assert_equal 'Teststring', xlsx.cell('a',1)
|
2331
|
+
assert_equal 'Teststring', xlsx.cell('a',2)
|
2332
|
+
end
|
2224
2333
|
end
|
2225
|
-
|
2334
|
+
|
2226
2335
|
def test_bug_guest_list_2011_05_05
|
2227
|
-
after Date.new(2011,
|
2336
|
+
after Date.new(2011,11,1) do
|
2228
2337
|
oo = Excel.new(File.join("..","confidential","guest_list_addresses.xls"))
|
2229
2338
|
oo.default_sheet = oo.sheets.first
|
2230
2339
|
assert_equal "lalala", oo.cell('a',1) # anderer Inhalt im Spreadsheet
|
@@ -2248,35 +2357,37 @@ where the expected result is
|
|
2248
2357
|
# don't test it with other spreadsheet types! this was only a problem
|
2249
2358
|
# with .xlsx files
|
2250
2359
|
def test_bug_date_not_recognized_2011_05_21
|
2251
|
-
|
2252
|
-
|
2253
|
-
|
2254
|
-
|
2255
|
-
|
2256
|
-
|
2257
|
-
|
2360
|
+
if EXCELX
|
2361
|
+
oo = Excelx.new(File.join('..','confidential','2011-05-21_sample_date_problem.xlsx'))
|
2362
|
+
oo.default_sheet = oo.sheets.first
|
2363
|
+
assert_equal Date.new(2011,3,24), oo.b4
|
2364
|
+
assert_equal Date.new(2011,3,25), oo.b5
|
2365
|
+
assert_equal Date.new(2011,5,5), oo.b6
|
2366
|
+
assert_equal Date.new(2012,3,23), oo.b7
|
2367
|
+
end
|
2258
2368
|
end
|
2259
2369
|
|
2260
2370
|
def test_bug_string_as_a_date_2011_05_21_spreadsheet_only
|
2261
|
-
after Date.new(2011,
|
2262
|
-
|
2263
|
-
|
2264
|
-
|
2265
|
-
|
2266
|
-
|
2267
|
-
|
2268
|
-
|
2269
|
-
|
2270
|
-
|
2271
|
-
|
2371
|
+
after Date.new(2011,12,28) do
|
2372
|
+
if EXCEL
|
2373
|
+
# to do
|
2374
|
+
# 'wieder entfernen'
|
2375
|
+
# end
|
2376
|
+
require 'spreadsheet'
|
2377
|
+
book = Spreadsheet.open File.join('..','confidential','2011-05-21_sample_type_problem.xls')
|
2378
|
+
sheet1 = book.worksheet 0
|
2379
|
+
sheet1.each_with_index do |row,rownum|
|
2380
|
+
# p row[0]
|
2381
|
+
if rownum == 2
|
2382
|
+
assert_equal 68, row[6]
|
2383
|
+
end
|
2272
2384
|
end
|
2273
|
-
|
2274
2385
|
end
|
2275
2386
|
end
|
2276
2387
|
end
|
2277
2388
|
|
2278
2389
|
def test_bug_string_as_a_date_2011_05_21
|
2279
|
-
after Date.new(2011,
|
2390
|
+
after Date.new(2011,11,1) do
|
2280
2391
|
#oo = Excel.new(File.join(TESTDIR,'2011-05-21_sample_type_problem.xls'))
|
2281
2392
|
oo = Excel.new(File.join('..','confidential','2011-05-21_sample_type_problem.xls'))
|
2282
2393
|
oo.default_sheet = oo.sheets.first
|
@@ -2354,26 +2465,136 @@ where the expected result is
|
|
2354
2465
|
|
2355
2466
|
# 2011-08-11
|
2356
2467
|
def test_bug_openoffice_formula_missing_letters
|
2357
|
-
|
2358
|
-
|
2359
|
-
|
2360
|
-
|
2361
|
-
|
2362
|
-
|
2363
|
-
|
2364
|
-
|
2365
|
-
|
2366
|
-
|
2367
|
-
|
2368
|
-
|
2369
|
-
|
2370
|
-
|
2371
|
-
|
2372
|
-
|
2373
|
-
|
2374
|
-
|
2468
|
+
if LIBREOFFICE
|
2469
|
+
# Dieses Dokument wurde mit LibreOffice angelegt.
|
2470
|
+
# Keine Ahnung, ob es damit zusammenhaengt, das diese
|
2471
|
+
# Formeln anders sind, als in der Datei formula.ods, welche
|
2472
|
+
# mit Openoffice angelegt wurde.
|
2473
|
+
# Bei den Openoffice-Dateien ist in diesem Feld in der XML-
|
2474
|
+
# Datei of: als Prefix enthalten, waehrend in dieser Datei
|
2475
|
+
# irgendetwas mit oooc: als Prefix verwendet wird.
|
2476
|
+
oo = Openoffice.new(File.join(TESTDIR,'dreimalvier.ods'))
|
2477
|
+
oo.default_sheet = oo.sheets.first
|
2478
|
+
assert_equal '=SUM([.A1:.D1])', oo.formula('e',1)
|
2479
|
+
assert_equal '=SUM([.A2:.D2])', oo.formula('e',2)
|
2480
|
+
assert_equal '=SUM([.A3:.D3])', oo.formula('e',3)
|
2481
|
+
assert_equal [
|
2482
|
+
[1,5,'=SUM([.A1:.D1])'],
|
2483
|
+
[2,5,'=SUM([.A2:.D2])'],
|
2484
|
+
[3,5,'=SUM([.A3:.D3])'],
|
2485
|
+
], oo.formulas
|
2486
|
+
|
2487
|
+
end
|
2488
|
+
end
|
2375
2489
|
|
2490
|
+
=begin
|
2491
|
+
def test_postprocessing_and_types_in_csv
|
2492
|
+
if CSV
|
2493
|
+
oo = Csv.new(File.join(TESTDIR,'csvtypes.csv'))
|
2494
|
+
oo.default_sheet = oo.sheets.first
|
2495
|
+
assert_equal(1,oo.a1)
|
2496
|
+
assert_equal(:float,oo.celltype('A',1))
|
2497
|
+
assert_equal("2",oo.b1)
|
2498
|
+
assert_equal(:string,oo.celltype('B',1))
|
2499
|
+
assert_equal("Mayer",oo.c1)
|
2500
|
+
assert_equal(:string,oo.celltype('C',1))
|
2501
|
+
end
|
2502
|
+
end
|
2503
|
+
=end
|
2504
|
+
|
2505
|
+
=begin
|
2506
|
+
def test_postprocessing_with_callback_function
|
2507
|
+
if CSV
|
2508
|
+
oo = Csv.new(File.join(TESTDIR,'csvtypes.csv'))
|
2509
|
+
oo.default_sheet = oo.sheets.first
|
2510
|
+
|
2511
|
+
#
|
2512
|
+
assert_equal(1, oo.last_column)
|
2513
|
+
end
|
2514
|
+
end
|
2515
|
+
=end
|
2516
|
+
|
2517
|
+
=begin
|
2518
|
+
def x_123
|
2519
|
+
class ::Csv
|
2520
|
+
def cell_postprocessing(row,col,value)
|
2521
|
+
if row < 3
|
2522
|
+
return nil
|
2523
|
+
end
|
2524
|
+
return value
|
2525
|
+
end
|
2526
|
+
end
|
2527
|
+
end
|
2528
|
+
=end
|
2529
|
+
|
2530
|
+
def test_nil_rows_and_lines_csv
|
2531
|
+
to do
|
2532
|
+
'wieder aktivieren'
|
2533
|
+
end
|
2534
|
+
=begin
|
2535
|
+
x_123
|
2536
|
+
if CSV
|
2537
|
+
oo = Csv.new(File.join(TESTDIR,'Bibelbund.csv'))
|
2538
|
+
oo.default_sheet = oo.sheets.first
|
2539
|
+
assert_equal 3, oo.first_row
|
2376
2540
|
end
|
2541
|
+
=end
|
2542
|
+
end
|
2543
|
+
|
2544
|
+
def test_bug_pfand_from_windows_phone_xlsx
|
2545
|
+
with_each_spreadsheet(:name=>'Pfand_from_windows_phone', :format=>:excelx) do |oo|
|
2546
|
+
oo.default_sheet = oo.sheets.first
|
2547
|
+
assert_equal ['Blatt1','Blatt2','Blatt3'], oo.sheets
|
2548
|
+
assert_equal 'Summe', oo.cell('b',1)
|
2549
|
+
|
2550
|
+
assert_equal Date.new(2011,9,14), oo.cell('a',2)
|
2551
|
+
assert_equal :date, oo.celltype('a',2)
|
2552
|
+
assert_equal Date.new(2011,9,15), oo.cell('a',3)
|
2553
|
+
assert_equal :date, oo.celltype('a',3)
|
2554
|
+
|
2555
|
+
assert_equal 3.81, oo.cell('b',2)
|
2556
|
+
assert_equal "SUM(C2:L2)", oo.formula('b',2)
|
2557
|
+
assert_equal 0.7, oo.cell('c',2)
|
2558
|
+
end # each
|
2559
|
+
end
|
2560
|
+
|
2561
|
+
def test_comment
|
2562
|
+
to do
|
2563
|
+
"more spreadsheet types"
|
2564
|
+
end
|
2565
|
+
with_each_spreadsheet(:name=>'comments', :format=>[:openoffice,:libreoffice,
|
2566
|
+
:excelx]) do |oo|
|
2567
|
+
oo.default_sheet = oo.sheets.first
|
2568
|
+
assert_equal 'Kommentar fuer B4',oo.comment('b',4)
|
2569
|
+
assert_equal 'Kommentar fuer B5',oo.comment('b',5)
|
2570
|
+
assert_nil oo.comment('b',99)
|
2571
|
+
# no comment at the second page
|
2572
|
+
oo.default_sheet = oo.sheets[1]
|
2573
|
+
assert_nil oo.comment('b',4)
|
2574
|
+
end
|
2575
|
+
end
|
2576
|
+
|
2577
|
+
def test_comment?
|
2578
|
+
with_each_spreadsheet(:name=>'comments', :format=>[:openoffice,:libreoffice,
|
2579
|
+
:excelx]) do |oo|
|
2580
|
+
oo.default_sheet = oo.sheets.first
|
2581
|
+
assert_equal true, oo.comment?('b',4)
|
2582
|
+
assert_equal false, oo.comment?('b',99)
|
2583
|
+
end
|
2584
|
+
end
|
2585
|
+
|
2586
|
+
def test_comments
|
2587
|
+
with_each_spreadsheet(:name=>'comments', :format=>[:openoffice,:libreoffice,
|
2588
|
+
:excelx]) do |oo|
|
2589
|
+
oo.default_sheet = oo.sheets.first
|
2590
|
+
assert_equal [
|
2591
|
+
[4, 2, "Kommentar fuer B4"],
|
2592
|
+
[5, 2, "Kommentar fuer B5"],
|
2593
|
+
], oo.comments(oo.sheets.first), "comments error in class #{oo.class}"
|
2594
|
+
# no comments at the second page
|
2595
|
+
oo.default_sheet = oo.sheets[1]
|
2596
|
+
assert_equal [], oo.comments, "comments error in class #{oo.class}"
|
2597
|
+
end
|
2377
2598
|
end
|
2378
2599
|
|
2379
2600
|
end # class
|