roo 0.2.3 → 0.2.4
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.
- data/History.txt +4 -0
- data/Manifest.txt +1 -0
- data/README.txt +2 -0
- data/Rakefile +2 -0
- data/lib/roo.rb +1 -0
- data/lib/roo/excel.rb +1 -1
- data/lib/roo/google.rb +182 -0
- data/lib/roo/openoffice.rb +70 -18
- data/lib/roo/version.rb +1 -1
- data/test/numbers1.ods +0 -0
- data/test/test_roo.rb +486 -255
- data/website/index.html +30 -40
- data/website/index.txt +28 -38
- metadata +13 -3
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
data/Rakefile
CHANGED
@@ -77,6 +77,8 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
|
77
77
|
# ['ruport-util', '>= 0.5.0'],
|
78
78
|
['parseexcel', '>= 0.5.1.1'],
|
79
79
|
['rubyzip', '>= 0.9.1'],
|
80
|
+
['hpricot', '>= 0.5'],
|
81
|
+
['hoe', '>= 0.0.0'],
|
80
82
|
]
|
81
83
|
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
82
84
|
end
|
data/lib/roo.rb
CHANGED
data/lib/roo/excel.rb
CHANGED
data/lib/roo/google.rb
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'uri'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'hpricot'
|
7
|
+
require 'timeout'
|
8
|
+
|
9
|
+
|
10
|
+
# Make it easy to use some of the convenience methods using https
|
11
|
+
#
|
12
|
+
module Net class HTTPS < HTTP
|
13
|
+
def initialize(address, port = nil)
|
14
|
+
super(address, port)
|
15
|
+
self.use_ssl = true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class GoogleSpreadSheet
|
21
|
+
GOOGLE_LOGIN_URL = URI.parse('https://www.google.com/accounts/ClientLogin')
|
22
|
+
|
23
|
+
def initialize(spreadsheet_key)
|
24
|
+
@spreadsheet_key = spreadsheet_key
|
25
|
+
@headers = nil
|
26
|
+
@default_sheet = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def default_sheet=(numberofsheet)
|
30
|
+
@default_sheet = numberofsheet
|
31
|
+
end
|
32
|
+
|
33
|
+
def authenticate(email, password)
|
34
|
+
$VERBOSE = nil
|
35
|
+
response = Net::HTTPS.post_form(GOOGLE_LOGIN_URL,
|
36
|
+
{'Email' => email,
|
37
|
+
'Passwd' => password,
|
38
|
+
'source' => "formula",
|
39
|
+
'service' => 'wise' })
|
40
|
+
@headers = { 'Authorization' => "GoogleLogin auth=#{response.body.split(/=/).last}",
|
41
|
+
'Content-Type' => 'application/atom+xml'
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def evaluate_cell(cell)
|
46
|
+
path = "/feeds/cells/#{@spreadsheet_key}/#{@default_sheet}/#{@headers ? "private" : "public"}/basic/#{cell}"
|
47
|
+
|
48
|
+
doc = Hpricot(request(path))
|
49
|
+
result = (doc/"content[@type='text']").inner_html
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_entry(entry)
|
53
|
+
path = "/feeds/cells/#{@spreadsheet_key}/#{@default_sheet}/#{@headers ? 'private' : 'public'}/full"
|
54
|
+
|
55
|
+
post(path, entry)
|
56
|
+
end
|
57
|
+
|
58
|
+
def entry(formula, row=1, col=1)
|
59
|
+
<<XML
|
60
|
+
<?xml version='1.0' ?>
|
61
|
+
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gs='http://schemas.google.com/spreadsheets/2006'>
|
62
|
+
<gs:cell row='#{row}' col='#{col}' inputValue='=#{formula}' />
|
63
|
+
</entry>
|
64
|
+
XML
|
65
|
+
end
|
66
|
+
|
67
|
+
def add_to_cell(formula) #puts entry(formula)
|
68
|
+
set_entry(entry(formula))
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
def request(path)
|
73
|
+
response, data = get_http.get(path, @headers)
|
74
|
+
data
|
75
|
+
end
|
76
|
+
|
77
|
+
def post(path, entry)
|
78
|
+
get_http.post(path, entry, @headers)
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_http
|
82
|
+
http = Net::HTTP.new('spreadsheets.google.com', 80)
|
83
|
+
#http.set_debug_output $stderr
|
84
|
+
http
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class Google < Openoffice
|
89
|
+
|
90
|
+
TIMEOUT_IN_SECONDS = 2
|
91
|
+
|
92
|
+
def initialize(user, password, spreadsheetkey)
|
93
|
+
@cells_read = false
|
94
|
+
@cell = Hash.new
|
95
|
+
@cell_type = Hash.new
|
96
|
+
Timeout.timeout(TIMEOUT_IN_SECONDS) {
|
97
|
+
@gs = GoogleSpreadSheet.new(spreadsheetkey)
|
98
|
+
@gs.authenticate(user, password)
|
99
|
+
@default_sheet = nil
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
def sheets
|
104
|
+
# http://spreadsheets.google.com/feeds/worksheets/ptu6bbahNZpYrdGHwteUNCw/private/full
|
105
|
+
if DateTime.now < Date.new(2007,6,15)
|
106
|
+
return ["Sheet eins","Sheet zwei","Sheet drei"]
|
107
|
+
else
|
108
|
+
return []
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def default_sheet=(numberofsheet)
|
113
|
+
@gs.default_sheet = numberofsheet
|
114
|
+
end
|
115
|
+
|
116
|
+
def cell(row, col)
|
117
|
+
row,col = normalize(row,col)
|
118
|
+
# formula = 42 || 'sin(0.2)'
|
119
|
+
|
120
|
+
# gs = GoogleSpreadSheet.new("ptu6bbahNZpYrdGHwteUNCw")
|
121
|
+
# gs.authenticate('thopre@gmail.com', 'nora3033')
|
122
|
+
# gs.add_to_cell formula
|
123
|
+
cellname = number_to_letter(col)+row.to_s
|
124
|
+
Timeout.timeout(TIMEOUT_IN_SECONDS) {
|
125
|
+
return @gs.evaluate_cell(cellname) # 'A1')
|
126
|
+
}
|
127
|
+
end
|
128
|
+
|
129
|
+
def celltype(row, col)
|
130
|
+
"string"
|
131
|
+
end
|
132
|
+
|
133
|
+
def empty?(row, col)
|
134
|
+
cell(row, col).empty?
|
135
|
+
end
|
136
|
+
|
137
|
+
def read_cells
|
138
|
+
# http://spreadsheets.google.com/feeds/list/ptu6bbahNZpYrdGHwteUNCw/1/private/full
|
139
|
+
file = File.new("/home/tp/aaa.xml")
|
140
|
+
@doc = REXML::Document.new file
|
141
|
+
file.close
|
142
|
+
@doc.each_element do |element|
|
143
|
+
if element.name == "feed"
|
144
|
+
p "feed gefunden"
|
145
|
+
element.each_element do |feed|
|
146
|
+
p feed
|
147
|
+
feed.each_element do |fe|
|
148
|
+
p fe.name
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
# @cell["1,2"] = 42
|
155
|
+
# @cell_type["1,2"] = "string"
|
156
|
+
# @cells_read = true
|
157
|
+
# return
|
158
|
+
|
159
|
+
#TODO: die Grenzen sind noch fix
|
160
|
+
1.upto(10) do |y|
|
161
|
+
Openoffice.letter_to_number('A').upto(Openoffice.letter_to_number('H')) do |x|
|
162
|
+
# p x.to_s+", "+y.to_s
|
163
|
+
# unless empty?(y,x)
|
164
|
+
# @cell["#{y},#{x}"] = cell(y,x)
|
165
|
+
# @cell_type["#{y},#{x}"] = cell(y,x)
|
166
|
+
# end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
@cells_read = true
|
170
|
+
end
|
171
|
+
|
172
|
+
def first_row
|
173
|
+
read_cells unless @cells_read
|
174
|
+
1
|
175
|
+
end
|
176
|
+
|
177
|
+
def last_row
|
178
|
+
read_cells unless @cells_read
|
179
|
+
100
|
180
|
+
end
|
181
|
+
|
182
|
+
end # class
|
data/lib/roo/openoffice.rb
CHANGED
@@ -13,6 +13,8 @@ end
|
|
13
13
|
|
14
14
|
class Openoffice
|
15
15
|
|
16
|
+
@@nr = 0
|
17
|
+
|
16
18
|
def initialize(filename)
|
17
19
|
@cells_read = false
|
18
20
|
@filename = filename
|
@@ -20,15 +22,32 @@ class Openoffice
|
|
20
22
|
unless File.exists?(@tmpdir)
|
21
23
|
FileUtils::mkdir(@tmpdir)
|
22
24
|
end
|
25
|
+
@@nr += 1
|
26
|
+
@file_nr = @@nr
|
23
27
|
extract_content
|
24
|
-
file = File.new(File.join(@tmpdir, "
|
28
|
+
file = File.new(File.join(@tmpdir, @file_nr.to_s+"_roo_content.xml"))
|
25
29
|
@doc = REXML::Document.new file
|
26
30
|
file.close
|
27
31
|
@cell = Hash.new
|
28
32
|
@cell_type = Hash.new
|
29
|
-
|
30
|
-
|
33
|
+
FileUtils::rm_r(@tmpdir)
|
34
|
+
@default_sheet = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
# reopens and read a spreadsheet document
|
38
|
+
def reload
|
39
|
+
@cells_read = false
|
40
|
+
@tmpdir = "oo_"+$$.to_s
|
41
|
+
unless File.exists?(@tmpdir)
|
42
|
+
FileUtils::mkdir(@tmpdir)
|
31
43
|
end
|
44
|
+
extract_content
|
45
|
+
file = File.new(File.join(@tmpdir, @file_nr.to_s+"_roo_content.xml"))
|
46
|
+
@doc = REXML::Document.new file
|
47
|
+
file.close
|
48
|
+
@cell = Hash.new
|
49
|
+
@cell_type = Hash.new
|
50
|
+
FileUtils::rm_r(@tmpdir)
|
32
51
|
@default_sheet = nil
|
33
52
|
end
|
34
53
|
|
@@ -39,9 +58,18 @@ class Openoffice
|
|
39
58
|
def cell(row,col)
|
40
59
|
read_cells unless @cells_read
|
41
60
|
row,col = normalize(row,col)
|
61
|
+
if celltype(row,col) == "date"
|
62
|
+
yyyy,mm,dd = @cell["#{row},#{col}"].split('-')
|
63
|
+
return Date.new(yyyy.to_i,mm.to_i,dd.to_i)
|
64
|
+
end
|
42
65
|
@cell["#{row},#{col}"]
|
43
66
|
end
|
44
67
|
|
68
|
+
def set(row,col,value)
|
69
|
+
puts "setze zelle(#{row},#{col})"
|
70
|
+
@cell["#{row},#{col}"] = value
|
71
|
+
end
|
72
|
+
|
45
73
|
# returns the open-office type of a cell
|
46
74
|
def celltype(row,col)
|
47
75
|
read_cells unless @cells_read
|
@@ -194,6 +222,21 @@ class Openoffice
|
|
194
222
|
false
|
195
223
|
end
|
196
224
|
|
225
|
+
def Openoffice.letter_to_number(letters)
|
226
|
+
result = 0
|
227
|
+
while letters && letters.length > 0
|
228
|
+
character = letters[0,1].upcase
|
229
|
+
num = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".index(character)+1
|
230
|
+
result = result * 26 + num
|
231
|
+
letters = letters[1..-1]
|
232
|
+
end
|
233
|
+
result
|
234
|
+
end
|
235
|
+
|
236
|
+
def save
|
237
|
+
42
|
238
|
+
end
|
239
|
+
|
197
240
|
private
|
198
241
|
|
199
242
|
# read all cells in the selected sheet
|
@@ -236,11 +279,31 @@ private
|
|
236
279
|
# p tr
|
237
280
|
if tr.name == 'table-cell'
|
238
281
|
skip = tr.attributes['number-columns-repeated']
|
239
|
-
if skip
|
240
|
-
x += (skip.to_i - 1)
|
241
|
-
end
|
242
282
|
vt = tr.attributes['value-type']
|
243
283
|
v = tr.attributes['value']
|
284
|
+
if skip
|
285
|
+
if v == nil
|
286
|
+
x += (skip.to_i - 1)
|
287
|
+
else
|
288
|
+
0.upto(skip.to_i-1) do |i|
|
289
|
+
@cell_type["#{y},#{x+i}"] = vt
|
290
|
+
if @cell_type["#{y},#{x+i}"] == 'float'
|
291
|
+
@cell["#{y},#{x+i}"] = v.to_f
|
292
|
+
elsif @cell_type["#{y},#{x+i}"] == 'string'
|
293
|
+
tr.each_element do |str|
|
294
|
+
if str.name == 'p'
|
295
|
+
@cell["#{y},#{x+i}"] = str.text
|
296
|
+
end
|
297
|
+
end
|
298
|
+
elsif @cell_type["#{y},#{x+i}"] == 'date'
|
299
|
+
@cell["#{y},#{x+i}"] = tr.attributes['date-value']
|
300
|
+
else
|
301
|
+
@cell["#{y},#{x+i}"] = v
|
302
|
+
end
|
303
|
+
end
|
304
|
+
x += 1
|
305
|
+
end
|
306
|
+
end # if skip
|
244
307
|
# puts "#{vt} #{v}"
|
245
308
|
@cell_type["#{y},#{x}"] = vt
|
246
309
|
if @cell_type["#{y},#{x}"] == 'float'
|
@@ -277,7 +340,7 @@ private
|
|
277
340
|
def process_zipfile(zip, path='')
|
278
341
|
if zip.file.file? path
|
279
342
|
if path == "content.xml"
|
280
|
-
open(@tmpdir+'/'+'
|
343
|
+
open(@tmpdir+'/'+@file_nr.to_s+'_roo_content.xml','w') {|f|
|
281
344
|
f << zip.read(path)
|
282
345
|
}
|
283
346
|
end
|
@@ -298,17 +361,6 @@ private
|
|
298
361
|
end
|
299
362
|
end
|
300
363
|
|
301
|
-
def Openoffice.letter_to_number(letters)
|
302
|
-
result = 0
|
303
|
-
while letters && letters.length > 0
|
304
|
-
character = letters[0,1].upcase
|
305
|
-
num = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".index(character)+1
|
306
|
-
result = result * 26 + num
|
307
|
-
letters = letters[1..-1]
|
308
|
-
end
|
309
|
-
result
|
310
|
-
end
|
311
|
-
|
312
364
|
# converts cell coordinate to numeric values of row,col
|
313
365
|
def normalize(row,col)
|
314
366
|
if row.class == String
|
data/lib/roo/version.rb
CHANGED
data/test/numbers1.ods
CHANGED
Binary file
|
data/test/test_roo.rb
CHANGED
@@ -1,23 +1,51 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
3
|
class TestRoo < Test::Unit::TestCase
|
4
|
-
|
4
|
+
|
5
|
+
OPENOFFICE = true # toggle Openoffice-Spreadsheet Test on/off
|
6
|
+
EXCEL = true # do Excel Tests?
|
7
|
+
GOOGLE = false # toggle Google-Spreadsheet Test on/off
|
8
|
+
|
9
|
+
OPENOFFICEWRITE = false # Tests fuer schreibenden Zugriff auf OO-Dokumente
|
10
|
+
|
11
|
+
def setup
|
12
|
+
if GOOGLE
|
13
|
+
@goo = Google.new(ENV['GOOGLE_MAIL'],
|
14
|
+
ENV['GOOGLE_PASSWORD'],
|
15
|
+
ENV['GOOGLE_KEY'])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
5
19
|
def test_letters
|
6
20
|
assert_equal 1, Openoffice.letter_to_number('A')
|
7
21
|
assert_equal 1, Openoffice.letter_to_number('a')
|
8
22
|
assert_equal 2, Openoffice.letter_to_number('B')
|
9
23
|
assert_equal 26, Openoffice.letter_to_number('Z')
|
10
24
|
assert_equal 27, Openoffice.letter_to_number('AA')
|
25
|
+
assert_equal 27, Openoffice.letter_to_number('aA')
|
26
|
+
assert_equal 27, Openoffice.letter_to_number('Aa')
|
27
|
+
assert_equal 27, Openoffice.letter_to_number('aa')
|
11
28
|
end
|
12
|
-
|
29
|
+
|
13
30
|
def test_sheets
|
14
31
|
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
15
|
-
assert_equal ["Tabelle1","Name of Sheet 2","Sheet3"], oo.sheets
|
32
|
+
assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4"], oo.sheets
|
16
33
|
#--
|
17
|
-
|
18
|
-
|
34
|
+
if EXCEL
|
35
|
+
if DateTime.now > Date.new(2007,6,30)
|
36
|
+
oo = Excel.new(File.join("test","numbers1.xls"))
|
37
|
+
assert_equal ["Tabelle1","Name of Sheet 2","Sheet3"], oo.sheets
|
38
|
+
end
|
39
|
+
end
|
40
|
+
#-- Google
|
41
|
+
if GOOGLE
|
42
|
+
if DateTime.now > Date.new(2007,6,10)
|
43
|
+
assert_equal "Testspreadsheet Roo", @goo.title
|
44
|
+
end
|
45
|
+
assert_equal ["Sheet eins","Sheet zwei","Sheet drei"], @goo.sheets
|
46
|
+
end
|
19
47
|
end
|
20
|
-
|
48
|
+
|
21
49
|
def test_cell
|
22
50
|
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
23
51
|
oo.default_sheet = oo.sheets.first
|
@@ -34,274 +62,477 @@ class TestRoo < Test::Unit::TestCase
|
|
34
62
|
assert_equal "string", oo.celltype(2,6)
|
35
63
|
assert_equal 11, oo.cell(2,7)
|
36
64
|
assert_equal "float", oo.celltype(2,7)
|
37
|
-
|
65
|
+
|
38
66
|
assert_equal 10, oo.cell(4,1)
|
39
67
|
assert_equal 11, oo.cell(4,2)
|
40
68
|
assert_equal 12, oo.cell(4,3)
|
41
69
|
assert_equal 13, oo.cell(4,4)
|
42
70
|
assert_equal 14, oo.cell(4,5)
|
43
|
-
|
71
|
+
|
44
72
|
assert_equal 10, oo.cell(4,'A')
|
45
73
|
assert_equal 11, oo.cell(4,'B')
|
46
74
|
assert_equal 12, oo.cell(4,'C')
|
47
75
|
assert_equal 13, oo.cell(4,'D')
|
48
76
|
assert_equal 14, oo.cell(4,'E')
|
49
|
-
|
77
|
+
|
50
78
|
assert_equal "date", oo.celltype(5,1)
|
51
|
-
assert_equal
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
assert_equal 1, oo.cell(1,1)
|
56
|
-
assert_equal 2, oo.cell(1,2)
|
57
|
-
assert_equal 3, oo.cell(1,3)
|
58
|
-
assert_equal 4, oo.cell(1,4)
|
59
|
-
assert_equal 5, oo.cell(2,1)
|
60
|
-
assert_equal 6, oo.cell(2,2)
|
61
|
-
assert_equal 7, oo.cell(2,3)
|
62
|
-
assert_equal 8, oo.cell(2,4)
|
63
|
-
assert_equal 9, oo.cell(2,5)
|
64
|
-
assert_equal "test", oo.cell(2,6)
|
65
|
-
assert_equal "string", oo.celltype(2,6)
|
66
|
-
assert_equal 11, oo.cell(2,7)
|
67
|
-
assert_equal "float", oo.celltype(2,7)
|
68
|
-
|
69
|
-
assert_equal 10, oo.cell(4,1)
|
70
|
-
assert_equal 11, oo.cell(4,2)
|
71
|
-
assert_equal 12, oo.cell(4,3)
|
72
|
-
assert_equal 13, oo.cell(4,4)
|
73
|
-
assert_equal 14, oo.cell(4,5)
|
74
|
-
|
75
|
-
assert_equal 10, oo.cell(4,'A')
|
76
|
-
assert_equal 11, oo.cell(4,'B')
|
77
|
-
assert_equal 12, oo.cell(4,'C')
|
78
|
-
assert_equal 13, oo.cell(4,'D')
|
79
|
-
assert_equal 14, oo.cell(4,'E')
|
80
|
-
|
81
|
-
assert_equal "date", oo.celltype(5,1)
|
82
|
-
assert_equal "1961-11-21", oo.cell(5,1)
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_cell_address
|
86
|
-
oo = Openoffice.new(File.join("test/numbers1.ods"))
|
87
|
-
oo.default_sheet = oo.sheets.first
|
88
|
-
assert_equal "tata", oo.cell(6,1)
|
89
|
-
assert_equal "tata", oo.cell(6,'A')
|
90
|
-
assert_equal "tata", oo.cell('A',6)
|
91
|
-
assert_equal "tata", oo.cell(6,'a')
|
92
|
-
assert_equal "tata", oo.cell('a',6)
|
93
|
-
|
94
|
-
assert_equal "thisisc8", oo.cell(8,3)
|
95
|
-
assert_equal "thisisc8", oo.cell(8,'C')
|
96
|
-
assert_equal "thisisc8", oo.cell('C',8)
|
97
|
-
assert_equal "thisisc8", oo.cell(8,'c')
|
98
|
-
assert_equal "thisisc8", oo.cell('c',8)
|
99
|
-
|
100
|
-
assert_equal "thisisd9", oo.cell('d',9)
|
101
|
-
assert_equal "thisisa11", oo.cell('a',11)
|
102
|
-
|
103
|
-
oo = Excel.new(File.join("test","numbers1.xls"))
|
104
|
-
oo.default_sheet = 1 # oo.sheets.first
|
105
|
-
assert_equal "tata", oo.cell(6,1)
|
106
|
-
assert_equal "tata", oo.cell(6,'A')
|
107
|
-
assert_equal "tata", oo.cell('A',6)
|
108
|
-
assert_equal "tata", oo.cell(6,'a')
|
109
|
-
assert_equal "tata", oo.cell('a',6)
|
110
|
-
|
111
|
-
assert_equal "thisisc8", oo.cell(8,3)
|
112
|
-
assert_equal "thisisc8", oo.cell(8,'C')
|
113
|
-
assert_equal "thisisc8", oo.cell('C',8)
|
114
|
-
assert_equal "thisisc8", oo.cell(8,'c')
|
115
|
-
assert_equal "thisisc8", oo.cell('c',8)
|
116
|
-
|
117
|
-
assert_equal "thisisd9", oo.cell('d',9)
|
118
|
-
assert_equal "thisisa11", oo.cell('a',11)
|
119
|
-
end
|
120
|
-
|
121
|
-
# Version of the (XML) office document
|
122
|
-
# please note that "1.0" is returned even if it was created with OpenOffice V. 2.0
|
123
|
-
def test_officeversion
|
124
|
-
#-- OpenOffice
|
125
|
-
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
126
|
-
assert_equal "1.0", oo.officeversion
|
127
|
-
#-- Excel
|
128
|
-
if DateTime.now > Date.new(2007,6,15)
|
79
|
+
assert_equal Date.new(1961,11,21), oo.cell(5,1)
|
80
|
+
assert_equal "1961-11-21", oo.cell(5,1).to_s
|
81
|
+
|
82
|
+
if EXCEL
|
129
83
|
oo = Excel.new(File.join("test","numbers1.xls"))
|
84
|
+
oo.default_sheet = 1 # oo.sheets.first
|
85
|
+
assert_equal 1, oo.cell(1,1)
|
86
|
+
assert_equal 2, oo.cell(1,2)
|
87
|
+
assert_equal 3, oo.cell(1,3)
|
88
|
+
assert_equal 4, oo.cell(1,4)
|
89
|
+
assert_equal 5, oo.cell(2,1)
|
90
|
+
assert_equal 6, oo.cell(2,2)
|
91
|
+
assert_equal 7, oo.cell(2,3)
|
92
|
+
assert_equal 8, oo.cell(2,4)
|
93
|
+
assert_equal 9, oo.cell(2,5)
|
94
|
+
assert_equal "test", oo.cell(2,6)
|
95
|
+
assert_equal "string", oo.celltype(2,6)
|
96
|
+
assert_equal 11, oo.cell(2,7)
|
97
|
+
assert_equal "float", oo.celltype(2,7)
|
98
|
+
|
99
|
+
assert_equal 10, oo.cell(4,1)
|
100
|
+
assert_equal 11, oo.cell(4,2)
|
101
|
+
assert_equal 12, oo.cell(4,3)
|
102
|
+
assert_equal 13, oo.cell(4,4)
|
103
|
+
assert_equal 14, oo.cell(4,5)
|
104
|
+
|
105
|
+
assert_equal 10, oo.cell(4,'A')
|
106
|
+
assert_equal 11, oo.cell(4,'B')
|
107
|
+
assert_equal 12, oo.cell(4,'C')
|
108
|
+
assert_equal 13, oo.cell(4,'D')
|
109
|
+
assert_equal 14, oo.cell(4,'E')
|
110
|
+
|
111
|
+
assert_equal "date", oo.celltype(5,1)
|
112
|
+
assert_equal Date.new(1961,11,21), oo.cell(5,1)
|
113
|
+
assert_equal "1961-11-21", oo.cell(5,1).to_s
|
114
|
+
end
|
115
|
+
|
116
|
+
if GOOGLE
|
117
|
+
@goo.default_sheet = 1 # @goo.sheets.first
|
118
|
+
assert_equal 1, @goo.cell(1,1).to_i
|
119
|
+
assert_equal 2, @goo.cell(1,2).to_i
|
120
|
+
assert_equal 3, @goo.cell(1,3).to_i
|
121
|
+
assert_equal 4, @goo.cell(1,4).to_i
|
122
|
+
assert_equal 5, @goo.cell(2,1).to_i
|
123
|
+
assert_equal 6, @goo.cell(2,2).to_i
|
124
|
+
assert_equal 7, @goo.cell(2,3).to_i
|
125
|
+
assert_equal 8, @goo.cell(2,4).to_i
|
126
|
+
assert_equal 9, @goo.cell(2,5).to_i
|
127
|
+
assert_equal "test", @goo.cell(2,6)
|
128
|
+
assert_equal "string", @goo.celltype(2,6)
|
129
|
+
assert_equal 11, @goo.cell(2,7).to_i
|
130
|
+
if DateTime.now > Date.new(2007,6,15)
|
131
|
+
assert_equal "float", @goo.celltype(2,7)
|
132
|
+
end
|
133
|
+
|
134
|
+
assert_equal 10, @goo.cell(4,1).to_i
|
135
|
+
assert_equal 11, @goo.cell(4,2).to_i
|
136
|
+
assert_equal 12, @goo.cell(4,3).to_i
|
137
|
+
assert_equal 13, @goo.cell(4,4).to_i
|
138
|
+
assert_equal 14, @goo.cell(4,5).to_i
|
139
|
+
|
140
|
+
assert_equal 10, @goo.cell(4,'A').to_i
|
141
|
+
assert_equal 11, @goo.cell(4,'B').to_i
|
142
|
+
assert_equal 12, @goo.cell(4,'C').to_i
|
143
|
+
assert_equal 13, @goo.cell(4,'D').to_i
|
144
|
+
assert_equal 14, @goo.cell(4,'E').to_i
|
145
|
+
|
146
|
+
if DateTime.now > Date.new(2007,6,15)
|
147
|
+
assert_equal "date", @goo.celltype(5,1)
|
148
|
+
end
|
149
|
+
if DateTime.now > Date.new(2007,6,15)
|
150
|
+
assert_equal Date.new(1961,11,21), @goo.cell(5,1)
|
151
|
+
assert_equal "1961-11-21", @goo.cell(5,1).to_s
|
152
|
+
else
|
153
|
+
assert_equal "21/11/1961", @goo.cell(5,1)
|
154
|
+
end
|
155
|
+
end # GOOGLE
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_cell_address
|
159
|
+
oo = Openoffice.new(File.join("test/numbers1.ods"))
|
160
|
+
oo.default_sheet = oo.sheets.first
|
161
|
+
assert_equal "tata", oo.cell(6,1)
|
162
|
+
assert_equal "tata", oo.cell(6,'A')
|
163
|
+
assert_equal "tata", oo.cell('A',6)
|
164
|
+
assert_equal "tata", oo.cell(6,'a')
|
165
|
+
assert_equal "tata", oo.cell('a',6)
|
166
|
+
|
167
|
+
assert_equal "thisisc8", oo.cell(8,3)
|
168
|
+
assert_equal "thisisc8", oo.cell(8,'C')
|
169
|
+
assert_equal "thisisc8", oo.cell('C',8)
|
170
|
+
assert_equal "thisisc8", oo.cell(8,'c')
|
171
|
+
assert_equal "thisisc8", oo.cell('c',8)
|
172
|
+
|
173
|
+
assert_equal "thisisd9", oo.cell('d',9)
|
174
|
+
assert_equal "thisisa11", oo.cell('a',11)
|
175
|
+
|
176
|
+
if EXCEL
|
177
|
+
oo = Excel.new(File.join("test","numbers1.xls"))
|
178
|
+
oo.default_sheet = 1 # oo.sheets.first
|
179
|
+
assert_equal "tata", oo.cell(6,1)
|
180
|
+
assert_equal "tata", oo.cell(6,'A')
|
181
|
+
assert_equal "tata", oo.cell('A',6)
|
182
|
+
assert_equal "tata", oo.cell(6,'a')
|
183
|
+
assert_equal "tata", oo.cell('a',6)
|
184
|
+
|
185
|
+
assert_equal "thisisc8", oo.cell(8,3)
|
186
|
+
assert_equal "thisisc8", oo.cell(8,'C')
|
187
|
+
assert_equal "thisisc8", oo.cell('C',8)
|
188
|
+
assert_equal "thisisc8", oo.cell(8,'c')
|
189
|
+
assert_equal "thisisc8", oo.cell('c',8)
|
190
|
+
|
191
|
+
assert_equal "thisisd9", oo.cell('d',9)
|
192
|
+
assert_equal "thisisa11", oo.cell('a',11)
|
193
|
+
end
|
194
|
+
|
195
|
+
if GOOGLE
|
196
|
+
@goo.default_sheet = 1 # @goo.sheets.first
|
197
|
+
assert_equal "tata", @goo.cell(6,1)
|
198
|
+
assert_equal "tata", @goo.cell(6,'A')
|
199
|
+
assert_equal "tata", @goo.cell('A',6)
|
200
|
+
assert_equal "tata", @goo.cell(6,'a')
|
201
|
+
assert_equal "tata", @goo.cell('a',6)
|
202
|
+
|
203
|
+
assert_equal "thisisc8", @goo.cell(8,3)
|
204
|
+
assert_equal "thisisc8", @goo.cell(8,'C')
|
205
|
+
assert_equal "thisisc8", @goo.cell('C',8)
|
206
|
+
assert_equal "thisisc8", @goo.cell(8,'c')
|
207
|
+
assert_equal "thisisc8", @goo.cell('c',8)
|
208
|
+
|
209
|
+
assert_equal "thisisd9", @goo.cell('d',9)
|
210
|
+
assert_equal "thisisa11", @goo.cell('a',11)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
# Version of the (XML) office document
|
215
|
+
# please note that "1.0" is returned even if it was created with OpenOffice V. 2.0
|
216
|
+
def test_officeversion
|
217
|
+
#-- OpenOffice
|
218
|
+
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
130
219
|
assert_equal "1.0", oo.officeversion
|
220
|
+
if EXCEL
|
221
|
+
# excel does not have a officeversion
|
222
|
+
# is there a similar version number which ist considerable
|
223
|
+
#-- Excel
|
224
|
+
#if DateTime.now > Date.new(2007,6,15)
|
225
|
+
# oo = Excel.new(File.join("test","numbers1.xls"))
|
226
|
+
# assert_equal "1.0", oo.officeversion
|
227
|
+
#end
|
228
|
+
end
|
229
|
+
#-- Google
|
230
|
+
if GOOGLE
|
231
|
+
if DateTime.now > Date.new(2007,6,15)
|
232
|
+
assert_equal "1.0", @goo.officeversion
|
233
|
+
end
|
234
|
+
end
|
131
235
|
end
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
236
|
+
|
237
|
+
def test_rows
|
238
|
+
#-- OpenOffice
|
239
|
+
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
240
|
+
oo.default_sheet = oo.sheets.first
|
241
|
+
assert_equal 41, oo.cell('a',12)
|
242
|
+
assert_equal 42, oo.cell('b',12)
|
243
|
+
assert_equal 43, oo.cell('c',12)
|
244
|
+
assert_equal 44, oo.cell('d',12)
|
245
|
+
assert_equal 45, oo.cell('e',12)
|
246
|
+
assert_equal [41.0,42.0,43.0,44.0,45.0], oo.row(12)
|
247
|
+
if EXCEL
|
248
|
+
if DateTime.now > Date.new(2007,6,17)
|
249
|
+
#-- Excel
|
250
|
+
oo = Excel.new(File.join("test","numbers1.xls"))
|
251
|
+
oo.default_sheet = 1 # oo.sheets.first
|
252
|
+
assert_equal 41, oo.cell('a',12)
|
253
|
+
assert_equal 42, oo.cell('b',12)
|
254
|
+
assert_equal 43, oo.cell('c',12)
|
255
|
+
assert_equal 44, oo.cell('d',12)
|
256
|
+
assert_equal 45, oo.cell('e',12)
|
257
|
+
assert_equal [41.0,42.0,43.0,44.0,45.0], oo.row(12)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
if DateTime.now > Date.new(2007,6,17)
|
261
|
+
#-- GOOGLE
|
262
|
+
if GOOGLE
|
263
|
+
oo = Google.new(File.join("test","numbers1.xls"))
|
264
|
+
oo.default_sheet = 1 # oo.sheets.first
|
265
|
+
assert_equal 41, oo.cell('a',12)
|
266
|
+
assert_equal 42, oo.cell('b',12)
|
267
|
+
assert_equal 43, oo.cell('c',12)
|
268
|
+
assert_equal 44, oo.cell('d',12)
|
269
|
+
assert_equal 45, oo.cell('e',12)
|
270
|
+
assert_equal [41.0,42.0,43.0,44.0,45.0], oo.row(12)
|
271
|
+
end
|
272
|
+
end
|
154
273
|
end
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
274
|
+
|
275
|
+
def test_last_row
|
276
|
+
#-- OpenOffice
|
277
|
+
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
278
|
+
oo.default_sheet = oo.sheets.first
|
279
|
+
assert_equal 18, oo.last_row
|
280
|
+
if EXCEL
|
281
|
+
#-- Excel
|
282
|
+
oo = Excel.new(File.join("test","numbers1.xls"))
|
283
|
+
oo.default_sheet = 1 # oo.sheets.first
|
284
|
+
assert_equal 18, oo.last_row
|
285
|
+
end
|
286
|
+
if GOOGLE
|
287
|
+
#-- Google
|
288
|
+
@goo.default_sheet = @goo.sheets.first
|
289
|
+
assert_equal 18, @goo.last_row
|
290
|
+
assert_equal "xxx", @goo.to_s, @goo.to_s
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_last_column
|
295
|
+
#-- OpenOffice
|
296
|
+
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
297
|
+
oo.default_sheet = oo.sheets.first
|
298
|
+
assert_equal 7, oo.last_column
|
299
|
+
if EXCEL
|
300
|
+
#-- Excel
|
301
|
+
oo = Excel.new(File.join("test","numbers1.xls"))
|
302
|
+
oo.default_sheet = 1 # oo.sheets.first
|
303
|
+
assert_equal 7, oo.last_column
|
304
|
+
end
|
305
|
+
if GOOGLE
|
306
|
+
#-- Google
|
307
|
+
@goo.default_sheet = @goo.sheets.first
|
308
|
+
assert_equal 7, @goo.last_column
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_last_column_as_letter
|
313
|
+
#-- OpenOffice
|
314
|
+
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
315
|
+
oo.default_sheet = oo.sheets.first
|
316
|
+
assert_equal 'G', oo.last_column_as_letter
|
317
|
+
if EXCEL
|
318
|
+
#-- Excel
|
319
|
+
oo = Excel.new(File.join("test","numbers1.xls"))
|
320
|
+
oo.default_sheet = 1 # oo.sheets.first
|
321
|
+
assert_equal 'G', oo.last_column_as_letter
|
322
|
+
end
|
323
|
+
if GOOGLE
|
324
|
+
#-- Google
|
325
|
+
@goo.default_sheet = @goo.sheets.first
|
326
|
+
assert_equal 'G', @goo.last_column_as_letter
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
def test_first_row
|
331
|
+
#-- OpenOffice
|
332
|
+
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
333
|
+
oo.default_sheet = oo.sheets.first
|
334
|
+
assert_equal 1, oo.first_row
|
335
|
+
if EXCEL
|
336
|
+
#-- Excel
|
337
|
+
oo = Excel.new(File.join("test","numbers1.xls"))
|
338
|
+
oo.default_sheet = 1 # oo.sheets.first
|
339
|
+
assert_equal 1, oo.first_row
|
340
|
+
end
|
341
|
+
if GOOGLE
|
342
|
+
#-- Google
|
343
|
+
@goo.default_sheet = @goo.sheets.first
|
344
|
+
assert_equal 1, @goo.first_row
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_first_column
|
349
|
+
#-- OpenOffice
|
350
|
+
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
351
|
+
oo.default_sheet = oo.sheets.first
|
352
|
+
assert_equal 1, oo.first_column
|
353
|
+
if EXCEL
|
354
|
+
#-- Excel
|
355
|
+
oo = Excel.new(File.join("test","numbers1.xls"))
|
356
|
+
oo.default_sheet = 1 # oo.sheets.first
|
357
|
+
assert_equal 1, oo.first_column
|
358
|
+
end
|
359
|
+
if GOOGLE
|
360
|
+
#-- Google
|
361
|
+
@goo.default_sheet = 1 # @goo.sheets.first
|
362
|
+
assert_equal 1, @goo.first_column
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
def test_first_column_as_letter
|
367
|
+
#-- OpenOffice
|
368
|
+
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
369
|
+
oo.default_sheet = oo.sheets.first
|
370
|
+
assert_equal 'A', oo.first_column_as_letter
|
371
|
+
if EXCEL
|
372
|
+
#-- Excel
|
373
|
+
oo = Excel.new(File.join("test","numbers1.xls"))
|
374
|
+
oo.default_sheet = 1 # oo.sheets.first
|
375
|
+
assert_equal 'A', oo.first_column_as_letter
|
376
|
+
end
|
377
|
+
if GOOGLE
|
378
|
+
#-- Google
|
379
|
+
@goo.default_sheet = @goo.sheets.first
|
380
|
+
assert_equal 'A', @goo.first_column_as_letter
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
def test_sheetname
|
385
|
+
#-- OpenOffice
|
386
|
+
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
387
|
+
oo.default_sheet = "Name of Sheet 2"
|
388
|
+
assert_equal 'I am sheet 2', oo.cell('C',5)
|
389
|
+
if DateTime.now > Date.new(2007,6,16)
|
390
|
+
#-- Excel
|
391
|
+
if DateTime.now > Date.new(2007,6,30)
|
392
|
+
oo = Excel.new(File.join("test","numbers1.xls"))
|
393
|
+
oo.default_sheet = "Name of Sheet 2"
|
394
|
+
assert_equal 'I am sheet 2', oo.cell('C',5)
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
def test_boundaries
|
400
|
+
#-- OpenOffice
|
401
|
+
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
402
|
+
oo.default_sheet = "Name of Sheet 2"
|
403
|
+
assert_equal 2, oo.first_column
|
404
|
+
assert_equal 'B', oo.first_column_as_letter
|
405
|
+
assert_equal 5, oo.first_row
|
406
|
+
assert_equal 'E', oo.last_column_as_letter
|
407
|
+
assert_equal 14, oo.last_row
|
408
|
+
assert_equal 'E', oo.first_row_as_letter
|
409
|
+
assert_equal 'N', oo.last_row_as_letter
|
410
|
+
if EXCEL
|
411
|
+
#-- Excel
|
412
|
+
oo = Excel.new(File.join("test","numbers1.xls"))
|
413
|
+
oo.default_sheet = 2 # "Name of Sheet 2"
|
414
|
+
assert_equal 2, oo.first_column
|
415
|
+
assert_equal 'B', oo.first_column_as_letter
|
416
|
+
assert_equal 5, oo.first_row
|
417
|
+
assert_equal 'E', oo.last_column_as_letter
|
418
|
+
assert_equal 14, oo.last_row
|
419
|
+
assert_equal 'E', oo.first_row_as_letter
|
420
|
+
assert_equal 'N', oo.last_row_as_letter
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
def test_multiple_letters
|
425
|
+
#-- OpenOffice
|
426
|
+
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
427
|
+
oo.default_sheet = "Sheet3"
|
428
|
+
assert_equal "i am AA", oo.cell('AA',1)
|
429
|
+
assert_equal "i am AB", oo.cell('AB',1)
|
430
|
+
assert_equal "i am BA", oo.cell('BA',1)
|
431
|
+
assert_equal 'BA', oo.last_column_as_letter
|
432
|
+
assert_equal "i am BA", oo.cell(1,'BA')
|
433
|
+
if EXCEL
|
434
|
+
#-- Excel
|
435
|
+
oo = Excel.new(File.join("test","numbers1.xls"))
|
436
|
+
oo.default_sheet = 3 # "Sheet3"
|
437
|
+
assert_equal "i am AA", oo.cell('AA',1)
|
438
|
+
assert_equal "i am AB", oo.cell('AB',1)
|
439
|
+
assert_equal "i am BA", oo.cell('BA',1)
|
440
|
+
assert_equal 'BA', oo.last_column_as_letter
|
441
|
+
assert_equal "i am BA", oo.cell(1,'BA')
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
def test_setting_cell
|
446
|
+
assert true
|
447
|
+
end
|
448
|
+
|
449
|
+
def test_argument_error
|
450
|
+
if EXCEL
|
451
|
+
oo = Excel.new(File.join("test","numbers1.xls"))
|
452
|
+
assert_raise(ArgumentError) {
|
453
|
+
oo.default_sheet = "first sheet"
|
454
|
+
}
|
455
|
+
assert_nothing_raised(ArgumentError) {
|
456
|
+
oo.default_sheet = 1
|
457
|
+
}
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
def test_empty_eh
|
462
|
+
#-- OpenOffice
|
463
|
+
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
464
|
+
oo.default_sheet = oo.sheets.first
|
465
|
+
assert oo.empty?('a',14)
|
466
|
+
assert ! oo.empty?('a',15)
|
467
|
+
assert oo.empty?('a',20)
|
468
|
+
if EXCEL
|
469
|
+
#-- Excel
|
470
|
+
oo = Excel.new(File.join("test","numbers1.xls"))
|
471
|
+
oo.default_sheet = 1
|
472
|
+
assert oo.empty?('a',14)
|
473
|
+
assert ! oo.empty?('a',15)
|
474
|
+
assert oo.empty?('a',20)
|
475
|
+
end
|
233
476
|
end
|
234
|
-
end
|
235
477
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
478
|
+
def test_writeopenoffice
|
479
|
+
if OPENOFFICEWRITE
|
480
|
+
File.cp(File.join("test","numbers1.ods"),
|
481
|
+
File.join("test","numbers2.ods"))
|
482
|
+
File.cp(File.join("test","numbers2.ods"),
|
483
|
+
File.join("test","bak_numbers2.ods"))
|
484
|
+
oo = Openoffice.new(File.join("test","numbers2.ods"))
|
485
|
+
oo.default_sheet = oo.sheets.first
|
486
|
+
oo.first_row.upto(oo.last_row) {|y|
|
487
|
+
oo.first_column.upto(oo.last_column) {|x|
|
488
|
+
unless oo.empty?(y,x)
|
489
|
+
oo.set(y, x, oo.cell(y,x) + 7) if oo.celltype(y,x) == "float"
|
490
|
+
end
|
491
|
+
}
|
492
|
+
}
|
493
|
+
oo.save
|
494
|
+
|
495
|
+
oo1 = Openoffice.new(File.join("test","numbers2.ods"))
|
496
|
+
oo2 = Openoffice.new(File.join("test","bak_numbers2.ods"))
|
497
|
+
p oo2.to_s
|
498
|
+
assert_equal 999, oo2.cell('a',1), oo2.cell('a',1)
|
499
|
+
assert_equal oo2.cell('a',1) + 7, oo1.cell('a',1)
|
500
|
+
assert_equal oo2.cell('b',1)+7, oo1.cell('b',1)
|
501
|
+
assert_equal oo2.cell('c',1)+7, oo1.cell('c',1)
|
502
|
+
assert_equal oo2.cell('d',1)+7, oo1.cell('d',1)
|
503
|
+
assert_equal oo2.cell('a',2)+7, oo1.cell('a',2)
|
504
|
+
assert_equal oo2.cell('b',2)+7, oo1.cell('b',2)
|
505
|
+
assert_equal oo2.cell('c',2)+7, oo1.cell('c',2)
|
506
|
+
assert_equal oo2.cell('d',2)+7, oo1.cell('d',2)
|
507
|
+
assert_equal oo2.cell('e',2)+7, oo1.cell('e',2)
|
508
|
+
|
509
|
+
File.cp(File.join("test","bak_numbers2.ods"),
|
510
|
+
File.join("test","numbers2.ods"))
|
511
|
+
end
|
512
|
+
end
|
258
513
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
assert_equal "i am AA", oo.cell('AA',1)
|
264
|
-
assert_equal "i am AB", oo.cell('AB',1)
|
265
|
-
assert_equal "i am BA", oo.cell('BA',1)
|
266
|
-
assert_equal 'BA', oo.last_column_as_letter
|
267
|
-
assert_equal "i am BA", oo.cell(1,'BA')
|
268
|
-
#-- Excel
|
269
|
-
oo = Excel.new(File.join("test","numbers1.xls"))
|
270
|
-
oo.default_sheet = 3 # "Sheet3"
|
271
|
-
assert_equal "i am AA", oo.cell('AA',1)
|
272
|
-
assert_equal "i am AB", oo.cell('AB',1)
|
273
|
-
assert_equal "i am BA", oo.cell('BA',1)
|
274
|
-
assert_equal 'BA', oo.last_column_as_letter
|
275
|
-
assert_equal "i am BA", oo.cell(1,'BA')
|
276
|
-
end
|
514
|
+
def test_reload
|
515
|
+
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
516
|
+
oo.default_sheet = oo.sheets.first
|
517
|
+
assert_equal 1, oo.cell(1,1)
|
277
518
|
|
278
|
-
|
279
|
-
|
280
|
-
|
519
|
+
if DateTime.now < Date.new(2007, 6, 15)
|
520
|
+
oo.reload
|
521
|
+
assert_equal 2, oo.cell(1,1)
|
522
|
+
end
|
523
|
+
end
|
281
524
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
oo.default_sheet = "
|
286
|
-
|
287
|
-
|
288
|
-
oo.
|
289
|
-
|
290
|
-
|
525
|
+
def test_bug_contiguous_cells
|
526
|
+
if OPENOFFICE
|
527
|
+
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
528
|
+
oo.default_sheet = "Sheet4"
|
529
|
+
assert_equal Date.new(2007,06,16), oo.cell('a',1)
|
530
|
+
assert_equal 10, oo.cell('b',1)
|
531
|
+
assert_equal 10, oo.cell('c',1)
|
532
|
+
assert_equal 10, oo.cell('d',1)
|
533
|
+
assert_equal 10, oo.cell('e',1)
|
534
|
+
end
|
291
535
|
|
292
|
-
|
293
|
-
#-- OpenOffice
|
294
|
-
oo = Openoffice.new(File.join("test","numbers1.ods"))
|
295
|
-
oo.default_sheet = oo.sheets.first
|
296
|
-
assert oo.empty?('a',14)
|
297
|
-
assert ! oo.empty?('a',15)
|
298
|
-
assert oo.empty?('a',20)
|
299
|
-
#-- Excel
|
300
|
-
oo = Excel.new(File.join("test","numbers1.xls"))
|
301
|
-
oo.default_sheet = 1
|
302
|
-
assert oo.empty?('a',14)
|
303
|
-
assert ! oo.empty?('a',15)
|
304
|
-
assert oo.empty?('a',20)
|
536
|
+
end
|
305
537
|
|
306
|
-
end
|
307
|
-
end
|
538
|
+
end # class
|