roo 1.11.2 → 1.12.0
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/CHANGELOG +26 -1
- data/Gemfile +2 -1
- data/Gemfile.lock +26 -0
- data/README.markdown +82 -62
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/examples/roo_soap_server.rb +1 -1
- data/lib/roo.rb +28 -10
- data/lib/roo/{generic_spreadsheet.rb → base.rb} +127 -159
- data/lib/roo/csv.rb +28 -30
- data/lib/roo/excel.rb +38 -48
- data/lib/roo/excel2003xml.rb +24 -36
- data/lib/roo/excelx.rb +59 -61
- data/lib/roo/google.rb +36 -59
- data/lib/roo/openoffice.rb +41 -65
- data/lib/roo/roo_rails_helper.rb +2 -1
- data/lib/roo/spreadsheet.rb +17 -8
- data/roo.gemspec +20 -8
- data/spec/fixtures/vcr_cassettes/google_drive.yml +165 -0
- data/spec/fixtures/vcr_cassettes/google_drive_access_token.yml +73 -0
- data/spec/lib/roo/base_spec.rb +7 -0
- data/spec/lib/roo/csv_spec.rb +54 -0
- data/spec/lib/roo/excel_spec.rb +17 -0
- data/spec/lib/roo/excelx_spec.rb +13 -0
- data/spec/lib/roo/google_spec.rb +36 -0
- data/spec/lib/roo/libreoffice_spec.rb +19 -0
- data/spec/lib/roo/openoffice_spec.rb +21 -0
- data/spec/lib/roo/spreadsheet_spec.rb +13 -1
- data/spec/spec_helper.rb +7 -0
- data/test/all_ss.rb +1 -1
- data/test/files/1900_base.xlsx +0 -0
- data/test/files/1904_base.xlsx +0 -0
- data/test/rm_sub_test.rb +1 -1
- data/test/test_generic_spreadsheet.rb +68 -66
- data/test/test_helper.rb +3 -84
- data/test/test_roo.rb +85 -708
- data/website/index.html +16 -16
- data/website/index.txt +42 -42
- metadata +44 -7
- data/TODO +0 -2
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Roo::LibreOffice do
|
4
|
+
describe '.new' do
|
5
|
+
subject {
|
6
|
+
Roo::LibreOffice.new('test/files/numbers1.ods')
|
7
|
+
}
|
8
|
+
|
9
|
+
it 'creates an instance' do
|
10
|
+
expect(subject).to be_a(Roo::LibreOffice)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Roo::Libreoffice do
|
16
|
+
it 'is an alias of LibreOffice' do
|
17
|
+
expect(Roo::Libreoffice).to eq(Roo::LibreOffice)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Roo::OpenOffice do
|
4
|
+
describe '.new' do
|
5
|
+
subject {
|
6
|
+
Roo::OpenOffice.new('test/files/numbers1.ods')
|
7
|
+
}
|
8
|
+
|
9
|
+
it 'creates an instance' do
|
10
|
+
expect(subject).to be_a(Roo::OpenOffice)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# OpenOffice is an alias of LibreOffice. See libreoffice_spec.
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Roo::Openoffice do
|
18
|
+
it 'is an alias of LibreOffice' do
|
19
|
+
expect(Roo::Openoffice).to eq(Roo::OpenOffice)
|
20
|
+
end
|
21
|
+
end
|
@@ -6,9 +6,21 @@ describe Roo::Spreadsheet do
|
|
6
6
|
let(:filename) { 'file.XLS' }
|
7
7
|
|
8
8
|
it 'loads the proper type' do
|
9
|
-
Roo::Excel.should_receive(:new).with(filename)
|
9
|
+
Roo::Excel.should_receive(:new).with(filename, {})
|
10
10
|
Roo::Spreadsheet.open(filename)
|
11
11
|
end
|
12
12
|
end
|
13
|
+
|
14
|
+
context 'for a csv file' do
|
15
|
+
let(:filename) { 'file.csv' }
|
16
|
+
let(:options) { {csv_options: {col_sep: '"'}} }
|
17
|
+
|
18
|
+
context 'with options' do
|
19
|
+
it 'passes the options through' do
|
20
|
+
Roo::CSV.should_receive(:new).with(filename, options)
|
21
|
+
Roo::Spreadsheet.open(filename, options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
13
25
|
end
|
14
26
|
end
|
data/spec/spec_helper.rb
CHANGED
data/test/all_ss.rb
CHANGED
Binary file
|
Binary file
|
data/test/rm_sub_test.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
require File.dirname(__FILE__) + '/test_helper'
|
3
3
|
|
4
|
-
class
|
4
|
+
class TestBase < Test::Unit::TestCase
|
5
5
|
|
6
6
|
def setup
|
7
|
-
@klass = Class.new(Roo::
|
7
|
+
@klass = Class.new(Roo::Base) do
|
8
8
|
def initialize(filename='some_file')
|
9
9
|
super
|
10
10
|
@filename = filename
|
@@ -32,73 +32,73 @@ class TestGenericSpreadsheet < Test::Unit::TestCase
|
|
32
32
|
setup_test_sheet(@oo)
|
33
33
|
end
|
34
34
|
|
35
|
-
context 'Roo::
|
35
|
+
context 'Roo::Base.letter_to_number(letter)' do
|
36
36
|
should "give us 1 for 'A' and 'a'" do
|
37
|
-
assert_equal 1, Roo::
|
38
|
-
assert_equal 1, Roo::
|
37
|
+
assert_equal 1, Roo::Base.letter_to_number('A')
|
38
|
+
assert_equal 1, Roo::Base.letter_to_number('a')
|
39
39
|
end
|
40
40
|
|
41
41
|
should "give us the correct value for 'Z'" do
|
42
|
-
assert_equal 26, Roo::
|
42
|
+
assert_equal 26, Roo::Base.letter_to_number('Z')
|
43
43
|
end
|
44
44
|
|
45
45
|
should "give us the correct value for 'AA' regardless of case mixing" do
|
46
|
-
assert_equal 27, Roo::
|
47
|
-
assert_equal 27, Roo::
|
48
|
-
assert_equal 27, Roo::
|
49
|
-
assert_equal 27, Roo::
|
46
|
+
assert_equal 27, Roo::Base.letter_to_number('AA')
|
47
|
+
assert_equal 27, Roo::Base.letter_to_number('aA')
|
48
|
+
assert_equal 27, Roo::Base.letter_to_number('Aa')
|
49
|
+
assert_equal 27, Roo::Base.letter_to_number('aa')
|
50
50
|
end
|
51
51
|
|
52
52
|
should "give us the correct value for 'AB'" do
|
53
|
-
assert_equal 28, Roo::
|
53
|
+
assert_equal 28, Roo::Base.letter_to_number('AB')
|
54
54
|
end
|
55
55
|
|
56
56
|
should "give us the correct value for 'AZ'" do
|
57
|
-
assert_equal 26*2, Roo::
|
57
|
+
assert_equal 26*2, Roo::Base.letter_to_number('AZ')
|
58
58
|
end
|
59
59
|
|
60
60
|
should "give us the correct value for 'BZ'" do
|
61
|
-
assert_equal 26*3, Roo::
|
61
|
+
assert_equal 26*3, Roo::Base.letter_to_number('BZ')
|
62
62
|
end
|
63
63
|
|
64
64
|
should "give us the correct value for 'ZZ'" do
|
65
|
-
assert_equal 26**2 + 26,Roo::
|
65
|
+
assert_equal 26**2 + 26,Roo::Base.letter_to_number('ZZ')
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
context "Roo::
|
70
|
-
Roo::
|
69
|
+
context "Roo::Base.number_to_letter" do
|
70
|
+
Roo::Base::LETTERS.each_with_index do |l,i|
|
71
71
|
should "return '#{l}' when passed #{i+1}" do
|
72
|
-
assert_equal l,Roo::
|
72
|
+
assert_equal l,Roo::Base.number_to_letter(i+1)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
should "return 'AA' when passed 27" do
|
77
|
-
assert_equal 'AA',Roo::
|
77
|
+
assert_equal 'AA',Roo::Base.number_to_letter(27)
|
78
78
|
end
|
79
79
|
|
80
80
|
should "return 'AZ' when passed #{26*2}" do
|
81
|
-
assert_equal 'AZ', Roo::
|
81
|
+
assert_equal 'AZ', Roo::Base.number_to_letter(26*2)
|
82
82
|
end
|
83
83
|
|
84
84
|
should "return 'BZ' when passed #{26*3}" do
|
85
|
-
assert_equal 'BZ', Roo::
|
85
|
+
assert_equal 'BZ', Roo::Base.number_to_letter(26*3)
|
86
86
|
end
|
87
87
|
|
88
88
|
should "return 'ZZ' when passed #{26**2 + 26}" do
|
89
|
-
assert_equal 'ZZ',Roo::
|
89
|
+
assert_equal 'ZZ',Roo::Base.number_to_letter(26**2 + 26)
|
90
90
|
end
|
91
91
|
|
92
92
|
should "return 'AAA' when passed #{26**2 + 27}" do
|
93
|
-
assert_equal 'AAA',Roo::
|
93
|
+
assert_equal 'AAA',Roo::Base.number_to_letter(26**2 + 27)
|
94
94
|
end
|
95
95
|
|
96
96
|
should "return 'ZZZ' when passed #{26**3 + 26**2 + 26}" do
|
97
|
-
assert_equal 'ZZZ',Roo::
|
97
|
+
assert_equal 'ZZZ',Roo::Base.number_to_letter(26**3 + 26**2 + 26)
|
98
98
|
end
|
99
99
|
|
100
100
|
should "return the correct letter when passed a Float" do
|
101
|
-
assert_equal 'A',Roo::
|
101
|
+
assert_equal 'A',Roo::Base.number_to_letter(1.0)
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
@@ -177,53 +177,55 @@ class TestGenericSpreadsheet < Test::Unit::TestCase
|
|
177
177
|
protected
|
178
178
|
def setup_test_sheet(workbook=nil)
|
179
179
|
workbook ||= @oo
|
180
|
-
|
181
|
-
|
182
|
-
|
180
|
+
set_sheet_values(workbook)
|
181
|
+
set_sheet_types(workbook)
|
182
|
+
set_cells_read(workbook)
|
183
183
|
end
|
184
184
|
|
185
185
|
def set_sheet_values(workbook)
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
186
|
+
workbook.instance_variable_get(:@cell)[workbook.default_sheet] = {
|
187
|
+
[5,1] => Date.civil(1961,11,21).to_s,
|
188
|
+
|
189
|
+
[8,3] => "thisisc8",
|
190
|
+
[8,7] => "thisisg8",
|
191
|
+
|
192
|
+
[12,1] => 41.0,
|
193
|
+
[12,2] => 42.0,
|
194
|
+
[12,3] => 43.0,
|
195
|
+
[12,4] => 44.0,
|
196
|
+
[12,5] => 45.0,
|
197
|
+
|
198
|
+
[15,3] => 43.0,
|
199
|
+
[15,4] => 44.0,
|
200
|
+
[15,5] => 45.0,
|
201
|
+
|
202
|
+
[16,3] => "dreiundvierzig",
|
203
|
+
[16,4] => "vierundvierzig",
|
204
|
+
[16,5] => "fuenfundvierzig"
|
205
|
+
}
|
205
206
|
end
|
206
207
|
|
207
208
|
def set_sheet_types(workbook)
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
209
|
+
workbook.instance_variable_get(:@cell_type)[workbook.default_sheet] = {
|
210
|
+
[5,1] => :date,
|
211
|
+
|
212
|
+
[8,3] => :string,
|
213
|
+
[8,7] => :string,
|
214
|
+
|
215
|
+
[12,1] => :float,
|
216
|
+
[12,2] => :float,
|
217
|
+
[12,3] => :float,
|
218
|
+
[12,4] => :float,
|
219
|
+
[12,5] => :float,
|
220
|
+
|
221
|
+
[15,3] => :float,
|
222
|
+
[15,4] => :float,
|
223
|
+
[15,5] => :float,
|
224
|
+
|
225
|
+
[16,3] => :string,
|
226
|
+
[16,4] => :string,
|
227
|
+
[16,5] => :string,
|
228
|
+
}
|
227
229
|
end
|
228
230
|
|
229
231
|
def set_first_row(workbook)
|
@@ -254,4 +256,4 @@ protected
|
|
254
256
|
def expected_csv
|
255
257
|
",,,,,,\n,,,,,,\n,,,,,,\n,,,,,,\n1961-11-21,,,,,,\n,,,,,,\n,,,,,,\n,,\"thisisc8\",,,,\"thisisg8\"\n,,,,,,\n,,,,,,\n,,,,,,\n41,42,43,44,45,,\n,,,,,,\n,,,,,,\n,,43,44,45,,\n,,\"dreiundvierzig\",\"vierundvierzig\",\"fuenfundvierzig\",,\n"
|
256
258
|
end
|
257
|
-
end
|
259
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -24,43 +24,6 @@ $log = Logger.new(LOG_FILE)
|
|
24
24
|
$log.level = Logger::DEBUG
|
25
25
|
|
26
26
|
DISPLAY_LOG = false
|
27
|
-
DB_LOG = false
|
28
|
-
|
29
|
-
if DB_LOG
|
30
|
-
require 'activerecord'
|
31
|
-
|
32
|
-
def activerecord_connect
|
33
|
-
ActiveRecord::Base.establish_connection(:adapter => "mysql",
|
34
|
-
:database => "test_runs",
|
35
|
-
:host => "localhost",
|
36
|
-
:username => "root",
|
37
|
-
:socket => "/var/run/mysqld/mysqld.sock")
|
38
|
-
end
|
39
|
-
|
40
|
-
class Testrun < ActiveRecord::Base
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
class Roo::Csv
|
46
|
-
remove_method :cell_postprocessing
|
47
|
-
def cell_postprocessing(row,col,value)
|
48
|
-
if row==1 and col==1
|
49
|
-
return value.to_f
|
50
|
-
end
|
51
|
-
if row==1 and col==2
|
52
|
-
return value.to_s
|
53
|
-
end
|
54
|
-
return value
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# helper method
|
59
|
-
def local_only
|
60
|
-
if ENV["roo_local"] == "thomas-p"
|
61
|
-
yield
|
62
|
-
end
|
63
|
-
end
|
64
27
|
|
65
28
|
# very simple diff implementation
|
66
29
|
# output is an empty string if the files are equal
|
@@ -100,16 +63,9 @@ class File
|
|
100
63
|
end
|
101
64
|
end
|
102
65
|
|
103
|
-
# :nodoc
|
104
|
-
class Fixnum
|
105
|
-
def minutes
|
106
|
-
self * 60
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
66
|
class Test::Unit::TestCase
|
111
67
|
def key_of(spreadsheetname)
|
112
|
-
|
68
|
+
{
|
113
69
|
#'formula' => 'rt4Pw1WmjxFtyfrqqy94wPw',
|
114
70
|
'formula' => 'o10837434939102457526.3022866619437760118',
|
115
71
|
#"write.me" => 'r6m7HFlUOwst0RTUTuhQ0Ow',
|
@@ -129,7 +85,6 @@ class Test::Unit::TestCase
|
|
129
85
|
'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
|
130
86
|
'whitespace' => "rZyQaoFebVGeHKzjG6e9gRQ",
|
131
87
|
'matrix' => '0AkCuGANLc3jFdHY3cWtYUkM4bVdadjZ5VGpfTzFEUEE',
|
132
|
-
}[spreadsheetname]
|
133
88
|
# 'numbers1' => "o10837434939102457526.4784396906364855777",
|
134
89
|
# 'borders' => "o10837434939102457526.664868920231926255",
|
135
90
|
# 'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
|
@@ -139,48 +94,12 @@ class Test::Unit::TestCase
|
|
139
94
|
# 'formula' => 'o10837434939102457526.3022866619437760118',
|
140
95
|
# 'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
|
141
96
|
# 'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
|
142
|
-
|
97
|
+
}.fetch(spreadsheetname)
|
98
|
+
rescue KeyError
|
143
99
|
raise "unknown spreadsheetname: #{spreadsheetname}"
|
144
100
|
end
|
145
101
|
|
146
102
|
def yaml_entry(row,col,type,value)
|
147
103
|
"cell_#{row}_#{col}: \n row: #{row} \n col: #{col} \n celltype: #{type} \n value: #{value} \n"
|
148
104
|
end
|
149
|
-
|
150
|
-
if DB_LOG
|
151
|
-
if ! (defined?(@connected) and @connected)
|
152
|
-
activerecord_connect
|
153
|
-
else
|
154
|
-
@connected = true
|
155
|
-
end
|
156
|
-
end
|
157
|
-
# alias unlogged_run run
|
158
|
-
# def run(result, &block)
|
159
|
-
# t1 = Time.now
|
160
|
-
# if DISPLAY_LOG
|
161
|
-
# v1,v2,_ = RUBY_VERSION.split('.')
|
162
|
-
# if v1.to_i > 1 or
|
163
|
-
# (v1.to_i == 1 and v2.to_i > 8)
|
164
|
-
# # Ruby 1.9.x
|
165
|
-
# print "RUNNING #{self.class} #{self.__name__} \t#{Time.now.to_s}"
|
166
|
-
# else
|
167
|
-
# # Ruby < 1.9.x
|
168
|
-
# print "RUNNING #{self.class} #{@method_name} \t#{Time.now.to_s}"
|
169
|
-
# end
|
170
|
-
# STDOUT.flush
|
171
|
-
# end
|
172
|
-
# unlogged_run result, &block
|
173
|
-
# t2 = Time.now
|
174
|
-
# if DISPLAY_LOG
|
175
|
-
# puts "\t#{t2-t1} seconds"
|
176
|
-
# end
|
177
|
-
# if DB_LOG
|
178
|
-
# Testrun.create(
|
179
|
-
# :class_name => self.class.to_s,
|
180
|
-
# :test_name => @method_name,
|
181
|
-
# :start => t1,
|
182
|
-
# :duration => t2-t1
|
183
|
-
# )
|
184
|
-
# end
|
185
|
-
# end
|
186
105
|
end
|
data/test/test_roo.rb
CHANGED
@@ -21,11 +21,11 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
21
21
|
|
22
22
|
class TestRoo < Test::Unit::TestCase
|
23
23
|
|
24
|
-
OPENOFFICE =
|
25
|
-
EXCEL = true
|
24
|
+
OPENOFFICE = true # do OpenOffice-Spreadsheet Tests? (.ods files)
|
25
|
+
EXCEL = true # do Excel Tests? (.xls files)
|
26
26
|
GOOGLE = false # do Google-Spreadsheet Tests?
|
27
27
|
EXCELX = true # do Excelx Tests? (.xlsx files)
|
28
|
-
LIBREOFFICE = true # do
|
28
|
+
LIBREOFFICE = true # do LibreOffice tests? (.ods files)
|
29
29
|
CSV = true # do CSV tests? (.csv files)
|
30
30
|
|
31
31
|
FORMATS = {
|
@@ -39,10 +39,6 @@ class TestRoo < Test::Unit::TestCase
|
|
39
39
|
ONLINE = false
|
40
40
|
LONG_RUN = false
|
41
41
|
|
42
|
-
def test_internal_minutes
|
43
|
-
assert_equal 42*60, 42.minutes
|
44
|
-
end
|
45
|
-
|
46
42
|
def fixture_filename(name, format)
|
47
43
|
case format
|
48
44
|
when :excel
|
@@ -52,7 +48,7 @@ class TestRoo < Test::Unit::TestCase
|
|
52
48
|
when :openoffice, :libreoffice
|
53
49
|
"#{name}.ods"
|
54
50
|
when :google
|
55
|
-
key_of(name)
|
51
|
+
key_of(name)
|
56
52
|
end
|
57
53
|
end
|
58
54
|
|
@@ -96,36 +92,9 @@ class TestRoo < Test::Unit::TestCase
|
|
96
92
|
end
|
97
93
|
end
|
98
94
|
|
99
|
-
def test_classes
|
100
|
-
if OPENOFFICE
|
101
|
-
oo = Roo::Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
|
102
|
-
assert_kind_of Roo::Openoffice, oo
|
103
|
-
end
|
104
|
-
if EXCEL
|
105
|
-
oo = Roo::Excel.new(File.join(TESTDIR,"numbers1.xls"))
|
106
|
-
assert_kind_of Roo::Excel, oo
|
107
|
-
end
|
108
|
-
if GOOGLE
|
109
|
-
oo = Roo::Google.new(key_of("numbers1"))
|
110
|
-
assert_kind_of Roo::Google, oo
|
111
|
-
end
|
112
|
-
if EXCELX
|
113
|
-
oo = Roo::Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
|
114
|
-
assert_kind_of Roo::Excelx, oo
|
115
|
-
end
|
116
|
-
if LIBREOFFICE
|
117
|
-
oo = Roo::Libreoffice.new(File.join(TESTDIR,"numbers1.ods"))
|
118
|
-
assert_kind_of Roo::Libreoffice, oo
|
119
|
-
end
|
120
|
-
if CSV
|
121
|
-
oo = Roo::Csv.new(File.join(TESTDIR,"numbers1.csv"))
|
122
|
-
assert_kind_of Roo::Csv, oo
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
95
|
def test_sheets_csv
|
127
96
|
if CSV
|
128
|
-
oo = Roo::
|
97
|
+
oo = Roo::CSV.new(File.join(TESTDIR,'numbers1.csv'))
|
129
98
|
assert_equal ["default"], oo.sheets
|
130
99
|
assert_raise(RangeError) { oo.default_sheet = "no_sheet" }
|
131
100
|
assert_raise(TypeError) { oo.default_sheet = [1,2,3] }
|
@@ -165,7 +134,7 @@ class TestRoo < Test::Unit::TestCase
|
|
165
134
|
assert_equal "test", oo.cell(2,6)
|
166
135
|
assert_equal :string, oo.celltype(2,6)
|
167
136
|
assert_equal 11, oo.cell(2,7)
|
168
|
-
unless oo.kind_of? Roo::
|
137
|
+
unless oo.kind_of? Roo::CSV
|
169
138
|
assert_equal :float, oo.celltype(2,7)
|
170
139
|
end
|
171
140
|
assert_equal 10, oo.cell(4,1)
|
@@ -178,7 +147,7 @@ class TestRoo < Test::Unit::TestCase
|
|
178
147
|
assert_equal 12, oo.cell(4,'C')
|
179
148
|
assert_equal 13, oo.cell(4,'D')
|
180
149
|
assert_equal 14, oo.cell(4,'E')
|
181
|
-
unless oo.kind_of? Roo::
|
150
|
+
unless oo.kind_of? Roo::CSV
|
182
151
|
assert_equal :date, oo.celltype(5,1)
|
183
152
|
assert_equal Date.new(1961,11,21), oo.cell(5,1)
|
184
153
|
assert_equal "1961-11-21", oo.cell(5,1).to_s
|
@@ -219,7 +188,7 @@ class TestRoo < Test::Unit::TestCase
|
|
219
188
|
|
220
189
|
def test_libre_office
|
221
190
|
if LIBREOFFICE
|
222
|
-
oo = Roo::
|
191
|
+
oo = Roo::LibreOffice.new(File.join(TESTDIR, "numbers1.ods"))
|
223
192
|
oo.default_sheet = oo.sheets.first
|
224
193
|
assert_equal 41, oo.cell('a',12)
|
225
194
|
end
|
@@ -235,16 +204,12 @@ class TestRoo < Test::Unit::TestCase
|
|
235
204
|
assert_raise(RangeError) { oo.celltype('C',5,"non existing sheet name")}
|
236
205
|
assert_raise(RangeError) { oo.empty?('C',5,"non existing sheet name")}
|
237
206
|
if oo.class == Roo::Excel
|
238
|
-
assert_raise(
|
239
|
-
assert_raise(
|
207
|
+
assert_raise(NotImplementedError) { oo.formula?('C',5,"non existing sheet name")}
|
208
|
+
assert_raise(NotImplementedError) { oo.formula('C',5,"non existing sheet name")}
|
240
209
|
else
|
241
210
|
assert_raise(RangeError) { oo.formula?('C',5,"non existing sheet name")}
|
242
211
|
assert_raise(RangeError) { oo.formula('C',5,"non existing sheet name")}
|
243
|
-
|
244
|
-
assert_raise(RangeError) { oo.set('C',5,42,"non existing sheet name")}
|
245
|
-
rescue NameError
|
246
|
-
#
|
247
|
-
end
|
212
|
+
assert_raise(RangeError) { oo.set('C',5,42,"non existing sheet name")}
|
248
213
|
assert_raise(RangeError) { oo.formulas("non existing sheet name")}
|
249
214
|
end
|
250
215
|
assert_raise(RangeError) { oo.to_yaml({},1,1,1,1,"non existing sheet name")}
|
@@ -319,7 +284,7 @@ class TestRoo < Test::Unit::TestCase
|
|
319
284
|
assert_equal "A:string",oo.cell(4, 3)+":"+oo.celltype(4, 3).to_s
|
320
285
|
|
321
286
|
# Cells values in row 5:
|
322
|
-
if oo.class == Roo::
|
287
|
+
if oo.class == Roo::OpenOffice
|
323
288
|
assert_equal "0.01:percentage",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
|
324
289
|
assert_equal "0.01:percentage",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
|
325
290
|
assert_equal "0.01:percentage",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
|
@@ -372,7 +337,7 @@ class TestRoo < Test::Unit::TestCase
|
|
372
337
|
assert_equal 21.0, oo.cell('A',7) #TODO: better solution Fixnum/Float
|
373
338
|
assert_equal :formula, oo.celltype('A',7)
|
374
339
|
# assert_equal "=[Sheet2.A1]", oo.formula('C',7)
|
375
|
-
# !!! different from formulas in
|
340
|
+
# !!! different from formulas in OpenOffice
|
376
341
|
#was: assert_equal "=sheet2!R[-6]C[-2]", oo.formula('C',7)
|
377
342
|
# has Google changed their format of formulas/references to other sheets?
|
378
343
|
assert_equal "=Sheet2!R[-6]C[-2]", oo.formula('C',7)
|
@@ -408,7 +373,7 @@ class TestRoo < Test::Unit::TestCase
|
|
408
373
|
assert_equal 21, oo.cell('A',7)
|
409
374
|
assert_equal :formula, oo.celltype('A',7)
|
410
375
|
#steht nicht in Datei, oder?
|
411
|
-
#nein, diesen Bezug habe ich nur in der
|
376
|
+
#nein, diesen Bezug habe ich nur in der OpenOffice-Datei
|
412
377
|
#assert_equal "=[Sheet2.A1]", oo.formula('C',7)
|
413
378
|
assert_nil oo.formula('A',6)
|
414
379
|
# assert_equal [[7, 1, "=SUM([.A1:.A6])"],
|
@@ -474,7 +439,7 @@ class TestRoo < Test::Unit::TestCase
|
|
474
439
|
end
|
475
440
|
end
|
476
441
|
|
477
|
-
def
|
442
|
+
def test_excel_download_uri_and_zipped
|
478
443
|
if EXCEL
|
479
444
|
if ONLINE
|
480
445
|
url = 'http://stiny-leonhard.de/bode-v1.xls.zip'
|
@@ -485,11 +450,11 @@ class TestRoo < Test::Unit::TestCase
|
|
485
450
|
end
|
486
451
|
end
|
487
452
|
|
488
|
-
def
|
453
|
+
def test_openoffice_download_uri_and_zipped
|
489
454
|
if OPENOFFICE
|
490
455
|
if ONLINE
|
491
456
|
url = 'http://spazioinwind.libero.it/s2/rata.ods.zip'
|
492
|
-
sheet = Roo::
|
457
|
+
sheet = Roo::OpenOffice.new(url, :zip)
|
493
458
|
#has been changed: assert_equal 'ist "e" im Nenner von H(s)', sheet.cell('b', 5)
|
494
459
|
assert_in_delta 0.001, 505.14, sheet.cell('c', 33).to_f
|
495
460
|
end
|
@@ -507,7 +472,7 @@ class TestRoo < Test::Unit::TestCase
|
|
507
472
|
def test_openoffice_zipped
|
508
473
|
if OPENOFFICE
|
509
474
|
begin
|
510
|
-
oo = Roo::
|
475
|
+
oo = Roo::OpenOffice.new(File.join(TESTDIR,"bode-v1.ods.zip"), :zip)
|
511
476
|
assert oo
|
512
477
|
assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
|
513
478
|
end
|
@@ -915,15 +880,15 @@ class TestRoo < Test::Unit::TestCase
|
|
915
880
|
|
916
881
|
def test_excel_does_not_support_formulas
|
917
882
|
with_each_spreadsheet(:name=>'false_encoding', :format=>:excel) do |oo|
|
918
|
-
assert_raise(
|
919
|
-
assert_raise(
|
920
|
-
assert_raise(
|
883
|
+
assert_raise(NotImplementedError) { oo.formula('a',1) }
|
884
|
+
assert_raise(NotImplementedError) { oo.formula?('a',1) }
|
885
|
+
assert_raise(NotImplementedError) { oo.formulas(oo.sheets.first) }
|
921
886
|
end
|
922
887
|
end
|
923
888
|
|
924
889
|
def get_extension(oo)
|
925
890
|
case oo
|
926
|
-
when Roo::
|
891
|
+
when Roo::OpenOffice
|
927
892
|
".ods"
|
928
893
|
when Roo::Excel
|
929
894
|
".xls"
|
@@ -983,35 +948,35 @@ class TestRoo < Test::Unit::TestCase
|
|
983
948
|
oo.default_sheet = "Tabelle1"
|
984
949
|
assert_equal 1, oo.first_row
|
985
950
|
assert_equal 18, oo.last_row
|
986
|
-
assert_equal Roo::
|
987
|
-
assert_equal Roo::
|
951
|
+
assert_equal Roo::OpenOffice.letter_to_number('A'), oo.first_column
|
952
|
+
assert_equal Roo::OpenOffice.letter_to_number('G'), oo.last_column
|
988
953
|
oo.default_sheet = "Name of Sheet 2"
|
989
954
|
assert_equal 5, oo.first_row
|
990
955
|
assert_equal 14, oo.last_row
|
991
|
-
assert_equal Roo::
|
992
|
-
assert_equal Roo::
|
956
|
+
assert_equal Roo::OpenOffice.letter_to_number('B'), oo.first_column
|
957
|
+
assert_equal Roo::OpenOffice.letter_to_number('E'), oo.last_column
|
993
958
|
oo.default_sheet = "Sheet3"
|
994
959
|
assert_equal 1, oo.first_row
|
995
960
|
assert_equal 1, oo.last_row
|
996
|
-
assert_equal Roo::
|
997
|
-
assert_equal Roo::
|
961
|
+
assert_equal Roo::OpenOffice.letter_to_number('A'), oo.first_column
|
962
|
+
assert_equal Roo::OpenOffice.letter_to_number('BA'), oo.last_column
|
998
963
|
oo.default_sheet = "Sheet4"
|
999
964
|
assert_equal 1, oo.first_row
|
1000
965
|
assert_equal 1, oo.last_row
|
1001
|
-
assert_equal Roo::
|
1002
|
-
assert_equal Roo::
|
966
|
+
assert_equal Roo::OpenOffice.letter_to_number('A'), oo.first_column
|
967
|
+
assert_equal Roo::OpenOffice.letter_to_number('E'), oo.last_column
|
1003
968
|
oo.default_sheet = "Sheet5"
|
1004
969
|
assert_equal 1, oo.first_row
|
1005
970
|
assert_equal 6, oo.last_row
|
1006
|
-
assert_equal Roo::
|
1007
|
-
assert_equal Roo::
|
971
|
+
assert_equal Roo::OpenOffice.letter_to_number('A'), oo.first_column
|
972
|
+
assert_equal Roo::OpenOffice.letter_to_number('E'), oo.last_column
|
1008
973
|
end
|
1009
974
|
end
|
1010
975
|
|
1011
976
|
def test_should_raise_file_not_found_error
|
1012
977
|
if OPENOFFICE
|
1013
978
|
assert_raise(IOError) {
|
1014
|
-
Roo::
|
979
|
+
Roo::OpenOffice.new(File.join('testnichtvorhanden','Bibelbund.ods'))
|
1015
980
|
}
|
1016
981
|
end
|
1017
982
|
if EXCEL
|
@@ -1203,9 +1168,9 @@ Sheet 3:
|
|
1203
1168
|
def test_file_warning_default
|
1204
1169
|
if OPENOFFICE
|
1205
1170
|
assert_raises(TypeError, "test/files/numbers1.xls is not an openoffice spreadsheet") {
|
1206
|
-
Roo::
|
1171
|
+
Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xls"))
|
1207
1172
|
}
|
1208
|
-
assert_raises(TypeError) { Roo::
|
1173
|
+
assert_raises(TypeError) { Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xlsx")) }
|
1209
1174
|
end
|
1210
1175
|
if EXCEL
|
1211
1176
|
assert_raises(TypeError) { Roo::Excel.new(File.join(TESTDIR,"numbers1.ods")) }
|
@@ -1219,8 +1184,8 @@ Sheet 3:
|
|
1219
1184
|
|
1220
1185
|
def test_file_warning_error
|
1221
1186
|
if OPENOFFICE
|
1222
|
-
assert_raises(TypeError) { Roo::
|
1223
|
-
assert_raises(TypeError) { Roo::
|
1187
|
+
assert_raises(TypeError) { Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xls"),false,:error) }
|
1188
|
+
assert_raises(TypeError) { Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) }
|
1224
1189
|
end
|
1225
1190
|
if EXCEL
|
1226
1191
|
assert_raises(TypeError) { Roo::Excel.new(File.join(TESTDIR,"numbers1.ods"),false,:error) }
|
@@ -1236,12 +1201,12 @@ Sheet 3:
|
|
1236
1201
|
if OPENOFFICE
|
1237
1202
|
assert_nothing_raised(TypeError) {
|
1238
1203
|
assert_raises(Zip::ZipError) {
|
1239
|
-
Roo::
|
1204
|
+
Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xls"),false, :warning)
|
1240
1205
|
}
|
1241
1206
|
}
|
1242
1207
|
assert_nothing_raised(TypeError) {
|
1243
1208
|
assert_raises(Errno::ENOENT) {
|
1244
|
-
Roo::
|
1209
|
+
Roo::OpenOffice.new(File.join(TESTDIR,"numbers1.xlsx"),false, :warning)
|
1245
1210
|
}
|
1246
1211
|
}
|
1247
1212
|
end
|
@@ -1273,18 +1238,18 @@ Sheet 3:
|
|
1273
1238
|
|
1274
1239
|
def test_file_warning_ignore
|
1275
1240
|
if OPENOFFICE
|
1276
|
-
# Files, die eigentlich
|
1241
|
+
# Files, die eigentlich OpenOffice-
|
1277
1242
|
# Files sind, aber die falsche Endung haben.
|
1278
1243
|
# Es soll ohne Fehlermeldung oder Warnung
|
1279
1244
|
# oder Abbruch die Datei geoffnet werden
|
1280
1245
|
|
1281
1246
|
# xls
|
1282
1247
|
assert_nothing_raised() {
|
1283
|
-
Roo::
|
1248
|
+
Roo::OpenOffice.new(File.join(TESTDIR,"type_openoffice.xls"),false, :ignore)
|
1284
1249
|
}
|
1285
1250
|
# xlsx
|
1286
1251
|
assert_nothing_raised() {
|
1287
|
-
Roo::
|
1252
|
+
Roo::OpenOffice.new(File.join(TESTDIR,"type_openoffice.xlsx"),false, :ignore)
|
1288
1253
|
}
|
1289
1254
|
end
|
1290
1255
|
if EXCEL
|
@@ -1576,6 +1541,19 @@ Sheet 3:
|
|
1576
1541
|
end
|
1577
1542
|
end
|
1578
1543
|
|
1544
|
+
# Excel has two base date formats one from 1900 and the other from 1904.
|
1545
|
+
# see #test_base_dates_in_excel
|
1546
|
+
def test_base_dates_in_excelx
|
1547
|
+
with_each_spreadsheet(:name=>'1900_base', :format=>:excelx) do |oo|
|
1548
|
+
assert_equal Date.new(2009,06,15), oo.cell(1,1)
|
1549
|
+
assert_equal :date, oo.celltype(1,1)
|
1550
|
+
end
|
1551
|
+
with_each_spreadsheet(:name=>'1904_base', :format=>:excelx) do |oo|
|
1552
|
+
assert_equal Date.new(2009,06,15), oo.cell(1,1)
|
1553
|
+
assert_equal :date, oo.celltype(1,1)
|
1554
|
+
end
|
1555
|
+
end
|
1556
|
+
|
1579
1557
|
def test_bad_date
|
1580
1558
|
with_each_spreadsheet(:name=>'prova', :format=>:excel) do |oo|
|
1581
1559
|
assert_nothing_raised(ArgumentError) {
|
@@ -1614,7 +1592,7 @@ Sheet 3:
|
|
1614
1592
|
def test_compare_large_spreadsheets
|
1615
1593
|
# problematisch, weil Formeln in Excel nicht unterstützt werden
|
1616
1594
|
if LONG_RUN
|
1617
|
-
qq = Roo::
|
1595
|
+
qq = Roo::OpenOffice.new(File.join('test',"Bibelbund.ods"))
|
1618
1596
|
with_each_spreadsheet(:name=>'Bibelbund') do |oo|
|
1619
1597
|
# p "comparing Bibelbund.ods with #{oo.class}"
|
1620
1598
|
oo.sheets.each do |sh|
|
@@ -1731,27 +1709,6 @@ Sheet 3:
|
|
1731
1709
|
end
|
1732
1710
|
end
|
1733
1711
|
|
1734
|
-
|
1735
|
-
def test_bug_excel_last_row_255
|
1736
|
-
if LONG_RUN
|
1737
|
-
local_only do
|
1738
|
-
oo = Roo::Excel.new(File.join('..','confidential','ScienceStaff.xls'))
|
1739
|
-
oo.default_sheet = oo.sheets.first
|
1740
|
-
assert_equal "COMSCI", oo.cell(255,1)
|
1741
|
-
assert_equal "lala", oo.cell(256,1)
|
1742
|
-
assert_equal 1537, oo.last_row
|
1743
|
-
end
|
1744
|
-
end
|
1745
|
-
end
|
1746
|
-
|
1747
|
-
def test_bug_excel_last_row_255_modified
|
1748
|
-
local_only do
|
1749
|
-
oo = Roo::Excel.new(File.join('..','confidential','ScienceStaff_modified.xls'))
|
1750
|
-
oo.default_sheet = oo.sheets.first
|
1751
|
-
assert_equal 1537, oo.last_row
|
1752
|
-
end
|
1753
|
-
end
|
1754
|
-
|
1755
1712
|
require 'matrix'
|
1756
1713
|
def test_matrix
|
1757
1714
|
with_each_spreadsheet(:name => 'matrix', :format => [:openoffice, :excel, :google]) do |oo|
|
@@ -1793,17 +1750,6 @@ Sheet 3:
|
|
1793
1750
|
end
|
1794
1751
|
end
|
1795
1752
|
|
1796
|
-
def test_bug_date_mileszs
|
1797
|
-
local_only do
|
1798
|
-
oo = Roo::Excel.new "/home/tp/Documents/feb-sales-analysis.xls"
|
1799
|
-
oo.default_sheet = oo.sheets.first
|
1800
|
-
# 2/1/2010 A2-A6 mm/dd/yyyy
|
1801
|
-
2.upto(6) do |i|
|
1802
|
-
assert_equal Date.new(2010,2,1), oo.cell('A',i)
|
1803
|
-
end
|
1804
|
-
end
|
1805
|
-
end
|
1806
|
-
|
1807
1753
|
# unter Windows soll es laut Bug-Reports nicht moeglich sein, eine Excel-Datei, die
|
1808
1754
|
# mit Excel.new geoeffnet wurde nach dem Processing anschliessend zu loeschen.
|
1809
1755
|
# Anmerkung: Das Spreadsheet-Gem erlaubt kein explizites Close von Spreadsheet-Dateien,
|
@@ -1842,85 +1788,6 @@ where the expected result is
|
|
1842
1788
|
end
|
1843
1789
|
end
|
1844
1790
|
|
1845
|
-
def test_bug_guest_list_2011_05_05
|
1846
|
-
local_only do
|
1847
|
-
oo = Roo::Excel.new(File.join("..","confidential","guest_list_addresses.xls"))
|
1848
|
-
oo.default_sheet = oo.sheets.first
|
1849
|
-
assert_equal "lalala", oo.cell('a',1) # anderer Inhalt im Spreadsheet
|
1850
|
-
assert_equal :string, oo.celltype('a',1)
|
1851
|
-
end
|
1852
|
-
end
|
1853
|
-
|
1854
|
-
def test_bug_guest_list_2011_05_05_spreadsheet
|
1855
|
-
local_only do
|
1856
|
-
require 'spreadsheet'
|
1857
|
-
book = Spreadsheet.open File.join('..','confidential','guest_list_addresses.xls')
|
1858
|
-
sheet1 = book.worksheet 0
|
1859
|
-
sheet1.each do |row|
|
1860
|
-
p row[0]
|
1861
|
-
end
|
1862
|
-
end
|
1863
|
-
end
|
1864
|
-
|
1865
|
-
# don't test it with other spreadsheet types! this was only a problem
|
1866
|
-
# with .xlsx files
|
1867
|
-
def test_bug_date_not_recognized_2011_05_21
|
1868
|
-
if EXCELX
|
1869
|
-
local_only do
|
1870
|
-
oo = Roo::Excelx.new(File.join('..','confidential','2011-05-21_sample_date_problem.xlsx'))
|
1871
|
-
oo.default_sheet = oo.sheets.first
|
1872
|
-
assert_equal Date.new(2011,3,24), oo.b4
|
1873
|
-
assert_equal Date.new(2011,3,25), oo.b5
|
1874
|
-
assert_equal Date.new(2011,5,5), oo.b6
|
1875
|
-
assert_equal Date.new(2012,3,23), oo.b7
|
1876
|
-
end
|
1877
|
-
end
|
1878
|
-
end
|
1879
|
-
|
1880
|
-
def test_bug_string_as_a_date_2011_05_21_spreadsheet_only
|
1881
|
-
if EXCEL
|
1882
|
-
local_only do
|
1883
|
-
require 'spreadsheet'
|
1884
|
-
book = Spreadsheet.open File.join('..','confidential','2011-05-21_sample_type_problem.xls')
|
1885
|
-
sheet1 = book.worksheet 0
|
1886
|
-
sheet1.each_with_index do |row,rownum|
|
1887
|
-
# p row[0]
|
1888
|
-
if rownum == 2
|
1889
|
-
assert_equal 68, row[6]
|
1890
|
-
end
|
1891
|
-
end
|
1892
|
-
end
|
1893
|
-
end
|
1894
|
-
end
|
1895
|
-
|
1896
|
-
def test_bug_string_as_a_date_2011_05_21
|
1897
|
-
if EXCEL
|
1898
|
-
local_only do
|
1899
|
-
oo = Roo::Excel.new(File.join('..','confidential','2011-05-21_sample_type_problem.xls'))
|
1900
|
-
oo.default_sheet = oo.sheets.first
|
1901
|
-
assert_equal 68, oo.g2
|
1902
|
-
assert_equal 72, oo.g3
|
1903
|
-
assert_equal 75, oo.g4
|
1904
|
-
assert_equal 76, oo.g5
|
1905
|
-
assert_equal 77, oo.g6
|
1906
|
-
assert_equal 78, oo.g7
|
1907
|
-
end
|
1908
|
-
end
|
1909
|
-
end
|
1910
|
-
|
1911
|
-
def test_bug_string_as_a_date_2011_05_21_saved_as_ods
|
1912
|
-
local_only do
|
1913
|
-
oo = Roo::Openoffice.new(File.join('..','confidential','2011-05-21_sample_type_problem.ods'))
|
1914
|
-
oo.default_sheet = oo.sheets.first
|
1915
|
-
assert_equal 68, oo.g2
|
1916
|
-
assert_equal 72, oo.g3
|
1917
|
-
assert_equal 75, oo.g4
|
1918
|
-
assert_equal 76, oo.g5
|
1919
|
-
assert_equal 77, oo.g6
|
1920
|
-
assert_equal 78, oo.g7
|
1921
|
-
end
|
1922
|
-
end
|
1923
|
-
|
1924
1791
|
# #formulas of an empty sheet should return an empty array and not result in
|
1925
1792
|
# an error message
|
1926
1793
|
# 2011-06-24
|
@@ -1982,11 +1849,11 @@ where the expected result is
|
|
1982
1849
|
# Dieses Dokument wurde mit LibreOffice angelegt.
|
1983
1850
|
# Keine Ahnung, ob es damit zusammenhaengt, das diese
|
1984
1851
|
# Formeln anders sind, als in der Datei formula.ods, welche
|
1985
|
-
# mit
|
1986
|
-
# Bei den
|
1852
|
+
# mit OpenOffice angelegt wurde.
|
1853
|
+
# Bei den OpenOffice-Dateien ist in diesem Feld in der XML-
|
1987
1854
|
# Datei of: als Prefix enthalten, waehrend in dieser Datei
|
1988
1855
|
# irgendetwas mit oooc: als Prefix verwendet wird.
|
1989
|
-
oo = Roo::
|
1856
|
+
oo = Roo::OpenOffice.new(File.join(TESTDIR,'dreimalvier.ods'))
|
1990
1857
|
oo.default_sheet = oo.sheets.first
|
1991
1858
|
assert_equal '=SUM([.A1:.D1])', oo.formula('e',1)
|
1992
1859
|
assert_equal '=SUM([.A2:.D2])', oo.formula('e',2)
|
@@ -2003,7 +1870,7 @@ where the expected result is
|
|
2003
1870
|
=begin
|
2004
1871
|
def test_postprocessing_and_types_in_csv
|
2005
1872
|
if CSV
|
2006
|
-
oo =
|
1873
|
+
oo = CSV.new(File.join(TESTDIR,'csvtypes.csv'))
|
2007
1874
|
oo.default_sheet = oo.sheets.first
|
2008
1875
|
assert_equal(1,oo.a1)
|
2009
1876
|
assert_equal(:float,oo.celltype('A',1))
|
@@ -2018,7 +1885,7 @@ where the expected result is
|
|
2018
1885
|
=begin
|
2019
1886
|
def test_postprocessing_with_callback_function
|
2020
1887
|
if CSV
|
2021
|
-
oo =
|
1888
|
+
oo = CSV.new(File.join(TESTDIR,'csvtypes.csv'))
|
2022
1889
|
oo.default_sheet = oo.sheets.first
|
2023
1890
|
|
2024
1891
|
#
|
@@ -2029,7 +1896,7 @@ where the expected result is
|
|
2029
1896
|
|
2030
1897
|
=begin
|
2031
1898
|
def x_123
|
2032
|
-
class ::
|
1899
|
+
class ::CSV
|
2033
1900
|
def cell_postprocessing(row,col,value)
|
2034
1901
|
if row < 3
|
2035
1902
|
return nil
|
@@ -2043,7 +1910,7 @@ where the expected result is
|
|
2043
1910
|
def test_nil_rows_and_lines_csv
|
2044
1911
|
# x_123
|
2045
1912
|
if CSV
|
2046
|
-
oo = Roo::
|
1913
|
+
oo = Roo::CSV.new(File.join(TESTDIR,'Bibelbund.csv'))
|
2047
1914
|
oo.default_sheet = oo.sheets.first
|
2048
1915
|
assert_equal 1, oo.first_row
|
2049
1916
|
end
|
@@ -2115,7 +1982,7 @@ where the expected result is
|
|
2115
1982
|
File.join(TESTDIR,"numbers2.ods"))
|
2116
1983
|
File.cp(File.join(TESTDIR,"numbers2.ods"),
|
2117
1984
|
File.join(TESTDIR,"bak_numbers2.ods"))
|
2118
|
-
oo =
|
1985
|
+
oo = OpenOffice.new(File.join(TESTDIR,"numbers2.ods"))
|
2119
1986
|
oo.default_sheet = oo.sheets.first
|
2120
1987
|
oo.first_row.upto(oo.last_row) {|y|
|
2121
1988
|
oo.first_column.upto(oo.last_column) {|x|
|
@@ -2127,8 +1994,8 @@ where the expected result is
|
|
2127
1994
|
}
|
2128
1995
|
oo.save
|
2129
1996
|
|
2130
|
-
oo1 = Roo::
|
2131
|
-
oo2 = Roo::
|
1997
|
+
oo1 = Roo::OpenOffice.new(File.join(TESTDIR,"numbers2.ods"))
|
1998
|
+
oo2 = Roo::OpenOffice.new(File.join(TESTDIR,"bak_numbers2.ods"))
|
2132
1999
|
#p oo2.to_s
|
2133
2000
|
assert_equal 999, oo2.cell('a',1), oo2.cell('a',1)
|
2134
2001
|
assert_equal oo2.cell('a',1) + 7, oo1.cell('a',1)
|
@@ -2146,27 +2013,6 @@ where the expected result is
|
|
2146
2013
|
end
|
2147
2014
|
end
|
2148
2015
|
|
2149
|
-
def test_possible_bug_snowboard_borders #no test file
|
2150
|
-
local_only do
|
2151
|
-
if EXCEL
|
2152
|
-
ex = Excel.new(File.join(TESTDIR,'problem.xls'))
|
2153
|
-
ex.default_sheet = ex.sheets.first
|
2154
|
-
assert_equal 2, ex.first_row
|
2155
|
-
assert_equal 30, ex.last_row
|
2156
|
-
assert_equal 'A', ex.first_column_as_letter
|
2157
|
-
assert_equal 'J', ex.last_column_as_letter
|
2158
|
-
end
|
2159
|
-
if EXCELX
|
2160
|
-
ex = Excelx.new(File.join(TESTDIR,'problem.xlsx'))
|
2161
|
-
ex.default_sheet = ex.sheets.first
|
2162
|
-
assert_equal 2, ex.first_row
|
2163
|
-
assert_equal 30, ex.last_row
|
2164
|
-
assert_equal 'A', ex.first_column_as_letter
|
2165
|
-
assert_equal 'J', ex.last_column_as_letter
|
2166
|
-
end
|
2167
|
-
end
|
2168
|
-
end
|
2169
|
-
|
2170
2016
|
def common_possible_bug_snowboard_cells(ss)
|
2171
2017
|
assert_equal "A.", ss.cell(13,'A'), ss.class
|
2172
2018
|
assert_equal 147, ss.cell(13,'f'), ss.class
|
@@ -2182,314 +2028,6 @@ where the expected result is
|
|
2182
2028
|
assert_equal "168W", ss.cell(13,'o'), ss.class
|
2183
2029
|
end
|
2184
2030
|
|
2185
|
-
def test_possible_bug_snowboard_cells # no test file
|
2186
|
-
local_only do
|
2187
|
-
# warten auf Bugfix in parseexcel
|
2188
|
-
if EXCEL
|
2189
|
-
ex = Roo::Excel.new(File.join(TESTDIR,'problem.xls'))
|
2190
|
-
ex.default_sheet = 'Custom X'
|
2191
|
-
common_possible_bug_snowboard_cells(ex)
|
2192
|
-
end
|
2193
|
-
if EXCELX
|
2194
|
-
ex = Roo::Excelx.new(File.join(TESTDIR,'problem.xlsx'))
|
2195
|
-
ex.default_sheet = 'Custom X'
|
2196
|
-
common_possible_bug_snowboard_cells(ex)
|
2197
|
-
end
|
2198
|
-
end
|
2199
|
-
end
|
2200
|
-
|
2201
|
-
if EXCELX
|
2202
|
-
def test_possible_bug_2008_09_13
|
2203
|
-
local_only do
|
2204
|
-
# war nur in der 1.0.0 Release ein Fehler und sollte mit aktueller
|
2205
|
-
# Release nicht mehr auftreten.
|
2206
|
-
=begin
|
2207
|
-
−
|
2208
|
-
<sst count="46" uniqueCount="39">
|
2209
|
-
−
|
2210
|
-
0<si>
|
2211
|
-
<t>Bond</t>
|
2212
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2213
|
-
</si>
|
2214
|
-
−
|
2215
|
-
1<si>
|
2216
|
-
<t>James</t>
|
2217
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2218
|
-
</si>
|
2219
|
-
−
|
2220
|
-
2<si>
|
2221
|
-
<t>8659</t>
|
2222
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2223
|
-
</si>
|
2224
|
-
−
|
2225
|
-
3<si>
|
2226
|
-
<t>12B</t>
|
2227
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2228
|
-
</si>
|
2229
|
-
−
|
2230
|
-
4<si>
|
2231
|
-
<t>087692</t>
|
2232
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2233
|
-
</si>
|
2234
|
-
−
|
2235
|
-
5<si>
|
2236
|
-
<t>Rowe</t>
|
2237
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2238
|
-
</si>
|
2239
|
-
−
|
2240
|
-
6<si>
|
2241
|
-
<t>Karl</t>
|
2242
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2243
|
-
</si>
|
2244
|
-
−
|
2245
|
-
7<si>
|
2246
|
-
<t>9128</t>
|
2247
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2248
|
-
</si>
|
2249
|
-
−
|
2250
|
-
8<si>
|
2251
|
-
<t>79A</t>
|
2252
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2253
|
-
</si>
|
2254
|
-
−
|
2255
|
-
9<si>
|
2256
|
-
<t>Benson</t>
|
2257
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2258
|
-
</si>
|
2259
|
-
−
|
2260
|
-
10<si>
|
2261
|
-
<t>Cedric</t>
|
2262
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2263
|
-
</si>
|
2264
|
-
−
|
2265
|
-
11<si>
|
2266
|
-
<t>Greenstreet</t>
|
2267
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2268
|
-
</si>
|
2269
|
-
−
|
2270
|
-
12<si>
|
2271
|
-
<t>Jenny</t>
|
2272
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2273
|
-
</si>
|
2274
|
-
−
|
2275
|
-
13<si>
|
2276
|
-
<t>Smith</t>
|
2277
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2278
|
-
</si>
|
2279
|
-
−
|
2280
|
-
14<si>
|
2281
|
-
<t>Greame</t>
|
2282
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2283
|
-
</si>
|
2284
|
-
−
|
2285
|
-
15<si>
|
2286
|
-
<t>Lucas</t>
|
2287
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2288
|
-
</si>
|
2289
|
-
−
|
2290
|
-
16<si>
|
2291
|
-
<t>Ward</t>
|
2292
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2293
|
-
</si>
|
2294
|
-
−
|
2295
|
-
17<si>
|
2296
|
-
<t>Lee</t>
|
2297
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2298
|
-
</si>
|
2299
|
-
−
|
2300
|
-
18<si>
|
2301
|
-
<t>Bret</t>
|
2302
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2303
|
-
</si>
|
2304
|
-
−
|
2305
|
-
19<si>
|
2306
|
-
<t>Warne</t>
|
2307
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2308
|
-
</si>
|
2309
|
-
−
|
2310
|
-
20<si>
|
2311
|
-
<t>Shane</t>
|
2312
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2313
|
-
</si>
|
2314
|
-
−
|
2315
|
-
21<si>
|
2316
|
-
<t>782</t>
|
2317
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2318
|
-
</si>
|
2319
|
-
−
|
2320
|
-
22<si>
|
2321
|
-
<t>876</t>
|
2322
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2323
|
-
</si>
|
2324
|
-
−
|
2325
|
-
23<si>
|
2326
|
-
<t>9901</t>
|
2327
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2328
|
-
</si>
|
2329
|
-
−
|
2330
|
-
24<si>
|
2331
|
-
<t>1235</t>
|
2332
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2333
|
-
</si>
|
2334
|
-
−
|
2335
|
-
25<si>
|
2336
|
-
<t>16547</t>
|
2337
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2338
|
-
</si>
|
2339
|
-
−
|
2340
|
-
26<si>
|
2341
|
-
<t>7789</t>
|
2342
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2343
|
-
</si>
|
2344
|
-
−
|
2345
|
-
27<si>
|
2346
|
-
<t>89</t>
|
2347
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2348
|
-
</si>
|
2349
|
-
−
|
2350
|
-
28<si>
|
2351
|
-
<t>12A</t>
|
2352
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2353
|
-
</si>
|
2354
|
-
−
|
2355
|
-
29<si>
|
2356
|
-
<t>19A</t>
|
2357
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2358
|
-
</si>
|
2359
|
-
−
|
2360
|
-
30<si>
|
2361
|
-
<t>256</t>
|
2362
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2363
|
-
</si>
|
2364
|
-
−
|
2365
|
-
31<si>
|
2366
|
-
<t>129B</t>
|
2367
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2368
|
-
</si>
|
2369
|
-
−
|
2370
|
-
32<si>
|
2371
|
-
<t>11</t>
|
2372
|
-
<phoneticPr fontId="1" type="noConversion"/>
|
2373
|
-
</si>
|
2374
|
-
−
|
2375
|
-
33<si>
|
2376
|
-
<t>Last Name</t>
|
2377
|
-
</si>
|
2378
|
-
−
|
2379
|
-
34<si>
|
2380
|
-
<t>First Name</t>
|
2381
|
-
</si>
|
2382
|
-
−
|
2383
|
-
35 <si>
|
2384
|
-
<t>Middle Name</t>
|
2385
|
-
</si>
|
2386
|
-
−
|
2387
|
-
36<si>
|
2388
|
-
<t>Resident ID</t>
|
2389
|
-
</si>
|
2390
|
-
−
|
2391
|
-
37<si>
|
2392
|
-
<t>Room Number</t>
|
2393
|
-
</si>
|
2394
|
-
−
|
2395
|
-
38<si>
|
2396
|
-
<t>Provider ID #</t>
|
2397
|
-
</si>
|
2398
|
-
</sst>
|
2399
|
-
Hello Thomas,
|
2400
|
-
How are you doing ? I am running into this strange issue with roo plugin (1.0.0). The attached
|
2401
|
-
spreadsheet has all the cells formatted as "text", when I view in the Excel spreadsheet. But when it
|
2402
|
-
get's into roo plugin (set_cell_values method - line 299), the values for the cells 1,1, 1,2, 1,3...1,6
|
2403
|
-
show as 'date' instead of 'string'.
|
2404
|
-
Because of this my parser is failing to get the proper values from the spreadsheet. Any ideas why
|
2405
|
-
the formatting is getting set to the wrong value ?
|
2406
|
-
Even stranger is if I save this file as ".XLS" and parse it the cells parse out fine as they are treated as
|
2407
|
-
'string' instead of 'date'.
|
2408
|
-
This attached file is the newer format of Microsoft Excel (.xlsx).
|
2409
|
-
|
2410
|
-
=end
|
2411
|
-
xx = Roo::Excelx.new(File.join(TESTDIR,'sample_file_2008-09-13.xlsx'))
|
2412
|
-
assert_equal 1, xx.sheets.size
|
2413
|
-
|
2414
|
-
assert_equal 1, xx.first_row
|
2415
|
-
assert_equal 9, xx.last_row # 9 ist richtig. Es sind zwar 44 Zeilen definiert, aber der Rest hat keinen Inhalt
|
2416
|
-
assert_equal 1, xx.first_column
|
2417
|
-
assert_equal 6, xx.last_column
|
2418
|
-
assert_equal 'A', xx.first_column_as_letter
|
2419
|
-
assert_equal 'F', xx.last_column_as_letter
|
2420
|
-
|
2421
|
-
assert_nothing_raised() {
|
2422
|
-
puts xx.info
|
2423
|
-
}
|
2424
|
-
p xx.cell(1,1)
|
2425
|
-
p xx.cell(1,2)
|
2426
|
-
p xx.cell(1,3)
|
2427
|
-
p xx.cell(1,4)
|
2428
|
-
p xx.cell(1,5)
|
2429
|
-
p xx.cell(1,6)
|
2430
|
-
xx.default_sheet = xx.sheets.first
|
2431
|
-
|
2432
|
-
assert_equal 'Last Name', xx.cell('A',1)
|
2433
|
-
|
2434
|
-
1.upto(6) do |col|
|
2435
|
-
assert_equal :string, xx.celltype(1,col)
|
2436
|
-
end
|
2437
|
-
#for col in (1..6)
|
2438
|
-
# assert_equal "1234", xx.cell(1,col)
|
2439
|
-
#end
|
2440
|
-
end
|
2441
|
-
end
|
2442
|
-
end
|
2443
|
-
|
2444
|
-
#-- bei diesen Test bekomme ich seltsamerweise einen Fehler can't allocate
|
2445
|
-
#-- memory innerhalb der zip-Routinen => erstmal deaktiviert
|
2446
|
-
def test_huge_table_timing_10_000_openoffice #no test file
|
2447
|
-
local_only do
|
2448
|
-
with_each_spreadsheet(:name=>'/home/tp/ruby-test/too-testing/speedtest_10000') do |oo|
|
2449
|
-
if LONG_RUN
|
2450
|
-
assert_nothing_raised(Timeout::Error) {
|
2451
|
-
Timeout::timeout(3.minutes) do |timeout_length|
|
2452
|
-
# process every cell
|
2453
|
-
sum = 0
|
2454
|
-
oo.sheets.each {|sheet|
|
2455
|
-
oo.default_sheet = sheet
|
2456
|
-
for row in oo.first_row..oo.last_row do
|
2457
|
-
for col in oo.first_column..oo.last_column do
|
2458
|
-
c = oo.cell(row,col)
|
2459
|
-
sum += c.length if c
|
2460
|
-
end
|
2461
|
-
end
|
2462
|
-
p sum
|
2463
|
-
assert sum > 0
|
2464
|
-
}
|
2465
|
-
end
|
2466
|
-
}
|
2467
|
-
end
|
2468
|
-
end
|
2469
|
-
end
|
2470
|
-
end
|
2471
|
-
|
2472
|
-
def test_bug_encoding_exported_from_google
|
2473
|
-
if EXCEL
|
2474
|
-
local_only do
|
2475
|
-
xl = Roo::Excel.new(File.join(TESTDIR,"numbers1_from_google.xls"))
|
2476
|
-
xl.default_sheet = xl.sheets.first
|
2477
|
-
assert_equal 'test', xl.cell(2,'F')
|
2478
|
-
end
|
2479
|
-
end
|
2480
|
-
end
|
2481
|
-
|
2482
|
-
def test_invalid_iconv_from_ms
|
2483
|
-
local_only do
|
2484
|
-
#TODO: does only run within a darwin-environment
|
2485
|
-
if RUBY_PLATFORM.downcase =~ /darwin/
|
2486
|
-
assert_nothing_raised() {
|
2487
|
-
Roo::Excel.new(File.join(TESTDIR,"ms.xls"))
|
2488
|
-
}
|
2489
|
-
end
|
2490
|
-
end
|
2491
|
-
end
|
2492
|
-
|
2493
2031
|
# def test_false_encoding
|
2494
2032
|
# ex = Roo::Excel.new(File.join(TESTDIR,'false_encoding.xls'))
|
2495
2033
|
# ex.default_sheet = ex.sheets.first
|
@@ -2513,162 +2051,12 @@ This attached file is the newer format of Microsoft Excel (.xlsx).
|
|
2513
2051
|
assert_equal "42", go.cell(1,1)
|
2514
2052
|
end
|
2515
2053
|
end
|
2516
|
-
def test_bug_c2 # no test file
|
2517
|
-
local_only do
|
2518
|
-
with_each_spreadsheet(:name=>'problem', :foramt=>:excel) do |oo|
|
2519
|
-
expected = ['Supermodel X','T6','Shaun White','Jeremy','Custom',
|
2520
|
-
'Warhol','Twin','Malolo','Supermodel','Air','Elite',
|
2521
|
-
'King','Dominant','Dominant Slick','Blunt','Clash',
|
2522
|
-
'Bullet','Tadashi Fuse','Jussi','Royale','S-Series',
|
2523
|
-
'Fish','Love','Feelgood ES','Feelgood','GTwin','Troop',
|
2524
|
-
'Lux','Stigma','Feather','Stria','Alpha','Feelgood ICS']
|
2525
|
-
result = oo.sheets[2..oo.sheets.length].map do |s|
|
2526
|
-
#(13..13).each do |s|
|
2527
|
-
#puts "#{name} (sheet: #{s})"
|
2528
|
-
#assert_equal "whatever (sheet: 13)", "#{name} (sheet: #{s})"
|
2529
|
-
oo.default_sheet = s
|
2530
|
-
oo.cell(2,'C')
|
2531
|
-
end
|
2532
|
-
assert_equal expected, result
|
2533
|
-
end
|
2534
|
-
end
|
2535
|
-
end
|
2536
2054
|
|
2537
|
-
def
|
2538
|
-
local_only do
|
2539
|
-
#-- this is OK
|
2540
|
-
@workbook = Spreadsheet::ParseExcel.parse(File.join(TESTDIR,"problem.xls"))
|
2541
|
-
worksheet = @workbook.worksheet(11)
|
2542
|
-
skip = 0
|
2543
|
-
line = 1
|
2544
|
-
row = 2
|
2545
|
-
col = 3
|
2546
|
-
worksheet.each(skip) { |row_par|
|
2547
|
-
if line == row
|
2548
|
-
if row_par == nil
|
2549
|
-
raise "nil"
|
2550
|
-
end
|
2551
|
-
cell = row_par.at(col-1)
|
2552
|
-
assert cell, "cell should not be nil"
|
2553
|
-
assert_equal "Air", cell.to_s('utf-8')
|
2554
|
-
end
|
2555
|
-
line += 1
|
2556
|
-
}
|
2557
|
-
#-- worksheet 12 does not work
|
2558
|
-
@workbook = Spreadsheet::ParseExcel.parse(File.join(TESTDIR,"problem.xls"))
|
2559
|
-
worksheet = @workbook.worksheet(12)
|
2560
|
-
skip = 0
|
2561
|
-
line = 1
|
2562
|
-
row = 2
|
2563
|
-
col = 3
|
2564
|
-
worksheet.each(skip) { |row_par|
|
2565
|
-
if line == row
|
2566
|
-
if row_par == nil
|
2567
|
-
raise "nil"
|
2568
|
-
end
|
2569
|
-
cell = row_par.at(col-1)
|
2570
|
-
assert cell, "cell should not be nil"
|
2571
|
-
assert_equal "Elite", cell.to_s('utf-8')
|
2572
|
-
end
|
2573
|
-
line += 1
|
2574
|
-
}
|
2575
|
-
end
|
2576
|
-
end
|
2577
|
-
|
2578
|
-
def test_bug_c2_excelx #no test file
|
2579
|
-
local_only do
|
2580
|
-
expected = ['Supermodel X','T6','Shaun White','Jeremy','Custom',
|
2581
|
-
'Warhol','Twin','Malolo','Supermodel','Air','Elite',
|
2582
|
-
'King','Dominant','Dominant Slick','Blunt','Clash',
|
2583
|
-
'Bullet','Tadashi Fuse','Jussi','Royale','S-Series',
|
2584
|
-
'Fish','Love','Feelgood ES','Feelgood','GTwin','Troop',
|
2585
|
-
'Lux','Stigma','Feather','Stria','Alpha','Feelgood ICS']
|
2586
|
-
@e = Roo::Excelx.new(File.join(TESTDIR,"problem.xlsx"))
|
2587
|
-
result = @e.sheets[2..@e.sheets.length].map do |s|
|
2588
|
-
@e.default_sheet = s
|
2589
|
-
# assert_equal "A.",@e.cell('a',13)
|
2590
|
-
#puts "#{name} (sheet: #{s})"
|
2591
|
-
#assert_equal :string, @e.celltype('c',2)
|
2592
|
-
#assert_equal "Vapor (sheet: Vapor)", "#{name} (sheet: #{@e.sheets.first})"
|
2593
|
-
assert @e.cell(2,'c')
|
2594
|
-
@e.cell(2,'C')
|
2595
|
-
end
|
2596
|
-
assert_equal expected, result
|
2597
|
-
|
2598
|
-
@e = Roo::Excelx.new(File.join(TESTDIR,"problem.xlsx"))
|
2599
|
-
#@e.sheets[2..@e.sheets.length].each do |s|
|
2600
|
-
(13..13).each do |s|
|
2601
|
-
@e.default_sheet = s
|
2602
|
-
name = @e.cell(2,'C')
|
2603
|
-
#puts "#{name} (sheet: #{s})"
|
2604
|
-
assert_equal "Elite (sheet: 13)", "#{name} (sheet: #{s})"
|
2605
|
-
end
|
2606
|
-
end
|
2607
|
-
end
|
2608
|
-
|
2609
|
-
def test_compare_csv_excelx_excel #no test file
|
2610
|
-
if EXCELX
|
2611
|
-
# parseexcel bug
|
2612
|
-
local_only do
|
2613
|
-
s1 = Roo::Excel.new(File.join(TESTDIR,"problem.xls"))
|
2614
|
-
s2 = Roo::Excelx.new(File.join(TESTDIR,"problem.xlsx"))
|
2615
|
-
s1.sheets.each {|sh| #TODO:
|
2616
|
-
s1.default_sheet = sh
|
2617
|
-
s2.default_sheet = sh
|
2618
|
-
File.delete_if_exist("/tmp/problem.csv")
|
2619
|
-
File.delete_if_exist("/tmp/problemx.csv")
|
2620
|
-
assert s1.to_csv("/tmp/problem.csv")
|
2621
|
-
assert s2.to_csv("/tmp/problemx.csv")
|
2622
|
-
assert File.exists?("/tmp/problem.csv")
|
2623
|
-
assert File.exists?("/tmp/problemx.csv")
|
2624
|
-
assert_equal "", `diff /tmp/problem.csv /tmp/problemx.csv`, "Unterschied in Sheet #{sh} #{s1.sheets.index(sh)}"
|
2625
|
-
}
|
2626
|
-
end
|
2627
|
-
end
|
2628
|
-
end
|
2629
|
-
|
2630
|
-
def test_problemx_csv_imported #no test file
|
2631
|
-
if EXCEL
|
2632
|
-
local_only do
|
2633
|
-
# wieder eingelesene CSV-Datei aus obigem Test
|
2634
|
-
# muss identisch mit problem.xls sein
|
2635
|
-
# Importieren aus csv-Datei muss manuell gemacht werden
|
2636
|
-
ex = Roo::Excel.new(File.join(TESTDIR,"problem.xls"))
|
2637
|
-
cs = Roo::Excel.new(File.join(TESTDIR,"problemx_csv_imported.xls"))
|
2638
|
-
# nur das erste sheet betrachten
|
2639
|
-
ex.default_sheet = ex.sheets.first
|
2640
|
-
cs.default_sheet = cs.sheets.first
|
2641
|
-
ex.first_row.upto(ex.last_row) do |row|
|
2642
|
-
ex.first_column.upto(ex.last_column) do |col|
|
2643
|
-
assert_equal ex.cell(row,col), cs.cell(row,col), "cell #{row}/#{col} does not match '#{ex.cell(row,col)}' '#{cs.cell(row,col)}'"
|
2644
|
-
assert_equal ex.celltype(row,col), cs.celltype(row,col), "celltype #{row}/#{col} does not match"
|
2645
|
-
assert_equal ex.empty?(row,col), cs.empty?(row,col), "empty? #{row}/#{col} does not match"
|
2646
|
-
if defined? excel_supports_formulas
|
2647
|
-
assert_equal ex.formula?(row,col), cs.formula?(row,col), "formula? #{row}/#{col} does not match"
|
2648
|
-
assert_equal ex.formula(row,col), cs.formula(row,col), "formula #{row}/#{col} does not match"
|
2649
|
-
end
|
2650
|
-
end
|
2651
|
-
end
|
2652
|
-
cs.first_row.upto(cs.last_row) do |row|
|
2653
|
-
cs.first_column.upto(cs.last_column) do |col|
|
2654
|
-
assert_equal ex.cell(row,col), cs.cell(row,col), "cell #{row}/#{col} does not match '#{ex.cell(row,col)}' '#{cs.cell(row,col)}'"
|
2655
|
-
assert_equal ex.celltype(row,col), cs.celltype(row,col), "celltype #{row}/#{col} does not match"
|
2656
|
-
assert_equal ex.empty?(row,col), cs.empty?(row,col), "empty? #{row}/#{col} does not match"
|
2657
|
-
if defined? excel_supports_formulas
|
2658
|
-
assert_equal ex.formula?(row,col), cs.formula?(row,col), "formula? #{row}/#{col} does not match"
|
2659
|
-
assert_equal ex.formula(row,col), cs.formula(row,col), "formula #{row}/#{col} does not match"
|
2660
|
-
end
|
2661
|
-
end
|
2662
|
-
end
|
2663
|
-
end
|
2664
|
-
end
|
2665
|
-
end
|
2666
|
-
|
2667
|
-
def test_open_from_uri
|
2055
|
+
def test_download_uri
|
2668
2056
|
if ONLINE
|
2669
2057
|
if OPENOFFICE
|
2670
2058
|
assert_raises(RuntimeError) {
|
2671
|
-
Roo::
|
2059
|
+
Roo::OpenOffice.new("http://gibbsnichtdomainxxxxx.com/file.ods")
|
2672
2060
|
}
|
2673
2061
|
end
|
2674
2062
|
if EXCEL
|
@@ -2684,11 +2072,11 @@ This attached file is the newer format of Microsoft Excel (.xlsx).
|
|
2684
2072
|
end
|
2685
2073
|
end
|
2686
2074
|
|
2687
|
-
def
|
2075
|
+
def test_download_uri_with_query_string
|
2688
2076
|
dir = File.expand_path("#{File.dirname __FILE__}/files")
|
2689
2077
|
{ xls: [EXCEL, Roo::Excel],
|
2690
2078
|
xlsx: [EXCELX, Roo::Excelx],
|
2691
|
-
ods: [OPENOFFICE, Roo::
|
2079
|
+
ods: [OPENOFFICE, Roo::OpenOffice]}.each do |extension, (flag, type)|
|
2692
2080
|
if flag
|
2693
2081
|
file = "#{dir}/simple_spreadsheet.#{extension}"
|
2694
2082
|
url = "http://test.example.com/simple_spreadsheet.#{extension}?query-param=value"
|
@@ -2700,25 +2088,6 @@ This attached file is the newer format of Microsoft Excel (.xlsx).
|
|
2700
2088
|
end
|
2701
2089
|
end
|
2702
2090
|
|
2703
|
-
def test_to_ascii_openoffice #file does not exist
|
2704
|
-
local_only do
|
2705
|
-
with_each_spreadsheet(:name=>'verysimple_spreadsheet', :format=>:openoffice) do |oo|
|
2706
|
-
oo.default_sheet = oo.sheets.first
|
2707
|
-
expected="
|
2708
|
-
A | B | C |
|
2709
|
-
-------+-------+------|
|
2710
|
-
7| 8| 9|
|
2711
|
-
-------+-------+------|
|
2712
|
-
4| 5| 6|
|
2713
|
-
-------+-------+------|
|
2714
|
-
1| 2| 3|
|
2715
|
-
----------------------/
|
2716
|
-
"
|
2717
|
-
assert_equal expected, oo.to_ascii
|
2718
|
-
end
|
2719
|
-
end
|
2720
|
-
end
|
2721
|
-
|
2722
2091
|
# def test_soap_server
|
2723
2092
|
# #threads = []
|
2724
2093
|
# #threads << Thread.new("serverthread") do
|
@@ -2784,10 +2153,10 @@ This attached file is the newer format of Microsoft Excel (.xlsx).
|
|
2784
2153
|
# arg = expression.split(':')
|
2785
2154
|
# b,z = split_coord(arg[0])
|
2786
2155
|
# first_row = z
|
2787
|
-
# first_col =
|
2156
|
+
# first_col = OpenOffice.letter_to_number(b)
|
2788
2157
|
# b,z = split_coord(arg[1])
|
2789
2158
|
# last_row = z
|
2790
|
-
# last_col =
|
2159
|
+
# last_col = OpenOffice.letter_to_number(b)
|
2791
2160
|
# result = 0
|
2792
2161
|
# first_row.upto(last_row) {|row|
|
2793
2162
|
# first_col.upto(last_col) {|col|
|
@@ -2798,7 +2167,7 @@ This attached file is the newer format of Microsoft Excel (.xlsx).
|
|
2798
2167
|
#end
|
2799
2168
|
|
2800
2169
|
#def test_dsl
|
2801
|
-
# s =
|
2170
|
+
# s = OpenOffice.new(File.join(TESTDIR,"numbers1.ods"))
|
2802
2171
|
# s.default_sheet = s.sheets.first
|
2803
2172
|
#
|
2804
2173
|
# s.set 'a',1, 5
|
@@ -2814,19 +2183,19 @@ This attached file is the newer format of Microsoft Excel (.xlsx).
|
|
2814
2183
|
# name = File.join(TESTDIR,'createdspreadsheet.ods')
|
2815
2184
|
# rm(name) if File.exists?(File.join(TESTDIR,'createdspreadsheet.ods'))
|
2816
2185
|
# # anlegen, falls noch nicht existierend
|
2817
|
-
# s =
|
2186
|
+
# s = OpenOffice.new(name,true)
|
2818
2187
|
# assert File.exists?(name)
|
2819
2188
|
#end
|
2820
2189
|
|
2821
2190
|
#def test_create_spreadsheet2
|
2822
2191
|
# # anlegen, falls noch nicht existierend
|
2823
|
-
# s =
|
2192
|
+
# s = OpenOffice.new(File.join(TESTDIR,"createdspreadsheet.ods"),true)
|
2824
2193
|
# s.set 'a',1,42
|
2825
2194
|
# s.set 'b',1,43
|
2826
2195
|
# s.set 'c',1,44
|
2827
2196
|
# s.save
|
2828
2197
|
#
|
2829
|
-
# t =
|
2198
|
+
# t = OpenOffice.new(File.join(TESTDIR,"createdspreadsheet.ods"))
|
2830
2199
|
# assert_equal 42, t.cell(1,'a')
|
2831
2200
|
# assert_equal 43, t.cell('b',1)
|
2832
2201
|
# assert_equal 44, t.cell('c',3)
|
@@ -2834,7 +2203,7 @@ This attached file is the newer format of Microsoft Excel (.xlsx).
|
|
2834
2203
|
|
2835
2204
|
# We don't have the bode-v1.xlsx test file
|
2836
2205
|
# #TODO: xlsx-Datei anpassen!
|
2837
|
-
# def
|
2206
|
+
# def test_excelx_download_uri_and_zipped
|
2838
2207
|
# #TODO: gezippte xlsx Datei online zum Testen suchen
|
2839
2208
|
# if EXCELX
|
2840
2209
|
# if ONLINE
|
@@ -2859,4 +2228,12 @@ This attached file is the newer format of Microsoft Excel (.xlsx).
|
|
2859
2228
|
# end
|
2860
2229
|
# end
|
2861
2230
|
|
2231
|
+
def test_csv_parsing_with_headers
|
2232
|
+
return unless CSV
|
2233
|
+
headers = ["TITEL", "VERFASSER", "OBJEKT", "NUMMER", "SEITE", "INTERNET", "PC", "KENNUNG"]
|
2234
|
+
|
2235
|
+
oo = Roo::Spreadsheet.open(File.join(TESTDIR, 'Bibelbund.csv'))
|
2236
|
+
parsed = oo.parse(:headers => true)
|
2237
|
+
assert_equal headers, parsed[1].keys
|
2238
|
+
end
|
2862
2239
|
end # class
|