roo 1.9.3 → 1.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +12 -0
- data/README.txt +3 -0
- data/Rakefile +31 -95
- data/TODO +2 -0
- data/a.xls +0 -0
- data/bin/roo +1 -1
- data/lib/roo.rb +2 -1
- data/lib/roo/.generic_spreadsheet.rb.rb.swp +0 -0
- data/lib/roo/excel.rb +33 -6
- data/lib/roo/excelx.rb +16 -5
- data/lib/roo/generic_spreadsheet.rb +53 -73
- data/lib/roo/google.rb +330 -325
- data/lib/roo/openoffice.rb +520 -503
- data/rm_sub_test.rb +13 -0
- data/rm_test.rb +20 -0
- data/test/Bibelbund.csv +0 -0
- data/test/bode-v1.ods.zip +0 -0
- data/test/bode-v1.xls.zip +0 -0
- data/test/formula_string_error.xlsx +0 -0
- data/test/style.xls +0 -0
- data/test/test_helper.rb +30 -0
- data/test/test_roo.rb +2254 -2022
- data/test/type_excel.ods +0 -0
- data/test/type_excel.xlsx +0 -0
- data/test/type_excelx.ods +0 -0
- data/test/type_excelx.xls +0 -0
- data/test/type_openoffice.xls +0 -0
- data/test/type_openoffice.xlsx +0 -0
- data/tmp.xls +0 -0
- data/{csv9419 → tmpBibelbund.csv} +3741 -3741
- data/tmp_output.xml +85 -0
- data/{test/numbers1.csv → tmpnumbers1.csv} +18 -18
- metadata +93 -51
- data/csv11159 +0 -2888
- data/csv1414 +0 -2525
- data/csv9957 +0 -915
- data/test/ScienceStaff.xls +0 -0
- data/test/ScienceStaff_modified.xls +0 -0
- data/test/test_spreadsheet.rb +0 -19
data/History.txt
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
== 1.9.4 2011-06-23
|
2
|
+
|
3
|
+
* 1 enhancement
|
4
|
+
* removed gem 'builder'. Functionality goes to gem 'nokogiri'.
|
5
|
+
* 3 bugfixes
|
6
|
+
* Excel: remove temporary files if spreadsheed-file is not an excel file
|
7
|
+
and an exception was raised
|
8
|
+
* Excelx: a referenced cell with a string had the content 0.0 not the
|
9
|
+
correct string
|
10
|
+
* Fixed a problem with a date cell which was not recognized as a Date
|
11
|
+
object (see 2011-05-21 in excelx.rb)
|
12
|
+
|
1
13
|
== 1.9.3 2010-02-12
|
2
14
|
|
3
15
|
* 1 enhancements
|
data/README.txt
CHANGED
@@ -20,6 +20,9 @@ under Linux without having to install the MS office suite.
|
|
20
20
|
Roo implements read access for all spreadsheet types and read/write access for
|
21
21
|
Google spreadsheets.
|
22
22
|
|
23
|
+
== SUPPORT ROO DEVELOPMENT:
|
24
|
+
|
25
|
+
If you want to support the further development of the Roo gem, send Bitcoins to the address <code>1KecEuitSFZwx2towBcwbBXmaY5eYjJC9h</code>
|
23
26
|
|
24
27
|
== SYNOPSIS:
|
25
28
|
|
data/Rakefile
CHANGED
@@ -1,95 +1,31 @@
|
|
1
|
-
begin
|
2
|
-
require 'bones'
|
3
|
-
rescue LoadError
|
4
|
-
|
5
|
-
end
|
6
|
-
|
7
|
-
ensure_in_path 'lib'
|
8
|
-
require 'roo'
|
9
|
-
|
10
|
-
task :default => 'test:run'
|
11
|
-
# task 'gem:release' => 'test:run'
|
12
|
-
|
13
|
-
Bones {
|
14
|
-
name 'roo'
|
15
|
-
authors 'Thomas Preymesser'
|
16
|
-
email 'thopre@gmail.com'
|
17
|
-
url 'http://roo.rubyforge.org/'
|
18
|
-
version Roo::VERSION
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
=begin
|
34
|
-
PROJ.gem.dependencies = [
|
35
|
-
# ['xmlsimple', '>= 0.0.1'],
|
36
|
-
['spreadsheet', '> 0.6.4'],
|
37
|
-
#--
|
38
|
-
# rel. 0.6.4 causes an invalid Date error if we
|
39
|
-
# have a datetime value of 2006-02-02 10:00:00
|
40
|
-
#++
|
41
|
-
['nokogiri', '>= 0.0.1'],
|
42
|
-
['builder', '>= 2.1.2'],
|
43
|
-
['gimite-google-spreadsheet-ruby','>= 0.0.5'],
|
44
|
-
['febeling-rubyzip','>= 0.9.2'], # meine aktuelle Version
|
45
|
-
]
|
46
|
-
=end
|
47
|
-
|
48
|
-
# EOF
|
49
|
-
__END__
|
50
|
-
# Look in the tasks/setup.rb file for the various options that can be
|
51
|
-
# configured in this Rakefile. The .rake files in the tasks directory
|
52
|
-
# are where the options are used.
|
53
|
-
|
54
|
-
begin
|
55
|
-
require 'bones'
|
56
|
-
# Bones.setup
|
57
|
-
rescue LoadError
|
58
|
-
begin
|
59
|
-
load 'tasks/setup.rb'
|
60
|
-
rescue LoadError
|
61
|
-
raise RuntimeError, '### please install the "bones" gem ###'
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
ensure_in_path 'lib'
|
66
|
-
module GData
|
67
|
-
class Base
|
68
|
-
end
|
69
|
-
end
|
70
|
-
require 'roo'
|
71
|
-
|
72
|
-
task :default => 'spec:run'
|
73
|
-
|
74
|
-
PROJ.name = 'roo'
|
75
|
-
PROJ.authors = 'Thomas Preymesser'
|
76
|
-
PROJ.email = 'thopre@gmail.com'
|
77
|
-
PROJ.url = 'http://roo.rubyforge.org/'
|
78
|
-
PROJ.version = Roo::VERSION
|
79
|
-
PROJ.rubyforge.name = 'roo'
|
80
|
-
PROJ.gem.dependencies = [
|
81
|
-
# ['xmlsimple', '>= 0.0.1'],
|
82
|
-
['spreadsheet', '> 0.6.4'],
|
83
|
-
#--
|
84
|
-
# rel. 0.6.4 causes an invalid Date error if we
|
85
|
-
# have a datetime value of 2006-02-02 10:00:00
|
86
|
-
#++
|
87
|
-
['nokogiri', '>= 0.0.1'],
|
88
|
-
['builder', '>= 2.1.2'],
|
89
|
-
['gimite-google-spreadsheet-ruby','>= 0.0.5'],
|
90
|
-
['febeling-rubyzip','>= 0.9.2'], # meine aktuelle Version
|
91
|
-
]
|
92
|
-
|
93
|
-
PROJ.spec.opts << '--color'
|
94
|
-
|
95
|
-
# EOF
|
1
|
+
begin
|
2
|
+
require 'bones'
|
3
|
+
rescue LoadError
|
4
|
+
puts '### Please install the "bones" gem ###'
|
5
|
+
end
|
6
|
+
|
7
|
+
ensure_in_path 'lib'
|
8
|
+
require 'roo'
|
9
|
+
|
10
|
+
task :default => 'test:run'
|
11
|
+
# task 'gem:release' => 'test:run'
|
12
|
+
|
13
|
+
Bones {
|
14
|
+
name 'roo'
|
15
|
+
authors 'Thomas Preymesser'
|
16
|
+
email 'thopre@gmail.com'
|
17
|
+
url 'http://roo.rubyforge.org/'
|
18
|
+
version Roo::VERSION
|
19
|
+
depend_on 'spreadsheet', '> 0.6.4'
|
20
|
+
#--
|
21
|
+
# rel. 0.6.4 causes an invalid Date error if we
|
22
|
+
# have a datetime value of 2006-02-02 10:00:00
|
23
|
+
#++
|
24
|
+
depend_on 'nokogiri' #, '>= 0.0.1'
|
25
|
+
#TODO: brauchen wir das noch? depend_on 'gimite-google-spreadsheet-ruby','>= 0.0.5'
|
26
|
+
#depend_on 'febeling-rubyzip','>= 0.9.2' # meine aktuelle Version
|
27
|
+
#TODO: warum brauchen wir das? es lief doch auch vorher ohne dieses spezielle gem
|
28
|
+
depend_on 'google-spreadsheet-ruby'
|
29
|
+
}
|
30
|
+
|
31
|
+
# EOF
|
data/TODO
ADDED
data/a.xls
ADDED
Binary file
|
data/bin/roo
CHANGED
data/lib/roo.rb
CHANGED
Binary file
|
data/lib/roo/excel.rb
CHANGED
@@ -109,16 +109,33 @@ class Excel < GenericSpreadsheet
|
|
109
109
|
filename = open_from_stream(filename[7..-1]) if filename[0,7] == "stream:"
|
110
110
|
filename = unzip(filename) if packed and packed == :zip
|
111
111
|
begin
|
112
|
+
begin
|
112
113
|
file_type_check(filename,'.xls','an Excel')
|
114
|
+
rescue TypeError
|
115
|
+
FileUtils::rm_r @tmpdir
|
116
|
+
raise
|
117
|
+
end
|
113
118
|
@filename = filename
|
114
119
|
unless File.file?(@filename)
|
115
120
|
raise IOError, "file #{@filename} does not exist"
|
116
121
|
end
|
117
|
-
|
122
|
+
begin
|
123
|
+
@workbook = Spreadsheet.open(filename)
|
124
|
+
rescue Ole::Storage::FormatError
|
125
|
+
FileUtils::rm_r(@tmpdir)
|
126
|
+
raise # nach aussen weiterhin sichtbar
|
127
|
+
end
|
118
128
|
@default_sheet = self.sheets.first
|
119
129
|
ensure
|
120
130
|
#if ENV["roo_local"] != "thomas-p"
|
121
|
-
|
131
|
+
# ich glaube ich darf hier noch nicht die temporaere
|
132
|
+
# Datei loeschen, weil
|
133
|
+
#to do
|
134
|
+
#"Loeschen temp. Directory anpassen"
|
135
|
+
#end
|
136
|
+
#if fremdrechner?
|
137
|
+
#FileUtils::rm_r(@tmpdir)
|
138
|
+
#end
|
122
139
|
#end
|
123
140
|
end
|
124
141
|
@cell = Hash.new
|
@@ -156,7 +173,12 @@ class Excel < GenericSpreadsheet
|
|
156
173
|
if celltype(row,col,sheet) == :string
|
157
174
|
return platform_specific_iconv(@cell[sheet][[row,col]])
|
158
175
|
else
|
159
|
-
return @cell[sheet][[row,col]]
|
176
|
+
#return @cell[sheet][[row,col]]
|
177
|
+
if @cell[sheet] and @cell[sheet][[row,col]]
|
178
|
+
return @cell[sheet][[row,col]]
|
179
|
+
else
|
180
|
+
return nil
|
181
|
+
end
|
160
182
|
end
|
161
183
|
end
|
162
184
|
|
@@ -173,10 +195,15 @@ class Excel < GenericSpreadsheet
|
|
173
195
|
read_cells(sheet) unless @cells_read[sheet]
|
174
196
|
row,col = normalize(row,col)
|
175
197
|
begin
|
176
|
-
if @formula[sheet][[row,col]]
|
198
|
+
if @formula[sheet] and @formula[sheet][[row,col]]
|
177
199
|
return :formula
|
178
200
|
else
|
179
|
-
@cell_type[sheet][[row,col]]
|
201
|
+
# @cell_type[sheet][[row,col]]
|
202
|
+
if @cell_type[sheet] and @cell_type[sheet][[row,col]]
|
203
|
+
return @cell_type[sheet][[row,col]]
|
204
|
+
else
|
205
|
+
return nil
|
206
|
+
end
|
180
207
|
end
|
181
208
|
rescue
|
182
209
|
puts "Error in sheet #{sheet}, row #{row}, col #{col}"
|
@@ -215,7 +242,7 @@ class Excel < GenericSpreadsheet
|
|
215
242
|
@cell[sheet].inspect
|
216
243
|
end
|
217
244
|
|
218
|
-
|
245
|
+
# returns the row,col values of the labelled cell
|
219
246
|
# (nil,nil) if label is not defined
|
220
247
|
# sheet parameter is not really needed because label names are global
|
221
248
|
# to the whole spreadsheet
|
data/lib/roo/excelx.rb
CHANGED
@@ -48,6 +48,7 @@ class Excelx < GenericSpreadsheet
|
|
48
48
|
'dd/mm/yy' => :date,
|
49
49
|
'hh:mm:ss' => :time,
|
50
50
|
"dd/mm/yy\\ hh:mm" => :datetime,
|
51
|
+
'dd/mmm/yy' => :date, # 2011-05-21
|
51
52
|
}
|
52
53
|
STANDARD_FORMATS = {
|
53
54
|
0 => 'General',
|
@@ -416,12 +417,16 @@ class Excelx < GenericSpreadsheet
|
|
416
417
|
#TODO: elsif (c.attributes.to_h['t'] == 'b')
|
417
418
|
elsif c['t'] == 'b'
|
418
419
|
tmp_type = :boolean
|
420
|
+
# 2011-02-25 BEGIN
|
421
|
+
elsif c['t'] == 'str'
|
422
|
+
tmp_type = :string
|
423
|
+
# 2011-02-25 END
|
419
424
|
else
|
420
|
-
|
425
|
+
#s_attribute = c.attributes.to_h['s'].to_i # was here
|
421
426
|
s_attribute = c['s'].to_i # was here
|
422
|
-
|
423
|
-
|
424
|
-
|
427
|
+
format = attribute2format(s_attribute)
|
428
|
+
tmp_type = format2type(format)
|
429
|
+
end
|
425
430
|
formula = nil
|
426
431
|
#TODO: c.each_element do |cell|
|
427
432
|
c.children.each do |cell|
|
@@ -462,6 +467,12 @@ class Excelx < GenericSpreadsheet
|
|
462
467
|
elsif tmp_type == :formula
|
463
468
|
vt = :formula
|
464
469
|
v = cell.content.to_f #TODO: !!!!
|
470
|
+
# 2011-02-25 BEGIN
|
471
|
+
elsif tmp_type == :string
|
472
|
+
vt = :string
|
473
|
+
str_v = cell.content
|
474
|
+
excelx_type = :string
|
475
|
+
# 2011-02-25 END
|
465
476
|
else
|
466
477
|
vt = :float
|
467
478
|
v = cell.content
|
@@ -609,7 +620,7 @@ class Excelx < GenericSpreadsheet
|
|
609
620
|
doc.xpath("//*[local-name()='cellXfs']").each do |xfs|
|
610
621
|
xfs.children.each do |xf|
|
611
622
|
#TODO: numFmtId = xf.attributes.to_h['numFmtId']
|
612
|
-
|
623
|
+
numFmtId = xf['numFmtId']
|
613
624
|
@cellXfs << [numFmtId]
|
614
625
|
#TODO: fontId = xf.attributes.to_h['fontId'].to_i
|
615
626
|
fontId = xf['fontId'].to_i
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'matrix'
|
3
|
-
require 'rubygems'
|
4
|
-
require 'builder'
|
5
3
|
|
6
4
|
# Base class for all other types of spreadsheets
|
7
5
|
class GenericSpreadsheet
|
@@ -11,10 +9,28 @@ class GenericSpreadsheet
|
|
11
9
|
# sets the line with attribute names (default: 1)
|
12
10
|
attr_accessor :header_line
|
13
11
|
|
14
|
-
|
15
|
-
end
|
12
|
+
protected
|
16
13
|
|
17
|
-
#
|
14
|
+
# Helper function for development
|
15
|
+
def fremdrechner? #nodoc
|
16
|
+
eigener = [
|
17
|
+
'C:\Users\thopre',
|
18
|
+
'c:/Users/thopre',
|
19
|
+
'/c/Users/thopre',
|
20
|
+
'/home/tp',
|
21
|
+
].include? ENV['HOME']
|
22
|
+
# if eigener
|
23
|
+
# puts "fremdrechner? ==> false"
|
24
|
+
# else
|
25
|
+
# puts "fremdrechner? ==> true"
|
26
|
+
# end
|
27
|
+
! eigener
|
28
|
+
end
|
29
|
+
|
30
|
+
public
|
31
|
+
|
32
|
+
# sets the working sheet in the document
|
33
|
+
# 'sheet' can be a number (0 = first sheet) or the name of a sheet.
|
18
34
|
def default_sheet=(sheet)
|
19
35
|
if sheet.kind_of? Fixnum
|
20
36
|
if sheet >= 0 and sheet <= sheets.length
|
@@ -300,10 +316,11 @@ class GenericSpreadsheet
|
|
300
316
|
|
301
317
|
# reopens and read a spreadsheet document
|
302
318
|
def reload
|
319
|
+
# von Abfrage der Klasse direkt auf .to_s == '..' umgestellt
|
303
320
|
ds = @default_sheet
|
304
|
-
initialize(@filename) if self.class == Openoffice or
|
305
|
-
self.class == Excel
|
306
|
-
initialize(@spreadsheetkey,@user,@password) if self.class == Google
|
321
|
+
initialize(@filename) if self.class.to_s == 'Openoffice' or
|
322
|
+
self.class.to_s == 'Excel'
|
323
|
+
initialize(@spreadsheetkey,@user,@password) if self.class.to_s == 'Google'
|
307
324
|
self.default_sheet = ds
|
308
325
|
#@first_row = @last_row = @first_column = @last_column = nil
|
309
326
|
end
|
@@ -322,7 +339,13 @@ class GenericSpreadsheet
|
|
322
339
|
# recursively removes the current temporary directory
|
323
340
|
# this is only needed if you work with zipped files or files via the web
|
324
341
|
def remove_tmp
|
342
|
+
#to do
|
343
|
+
# "remove_tmp wieder aktivieren"
|
344
|
+
#end
|
345
|
+
#return
|
346
|
+
#$log.debug("remove_tmp('#{@tmpdir}')")
|
325
347
|
if File.exists?(@tmpdir)
|
348
|
+
#$log.debug("#{@tmpdir} exists")
|
326
349
|
FileUtils::rm_r(@tmpdir)
|
327
350
|
end
|
328
351
|
end
|
@@ -352,30 +375,29 @@ class GenericSpreadsheet
|
|
352
375
|
end
|
353
376
|
|
354
377
|
def to_xml
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
:type => celltype(row,col))
|
378
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
379
|
+
xml.spreadsheet {
|
380
|
+
self.sheets.each do |sheet|
|
381
|
+
self.default_sheet = sheet
|
382
|
+
xml.sheet(:name => sheet) { |x|
|
383
|
+
if first_row and last_row and first_column and last_column
|
384
|
+
# sonst gibt es Fehler bei leeren Blaettern
|
385
|
+
first_row.upto(last_row) do |row|
|
386
|
+
first_column.upto(last_column) do |col|
|
387
|
+
unless empty?(row,col)
|
388
|
+
x.cell(cell(row,col),
|
389
|
+
:row =>row,
|
390
|
+
:column => col,
|
391
|
+
:type => celltype(row,col))
|
392
|
+
end
|
371
393
|
end
|
372
394
|
end
|
373
395
|
end
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
396
|
+
}
|
397
|
+
end
|
398
|
+
}
|
399
|
+
end
|
400
|
+
return builder.to_xml
|
379
401
|
end
|
380
402
|
|
381
403
|
# when a method like spreadsheet.a42 is called
|
@@ -391,18 +413,9 @@ class GenericSpreadsheet
|
|
391
413
|
else
|
392
414
|
return cell(row,col)
|
393
415
|
end
|
394
|
-
|
395
|
-
|
396
|
-
# es definiert ist
|
397
|
-
# p "Label #{m} angesprochen?"
|
398
|
-
# row,col,sheet = label('anton')
|
399
|
-
# # row,col,sheet = label(m)
|
400
|
-
# p "row: #{row}"
|
401
|
-
# p "col: #{col}"
|
402
|
-
# p "sheet: #{sheet}"
|
403
|
-
# return cell(row,col)
|
416
|
+
else
|
417
|
+
super
|
404
418
|
end
|
405
|
-
raise ArgumentError, "Method #{m} missing. Args: #{args}"
|
406
419
|
end
|
407
420
|
|
408
421
|
protected
|
@@ -470,39 +483,6 @@ class GenericSpreadsheet
|
|
470
483
|
return row,col
|
471
484
|
end
|
472
485
|
|
473
|
-
# def open_from_uri(uri)
|
474
|
-
# require 'open-uri' ;
|
475
|
-
# tempfilename = File.join(@tmpdir, File.basename(uri))
|
476
|
-
# f = File.open(tempfilename,"wb")
|
477
|
-
# begin
|
478
|
-
# open(uri) do |net|
|
479
|
-
# f.write(net.read)
|
480
|
-
# end
|
481
|
-
# rescue
|
482
|
-
# raise "could not open #{uri}"
|
483
|
-
# end
|
484
|
-
# f.close
|
485
|
-
# File.join(@tmpdir, File.basename(uri))
|
486
|
-
# end
|
487
|
-
|
488
|
-
# OpenURI::HTTPError
|
489
|
-
# def open_from_uri(uri)
|
490
|
-
# require 'open-uri'
|
491
|
-
# #existiert URL?
|
492
|
-
# r = Net::HTTP.get_response(URI.parse(uri))
|
493
|
-
# raise "URL nicht verfuegbar" unless r.is_a? Net::HTTPOK
|
494
|
-
# tempfilename = File.join(@tmpdir, File.basename(uri))
|
495
|
-
# f = File.open(tempfilename,"wb")
|
496
|
-
# open(uri) do |net|
|
497
|
-
# f.write(net.read)
|
498
|
-
# end
|
499
|
-
# # rescue
|
500
|
-
# # raise "could not open #{uri}"
|
501
|
-
# # end
|
502
|
-
# f.close
|
503
|
-
# File.join(@tmpdir, File.basename(uri))
|
504
|
-
# end
|
505
|
-
|
506
486
|
def open_from_uri(uri)
|
507
487
|
require 'open-uri'
|
508
488
|
response = ''
|