robust_excel_ole 1.0 → 1.0.1
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 +14 -0
- data/README.rdoc +94 -351
- data/README_detail.rdoc +791 -0
- data/examples/edit_sheets/example_saving.rb +1 -1
- data/examples/open_save_close/example_default_excel.rb +5 -5
- data/examples/open_save_close/example_force_excel.rb +2 -2
- data/lib/robust_excel_ole/book.rb +237 -161
- data/lib/robust_excel_ole/excel.rb +96 -68
- data/lib/robust_excel_ole/reo_common.rb +19 -1
- data/lib/robust_excel_ole/sheet.rb +2 -3
- data/lib/robust_excel_ole/version.rb +1 -1
- data/robust_excel_ole.gemspec +2 -2
- data/spec/book_spec.rb +71 -16
- data/spec/book_specs/book_misc_spec.rb +244 -7
- data/spec/book_specs/book_open_spec.rb +472 -33
- data/spec/book_specs/book_save_spec.rb +19 -0
- data/spec/book_specs/book_unobtr_spec.rb +46 -4
- data/spec/data/another_workbook.xls +0 -0
- data/spec/data/book_with_blank.xls +0 -0
- data/spec/data/different_workbook.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +134 -31
- metadata +7 -6
- data/spec/data/refed_wb.xls +0 -0
@@ -47,11 +47,239 @@ describe Book do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
describe "with retain_saved" do
|
51
|
+
|
52
|
+
before do
|
53
|
+
@book = Book.open(@simple_file)
|
54
|
+
end
|
55
|
+
|
56
|
+
after do
|
57
|
+
@book.close(:if_unsaved => :forget)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should keep the save state 'saved' with empty assignments" do
|
61
|
+
@book.Saved.should be_true
|
62
|
+
@book.retain_saved do
|
63
|
+
end
|
64
|
+
@book.Saved.should be_true
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should keep the save state 'saved' with non-affecting assignments" do
|
68
|
+
@book.Saved.should be_true
|
69
|
+
@book.retain_saved do
|
70
|
+
sheet = @book.sheet(1)
|
71
|
+
a = sheet[1,1]
|
72
|
+
b = @book.visible
|
73
|
+
end
|
74
|
+
@book.Saved.should be_true
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should keep the save state 'unsaved'" do
|
78
|
+
sheet = @book.sheet(1)
|
79
|
+
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
80
|
+
@book.Saved.should be_false
|
81
|
+
@book.retain_saved do
|
82
|
+
sheet = @book.sheet(1)
|
83
|
+
a = sheet[1,1]
|
84
|
+
b = @book.visible
|
85
|
+
end
|
86
|
+
@book.Saved.should be_false
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should keep the save state 'saved'" do
|
90
|
+
@book.Saved.should be_true
|
91
|
+
@book.retain_saved do
|
92
|
+
sheet = @book.sheet(1)
|
93
|
+
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
94
|
+
@book.Saved.should be_false
|
95
|
+
end
|
96
|
+
@book.Saved.should be_true
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should keep the save state 'unsaved' even when the workbook was saved before" do
|
100
|
+
sheet = @book.sheet(1)
|
101
|
+
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
102
|
+
@book.Saved.should be_false
|
103
|
+
@book.retain_saved do
|
104
|
+
@book.save
|
105
|
+
@book.Saved.should be_true
|
106
|
+
end
|
107
|
+
@book.Saved.should be_false
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "default-visible" do
|
112
|
+
|
113
|
+
it "should keep the visibility of the open workbook" do
|
114
|
+
book1 = Book.open(@simple_file1)
|
115
|
+
book1.excel.Visible.should be_false
|
116
|
+
book1.Windows(book1.Name).Visible.should be_true
|
117
|
+
book1.visible.should be_false
|
118
|
+
book2 = Book.open(@simple_file1, :default => {:visible => true})
|
119
|
+
book2.visible.should be_false
|
120
|
+
book2.excel.Visible.should be_false
|
121
|
+
book2.Windows(book2.Name).Visible.should be_true
|
122
|
+
book1.visible.should be_false
|
123
|
+
book2 = Book.open(@simple_file1, :default => {:visible => false})
|
124
|
+
book2.visible.should be_false
|
125
|
+
book2.excel.Visible.should be_false
|
126
|
+
book2.Windows(book2.Name).Visible.should be_true
|
127
|
+
book1.visible.should be_false
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should keep the visibility of the open workbook per default" do
|
131
|
+
book1 = Book.open(@simple_file1)
|
132
|
+
book1.excel.Visible.should be_false
|
133
|
+
book1.Windows(book1.Name).Visible.should be_true
|
134
|
+
book1.visible.should be_false
|
135
|
+
book2 = Book.open(@simple_file1)
|
136
|
+
book2.visible.should be_false
|
137
|
+
book2.excel.Visible.should be_false
|
138
|
+
book2.Windows(book2.Name).Visible.should be_true
|
139
|
+
book1.visible.should be_false
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should keep the found Excel instance invisible" do
|
143
|
+
book1 = Book.open(@simple_file1)
|
144
|
+
excel1 = book1.excel
|
145
|
+
excel1.Visible.should be_false
|
146
|
+
book1.close
|
147
|
+
book2 = Book.open(@simple_file1, :default => {:visible => true})
|
148
|
+
excel2 = book2.excel
|
149
|
+
excel2.should == excel1
|
150
|
+
excel2.Visible.should be_false
|
151
|
+
book2.Windows(book2.Name).Visible.should be_true
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should keep the found Excel instance invisible with default invisible" do
|
155
|
+
book1 = Book.open(@simple_file1)
|
156
|
+
excel1 = book1.excel
|
157
|
+
excel1.Visible.should be_false
|
158
|
+
book1.close
|
159
|
+
book2 = Book.open(@simple_file1, :default => {:visible => false})
|
160
|
+
excel2 = book1.excel
|
161
|
+
excel2.should == excel1
|
162
|
+
excel2.Visible.should be_false
|
163
|
+
book2.Windows(book2.Name).Visible.should be_false
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should keep the found Excel instance visible" do
|
167
|
+
book1 = Book.open(@simple_file1, :visible => true)
|
168
|
+
excel1 = book1.excel
|
169
|
+
book1.Windows(book1.Name).Visible.should be_true
|
170
|
+
excel1.Visible.should be_true
|
171
|
+
book1.close
|
172
|
+
book2 = Book.open(@simple_file1, :default => {:visible => false})
|
173
|
+
excel2 = book1.excel
|
174
|
+
excel2.should == excel1
|
175
|
+
excel2.Visible.should be_true
|
176
|
+
book2.Windows(book2.Name).Visible.should be_false
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should keep the found Excel instance visible with default visible true" do
|
180
|
+
book1 = Book.open(@simple_file1, :visible => true)
|
181
|
+
excel1 = book1.excel
|
182
|
+
book1.Windows(book1.Name).Visible.should be_true
|
183
|
+
excel1.Visible.should be_true
|
184
|
+
book1.close
|
185
|
+
book2 = Book.open(@simple_file1, :default => {:visible => true})
|
186
|
+
excel2 = book1.excel
|
187
|
+
excel2.should == excel1
|
188
|
+
excel2.Visible.should be_true
|
189
|
+
book2.Windows(book2.Name).Visible.should be_true
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should keep the found Excel instance invisible per default" do
|
193
|
+
book1 = Book.open(@simple_file1)
|
194
|
+
excel1 = book1.excel
|
195
|
+
excel1.Visible.should be_false
|
196
|
+
book1.close
|
197
|
+
book2 = Book.open(@simple_file1)
|
198
|
+
excel2 = book1.excel
|
199
|
+
excel2.should == excel1
|
200
|
+
excel2.Visible.should be_false
|
201
|
+
book2.Windows(book2.Name).Visible.should be_true
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should open the workbook visible if the workbook is new" do
|
205
|
+
book1 = Book.open(@simple_file1, :default => {:visible => true})
|
206
|
+
book1.visible.should be_true
|
207
|
+
book1.excel.Visible.should be_true
|
208
|
+
book1.Windows(book1.Name).Visible.should be_true
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should open the workbook invisible if the workbook is new" do
|
212
|
+
book1 = Book.open(@simple_file1, :default => {:visible => false})
|
213
|
+
book1.visible.should be_false
|
214
|
+
book1.excel.Visible.should be_false
|
215
|
+
book1.Windows(book1.Name).Visible.should be_false
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should open the workbook invisible per default if the workbook is new" do
|
219
|
+
book1 = Book.open(@simple_file1)
|
220
|
+
book1.visible.should be_false
|
221
|
+
book1.excel.Visible.should be_false
|
222
|
+
book1.Windows(book1.Name).Visible.should be_true
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should open the workbook visible if the old Excel is closed" do
|
226
|
+
book1 = Book.open(@simple_file1)
|
227
|
+
book1.visible.should be_false
|
228
|
+
excel1 = book1.excel
|
229
|
+
excel1.Visible.should be_false
|
230
|
+
book1.Windows(book1.Name).Visible.should be_true
|
231
|
+
book1.close
|
232
|
+
excel1.close
|
233
|
+
book2 = Book.open(@simple_file1, :default => {:visible => true})
|
234
|
+
excel2 = book2.excel
|
235
|
+
book2.visible.should be_true
|
236
|
+
excel2.Visible.should be_true
|
237
|
+
book1.Windows(book1.Name).Visible.should be_true
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should open the workbook invisible if the old Excel is closed" do
|
241
|
+
book1 = Book.open(@simple_file1, :default => {:visible => true})
|
242
|
+
book1.visible.should be_true
|
243
|
+
excel1 = book1.excel
|
244
|
+
excel1.Visible.should be_true
|
245
|
+
book1.Windows(book1.Name).Visible.should be_true
|
246
|
+
book1.close
|
247
|
+
excel1.close
|
248
|
+
book2 = Book.open(@simple_file1, :default => {:visible => false})
|
249
|
+
excel2 = book2.excel
|
250
|
+
book2.visible.should be_false
|
251
|
+
excel2.Visible.should be_false
|
252
|
+
book1.Windows(book1.Name).Visible.should be_false
|
253
|
+
end
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
describe "force-visible" do
|
258
|
+
|
259
|
+
it "should change the visibility of the workbooks" do
|
260
|
+
book1 = Book.open(@simple_file)
|
261
|
+
book1.excel.Visible.should be_false
|
262
|
+
book1.Windows(book1.Name).Visible.should be_true
|
263
|
+
book1.visible.should be_false
|
264
|
+
book2 = Book.open(@simple_file, :visible => true)
|
265
|
+
book2.visible.should be_true
|
266
|
+
book2.excel.Visible.should be_true
|
267
|
+
book2.Windows(book2.Name).Visible.should be_true
|
268
|
+
book1.visible.should be_true
|
269
|
+
book2 = Book.open(@simple_file, :visible => false)
|
270
|
+
book2.visible.should be_false
|
271
|
+
book2.excel.Visible.should be_true
|
272
|
+
book2.Windows(book2.Name).Visible.should be_false
|
273
|
+
book1.visible.should be_false
|
274
|
+
book1.Windows(book2.Name).Visible.should be_false
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
50
278
|
describe "with visible" do
|
51
279
|
|
52
280
|
it "should adapt its default value at the visible value of the Excel" do
|
53
281
|
excel1 = Excel.create
|
54
|
-
excel1.
|
282
|
+
excel1.visible = true
|
55
283
|
book1 = Book.open(@simple_file)
|
56
284
|
excel1.Visible.should be_true
|
57
285
|
excel1.visible.should be_true
|
@@ -68,7 +296,7 @@ describe Book do
|
|
68
296
|
it "should set :visible to false" do
|
69
297
|
book1 = Book.open(@simple_file, :visible => false)
|
70
298
|
book1.excel.Visible.should be_false
|
71
|
-
book1.Windows(book1.Name).Visible.should
|
299
|
+
book1.Windows(book1.Name).Visible.should be_false
|
72
300
|
book1.visible.should be_false
|
73
301
|
end
|
74
302
|
|
@@ -87,11 +315,20 @@ describe Book do
|
|
87
315
|
book1.visible.should be_true
|
88
316
|
end
|
89
317
|
|
318
|
+
it "should preserve :visible" do
|
319
|
+
excel1 = Excel.create
|
320
|
+
book1 = Book.open(@simple_file)
|
321
|
+
book1.excel.Visible.should be_false
|
322
|
+
book1.Windows(book1.Name).Visible.should be_true
|
323
|
+
book1.visible.should be_false
|
324
|
+
end
|
325
|
+
|
326
|
+
|
90
327
|
it "should preserve :visible if it is set to false" do
|
91
328
|
excel1 = Excel.create
|
92
329
|
book1 = Book.open(@simple_file, :visible => false)
|
93
330
|
book1.excel.Visible.should be_false
|
94
|
-
book1.Windows(book1.Name).Visible.should
|
331
|
+
book1.Windows(book1.Name).Visible.should be_false
|
95
332
|
book1.visible.should be_false
|
96
333
|
end
|
97
334
|
|
@@ -142,7 +379,7 @@ describe Book do
|
|
142
379
|
book1 = Book.open(@simple_file)
|
143
380
|
book2 = Book.open(@different_file, :default_excel => :new, :visible => false)
|
144
381
|
book2.excel.Visible.should be_false
|
145
|
-
book2.Windows(book2.Name).Visible.should
|
382
|
+
book2.Windows(book2.Name).Visible.should be_false
|
146
383
|
book2.visible.should be_false
|
147
384
|
end
|
148
385
|
|
@@ -560,7 +797,7 @@ describe Book do
|
|
560
797
|
excel1 = Excel.new(:reuse => false, :visible => false)
|
561
798
|
book1 = Book.open(@simple_file, :visible => false)
|
562
799
|
excel1.Visible.should be_false
|
563
|
-
book1.Windows(book1.Name).Visible.should
|
800
|
+
book1.Windows(book1.Name).Visible.should be_false
|
564
801
|
book1.visible.should be_false
|
565
802
|
end
|
566
803
|
|
@@ -629,7 +866,7 @@ describe Book do
|
|
629
866
|
excel1 = Excel.new(:reuse => false, :visible => false)
|
630
867
|
book1 = Book.open(@simple_file, :visible => false)
|
631
868
|
excel1.Visible.should be_false
|
632
|
-
book1.Windows(book1.Name).Visible.should
|
869
|
+
book1.Windows(book1.Name).Visible.should be_false
|
633
870
|
book1.visible.should be_false
|
634
871
|
excel1.visible = true
|
635
872
|
book2 = Book.open(@different_file)
|
@@ -679,7 +916,7 @@ describe Book do
|
|
679
916
|
@book2.visible = false
|
680
917
|
@book2.Saved.should be_true
|
681
918
|
@book2.excel.Visible.should be_false
|
682
|
-
@book2.Windows(@book2.Name).Visible.should
|
919
|
+
@book2.Windows(@book2.Name).Visible.should be_false
|
683
920
|
@book2.visible.should be_false
|
684
921
|
end
|
685
922
|
|
@@ -38,6 +38,103 @@ describe Book do
|
|
38
38
|
|
39
39
|
describe "open" do
|
40
40
|
|
41
|
+
context "with calculation mode" do
|
42
|
+
|
43
|
+
it "should set calculation mode" do
|
44
|
+
book1 = Book.open(@simple_file, :visible => true, :calculation => :manual)
|
45
|
+
book1.excel.Calculation.should == -4135
|
46
|
+
book1.excel.calculation.should == :manual
|
47
|
+
book1.save
|
48
|
+
book1.excel.close
|
49
|
+
book2 = Book.open(@simple_file, :visible => true, :calculation => :automatic)
|
50
|
+
book2.excel.Calculation.should == -4105
|
51
|
+
book2.excel.calculation.should == :automatic
|
52
|
+
book2.save
|
53
|
+
book2.excel.close
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should set calculation mode and overwrite Excel calculation mode" do
|
57
|
+
excel1 = Excel.new(:calculation => :automatic)
|
58
|
+
book1 = Book.open(@simple_file, :visible => true, :calculation => :manual)
|
59
|
+
book1.excel.Calculation.should == -4135
|
60
|
+
book1.excel.calculation.should == :manual
|
61
|
+
book1.save
|
62
|
+
book1.excel.close
|
63
|
+
excel2 = Excel.new(:calculation => :manual)
|
64
|
+
book2 = Book.open(@simple_file, :visible => true, :calculation => :automatic)
|
65
|
+
book2.excel.Calculation.should == -4105
|
66
|
+
book2.excel.calculation.should == :automatic
|
67
|
+
book2.save
|
68
|
+
book2.excel.close
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should set calculation mode" do
|
72
|
+
excel1 = Excel.new(:calculation => :automatic)
|
73
|
+
book1 = Book.open(@simple_file, :visible => true)
|
74
|
+
book1.excel.Calculation.should == -4105
|
75
|
+
book1.excel.calculation.should == :automatic
|
76
|
+
book1.save
|
77
|
+
book1.close
|
78
|
+
book2 = Book.open(@simple_file, :visible => true, :calculation => :manual)
|
79
|
+
book2.excel.Calculation.should == -4135
|
80
|
+
book2.excel.calculation.should == :manual
|
81
|
+
book2.save
|
82
|
+
book2.excel.close
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should not set the default value" do
|
86
|
+
book1 = Book.open(@simple_file)
|
87
|
+
book1.excel.calculation.should == nil
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should set the default value" do
|
91
|
+
book1 = Book.open(@simple_file)
|
92
|
+
book1.excel.calculation.should == nil
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should set the calculation mode to automatic" do
|
96
|
+
excel = Excel.create(:calculation => :automatic)
|
97
|
+
excel.calculation.should == :automatic
|
98
|
+
book1 = Book.open(@simple_file)
|
99
|
+
book1.excel.Calculation.should == -4105
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should set the calculation mode to manual" do
|
103
|
+
excel = Excel.create(:calculation => :manual)
|
104
|
+
excel.calculation.should == :manual
|
105
|
+
book1 = Book.open(@simple_file)
|
106
|
+
excel.calculation.should == :manual
|
107
|
+
book1.excel.Calculation.should == -4135
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should set the calculation mode to automatic" do
|
111
|
+
excel = Excel.create(:calculation => :automatic)
|
112
|
+
excel.calculation.should == :automatic
|
113
|
+
book1 = Book.open(@simple_file)
|
114
|
+
book1.excel.Calculation.should == -4105
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should change the calculation mode from manual to automatic" do
|
118
|
+
book1 = Book.open(@simple_file, :visible => true)
|
119
|
+
excel1 = Excel.current(:calculation => :automatic)
|
120
|
+
book2 = Book.open(@different_file, :visible => true)
|
121
|
+
book2.excel.Calculation.should == -4105
|
122
|
+
book1.excel.Calculation.should == -4105
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should change the calculation mode from automatic to manual" do
|
126
|
+
excel = Excel.create(:calculation => :automatic)
|
127
|
+
book1 = Book.open(@simple_file)
|
128
|
+
book1.excel.Calculation.should == -4105
|
129
|
+
excel2 = Excel.new(:reuse => false, :calculation => :manual)
|
130
|
+
book2 = Book.open(@different_file, :force => {:excel => excel2})
|
131
|
+
book2.excel.Calculation.should == -4135
|
132
|
+
book1.excel.Calculation.should == -4105
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
|
41
138
|
context "with causing warning dead excel without window handle" do
|
42
139
|
|
43
140
|
it "combined" do
|
@@ -62,7 +159,7 @@ describe Book do
|
|
62
159
|
end
|
63
160
|
|
64
161
|
it "should open in a new Excel" do
|
65
|
-
book2 = Workbook.open(@simple_file, :
|
162
|
+
book2 = Workbook.open(@simple_file, :force => {:excel => :new})
|
66
163
|
book2.should be_alive
|
67
164
|
book2.should be_a Book
|
68
165
|
book2.excel.should_not == @book.excel
|
@@ -165,7 +262,7 @@ describe Book do
|
|
165
262
|
end
|
166
263
|
|
167
264
|
it "should yield different Book objects when opened the same file in different Excel instances" do
|
168
|
-
book2 = Book.open(@simple_file, :
|
265
|
+
book2 = Book.open(@simple_file, :force => {:excel => :new})
|
169
266
|
book2.should_not === @book
|
170
267
|
book2.close
|
171
268
|
end
|
@@ -195,7 +292,7 @@ describe Book do
|
|
195
292
|
old_excel = @book.excel
|
196
293
|
@book.close
|
197
294
|
@book.should_not be_alive
|
198
|
-
book2 = Book.open(@simple_file1, :
|
295
|
+
book2 = Book.open(@simple_file1, :force => {:excel => :new})
|
199
296
|
book2.should_not === @book
|
200
297
|
book2.should be_alive
|
201
298
|
book2.excel.should_not == old_excel
|
@@ -207,7 +304,7 @@ describe Book do
|
|
207
304
|
new_excel = Excel.new(:reuse => false)
|
208
305
|
@book.close
|
209
306
|
@book.should_not be_alive
|
210
|
-
book2 = Book.open(@simple_file1, :
|
307
|
+
book2 = Book.open(@simple_file1, :force => {:excel => new_excel})
|
211
308
|
book2.should_not === @book
|
212
309
|
book2.should be_alive
|
213
310
|
book2.excel.should == new_excel
|
@@ -220,7 +317,7 @@ describe Book do
|
|
220
317
|
new_excel = Excel.new(:reuse => false)
|
221
318
|
@book.close
|
222
319
|
@book.should_not be_alive
|
223
|
-
book2 = Book.open(@simple_file1, :
|
320
|
+
book2 = Book.open(@simple_file1, :force => {:excel => old_excel})
|
224
321
|
book2.should === @book
|
225
322
|
book2.should be_alive
|
226
323
|
book2.excel.should == old_excel
|
@@ -230,6 +327,164 @@ describe Book do
|
|
230
327
|
|
231
328
|
end
|
232
329
|
|
330
|
+
context "with :force => {:excel}" do
|
331
|
+
|
332
|
+
before do
|
333
|
+
@book = Book.open(@simple_file1)
|
334
|
+
end
|
335
|
+
|
336
|
+
after do
|
337
|
+
@book.close rescue nil
|
338
|
+
end
|
339
|
+
|
340
|
+
it "should open in a given Excel provided as Excel, Book, or WIN32OLE representing an Excel or Workbook" do
|
341
|
+
book2 = Book.open(@another_simple_file)
|
342
|
+
book3 = Book.open(@different_file)
|
343
|
+
book3 = Book.open(@simple_file1, :force => {:excel => book2.excel})
|
344
|
+
book3.excel.should === book2.excel
|
345
|
+
book4 = Book.open(@simple_file1, :force => {:excel => @book})
|
346
|
+
book4.excel.should === @book.excel
|
347
|
+
book3.close
|
348
|
+
book4.close
|
349
|
+
book5 = Book.open(@simple_file1, :force => {:excel => book2.ole_workbook})
|
350
|
+
book5.excel.should === book2.excel
|
351
|
+
win32ole_excel1 = WIN32OLE.connect(@book.ole_workbook.Fullname).Application
|
352
|
+
book6 = Book.open(@simple_file1, :force => {:excel => win32ole_excel1})
|
353
|
+
book6.excel.should === @book.excel
|
354
|
+
end
|
355
|
+
|
356
|
+
|
357
|
+
it "should open in a new Excel" do
|
358
|
+
book2 = Book.open(@simple_file1, :force => {:excel => :new})
|
359
|
+
book2.should be_alive
|
360
|
+
book2.should be_a Book
|
361
|
+
book2.excel.should_not == @book.excel
|
362
|
+
book2.should_not == @book
|
363
|
+
@book.Readonly.should be_false
|
364
|
+
book2.Readonly.should be_true
|
365
|
+
book2.close
|
366
|
+
end
|
367
|
+
|
368
|
+
it "should open in a given Excel, not provide identity transparency, because old book readonly, new book writable" do
|
369
|
+
book2 = Book.open(@simple_file1, :force => {:excel => :new})
|
370
|
+
book2.excel.should_not == @book.excel
|
371
|
+
book3 = Book.open(@simple_file1, :force => {:excel => :new})
|
372
|
+
book3.excel.should_not == book2.excel
|
373
|
+
book3.excel.should_not == @book.excel
|
374
|
+
book2.close
|
375
|
+
book4 = Book.open(@simple_file1, :force => {:excel => book2.excel})
|
376
|
+
book4.should be_alive
|
377
|
+
book4.should be_a Book
|
378
|
+
book4.excel.should == book2.excel
|
379
|
+
book4.Readonly.should == true
|
380
|
+
book4.should_not == book2
|
381
|
+
book4.close
|
382
|
+
book5 = Book.open(@simple_file1, :force => {:excel => book2})
|
383
|
+
book5.should be_alive
|
384
|
+
book5.should be_a Book
|
385
|
+
book5.excel.should == book2.excel
|
386
|
+
book5.Readonly.should == true
|
387
|
+
book5.should_not == book2
|
388
|
+
book5.close
|
389
|
+
book3.close
|
390
|
+
end
|
391
|
+
|
392
|
+
it "should open in a given Excel, provide identity transparency, because book can be readonly, such that the old and the new book are readonly" do
|
393
|
+
book2 = Book.open(@simple_file1, :force => {:excel => :new})
|
394
|
+
book2.excel.should_not == @book.excel
|
395
|
+
book3 = Book.open(@simple_file1, :force => {:excel => :new})
|
396
|
+
book3.excel.should_not == book2.excel
|
397
|
+
book3.excel.should_not == @book.excel
|
398
|
+
book2.close
|
399
|
+
book3.close
|
400
|
+
@book.close
|
401
|
+
book4 = Book.open(@simple_file1, :force => {:excel => book2.excel}, :read_only => true)
|
402
|
+
book4.should be_alive
|
403
|
+
book4.should be_a Book
|
404
|
+
book4.excel.should == book2.excel
|
405
|
+
book4.ReadOnly.should be_true
|
406
|
+
book4.should == book2
|
407
|
+
book4.close
|
408
|
+
book5 = Book.open(@simple_file1, :force => {:excel => book2}, :read_only => true)
|
409
|
+
book5.should be_alive
|
410
|
+
book5.should be_a Book
|
411
|
+
book5.excel.should == book2.excel
|
412
|
+
book5.ReadOnly.should be_true
|
413
|
+
book5.should == book2
|
414
|
+
book5.close
|
415
|
+
book3.close
|
416
|
+
end
|
417
|
+
|
418
|
+
it "should open in a given Excel, provide identity transparency, because book can be readonly, such that the old and the new book are readonly" do
|
419
|
+
book2 = Book.open(@simple_file1, :force => {:excel => :new})
|
420
|
+
book2.excel.should_not == @book.excel
|
421
|
+
book2.close
|
422
|
+
@book.close
|
423
|
+
book4 = Book.open(@simple_file1, :force => {:excel => book2}, :read_only => true)
|
424
|
+
book4.should be_alive
|
425
|
+
book4.should be_a Book
|
426
|
+
book4.excel.should == book2.excel
|
427
|
+
book4.ReadOnly.should be_true
|
428
|
+
book4.should == book2
|
429
|
+
book4.close
|
430
|
+
end
|
431
|
+
|
432
|
+
it "should raise an error if no Excel or Book is given" do
|
433
|
+
expect{
|
434
|
+
Book.open(@simple_file1, :force => {:excel => :b})
|
435
|
+
}.to raise_error(TypeErrorREO, "given object is neither an Excel, a Workbook, nor a Win32ole")
|
436
|
+
end
|
437
|
+
|
438
|
+
it "should do force_excel even if both force_ and default_excel is given" do
|
439
|
+
book2 = Book.open(@simple_file1, :default => {:excel => @book.excel}, :force => {:excel => :new})
|
440
|
+
book2.should be_alive
|
441
|
+
book2.should be_a Book
|
442
|
+
book2.excel.should_not == @book.excel
|
443
|
+
book2.should_not == @book
|
444
|
+
end
|
445
|
+
|
446
|
+
it "should do default_excel if force_excel is nil" do
|
447
|
+
book2 = Book.open(@another_simple_file, :force => {:excel => nil})
|
448
|
+
book2.should be_alive
|
449
|
+
book2.should be_a Book
|
450
|
+
book2.excel.should == @book.excel
|
451
|
+
end
|
452
|
+
|
453
|
+
it "should force_excel with :reuse" do
|
454
|
+
book2 = Book.open(@different_file, :force => {:excel => :current})
|
455
|
+
book2.should be_alive
|
456
|
+
book2.should be_a Book
|
457
|
+
book2.excel.should == @book.excel
|
458
|
+
end
|
459
|
+
|
460
|
+
it "should force_excel with :reuse even if :default_excel says sth. else" do
|
461
|
+
book2 = Book.open(@different_file, :force => {:excel => :current}, :default => {:excel => :new})
|
462
|
+
book2.should be_alive
|
463
|
+
book2.should be_a Book
|
464
|
+
book2.excel.should == @book.excel
|
465
|
+
end
|
466
|
+
|
467
|
+
it "should force_excel with :reuse when reopening and the Excel is not alive even if :default_excel says sth. else" do
|
468
|
+
excel2 = Excel.new(:reuse => false)
|
469
|
+
@book.excel.close
|
470
|
+
book2 = Book.open(@simple_file1, :force => {:excel => :current}, :default => {:excel => :new})
|
471
|
+
book2.should be_alive
|
472
|
+
book2.should be_a Book
|
473
|
+
book2.excel.should === excel2
|
474
|
+
end
|
475
|
+
|
476
|
+
it "should force_excel with :reuse when reopening and the Excel is not alive even if :default_excel says sth. else" do
|
477
|
+
book2 = Book.open(@different_file1, :force => {:excel => :new})
|
478
|
+
book2.excel.close
|
479
|
+
book3 = Book.open(@different_file1, :force => {:excel => :current}, :default => {:excel => :new})
|
480
|
+
book3.should be_alive
|
481
|
+
book3.should be_a Book
|
482
|
+
book3.excel.should == @book.excel
|
483
|
+
end
|
484
|
+
|
485
|
+
end
|
486
|
+
|
487
|
+
|
233
488
|
context "with :force_excel" do
|
234
489
|
|
235
490
|
before do
|
@@ -387,6 +642,188 @@ describe Book do
|
|
387
642
|
|
388
643
|
end
|
389
644
|
|
645
|
+
context "with :default => {:excel}" do
|
646
|
+
|
647
|
+
before do
|
648
|
+
@book = Book.open(@simple_file1, :visible => true)
|
649
|
+
end
|
650
|
+
|
651
|
+
after do
|
652
|
+
@book.close rescue nil
|
653
|
+
end
|
654
|
+
|
655
|
+
it "should use the open book" do
|
656
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :current})
|
657
|
+
book2.excel.should == @book.excel
|
658
|
+
book2.should be_alive
|
659
|
+
book2.should be_a Book
|
660
|
+
book2.should == @book
|
661
|
+
book2.close
|
662
|
+
end
|
663
|
+
|
664
|
+
it "should reopen the book in the excel instance where it was opened before" do
|
665
|
+
excel = Excel.new(:reuse => false)
|
666
|
+
@book.close
|
667
|
+
book2 = Book.open(@simple_file1)
|
668
|
+
book2.should be_alive
|
669
|
+
book2.should be_a Book
|
670
|
+
book2.excel.should == @book.excel
|
671
|
+
book2.excel.should_not == excel
|
672
|
+
book2.filename.should == @book.filename
|
673
|
+
@book.should be_alive
|
674
|
+
book2.should == @book
|
675
|
+
book2.close
|
676
|
+
end
|
677
|
+
|
678
|
+
it "should reopen a book in a new Excel if all Excel instances are closed" do
|
679
|
+
excel = Excel.new(:reuse => false)
|
680
|
+
excel2 = @book.excel
|
681
|
+
fn = @book.filename
|
682
|
+
@book.close
|
683
|
+
Excel.close_all
|
684
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :current})
|
685
|
+
book2.should be_alive
|
686
|
+
book2.should be_a Book
|
687
|
+
book2.filename.should == fn
|
688
|
+
@book.should be_alive
|
689
|
+
book2.should == @book
|
690
|
+
book2.close
|
691
|
+
end
|
692
|
+
|
693
|
+
it "should reopen a book in the first opened Excel if the old Excel is closed" do
|
694
|
+
excel = @book.excel
|
695
|
+
Excel.close_all
|
696
|
+
new_excel = Excel.new(:reuse => false)
|
697
|
+
new_excel2 = Excel.new(:reuse => false)
|
698
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :current})
|
699
|
+
book2.should be_alive
|
700
|
+
book2.should be_a Book
|
701
|
+
book2.excel.should_not == excel
|
702
|
+
book2.excel.should_not == new_excel2
|
703
|
+
book2.excel.should == new_excel
|
704
|
+
@book.should be_alive
|
705
|
+
book2.should == @book
|
706
|
+
book2.close
|
707
|
+
end
|
708
|
+
|
709
|
+
it "should reopen a book in the first opened excel, if the book cannot be reopened" do
|
710
|
+
@book.close
|
711
|
+
Excel.close_all
|
712
|
+
excel1 = Excel.new(:reuse => false)
|
713
|
+
excel2 = Excel.new(:reuse => false)
|
714
|
+
book2 = Book.open(@different_file, :default => {:excel => :current})
|
715
|
+
book2.should be_alive
|
716
|
+
book2.should be_a Book
|
717
|
+
book2.excel.should == excel1
|
718
|
+
book2.excel.should_not == excel2
|
719
|
+
book2.close
|
720
|
+
end
|
721
|
+
|
722
|
+
it "should reopen the book in the Excel where it was opened most recently" do
|
723
|
+
excel1 = @book.excel
|
724
|
+
excel2 = Excel.new(:reuse => false)
|
725
|
+
@book.close
|
726
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :current})
|
727
|
+
book2.excel.should == excel1
|
728
|
+
book2.close
|
729
|
+
book3 = Book.open(@simple_file1, :force => {:excel => excel2})
|
730
|
+
book3.close
|
731
|
+
book3 = Book.open(@simple_file1, :default => {:excel => :current})
|
732
|
+
book3.excel.should == excel2
|
733
|
+
book3.close
|
734
|
+
end
|
735
|
+
|
736
|
+
it "should reopen a book in the excel instance where it was opened most recently" do
|
737
|
+
book2 = Book.open(@simple_file, :force => {:excel => :new})
|
738
|
+
@book.close
|
739
|
+
book2.close
|
740
|
+
book3 = Book.open(@simple_file1)
|
741
|
+
book2.should be_alive
|
742
|
+
book2.should be_a Book
|
743
|
+
book3.excel.should == book2.excel
|
744
|
+
book3.excel.should_not == @book.excel
|
745
|
+
book3.should == book2
|
746
|
+
book3.should_not == @book
|
747
|
+
end
|
748
|
+
|
749
|
+
it "should open the book in a new excel if the book was not opened before" do
|
750
|
+
book2 = Book.open(@different_file, :default => {:excel => :current})
|
751
|
+
book2.excel.should == @book.excel
|
752
|
+
book3 = Book.open(@another_simple_file, :default => {:excel => :new})
|
753
|
+
book3.excel.should_not == @book.excel
|
754
|
+
end
|
755
|
+
|
756
|
+
it "should open the book in a new excel if the book was opened before but the excel has been closed" do
|
757
|
+
excel = @book.excel
|
758
|
+
excel2 = Excel.new(:reuse => false)
|
759
|
+
excel.close
|
760
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :new})
|
761
|
+
book2.excel.should_not == excel2
|
762
|
+
book2.close
|
763
|
+
end
|
764
|
+
|
765
|
+
it "should open the book in a given excel if the book was not opened before" do
|
766
|
+
book2 = Book.open(@different_file, :default => {:excel => :current})
|
767
|
+
book2.excel.should == @book.excel
|
768
|
+
excel = Excel.new(:reuse => false)
|
769
|
+
book3 = Book.open(@another_simple_file, :default => {:excel => excel})
|
770
|
+
book3.excel.should == excel
|
771
|
+
end
|
772
|
+
|
773
|
+
it "should open the book in a given excel if the book was opened before but the excel has been closed" do
|
774
|
+
excel2 = Excel.new(:reuse => false, :visible => true)
|
775
|
+
@book.excel.close
|
776
|
+
book2 = Book.open(@simple_file1, :default => {:excel => excel2, :visible => true})
|
777
|
+
book2.excel.should == excel2
|
778
|
+
end
|
779
|
+
|
780
|
+
it "should open a new excel, if the book cannot be reopened" do
|
781
|
+
@book.close
|
782
|
+
new_excel = Excel.new(:reuse => false)
|
783
|
+
book2 = Book.open(@different_file, :default => {:excel => :new})
|
784
|
+
book2.should be_alive
|
785
|
+
book2.should be_a Book
|
786
|
+
book2.excel.should_not == new_excel
|
787
|
+
book2.excel.should_not == @book.excel
|
788
|
+
book2.close
|
789
|
+
end
|
790
|
+
|
791
|
+
it "should open a given excel, if the book cannot be reopened" do
|
792
|
+
@book.close
|
793
|
+
new_excel = Excel.new(:reuse => false)
|
794
|
+
book2 = Book.open(@different_file, :default => {:excel => @book.excel})
|
795
|
+
book2.should be_alive
|
796
|
+
book2.should be_a Book
|
797
|
+
book2.excel.should_not == new_excel
|
798
|
+
book2.excel.should == @book.excel
|
799
|
+
book2.close
|
800
|
+
end
|
801
|
+
|
802
|
+
it "should open a given excel, if the book cannot be reopened" do
|
803
|
+
@book.close
|
804
|
+
new_excel = Excel.new(:reuse => false)
|
805
|
+
book2 = Book.open(@different_file, :default => {:excel => @book})
|
806
|
+
book2.should be_alive
|
807
|
+
book2.should be_a Book
|
808
|
+
book2.excel.should_not == new_excel
|
809
|
+
book2.excel.should == @book.excel
|
810
|
+
book2.close
|
811
|
+
end
|
812
|
+
|
813
|
+
it "should reuse an open book by default" do
|
814
|
+
book2 = Book.open(@simple_file1)
|
815
|
+
book2.excel.should == @book.excel
|
816
|
+
book2.should == @book
|
817
|
+
end
|
818
|
+
|
819
|
+
it "should raise an error if no Excel or Book is given" do
|
820
|
+
expect{
|
821
|
+
Book.open(@different_file, :default => {:excel => :a})
|
822
|
+
}.to raise_error(TypeErrorREO, "given object is neither an Excel, a Workbook, nor a Win32ole")
|
823
|
+
end
|
824
|
+
|
825
|
+
end
|
826
|
+
|
390
827
|
context "with :default_excel" do
|
391
828
|
|
392
829
|
before do
|
@@ -580,14 +1017,14 @@ describe Book do
|
|
580
1017
|
end
|
581
1018
|
|
582
1019
|
it "should force_excel with :active" do
|
583
|
-
book2 = Book.open(@different_file, :
|
1020
|
+
book2 = Book.open(@different_file, :force => {:excel => :active})
|
584
1021
|
book2.should be_alive
|
585
1022
|
book2.should be_a Book
|
586
1023
|
book2.excel.should == @book.excel
|
587
1024
|
end
|
588
1025
|
|
589
1026
|
it "should force_excel with :reuse even if :default_excel says sth. else" do
|
590
|
-
book2 = Book.open(@different_file, :
|
1027
|
+
book2 = Book.open(@different_file, :force => {:excel => :active}, :default => {:excel => :new})
|
591
1028
|
book2.should be_alive
|
592
1029
|
book2.should be_a Book
|
593
1030
|
book2.excel.should == @book.excel
|
@@ -596,23 +1033,23 @@ describe Book do
|
|
596
1033
|
it "should open force_excel with :reuse when reopening and the Excel is not alive even if :default_excel says sth. else" do
|
597
1034
|
excel2 = Excel.new(:reuse => false)
|
598
1035
|
@book.excel.close
|
599
|
-
book2 = Book.open(@simple_file1, :
|
1036
|
+
book2 = Book.open(@simple_file1, :force => {:excel => :active}, :default => {:excel => :new})
|
600
1037
|
book2.should be_alive
|
601
1038
|
book2.should be_a Book
|
602
1039
|
book2.excel.should === excel2
|
603
1040
|
end
|
604
1041
|
|
605
1042
|
it "should force_excel with :reuse when reopening and the Excel is not alive even if :default_excel says sth. else" do
|
606
|
-
book2 = Book.open(@different_file1, :
|
1043
|
+
book2 = Book.open(@different_file1, :force => {:excel => :new})
|
607
1044
|
book2.excel.close
|
608
|
-
book3 = Book.open(@different_file1, :
|
1045
|
+
book3 = Book.open(@different_file1, :force => {:excel => :active}, :default => {:excel => :new})
|
609
1046
|
book3.should be_alive
|
610
1047
|
book3.should be_a Book
|
611
1048
|
book3.excel.should == @book.excel
|
612
1049
|
end
|
613
1050
|
|
614
1051
|
it "should use the open book" do
|
615
|
-
book2 = Book.open(@simple_file1, :
|
1052
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :active})
|
616
1053
|
book2.excel.should == @book.excel
|
617
1054
|
book2.should be_alive
|
618
1055
|
book2.should be_a Book
|
@@ -626,7 +1063,7 @@ describe Book do
|
|
626
1063
|
fn = @book.filename
|
627
1064
|
@book.close
|
628
1065
|
Excel.close_all
|
629
|
-
book2 = Book.open(@simple_file1, :
|
1066
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :active})
|
630
1067
|
book2.should be_alive
|
631
1068
|
book2.should be_a Book
|
632
1069
|
book2.filename.should == fn
|
@@ -640,7 +1077,7 @@ describe Book do
|
|
640
1077
|
Excel.close_all
|
641
1078
|
new_excel = Excel.new(:reuse => false)
|
642
1079
|
new_excel2 = Excel.new(:reuse => false)
|
643
|
-
book2 = Book.open(@simple_file1, :
|
1080
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :active})
|
644
1081
|
book2.should be_alive
|
645
1082
|
book2.should be_a Book
|
646
1083
|
book2.excel.should_not == excel
|
@@ -656,7 +1093,7 @@ describe Book do
|
|
656
1093
|
Excel.close_all
|
657
1094
|
excel1 = Excel.new(:reuse => false)
|
658
1095
|
excel2 = Excel.new(:reuse => false)
|
659
|
-
book2 = Book.open(@different_file, :
|
1096
|
+
book2 = Book.open(@different_file, :default => {:excel => :active})
|
660
1097
|
book2.should be_alive
|
661
1098
|
book2.should be_a Book
|
662
1099
|
book2.excel.should == excel1
|
@@ -668,12 +1105,12 @@ describe Book do
|
|
668
1105
|
excel1 = @book.excel
|
669
1106
|
excel2 = Excel.new(:reuse => false)
|
670
1107
|
@book.close
|
671
|
-
book2 = Book.open(@simple_file1, :
|
1108
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :active})
|
672
1109
|
book2.excel.should == excel1
|
673
1110
|
book2.close
|
674
|
-
book3 = Book.open(@simple_file1, :
|
1111
|
+
book3 = Book.open(@simple_file1, :force => {:excel => excel2})
|
675
1112
|
book3.close
|
676
|
-
book3 = Book.open(@simple_file1, :
|
1113
|
+
book3 = Book.open(@simple_file1, :default => {:excel => :active})
|
677
1114
|
book3.excel.should == excel2
|
678
1115
|
book3.close
|
679
1116
|
end
|
@@ -691,14 +1128,14 @@ describe Book do
|
|
691
1128
|
end
|
692
1129
|
|
693
1130
|
it "should force_excel with :reuse" do
|
694
|
-
book2 = Book.open(@different_file, :
|
1131
|
+
book2 = Book.open(@different_file, :force => {:excel => :reuse})
|
695
1132
|
book2.should be_alive
|
696
1133
|
book2.should be_a Book
|
697
1134
|
book2.excel.should == @book.excel
|
698
1135
|
end
|
699
1136
|
|
700
1137
|
it "should force_excel with :reuse even if :default_excel says sth. else" do
|
701
|
-
book2 = Book.open(@different_file, :
|
1138
|
+
book2 = Book.open(@different_file, :force => {:excel => :reuse}, :default => {:excel => :new})
|
702
1139
|
book2.should be_alive
|
703
1140
|
book2.should be_a Book
|
704
1141
|
book2.excel.should == @book.excel
|
@@ -707,23 +1144,23 @@ describe Book do
|
|
707
1144
|
it "should open force_excel with :reuse when reopening and the Excel is not alive even if :default_excel says sth. else" do
|
708
1145
|
excel2 = Excel.new(:reuse => false)
|
709
1146
|
@book.excel.close
|
710
|
-
book2 = Book.open(@simple_file1, :
|
1147
|
+
book2 = Book.open(@simple_file1, :force => {:excel => :reuse}, :default => {:excel => :new})
|
711
1148
|
book2.should be_alive
|
712
1149
|
book2.should be_a Book
|
713
1150
|
book2.excel.should === excel2
|
714
1151
|
end
|
715
1152
|
|
716
1153
|
it "should force_excel with :reuse when reopening and the Excel is not alive even if :default_excel says sth. else" do
|
717
|
-
book2 = Book.open(@different_file1, :
|
1154
|
+
book2 = Book.open(@different_file1, :force => {:excel => :new})
|
718
1155
|
book2.excel.close
|
719
|
-
book3 = Book.open(@different_file1, :
|
1156
|
+
book3 = Book.open(@different_file1, :force => {:excel => :reuse}, :default => {:excel => :new})
|
720
1157
|
book3.should be_alive
|
721
1158
|
book3.should be_a Book
|
722
1159
|
book3.excel.should == @book.excel
|
723
1160
|
end
|
724
1161
|
|
725
1162
|
it "should use the open book" do
|
726
|
-
book2 = Book.open(@simple_file1, :
|
1163
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :reuse})
|
727
1164
|
book2.excel.should == @book.excel
|
728
1165
|
book2.should be_alive
|
729
1166
|
book2.should be_a Book
|
@@ -737,7 +1174,7 @@ describe Book do
|
|
737
1174
|
fn = @book.filename
|
738
1175
|
@book.close
|
739
1176
|
Excel.close_all
|
740
|
-
book2 = Book.open(@simple_file1, :
|
1177
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :reuse})
|
741
1178
|
book2.should be_alive
|
742
1179
|
book2.should be_a Book
|
743
1180
|
book2.filename.should == fn
|
@@ -751,7 +1188,7 @@ describe Book do
|
|
751
1188
|
Excel.close_all
|
752
1189
|
new_excel = Excel.new(:reuse => false)
|
753
1190
|
new_excel2 = Excel.new(:reuse => false)
|
754
|
-
book2 = Book.open(@simple_file1, :
|
1191
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :reuse})
|
755
1192
|
book2.should be_alive
|
756
1193
|
book2.should be_a Book
|
757
1194
|
book2.excel.should_not == excel
|
@@ -767,7 +1204,7 @@ describe Book do
|
|
767
1204
|
Excel.close_all
|
768
1205
|
excel1 = Excel.new(:reuse => false)
|
769
1206
|
excel2 = Excel.new(:reuse => false)
|
770
|
-
book2 = Book.open(@different_file, :
|
1207
|
+
book2 = Book.open(@different_file, :default => {:excel => :reuse})
|
771
1208
|
book2.should be_alive
|
772
1209
|
book2.should be_a Book
|
773
1210
|
book2.excel.should == excel1
|
@@ -779,12 +1216,12 @@ describe Book do
|
|
779
1216
|
excel1 = @book.excel
|
780
1217
|
excel2 = Excel.new(:reuse => false)
|
781
1218
|
@book.close
|
782
|
-
book2 = Book.open(@simple_file1, :
|
1219
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :reuse})
|
783
1220
|
book2.excel.should == excel1
|
784
1221
|
book2.close
|
785
|
-
book3 = Book.open(@simple_file1, :
|
1222
|
+
book3 = Book.open(@simple_file1, :force => {:excel => excel2})
|
786
1223
|
book3.close
|
787
|
-
book3 = Book.open(@simple_file1, :
|
1224
|
+
book3 = Book.open(@simple_file1, :default => {:excel => :reuse})
|
788
1225
|
book3.excel.should == excel2
|
789
1226
|
book3.close
|
790
1227
|
end
|
@@ -795,6 +1232,7 @@ describe Book do
|
|
795
1232
|
|
796
1233
|
before do
|
797
1234
|
@book = Book.open(@simple_file1)
|
1235
|
+
#@book.Windows(@book.Name).Visible = true
|
798
1236
|
@sheet = @book.sheet(1)
|
799
1237
|
@book.add_sheet(@sheet, :as => 'a_name')
|
800
1238
|
end
|
@@ -924,6 +1362,7 @@ describe Book do
|
|
924
1362
|
book_before.close
|
925
1363
|
end
|
926
1364
|
@book = Book.open(@simple_file_other_path)
|
1365
|
+
#@book.Windows(@book.Name).Visible = true
|
927
1366
|
@sheet_count = @book.ole_workbook.Worksheets.Count
|
928
1367
|
@sheet = @book.sheet(1)
|
929
1368
|
@book.add_sheet(@sheet, :as => 'a_name')
|
@@ -1146,7 +1585,7 @@ describe Book do
|
|
1146
1585
|
old_cell_value = sheet[1,1].value
|
1147
1586
|
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
1148
1587
|
book.Saved.should be_false
|
1149
|
-
new_book = Book.open(@simple_file1, :if_unsaved => :accept, :
|
1588
|
+
new_book = Book.open(@simple_file1, :if_unsaved => :accept, :force => {:excel => book.excel}, :read_only => false)
|
1150
1589
|
new_book.ReadOnly.should be_false
|
1151
1590
|
new_book.should be_alive
|
1152
1591
|
book.should be_alive
|
@@ -1157,14 +1596,14 @@ describe Book do
|
|
1157
1596
|
end
|
1158
1597
|
|
1159
1598
|
it "should reopen the book with readonly (unsaved changes of the writable should be saved)" do
|
1160
|
-
book = Book.open(@simple_file1, :
|
1599
|
+
book = Book.open(@simple_file1, :force => {:excel => :new}, :read_only => false)
|
1161
1600
|
book.ReadOnly.should be_false
|
1162
1601
|
book.should be_alive
|
1163
1602
|
sheet = book.sheet(1)
|
1164
1603
|
old_cell_value = sheet[1,1].value
|
1165
1604
|
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
1166
1605
|
book.Saved.should be_false
|
1167
|
-
new_book = Book.open(@simple_file1, :
|
1606
|
+
new_book = Book.open(@simple_file1, :force => {:excel => book.excel}, :read_only => true, :if_unsaved => :accept)
|
1168
1607
|
new_book.ReadOnly.should be_false
|
1169
1608
|
new_book.Saved.should be_false
|
1170
1609
|
new_book.should == book
|
@@ -1173,7 +1612,7 @@ describe Book do
|
|
1173
1612
|
it "should open the second book in another Excel as writable" do
|
1174
1613
|
book = Book.open(@simple_file1, :read_only => true)
|
1175
1614
|
book.ReadOnly.should be_true
|
1176
|
-
new_book = Book.open(@simple_file1, :
|
1615
|
+
new_book = Book.open(@simple_file1, :force => {:excel => :new}, :read_only => false)
|
1177
1616
|
new_book.ReadOnly.should be_false
|
1178
1617
|
new_book.close
|
1179
1618
|
book.close
|