robust_excel_ole 1.16 → 1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/README_open.rdoc +4 -0
- data/lib/robust_excel_ole.rb +5 -4
- data/lib/robust_excel_ole/{address.rb → address_tool.rb} +23 -22
- data/lib/robust_excel_ole/{reo_common.rb → base.rb} +2 -90
- data/lib/robust_excel_ole/bookstore.rb +2 -2
- data/lib/robust_excel_ole/cell.rb +21 -17
- data/lib/robust_excel_ole/excel.rb +64 -26
- data/lib/robust_excel_ole/general.rb +7 -5
- data/lib/robust_excel_ole/range.rb +15 -7
- data/lib/robust_excel_ole/range_owners.rb +18 -6
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +140 -147
- data/lib/robust_excel_ole/worksheet.rb +7 -7
- data/spec/address_tool_spec.rb +175 -0
- data/spec/{reo_common_spec.rb → base_spec.rb} +10 -29
- data/spec/cell_spec.rb +67 -25
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +25 -273
- data/spec/general_spec.rb +16 -19
- data/spec/range_spec.rb +1 -1
- data/spec/workbook_spec.rb +7 -75
- data/spec/workbook_specs/workbook_misc_spec.rb +10 -10
- data/spec/workbook_specs/workbook_open_spec.rb +228 -14
- data/spec/workbook_specs/workbook_unobtr_spec.rb +31 -31
- metadata +6 -6
- data/spec/address_spec.rb +0 -174
@@ -12,7 +12,7 @@ module RobustExcelOle
|
|
12
12
|
class Worksheet < RangeOwners
|
13
13
|
|
14
14
|
attr_reader :ole_worksheet
|
15
|
-
|
15
|
+
attr_reader :workbook
|
16
16
|
|
17
17
|
def initialize(win32_worksheet)
|
18
18
|
@ole_worksheet = win32_worksheet
|
@@ -28,17 +28,18 @@ module RobustExcelOle
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def workbook
|
31
|
-
|
32
|
-
begin
|
31
|
+
@workbook ||= begin
|
33
32
|
ole_workbook = self.Parent
|
34
33
|
saved_status = ole_workbook.Saved
|
35
34
|
ole_workbook.Saved = true unless saved_status
|
36
35
|
@workbook = workbook_class.new(ole_workbook)
|
37
36
|
ole_workbook.Saved = saved_status
|
38
|
-
|
39
|
-
nil
|
37
|
+
@workbook
|
40
38
|
end
|
41
|
-
|
39
|
+
end
|
40
|
+
|
41
|
+
def excel
|
42
|
+
workbook.excel
|
42
43
|
end
|
43
44
|
|
44
45
|
# sheet name
|
@@ -218,7 +219,6 @@ module RobustExcelOle
|
|
218
219
|
|
219
220
|
private
|
220
221
|
|
221
|
-
# @private
|
222
222
|
def method_missing(name, *args)
|
223
223
|
if name.to_s[0,1] =~ /[A-Z]/
|
224
224
|
if ::ERRORMESSAGE_JRUBY_BUG
|
@@ -0,0 +1,175 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), './spec_helper')
|
4
|
+
require File.expand_path( '../../lib/robust_excel_ole/base', __FILE__)
|
5
|
+
|
6
|
+
$VERBOSE = nil
|
7
|
+
|
8
|
+
include General
|
9
|
+
include RobustExcelOle
|
10
|
+
|
11
|
+
module RobustExcelOle
|
12
|
+
|
13
|
+
describe AddressTool do
|
14
|
+
|
15
|
+
before(:all) do
|
16
|
+
excel = Excel.new(:reuse => true)
|
17
|
+
open_books = excel == nil ? 0 : excel.Workbooks.Count
|
18
|
+
puts "*** open books *** : #{open_books}" if open_books > 0
|
19
|
+
Excel.kill_all
|
20
|
+
@dir = create_tmpdir
|
21
|
+
@simple_file = @dir + '/workbook.xls'
|
22
|
+
@workbook = Workbook.open(@simple_file)
|
23
|
+
@address_tool = @workbook.excel.address_tool
|
24
|
+
end
|
25
|
+
|
26
|
+
after(:all) do
|
27
|
+
@workbook.close
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should transform relative r1c1-reference into r1c1-format" do
|
31
|
+
@address_tool.as_r1c1("Z1S[2]:Z[-1]S4").should == "Z1S(2):Z(-1)S4"
|
32
|
+
@address_tool.as_r1c1("Z[1]S2:Z3S[4]").should == "Z(1)S2:Z3S(4)"
|
33
|
+
@address_tool.as_r1c1("Z1S[2]").should == "Z1S(2)"
|
34
|
+
@address_tool.as_r1c1("Z[-1]S4").should == "Z(-1)S4"
|
35
|
+
@address_tool.as_r1c1("Z[3]").should == "Z(3)"
|
36
|
+
@address_tool.as_r1c1("S[-2]").should == "S(-2)"
|
37
|
+
end
|
38
|
+
|
39
|
+
# test for 1.8.6
|
40
|
+
it "should transform relative integer_ranges-format into r1c1-format" do
|
41
|
+
@address_tool.as_r1c1([1..2,[3]..4]).should == "Z1S(3):Z2S4"
|
42
|
+
@address_tool.as_r1c1([[1]..2,3..4]).should == "Z(1)S3:Z2S4"
|
43
|
+
@address_tool.as_r1c1([[1]..2,nil]).should == "Z(1):Z2"
|
44
|
+
@address_tool.as_r1c1([nil,[1]..2]).should == "S(1):S2"
|
45
|
+
@address_tool.as_r1c1([nil,[1]]).should == "S(1):S(1)"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should transform relative integer_ranges-format into r1c1-format" do
|
49
|
+
@address_tool.as_r1c1([1..[-2],[3]..4]).should == "Z1S(3):Z(-2)S4"
|
50
|
+
@address_tool.as_r1c1([[1]..2,3..[4]]).should == "Z(1)S3:Z2S(4)"
|
51
|
+
@address_tool.as_r1c1([1..[-2],nil]).should == "Z1:Z(-2)"
|
52
|
+
@address_tool.as_r1c1([nil,[-1]..2]).should == "S(-1):S2"
|
53
|
+
@address_tool.as_r1c1([[3]..[3],nil]).should == "Z(3):Z(3)"
|
54
|
+
@address_tool.as_r1c1([nil,[-2]..[-2]]).should == "S(-2):S(-2)"
|
55
|
+
@address_tool.as_r1c1([[3],nil]).should == "Z(3):Z(3)"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should transform relative r1c1-format into r1c1-format" do
|
59
|
+
@address_tool.as_integer_ranges("Z1S[2]:Z[3]S4").should == [1..[3],[2]..4]
|
60
|
+
@address_tool.as_integer_ranges("Z[1]S2:Z3S[4]").should == [[1]..3,2..[4]]
|
61
|
+
@address_tool.as_integer_ranges("Z1S[2]").should == [1..1,[2]..[2]]
|
62
|
+
@address_tool.as_integer_ranges("Z[3]S4").should == [[3]..[3],4..4]
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should transform a1-format" do
|
66
|
+
@address_tool.as_a1("A2").should == "A2"
|
67
|
+
@address_tool.as_r1c1("A2").should == "Z2S1:Z2S1"
|
68
|
+
@address_tool.as_integer_ranges("A2").should == [2..2,1..1]
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should transform several-letter-a1-format" do
|
72
|
+
@address_tool.as_a1("ABO15").should == "ABO15"
|
73
|
+
@address_tool.as_r1c1("ABO15").should == "Z15S743:Z15S743"
|
74
|
+
@address_tool.as_integer_ranges("ABO15").should == [15..15,743..743]
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should transform complex a1-format" do
|
78
|
+
@address_tool.as_a1("A2:B3").should == "A2:B3"
|
79
|
+
@address_tool.as_r1c1("A2:B3").should == "Z2S1:Z3S2"
|
80
|
+
@address_tool.as_integer_ranges("A2:B3").should == [2..3,1..2]
|
81
|
+
@address_tool.as_a1("S1:DP2").should == "S1:DP2"
|
82
|
+
@address_tool.as_r1c1("S1:DP2").should == "Z1S19:Z2S120"
|
83
|
+
@address_tool.as_integer_ranges("S1:DP2").should == [1..2,19..120]
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should transform infinite a1-format" do
|
87
|
+
@address_tool.as_a1("A:B").should == "A:B"
|
88
|
+
@address_tool.as_r1c1("A:B").should == "S1:S2"
|
89
|
+
@address_tool.as_integer_ranges("A:B").should == [nil,1..2]
|
90
|
+
@address_tool.as_a1("1:3").should == "1:3"
|
91
|
+
@address_tool.as_r1c1("1:3").should == "Z1:Z3"
|
92
|
+
@address_tool.as_integer_ranges("1:3").should == [1..3,nil]
|
93
|
+
@address_tool.as_a1("B").should == "B"
|
94
|
+
@address_tool.as_r1c1("B").should == "S2:S2"
|
95
|
+
@address_tool.as_integer_ranges("B").should == [nil,2..2]
|
96
|
+
@address_tool.as_a1("3").should == "3"
|
97
|
+
@address_tool.as_r1c1("3").should == "Z3:Z3"
|
98
|
+
@address_tool.as_integer_ranges("3").should == [3..3,nil]
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should transform r1c1-format" do
|
102
|
+
@address_tool.as_r1c1("Z2S1").should == "Z2S1"
|
103
|
+
@address_tool.as_integer_ranges("Z2S1").should == [2..2,1..1]
|
104
|
+
expect{
|
105
|
+
@address_tool.as_a1("Z2S1")
|
106
|
+
}.to raise_error(NotImplementedREOError)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should transform complex r1c1-format" do
|
110
|
+
@address_tool.as_r1c1("Z2S1:Z3S2").should == "Z2S1:Z3S2"
|
111
|
+
@address_tool.as_integer_ranges("Z2S1:Z3S2").should == [2..3,1..2]
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should transform as_integer_ranges format" do
|
115
|
+
@address_tool.as_integer_ranges([2..2,1..1]).should == [2..2,1..1]
|
116
|
+
@address_tool.as_r1c1([2..2,1..1]).should == "Z2S1:Z2S1"
|
117
|
+
expect{
|
118
|
+
@address_tool.as_a1([2..2,1..1])
|
119
|
+
}.to raise_error(NotImplementedREOError)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should transform simple as_integer_ranges format" do
|
123
|
+
@address_tool.as_integer_ranges([2,1]).should == [2..2,1..1]
|
124
|
+
@address_tool.as_r1c1([2,1]).should == "Z2S1:Z2S1"
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should transform complex as_integer_ranges format" do
|
128
|
+
@address_tool.as_integer_ranges([2,"A"]).should == [2..2,1..1]
|
129
|
+
@address_tool.as_r1c1([2,"A"]).should == "Z2S1:Z2S1"
|
130
|
+
@address_tool.as_integer_ranges([2,"A".."B"]).should == [2..2,1..2]
|
131
|
+
@address_tool.as_r1c1([2,"A".."B"]).should == "Z2S1:Z2S2"
|
132
|
+
@address_tool.as_integer_ranges([1..2,"C"]).should == [1..2,3..3]
|
133
|
+
@address_tool.as_r1c1([1..2,"C"]).should == "Z1S3:Z2S3"
|
134
|
+
@address_tool.as_integer_ranges([1..2,"C".."E"]).should == [1..2,3..5]
|
135
|
+
@address_tool.as_r1c1([1..2,"C".."E"]).should == "Z1S3:Z2S5"
|
136
|
+
@address_tool.as_integer_ranges([2,3..5]).should == [2..2,3..5]
|
137
|
+
@address_tool.as_r1c1([2,3..5]).should == "Z2S3:Z2S5"
|
138
|
+
@address_tool.as_integer_ranges([1..2,3..5]).should == [1..2,3..5]
|
139
|
+
@address_tool.as_r1c1([1..2,3..5]).should == "Z1S3:Z2S5"
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should transform infinite as_integer_ranges format" do
|
143
|
+
@address_tool.as_integer_ranges([nil,1..2]).should == [nil,1..2]
|
144
|
+
@address_tool.as_r1c1([nil,1..2]).should == "S1:S2"
|
145
|
+
@address_tool.as_integer_ranges([1..3,nil]).should == [1..3,nil]
|
146
|
+
@address_tool.as_r1c1([1..3,nil]).should == "Z1:Z3"
|
147
|
+
@address_tool.as_integer_ranges([nil,2]).should == [nil,2..2]
|
148
|
+
@address_tool.as_r1c1([nil,2]).should == "S2:S2"
|
149
|
+
@address_tool.as_integer_ranges([3,nil]).should == [3..3,nil]
|
150
|
+
@address_tool.as_r1c1([3,nil]).should == "Z3:Z3"
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should raise an error" do
|
154
|
+
expect{
|
155
|
+
@address_tool.as_a1("1A")
|
156
|
+
}.to raise_error(AddressInvalid, /format not correct/)
|
157
|
+
expect{
|
158
|
+
@address_tool.as_r1c1("A1B")
|
159
|
+
}.to raise_error(AddressInvalid, /format not correct/)
|
160
|
+
#expect{
|
161
|
+
# @address_tool.as_integer_ranges(["A".."B","C".."D"])
|
162
|
+
#}.to raise_error(AddressInvalid, /format not correct/)
|
163
|
+
#expect{
|
164
|
+
# @address_tool.as_integer_ranges(["A".."B",1..2])
|
165
|
+
#}.to raise_error(AddressInvalid, /format not correct/)
|
166
|
+
#expect{
|
167
|
+
# @address_tool.as_integer_ranges(["A".."B",nil])
|
168
|
+
#}.to raise_error(AddressInvalid, /format not correct/)
|
169
|
+
expect{
|
170
|
+
@address_tool.as_integer_ranges(["A",1,2])
|
171
|
+
}.to raise_error(AddressInvalid, /more than two components/)
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
require File.join(File.dirname(__FILE__), './spec_helper')
|
4
|
-
require File.expand_path( '../../lib/robust_excel_ole/
|
4
|
+
require File.expand_path( '../../lib/robust_excel_ole/base', __FILE__)
|
5
5
|
|
6
6
|
$VERBOSE = nil
|
7
7
|
|
@@ -10,7 +10,7 @@ include RobustExcelOle
|
|
10
10
|
|
11
11
|
module RobustExcelOle
|
12
12
|
|
13
|
-
describe
|
13
|
+
describe Base do
|
14
14
|
|
15
15
|
before(:all) do
|
16
16
|
excel = Excel.new(:reuse => true)
|
@@ -40,12 +40,12 @@ module RobustExcelOle
|
|
40
40
|
|
41
41
|
it "should put some number" do
|
42
42
|
a = 4
|
43
|
-
|
43
|
+
Base::trace "some text #{a}"
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should put another text" do
|
47
47
|
b = Workbook.open(@simple_file)
|
48
|
-
|
48
|
+
Base::trace "book: #{b}"
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -82,45 +82,26 @@ module RobustExcelOle
|
|
82
82
|
|
83
83
|
end
|
84
84
|
|
85
|
-
describe "Object methods" do
|
86
|
-
|
87
|
-
before do
|
88
|
-
@book = Workbook.open(@simple_file)
|
89
|
-
@sheet = @book.sheet(1)
|
90
|
-
end
|
91
|
-
|
92
|
-
before do
|
93
|
-
@book.close
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should raise an error when asking excel of a sheet" do
|
97
|
-
expect{
|
98
|
-
@sheet.excel
|
99
|
-
}.to raise_error(TypeREOError, "receiver instance is neither an Excel nor a Workbook")
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
85
|
describe "misc" do
|
105
86
|
|
106
87
|
it "should" do
|
107
88
|
|
108
89
|
LOG_TO_STDOUT = true
|
109
|
-
|
90
|
+
Base::trace "foo"
|
110
91
|
|
111
92
|
LOG_TO_STDOUT = false
|
112
|
-
|
93
|
+
Base::trace "foo"
|
113
94
|
|
114
95
|
REO_LOG_DIR = ""
|
115
|
-
|
96
|
+
Base::trace "foo"
|
116
97
|
|
117
98
|
#REO_LOG_DIR = "C:"
|
118
|
-
#
|
99
|
+
#Base::trace "foo"
|
119
100
|
|
120
|
-
|
101
|
+
Base::tr1 "foo"
|
121
102
|
|
122
103
|
h = {:a => {:c => 4}, :b => 2}
|
123
|
-
|
104
|
+
Base::puts_hash(h)
|
124
105
|
|
125
106
|
end
|
126
107
|
|
data/spec/cell_spec.rb
CHANGED
@@ -15,54 +15,66 @@ describe Cell do
|
|
15
15
|
|
16
16
|
before do
|
17
17
|
@dir = create_tmpdir
|
18
|
+
@simple_file = @dir + '/workbook.xls'
|
19
|
+
@merge_cells_file = @dir + '/merge_cells.xls'
|
20
|
+
@book = Workbook.open(@simple_file)
|
21
|
+
@sheet = @book.sheet(1)
|
22
|
+
@cell = @sheet[1, 1]
|
18
23
|
end
|
19
24
|
|
20
25
|
after do
|
26
|
+
Excel.kill_all
|
21
27
|
rm_tmp(@dir)
|
22
28
|
end
|
23
29
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@cell
|
30
|
+
|
31
|
+
describe "values" do
|
32
|
+
|
33
|
+
it "should yield one element values" do
|
34
|
+
@cell.values.should == ["foo"]
|
29
35
|
end
|
30
36
|
|
31
|
-
|
32
|
-
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#[]" do
|
40
|
+
|
41
|
+
it "should access to the cell itself" do
|
42
|
+
@cell[0].should be_kind_of RobustExcelOle::Cell
|
43
|
+
@cell[0].v.should == "foo"
|
33
44
|
end
|
34
45
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
46
|
+
it "should access to the cell itself" do
|
47
|
+
@cell[1].should be_kind_of RobustExcelOle::Cell
|
48
|
+
@cell[1].v.should == 'foo'
|
39
49
|
end
|
50
|
+
|
51
|
+
end
|
40
52
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
53
|
+
describe "#copy" do
|
54
|
+
|
55
|
+
before do
|
56
|
+
@book1 = Workbook.open(@dir + '/workbook.xls')
|
57
|
+
@sheet1 = @book1.sheet(1)
|
58
|
+
@cell1 = @sheet1[1,1]
|
46
59
|
end
|
47
60
|
|
48
|
-
|
49
|
-
|
50
|
-
it { expect { @cell.hogehogefoo }.to raise_error }
|
51
|
-
end
|
61
|
+
after do
|
62
|
+
@book1.close(:if_unsaved => :forget)
|
52
63
|
end
|
53
64
|
|
65
|
+
it "should copy range" do
|
66
|
+
@cell1.copy([2,3])
|
67
|
+
@sheet1.range([1..2,1..3]).v.should == [["foo", "workbook", "sheet1"],["foo", nil, "foo"]]
|
68
|
+
end
|
54
69
|
end
|
55
70
|
|
56
71
|
context "open merge_cells.xls" do
|
72
|
+
|
57
73
|
before do
|
58
|
-
@book = Workbook.open(@
|
74
|
+
@book = Workbook.open(@merge_cells_file, :read_only => true)
|
59
75
|
@sheet = @book.sheet(1)
|
60
76
|
end
|
61
77
|
|
62
|
-
after do
|
63
|
-
@book.close
|
64
|
-
end
|
65
|
-
|
66
78
|
it "merged cell get same value" do
|
67
79
|
@sheet[1, 1].Value.should be_nil
|
68
80
|
@sheet[2, 1].Value.should eq 'first merged'
|
@@ -74,4 +86,34 @@ describe Cell do
|
|
74
86
|
@sheet[2, 2].Value.should eq "set merge cell"
|
75
87
|
end
|
76
88
|
end
|
89
|
+
|
90
|
+
describe "==" do
|
91
|
+
|
92
|
+
it "should check equality of cells" do
|
93
|
+
@cell.should == @sheet[1,1]
|
94
|
+
@cell.should_not == @sheet[1,2]
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#Value" do
|
100
|
+
it "get cell's value" do
|
101
|
+
@cell.Value.should eq 'foo'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#Value=" do
|
106
|
+
it "change cell data to 'fooooo'" do
|
107
|
+
@cell.Value = 'fooooo'
|
108
|
+
@cell.Value.should eq 'fooooo'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#method_missing" do
|
113
|
+
context "unknown method" do
|
114
|
+
it { expect { @cell.hogehogefoo }.to raise_error(NoMethodError) }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
77
118
|
end
|
119
|
+
|
Binary file
|
data/spec/data/workbook.xls
CHANGED
Binary file
|
data/spec/excel_spec.rb
CHANGED
@@ -23,6 +23,11 @@ module RobustExcelOle
|
|
23
23
|
@invalid_name_file = 'b/workbook.xls'
|
24
24
|
@simple_file1 = @simple_file
|
25
25
|
@different_file1 = @different_file
|
26
|
+
@error_unsaved_workbooks = "Excel contains unsaved workbooks" +
|
27
|
+
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
28
|
+
Excel instance without or with saving the unsaved workbooks before, respectively"
|
29
|
+
@error_invalid_option = ":if_unsaved: invalid option: :invalid_option" +
|
30
|
+
"\nHint: Valid values are :raise, :forget, :save and :alert"
|
26
31
|
end
|
27
32
|
|
28
33
|
after do
|
@@ -627,15 +632,13 @@ module RobustExcelOle
|
|
627
632
|
@excel2 = book2.excel
|
628
633
|
sheet2 = book2.sheet(1)
|
629
634
|
@old_cell_value2 = sheet2[1,1].Value
|
630
|
-
sheet2[1,1] = sheet2[1,1].Value == "foo" ? "bar" : "foo"
|
635
|
+
sheet2[1,1] = sheet2[1,1].Value == "foo" ? "bar" : "foo"
|
631
636
|
end
|
632
637
|
|
633
638
|
it "should close the first Excel without unsaved workbooks and then raise an error" do
|
634
639
|
expect{
|
635
640
|
Excel.close_all(:if_unsaved => :raise)
|
636
|
-
}.to raise_error(UnsavedWorkbooks,
|
637
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
638
|
-
Excel instance without or with saving the unsaved workbooks before, respectively")
|
641
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
639
642
|
sleep 0.2
|
640
643
|
@excel1.should_not be_alive
|
641
644
|
@excel2.should be_alive
|
@@ -648,9 +651,7 @@ module RobustExcelOle
|
|
648
651
|
it "should close the first Excel without unsaved workbooks and then raise an error" do
|
649
652
|
expect{
|
650
653
|
Excel.close_all
|
651
|
-
}.to raise_error(UnsavedWorkbooks,
|
652
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
653
|
-
Excel instance without or with saving the unsaved workbooks before, respectively")
|
654
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
654
655
|
sleep 0.2
|
655
656
|
@excel1.should_not be_alive
|
656
657
|
@excel2.should be_alive
|
@@ -687,8 +688,7 @@ module RobustExcelOle
|
|
687
688
|
it "should raise an error for invalid option" do
|
688
689
|
expect {
|
689
690
|
Excel.close_all(:if_unsaved => :invalid_option)
|
690
|
-
}.to raise_error(OptionInvalid,
|
691
|
-
"\nHint: Valid values are :raise, :forget, :save and :alert")
|
691
|
+
}.to raise_error(OptionInvalid, @error_invalid_option)
|
692
692
|
end
|
693
693
|
end
|
694
694
|
|
@@ -705,9 +705,7 @@ module RobustExcelOle
|
|
705
705
|
it "should close the 1st and 3rd Excel instances that have saved workbooks" do
|
706
706
|
expect{
|
707
707
|
Excel.close_all(:if_unsaved => :raise)
|
708
|
-
}.to raise_error(UnsavedWorkbooks,
|
709
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
710
|
-
Excel instance without or with saving the unsaved workbooks before, respectively")
|
708
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
711
709
|
sleep 0.2
|
712
710
|
@book1.excel.should_not be_alive
|
713
711
|
@book2.excel.should be_alive
|
@@ -732,9 +730,7 @@ module RobustExcelOle
|
|
732
730
|
it "should close three Excel instances that have saved workbooks" do
|
733
731
|
expect{
|
734
732
|
Excel.close_all(:if_unsaved => :raise)
|
735
|
-
}.to raise_error(UnsavedWorkbooks,
|
736
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
737
|
-
Excel instance without or with saving the unsaved workbooks before, respectively")
|
733
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
738
734
|
sleep 0.2
|
739
735
|
expect{
|
740
736
|
@ole_xl.Name
|
@@ -812,17 +808,13 @@ module RobustExcelOle
|
|
812
808
|
it "should raise an error" do
|
813
809
|
expect{
|
814
810
|
@excel.close(:if_unsaved => :raise)
|
815
|
-
}.to raise_error(UnsavedWorkbooks,
|
816
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
817
|
-
Excel instance without or with saving the unsaved workbooks before, respectively")
|
811
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
818
812
|
end
|
819
813
|
|
820
814
|
it "should raise an error per default" do
|
821
815
|
expect{
|
822
816
|
@excel.close(:if_unsaved => :raise)
|
823
|
-
}.to raise_error(UnsavedWorkbooks,
|
824
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
825
|
-
Excel instance without or with saving the unsaved workbooks before, respectively")
|
817
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
826
818
|
end
|
827
819
|
|
828
820
|
it "should close the Excel without saving the workbook" do
|
@@ -865,8 +857,7 @@ module RobustExcelOle
|
|
865
857
|
it "should raise an error for invalid option" do
|
866
858
|
expect {
|
867
859
|
@excel.close(:if_unsaved => :invalid_option)
|
868
|
-
}.to raise_error(OptionInvalid,
|
869
|
-
"\nHint: Valid values are :raise, :forget, :save and :alert")
|
860
|
+
}.to raise_error(OptionInvalid, @error_invalid_option)
|
870
861
|
end
|
871
862
|
end
|
872
863
|
|
@@ -955,18 +946,13 @@ module RobustExcelOle
|
|
955
946
|
it "should raise error" do
|
956
947
|
expect{
|
957
948
|
@excel.close_workbooks(:if_unsaved => :raise)
|
958
|
-
}.to raise_error(UnsavedWorkbooks,
|
959
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
960
|
-
Excel instance without or with saving the unsaved workbooks before, respectively" )
|
961
|
-
|
949
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
962
950
|
end
|
963
951
|
|
964
952
|
it "should raise error per default" do
|
965
953
|
expect{
|
966
954
|
@excel.close_workbooks
|
967
|
-
}.to raise_error(UnsavedWorkbooks,
|
968
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
969
|
-
Excel instance without or with saving the unsaved workbooks before, respectively")
|
955
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
970
956
|
end
|
971
957
|
|
972
958
|
it "should close the workbook with forgetting the workbook" do
|
@@ -994,8 +980,7 @@ module RobustExcelOle
|
|
994
980
|
it "should raise an error for invalid option" do
|
995
981
|
expect {
|
996
982
|
@excel.close_workbooks(:if_unsaved => :invalid_option)
|
997
|
-
}.to raise_error(OptionInvalid,
|
998
|
-
"\nHint: Valid values are :raise, :forget, :save and :alert")
|
983
|
+
}.to raise_error(OptionInvalid, @error_invalid_option)
|
999
984
|
end
|
1000
985
|
end
|
1001
986
|
end
|
@@ -1925,14 +1910,14 @@ module RobustExcelOle
|
|
1925
1910
|
@excel2.Hwnd.should == @excel2.hwnd
|
1926
1911
|
end
|
1927
1912
|
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1913
|
+
# it "should provide the same excel instances" do
|
1914
|
+
# @excel1.should_not == @excel2
|
1915
|
+
# excel3 = Excel.hwnd2excel(@excel1.hwnd)
|
1916
|
+
# excel4 = Excel.hwnd2excel(@excel2.hwnd)
|
1917
|
+
# @excel1.should == excel3
|
1918
|
+
# @excel2.should == excel4
|
1919
|
+
# excel3.should_not == excel4
|
1920
|
+
# end
|
1936
1921
|
|
1937
1922
|
=begin
|
1938
1923
|
# does not work yet
|
@@ -2018,239 +2003,6 @@ module RobustExcelOle
|
|
2018
2003
|
|
2019
2004
|
end
|
2020
2005
|
end
|
2021
|
-
|
2022
|
-
context "setting the name of a range" do
|
2023
|
-
|
2024
|
-
before do
|
2025
|
-
@book1 = Workbook.open(@dir + '/another_workbook.xls', :read_only => true, :visible => true)
|
2026
|
-
@book1.excel.displayalerts = false
|
2027
|
-
@excel1 = @book1.excel
|
2028
|
-
end
|
2029
|
-
|
2030
|
-
after do
|
2031
|
-
@book1.close
|
2032
|
-
end
|
2033
|
-
|
2034
|
-
it "should name an unnamed range with a giving address" do
|
2035
|
-
@excel1.add_name("foo",[1,2])
|
2036
|
-
@excel1.Names.Item("foo").Name.should == "foo"
|
2037
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$B$1:$B$1"
|
2038
|
-
end
|
2039
|
-
|
2040
|
-
it "should rename an already named range with a giving address" do
|
2041
|
-
@excel1.add_name("foo",[1,1])
|
2042
|
-
@excel1.Names.Item("foo").Name.should == "foo"
|
2043
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$A$1:$A$1"
|
2044
|
-
end
|
2045
|
-
|
2046
|
-
it "should raise an error" do
|
2047
|
-
expect{
|
2048
|
-
@excel1.add_name("foo", [-2, 1])
|
2049
|
-
}.to raise_error(RangeNotEvaluatable, /cannot add name "foo" to range/)
|
2050
|
-
end
|
2051
|
-
|
2052
|
-
it "should rename a range" do
|
2053
|
-
@excel1.add_name("foo",[1,1])
|
2054
|
-
@excel1.rename_range("foo","bar")
|
2055
|
-
@excel1.namevalue_glob("bar").should == "foo"
|
2056
|
-
end
|
2057
|
-
|
2058
|
-
it "should delete a name of a range" do
|
2059
|
-
@excel1.add_name("foo",[1,1])
|
2060
|
-
@excel1.delete_name("foo")
|
2061
|
-
expect{
|
2062
|
-
@excel1.namevalue_glob("foo")
|
2063
|
-
}.to raise_error(NameNotFound, /name "foo"/)
|
2064
|
-
end
|
2065
|
-
|
2066
|
-
it "should add a name of a rectangular range" do
|
2067
|
-
@excel1.add_name("foo",[1..3,1..4])
|
2068
|
-
@excel1["foo"].should == [["foo", "workbook", "sheet1", nil], ["foo", 1.0, 2.0, 4.0], ["matz", 3.0, 4.0, 4.0]]
|
2069
|
-
end
|
2070
|
-
|
2071
|
-
it "should accept the old interface" do
|
2072
|
-
@excel1.add_name("foo",1..3,1..4)
|
2073
|
-
@excel1["foo"].should == [["foo", "workbook", "sheet1", nil], ["foo", 1.0, 2.0, 4.0], ["matz", 3.0, 4.0, 4.0]]
|
2074
|
-
end
|
2075
|
-
|
2076
|
-
it "should add a name of an infinite row range" do
|
2077
|
-
@excel1.add_name("foo",[1..3, nil])
|
2078
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$1:$3"
|
2079
|
-
end
|
2080
|
-
|
2081
|
-
it "should add a name of an infinite column range" do
|
2082
|
-
@excel1.add_name("foo",[nil, "A".."C"])
|
2083
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$A:$C"
|
2084
|
-
end
|
2085
|
-
|
2086
|
-
it "should add a name of an infinite row range" do
|
2087
|
-
@excel1.add_name("foo",[nil, 1..3])
|
2088
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$A:$C"
|
2089
|
-
end
|
2090
|
-
|
2091
|
-
it "should add a name of an infinite column range" do
|
2092
|
-
@excel1.add_name("foo",["A:C"])
|
2093
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$A:$C"
|
2094
|
-
end
|
2095
|
-
|
2096
|
-
it "should add a name of an infinite column range" do
|
2097
|
-
@excel1.add_name("foo",["1:2"])
|
2098
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$1:$2"
|
2099
|
-
end
|
2100
|
-
|
2101
|
-
end
|
2102
|
-
|
2103
|
-
describe "namevalue_glob, set_namevalue_glob" do
|
2104
|
-
|
2105
|
-
before do
|
2106
|
-
@book1 = Workbook.open(@dir + '/another_workbook.xls')
|
2107
|
-
@book1.Windows(@book1.Name).Visible = true
|
2108
|
-
@excel1 = @book1.excel
|
2109
|
-
end
|
2110
|
-
|
2111
|
-
after do
|
2112
|
-
@book1.close(:if_unsaved => :forget)
|
2113
|
-
end
|
2114
|
-
|
2115
|
-
it "should return value of a defined name" do
|
2116
|
-
@excel1.namevalue_glob("firstcell").should == "foo"
|
2117
|
-
@excel1["firstcell"].should == "foo"
|
2118
|
-
end
|
2119
|
-
|
2120
|
-
#it "should evaluate a formula" do
|
2121
|
-
# @excel1.namevalue_glob("named_formula").should == 4
|
2122
|
-
# @excel1["named_formula"].should == 4
|
2123
|
-
#end
|
2124
|
-
|
2125
|
-
it "should raise an error if name not defined" do
|
2126
|
-
expect {
|
2127
|
-
@excel1.namevalue_glob("foo")
|
2128
|
-
}.to raise_error(NameNotFound, /name "foo"/)
|
2129
|
-
expect {
|
2130
|
-
@excel1["foo"]
|
2131
|
-
}.to raise_error(NameNotFound, /name "foo"/)
|
2132
|
-
expect {
|
2133
|
-
excel2 = Excel.create
|
2134
|
-
excel2.namevalue_glob("one")
|
2135
|
-
}.to raise_error(NameNotFound, /name "one"/)
|
2136
|
-
expect {
|
2137
|
-
excel3 = Excel.create(:visible => true)
|
2138
|
-
excel3["one"]
|
2139
|
-
}.to raise_error(NameNotFound, /name "one"/)
|
2140
|
-
end
|
2141
|
-
|
2142
|
-
it "should set a range to a value" do
|
2143
|
-
@excel1.namevalue_glob("firstcell").should == "foo"
|
2144
|
-
@excel1.set_namevalue_glob("firstcell","bar")
|
2145
|
-
@excel1.namevalue_glob("firstcell").should == "bar"
|
2146
|
-
@excel1["firstcell"] = "foo"
|
2147
|
-
@excel1.namevalue_glob("firstcell").should == "foo"
|
2148
|
-
end
|
2149
|
-
|
2150
|
-
it "should raise an error if name cannot be evaluated" do
|
2151
|
-
expect{
|
2152
|
-
@excel1.set_namevalue_glob("foo", 1)
|
2153
|
-
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo"/)
|
2154
|
-
expect{
|
2155
|
-
@excel1["foo"] = 1
|
2156
|
-
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo"/)
|
2157
|
-
end
|
2158
|
-
|
2159
|
-
it "should color the cell (deprecated)" do
|
2160
|
-
@excel1.set_namevalue_glob("firstcell", "foo")
|
2161
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == -4142
|
2162
|
-
@excel1.set_namevalue_glob("firstcell", "foo", :color => 4)
|
2163
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 4
|
2164
|
-
@excel1["firstcell"].should == "foo"
|
2165
|
-
@excel1["firstcell"] = "foo"
|
2166
|
-
@excel1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 42
|
2167
|
-
@book1.save
|
2168
|
-
end
|
2169
|
-
|
2170
|
-
it "should color the cell" do
|
2171
|
-
@excel1.set_namevalue_glob("firstcell", "foo")
|
2172
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == -4142
|
2173
|
-
@excel1.set_namevalue_glob("firstcell", "foo", :color => 4)
|
2174
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 4
|
2175
|
-
@excel1["firstcell"].should == "foo"
|
2176
|
-
@excel1["firstcell"] = "foo"
|
2177
|
-
@excel1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 42
|
2178
|
-
@book1.save
|
2179
|
-
end
|
2180
|
-
|
2181
|
-
|
2182
|
-
end
|
2183
|
-
|
2184
|
-
describe "namevalue, set_namevalue" do
|
2185
|
-
|
2186
|
-
before do
|
2187
|
-
@book1 = Workbook.open(@another_simple_file)
|
2188
|
-
@excel1 = @book1.excel
|
2189
|
-
# for some reason the workbook must be visible
|
2190
|
-
@book1.visible = true
|
2191
|
-
end
|
2192
|
-
|
2193
|
-
after do
|
2194
|
-
@book1.close(:if_unsaved => :forget)
|
2195
|
-
end
|
2196
|
-
|
2197
|
-
it "should return value of a locally defined name" do
|
2198
|
-
@excel1.namevalue("firstcell").should == "foo"
|
2199
|
-
end
|
2200
|
-
|
2201
|
-
it "should return value of a defined name" do
|
2202
|
-
@excel1.namevalue("new").should == "foo"
|
2203
|
-
@excel1.namevalue("one").should == 1.0
|
2204
|
-
@excel1.namevalue("four").should == [[1,2],[3,4]]
|
2205
|
-
@excel1.namevalue("firstrow").should == [[1,2]]
|
2206
|
-
end
|
2207
|
-
|
2208
|
-
it "should return default value if name not defined and default value is given" do
|
2209
|
-
@excel1.namevalue("foo", :default => 2).should == 2
|
2210
|
-
end
|
2211
|
-
|
2212
|
-
it "should raise an error if name not defined for the sheet" do
|
2213
|
-
expect {
|
2214
|
-
@excel1.namevalue("foo")
|
2215
|
-
}.to raise_error(NameNotFound, /name "foo" not in/)
|
2216
|
-
expect {
|
2217
|
-
@excel1.namevalue("named_formula")
|
2218
|
-
}.to raise_error(NameNotFound, /name "named_formula" not in/)
|
2219
|
-
expect {
|
2220
|
-
excel2 = Excel.create
|
2221
|
-
excel2.namevalue("one")
|
2222
|
-
}.to raise_error(NameNotFound, /name "one" not in/)
|
2223
|
-
end
|
2224
|
-
|
2225
|
-
it "should set a range to a value" do
|
2226
|
-
@excel1.namevalue("firstcell").should == "foo"
|
2227
|
-
@excel1.set_namevalue("firstcell","bar")
|
2228
|
-
@excel1.namevalue("firstcell").should == "bar"
|
2229
|
-
end
|
2230
|
-
|
2231
|
-
it "should raise an error if name cannot be evaluated" do
|
2232
|
-
expect{
|
2233
|
-
@excel1.set_namevalue_glob("foo", 1)
|
2234
|
-
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo" in/)
|
2235
|
-
end
|
2236
|
-
|
2237
|
-
it "should color the cell (depracated)" do
|
2238
|
-
@excel1.set_namevalue("firstcell", "foo")
|
2239
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == -4142
|
2240
|
-
@excel1.set_namevalue("firstcell", "foo", :color => 4)
|
2241
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 4
|
2242
|
-
end
|
2243
|
-
|
2244
|
-
it "should color the cell" do
|
2245
|
-
@excel1.set_namevalue("firstcell", "foo")
|
2246
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == -4142
|
2247
|
-
@excel1.set_namevalue("firstcell", "foo", :color => 4)
|
2248
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 4
|
2249
|
-
end
|
2250
|
-
|
2251
|
-
|
2252
|
-
end
|
2253
|
-
|
2254
2006
|
end
|
2255
2007
|
end
|
2256
2008
|
|