robust_excel_ole 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +8 -0
- data/README.rdoc +7 -4
- data/README_detail.rdoc +7 -3
- data/lib/reo_console.rb +1 -1
- data/lib/robust_excel_ole.rb +1 -0
- data/lib/robust_excel_ole/book.rb +26 -22
- data/lib/robust_excel_ole/excel.rb +38 -21
- data/lib/robust_excel_ole/general.rb +2 -1
- data/lib/robust_excel_ole/reo_common.rb +0 -3
- data/lib/robust_excel_ole/version.rb +1 -1
- data/spec/book_spec.rb +16 -15
- data/spec/book_specs/book_misc_spec.rb +22 -8
- data/spec/book_specs/book_open_spec.rb +3 -3
- data/spec/book_specs/book_save_spec.rb +1 -1
- data/spec/book_specs/book_sheet_spec.rb +12 -6
- data/spec/book_specs/book_unobtr_spec.rb +5 -11
- data/spec/data/another_workbook.xls +0 -0
- data/spec/data/different_workbook.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +247 -102
- data/spec/general_spec.rb +1 -1
- data/spec/reo_common_spec.rb +5 -1
- metadata +4 -4
@@ -257,7 +257,21 @@ describe Book do
|
|
257
257
|
it "should set visible and displayalerts if displayalerts => :if_visible" do
|
258
258
|
book1 = Book.open(@simple_file)
|
259
259
|
book1.excel.Visible.should be_false
|
260
|
-
book1.excel.displayalerts
|
260
|
+
book1.excel.displayalerts.should == :if_visible
|
261
|
+
book1.Windows(book1.Name).Visible.should be_true
|
262
|
+
book1.visible.should be_false
|
263
|
+
book2 = Book.open(@different_file)
|
264
|
+
book2.excel.Visible.should be_false
|
265
|
+
book2.Windows(book2.Name).Visible.should be_true
|
266
|
+
book2.visible.should be_false
|
267
|
+
book2.excel.visible.should be_false
|
268
|
+
book2.excel.displayalerts.should == :if_visible
|
269
|
+
book2.excel.DisplayAlerts.should be_false
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should set visible and displayalerts if displayalerts => :if_visible" do
|
273
|
+
book1 = Book.open(@simple_file)
|
274
|
+
book1.excel.Visible.should be_false
|
261
275
|
book1.excel.displayalerts.should == :if_visible
|
262
276
|
book1.Windows(book1.Name).Visible.should be_true
|
263
277
|
book1.visible.should be_false
|
@@ -266,7 +280,7 @@ describe Book do
|
|
266
280
|
book2.Windows(book2.Name).Visible.should be_true
|
267
281
|
book2.visible.should be_true
|
268
282
|
book2.excel.visible.should be_true
|
269
|
-
book2.excel.displayalerts.should
|
283
|
+
book2.excel.displayalerts.should == :if_visible
|
270
284
|
book2.excel.DisplayAlerts.should be_true
|
271
285
|
end
|
272
286
|
end
|
@@ -428,7 +442,7 @@ describe Book do
|
|
428
442
|
end
|
429
443
|
end
|
430
444
|
|
431
|
-
describe "alive?, filename, ==, visible,
|
445
|
+
describe "alive?, filename, ==, visible, focus, saved, check_compatibility" do
|
432
446
|
|
433
447
|
context "with alive?" do
|
434
448
|
|
@@ -671,13 +685,13 @@ describe Book do
|
|
671
685
|
|
672
686
|
end
|
673
687
|
|
674
|
-
context "with
|
688
|
+
context "with focus" do
|
675
689
|
|
676
690
|
before do
|
677
691
|
@key_sender = IO.popen 'ruby "' + File.join(File.dirname(__FILE__), '../helpers/key_sender.rb') + '" "Microsoft Office Excel" ' , "w"
|
678
692
|
@book = Book.open(@simple_file, :visible => true)
|
679
693
|
@book.excel.displayalerts = false
|
680
|
-
@book2 = Book.open(@another_simple_file, :
|
694
|
+
@book2 = Book.open(@another_simple_file, :visible => true)
|
681
695
|
@book2.excel.displayalerts = false
|
682
696
|
end
|
683
697
|
|
@@ -687,7 +701,7 @@ describe Book do
|
|
687
701
|
@key_sender.close
|
688
702
|
end
|
689
703
|
|
690
|
-
it "should
|
704
|
+
it "should bring a book to focus" do
|
691
705
|
sheet = @book.sheet(2)
|
692
706
|
sheet.Activate
|
693
707
|
sheet[2,3].Activate
|
@@ -695,12 +709,12 @@ describe Book do
|
|
695
709
|
sheet2.Activate
|
696
710
|
sheet2[3,2].Activate
|
697
711
|
Excel.current.should == @book.excel
|
698
|
-
@book2.
|
712
|
+
@book2.focus
|
699
713
|
@key_sender.puts "{a}{enter}"
|
700
714
|
sleep 1
|
701
715
|
sheet2[3,2].Value.should == "a"
|
702
716
|
#Excel.current.should == @book2.excel
|
703
|
-
@book.
|
717
|
+
@book.focus
|
704
718
|
@key_sender.puts "{a}{enter}"
|
705
719
|
sleep 1
|
706
720
|
sheet[2,3].Value.should == "a"
|
@@ -1039,7 +1039,7 @@ describe Book do
|
|
1039
1039
|
File.delete @simple_save_file rescue nil
|
1040
1040
|
expect {
|
1041
1041
|
Book.open(@simple_save_file, :if_absent => :raise)
|
1042
|
-
}.to raise_error(FileNotFound, "file
|
1042
|
+
}.to raise_error(FileNotFound, "file #{General::absolute_path(@simple_save_file).gsub("/","\\").inspect} not found")
|
1043
1043
|
end
|
1044
1044
|
|
1045
1045
|
it "should create a workbook" do
|
@@ -1054,7 +1054,7 @@ describe Book do
|
|
1054
1054
|
File.delete @simple_save_file rescue nil
|
1055
1055
|
expect {
|
1056
1056
|
Book.open(@simple_save_file)
|
1057
|
-
}.to raise_error(FileNotFound, "file
|
1057
|
+
}.to raise_error(FileNotFound, "file #{General::absolute_path(@simple_save_file).gsub("/","\\").inspect} not found")
|
1058
1058
|
end
|
1059
1059
|
|
1060
1060
|
end
|
@@ -1237,7 +1237,7 @@ describe Book do
|
|
1237
1237
|
expected_path = Regexp.new(File.expand_path(path).gsub(/\//, "."))
|
1238
1238
|
expect {
|
1239
1239
|
Book.open(path)
|
1240
|
-
}.to raise_error(FileNotFound, "file
|
1240
|
+
}.to raise_error(FileNotFound, "file #{General::absolute_path(path).gsub("/","\\").inspect} not found")
|
1241
1241
|
end
|
1242
1242
|
end
|
1243
1243
|
end
|
@@ -172,11 +172,13 @@ describe Book do
|
|
172
172
|
end
|
173
173
|
|
174
174
|
it "should copy the first sheet before the third sheet and give 'before' the highest priority" do
|
175
|
-
@book.add_sheet(@sheet, :after => @sheet, :before => @book.sheet(3))
|
175
|
+
@book.add_sheet(@sheet, :after => @sheet, :before => @book.sheet(3))
|
176
|
+
@book.Worksheets.Count.should == 4
|
176
177
|
end
|
177
178
|
|
178
179
|
it "should copy the first sheet before the third sheet and give 'before' the highest priority" do
|
179
|
-
@book.add_sheet(@sheet, :before => @book.sheet(3), :after => @sheet)
|
180
|
+
@book.add_sheet(@sheet, :before => @book.sheet(3), :after => @sheet)
|
181
|
+
@book.Worksheets.Count.should == 4
|
180
182
|
end
|
181
183
|
|
182
184
|
it "should raise error with giving a name that already exists" do
|
@@ -270,11 +272,13 @@ describe Book do
|
|
270
272
|
end
|
271
273
|
|
272
274
|
it "should copy the first sheet before the third sheet and give 'before' the highest priority" do
|
273
|
-
@book.copy_sheet(@sheet, :after => @sheet, :before => @book.sheet(3))
|
275
|
+
@book.copy_sheet(@sheet, :after => @sheet, :before => @book.sheet(3))
|
276
|
+
@book.Worksheets.Count.should == 4
|
274
277
|
end
|
275
278
|
|
276
279
|
it "should copy the first sheet before the third sheet and give 'before' the highest priority" do
|
277
|
-
@book.copy_sheet(@sheet, :before => @book.sheet(3), :after => @sheet)
|
280
|
+
@book.copy_sheet(@sheet, :before => @book.sheet(3), :after => @sheet)
|
281
|
+
@book.Worksheets.Count.should == 4
|
278
282
|
end
|
279
283
|
|
280
284
|
it "should raise error with giving a name that already exists" do
|
@@ -370,11 +374,13 @@ describe Book do
|
|
370
374
|
end
|
371
375
|
|
372
376
|
it "should copy the first sheet before the third sheet and give 'before' the highest priority" do
|
373
|
-
@book.add_or_copy_sheet(@sheet, :after => @sheet, :before => @book.sheet(3))
|
377
|
+
@book.add_or_copy_sheet(@sheet, :after => @sheet, :before => @book.sheet(3))
|
378
|
+
@book.Worksheets.Count.should == 4
|
374
379
|
end
|
375
380
|
|
376
381
|
it "should copy the first sheet before the third sheet and give 'before' the highest priority" do
|
377
|
-
@book.add_or_copy_sheet(@sheet, :before => @book.sheet(3), :after => @sheet)
|
382
|
+
@book.add_or_copy_sheet(@sheet, :before => @book.sheet(3), :after => @sheet)
|
383
|
+
@book.Worksheets.Count.should == 4
|
378
384
|
end
|
379
385
|
|
380
386
|
it "should raise error with giving a name that already exists" do
|
@@ -32,7 +32,7 @@ describe Book do
|
|
32
32
|
|
33
33
|
after do
|
34
34
|
Excel.kill_all
|
35
|
-
rm_tmp(@dir)
|
35
|
+
#rm_tmp(@dir)
|
36
36
|
end
|
37
37
|
|
38
38
|
|
@@ -238,29 +238,23 @@ describe Book do
|
|
238
238
|
end
|
239
239
|
|
240
240
|
it "should set checkcompatibilty to true" do
|
241
|
+
@book.CheckCompatibility.should be_false
|
241
242
|
Book.unobtrusively(@simple_file, :check_compatibility => true) do |book|
|
242
243
|
book.should be_a Book
|
243
244
|
book.CheckCompatibility.should be_true
|
244
245
|
end
|
245
|
-
@book.CheckCompatibility.should
|
246
|
+
@book.CheckCompatibility.should be_false
|
246
247
|
end
|
247
248
|
|
248
249
|
it "should set the checkcompatibilty to false" do
|
250
|
+
@book.CheckCompatibility.should be_false
|
249
251
|
Book.unobtrusively(@simple_file, :check_compatibility => false) do |book|
|
250
252
|
book.should be_a Book
|
251
253
|
book.CheckCompatibility.should be_false
|
252
254
|
end
|
253
|
-
@book.CheckCompatibility.should be_true
|
254
|
-
end
|
255
|
-
|
256
|
-
it "should set the checkcompatibilty to false" do
|
257
|
-
@book.CheckCompatibility = false
|
258
|
-
Book.unobtrusively(@simple_file, :check_compatibility => true) do |book|
|
259
|
-
book.should be_a Book
|
260
|
-
book.CheckCompatibility.should be_true
|
261
|
-
end
|
262
255
|
@book.CheckCompatibility.should be_false
|
263
256
|
end
|
257
|
+
|
264
258
|
end
|
265
259
|
|
266
260
|
context "with a closed book" do
|
Binary file
|
Binary file
|
data/spec/data/workbook.xls
CHANGED
Binary file
|
data/spec/excel_spec.rb
CHANGED
@@ -12,6 +12,7 @@ module RobustExcelOle
|
|
12
12
|
|
13
13
|
before(:all) do
|
14
14
|
Excel.kill_all
|
15
|
+
sleep 0.2
|
15
16
|
end
|
16
17
|
|
17
18
|
before do
|
@@ -161,6 +162,7 @@ module RobustExcelOle
|
|
161
162
|
it "should create a new Excel if there is no Excel to connect with" do
|
162
163
|
excel1 = Excel.create
|
163
164
|
excel1.close
|
165
|
+
sleep 0.2
|
164
166
|
excel2 = Excel.current
|
165
167
|
excel1.should_not be_alive
|
166
168
|
excel2.should be_alive
|
@@ -171,6 +173,7 @@ module RobustExcelOle
|
|
171
173
|
excel1 = Excel.create
|
172
174
|
excel2 = Excel.current
|
173
175
|
excel1.close
|
176
|
+
sleep 0.2
|
174
177
|
excel1.should_not be_alive
|
175
178
|
excel2.should_not be_alive
|
176
179
|
sleep 0.2
|
@@ -181,6 +184,7 @@ module RobustExcelOle
|
|
181
184
|
excel1 = Excel.create
|
182
185
|
excel2 = Excel.create
|
183
186
|
excel2.close
|
187
|
+
sleep 0.2
|
184
188
|
excel3 = Excel.current
|
185
189
|
excel3.should === excel1
|
186
190
|
end
|
@@ -198,12 +202,14 @@ module RobustExcelOle
|
|
198
202
|
|
199
203
|
context "excels_number" do
|
200
204
|
|
201
|
-
it "should return right number of excel instances" do
|
202
|
-
Excel.
|
205
|
+
it "should return right number of excel instances" do
|
206
|
+
Excel.kill_all
|
207
|
+
sleep 0.2
|
208
|
+
n1 = Excel.excels_number
|
203
209
|
e1 = Excel.create
|
204
|
-
Excel.excels_number.should == 1
|
210
|
+
Excel.excels_number.should == n1 + 1
|
205
211
|
e2 = Excel.create
|
206
|
-
Excel.excels_number.should == 2
|
212
|
+
Excel.excels_number.should == n1 + 2
|
207
213
|
end
|
208
214
|
end
|
209
215
|
|
@@ -302,8 +308,9 @@ module RobustExcelOle
|
|
302
308
|
end
|
303
309
|
|
304
310
|
it "should recreate several Excel instances" do
|
305
|
-
@excel1.close
|
311
|
+
@excel1.close(:if_unsaved => :forget)
|
306
312
|
@excel3.close
|
313
|
+
sleep 0.2
|
307
314
|
@excel1.should_not be_alive
|
308
315
|
@excel3.should_not be_alive
|
309
316
|
@excel1.recreate(:reopen_workbooks => true, :displayalerts => true)
|
@@ -321,9 +328,11 @@ module RobustExcelOle
|
|
321
328
|
@book3.reopen
|
322
329
|
@book3.should be_alive
|
323
330
|
@book3.excel.should == @excel3
|
324
|
-
@excel1.close
|
331
|
+
@excel1.close(:if_unsaved => :forget)
|
332
|
+
sleep 0.2
|
325
333
|
@excel1.should_not be_alive
|
326
334
|
@excel3.close
|
335
|
+
sleep 0.2
|
327
336
|
@excel3.should_not be_alive
|
328
337
|
end
|
329
338
|
end
|
@@ -363,6 +372,7 @@ module RobustExcelOle
|
|
363
372
|
it "should close one Excel instance" do
|
364
373
|
excel1 = Excel.create
|
365
374
|
Excel.close_all
|
375
|
+
sleep 0.2
|
366
376
|
excel1.should_not be_alive
|
367
377
|
Excel.excels_number.should == 0
|
368
378
|
end
|
@@ -371,99 +381,162 @@ module RobustExcelOle
|
|
371
381
|
excel1 = Excel.create
|
372
382
|
excel2 = Excel.create
|
373
383
|
Excel.close_all
|
384
|
+
sleep 0.2
|
374
385
|
excel1.should_not be_alive
|
375
386
|
excel2.should_not be_alive
|
376
387
|
Excel.excels_number.should == 0
|
377
388
|
end
|
378
389
|
end
|
379
390
|
|
380
|
-
context "with
|
381
|
-
|
382
|
-
before do
|
383
|
-
book1 = Book.open(@simple_file1, :force_excel => :new)
|
384
|
-
book2 = Book.open(@different_file, :force_excel => :new)
|
385
|
-
@excel1 = book1.excel
|
386
|
-
sheet1 = book1.sheet(1)
|
387
|
-
@old_cell_value1 = sheet1[1,1].value
|
388
|
-
sheet1[1,1] = sheet1[1,1].value == "foo" ? "bar" : "foo"
|
389
|
-
@excel2 = book2.excel
|
390
|
-
sheet2 = book2.sheet(1)
|
391
|
-
@old_cell_value2 = sheet2[1,1].value
|
392
|
-
sheet2[1,1] = sheet2[1,1].value == "foo" ? "bar" : "foo"
|
393
|
-
end
|
391
|
+
context "with unsaved workbooks" do
|
394
392
|
|
395
|
-
|
396
|
-
expect{
|
397
|
-
Excel.close_all(:if_unsaved => :raise)
|
398
|
-
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks")
|
399
|
-
@excel1.should be_alive
|
400
|
-
@excel2.should be_alive
|
401
|
-
end
|
393
|
+
context "with three Excel instances" do
|
402
394
|
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
@excel2.should be_alive
|
409
|
-
end
|
395
|
+
before do
|
396
|
+
@book1 = Book.open(@simple_file1, :force_excel => :new)
|
397
|
+
@book2 = Book.open(@another_simple_file, :force_excel => :new)
|
398
|
+
@book3 = Book.open(@different_file, :force_excel => :new)
|
399
|
+
end
|
410
400
|
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
401
|
+
it "should close the 2nd and 3rd Excel instances that have saved workbooks" do
|
402
|
+
old_cell_value1 = @book1.sheet(1)[1,1].value
|
403
|
+
@book1.sheet(1)[1,1] = old_cell_value1 == "foo" ? "bar" : "foo"
|
404
|
+
expect{
|
405
|
+
Excel.close_all(:if_unsaved => :raise)
|
406
|
+
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks")
|
407
|
+
sleep 0.2
|
408
|
+
@book1.excel.should be_alive
|
409
|
+
@book2.excel.should_not be_alive
|
410
|
+
@book3.excel.should_not be_alive
|
411
|
+
@book1.should be_alive
|
412
|
+
@book2.should_not be_alive
|
413
|
+
@book3.should_not be_alive
|
414
|
+
end
|
424
415
|
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
416
|
+
it "should close the 1st and 3rd Excel instances that have saved workbooks" do
|
417
|
+
old_cell_value2 = @book2.sheet(1)[1,1].value
|
418
|
+
@book2.sheet(1)[1,1] = old_cell_value2 == "foo" ? "bar" : "foo"
|
419
|
+
expect{
|
420
|
+
Excel.close_all(:if_unsaved => :raise)
|
421
|
+
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks")
|
422
|
+
sleep 0.2
|
423
|
+
@book2.excel.should be_alive
|
424
|
+
@book1.excel.should_not be_alive
|
425
|
+
@book3.excel.should_not be_alive
|
426
|
+
@book2.should be_alive
|
427
|
+
@book1.should_not be_alive
|
428
|
+
@book3.should_not be_alive
|
429
|
+
end
|
430
|
+
|
431
|
+
it "should close the 2nd and 3rd Excel instances that have saved workbooks" do
|
432
|
+
old_cell_value3 = @book3.sheet(1)[1,1].value
|
433
|
+
@book3.sheet(1)[1,1] = old_cell_value3 == "foo" ? "bar" : "foo"
|
434
|
+
expect{
|
435
|
+
Excel.close_all(:if_unsaved => :raise)
|
436
|
+
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks")
|
437
|
+
sleep 0.2
|
438
|
+
@book3.excel.should be_alive
|
439
|
+
@book1.excel.should_not be_alive
|
440
|
+
@book2.excel.should_not be_alive
|
441
|
+
@book3.should be_alive
|
442
|
+
@book1.should_not be_alive
|
443
|
+
@book2.should_not be_alive
|
444
|
+
end
|
438
445
|
|
439
|
-
it "should raise an error for invalid option" do
|
440
|
-
expect {
|
441
|
-
Excel.close_all(:if_unsaved => :invalid_option)
|
442
|
-
}.to raise_error(OptionInvalid, ":if_unsaved: invalid option: :invalid_option")
|
443
446
|
end
|
444
447
|
|
445
|
-
|
448
|
+
context "with two Excel instances" do
|
449
|
+
|
450
|
+
before do
|
451
|
+
book1 = Book.open(@simple_file1, :force_excel => :new)
|
452
|
+
book2 = Book.open(@different_file, :force_excel => :new)
|
453
|
+
@excel1 = book1.excel
|
454
|
+
sheet1 = book1.sheet(1)
|
455
|
+
@old_cell_value1 = sheet1[1,1].value
|
456
|
+
sheet1[1,1] = sheet1[1,1].value == "foo" ? "bar" : "foo"
|
457
|
+
@excel2 = book2.excel
|
458
|
+
sheet2 = book2.sheet(1)
|
459
|
+
@old_cell_value2 = sheet2[1,1].value
|
460
|
+
sheet2[1,1] = sheet2[1,1].value == "foo" ? "bar" : "foo"
|
461
|
+
end
|
462
|
+
|
463
|
+
it "should close the first Excel without unsaved workbooks and then raise an error" do
|
464
|
+
expect{
|
465
|
+
Excel.close_all(:if_unsaved => :raise)
|
466
|
+
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks")
|
467
|
+
sleep 0.2
|
468
|
+
@excel1.should be_alive
|
469
|
+
@excel2.should be_alive
|
470
|
+
end
|
446
471
|
|
447
|
-
|
472
|
+
it "should close the first Excel without unsaved workbooks and then raise an error per default" do
|
473
|
+
expect{
|
474
|
+
Excel.close_all
|
475
|
+
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks")
|
476
|
+
sleep 0.2
|
477
|
+
@excel1.should be_alive
|
478
|
+
@excel2.should be_alive
|
479
|
+
end
|
448
480
|
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
481
|
+
it "should close the Excel instances with saving the unsaved workbooks" do
|
482
|
+
Excel.close_all(:if_unsaved => :save)
|
483
|
+
sleep 0.2
|
484
|
+
@excel1.should_not be_alive
|
485
|
+
@excel2.should_not be_alive
|
486
|
+
new_book1 = Book.open(@simple_file1)
|
487
|
+
new_sheet1 = new_book1.sheet(1)
|
488
|
+
new_sheet1[1,1].value.should_not == @old_cell_value1
|
489
|
+
new_book1.close
|
490
|
+
new_book2 = Book.open(@different_file1)
|
491
|
+
new_sheet2 = new_book2.sheet(1)
|
492
|
+
new_sheet2[1,1].value.should_not == @old_cell_value2
|
493
|
+
new_book2.close
|
494
|
+
end
|
495
|
+
|
496
|
+
it "should close the Excel instances without saving the unsaved workbooks" do
|
497
|
+
Excel.close_all(:if_unsaved => :forget)
|
498
|
+
sleep 0.2
|
499
|
+
@excel1.should_not be_alive
|
500
|
+
@excel2.should_not be_alive
|
501
|
+
new_book1 = Book.open(@simple_file1)
|
502
|
+
new_sheet1 = new_book1.sheet(1)
|
503
|
+
new_sheet1[1,1].value.should == @old_cell_value1
|
504
|
+
new_book1.close
|
505
|
+
new_book2 = Book.open(@different_file1)
|
506
|
+
new_sheet2 = new_book2.sheet(1)
|
507
|
+
new_sheet2[1,1].value.should == @old_cell_value2
|
508
|
+
new_book2.close
|
509
|
+
end
|
510
|
+
|
511
|
+
it "should raise an error for invalid option" do
|
512
|
+
expect {
|
513
|
+
Excel.close_all(:if_unsaved => :invalid_option)
|
514
|
+
}.to raise_error(OptionInvalid, ":if_unsaved: invalid option: :invalid_option")
|
515
|
+
end
|
455
516
|
|
456
|
-
it "should forget the unsaved workbook" do
|
457
|
-
book1 = Book.open(@simple_file, :visible => true)
|
458
|
-
excel1 = book1.excel
|
459
|
-
excel1.displayalerts = false
|
460
|
-
sheet1 = book1.sheet(1)
|
461
|
-
old_cell_value1 = sheet1[1,1].value
|
462
|
-
sheet1[1,1] = sheet1[1,1].value == "foo" ? "bar" : "foo"
|
463
|
-
book1.Saved.should be_false
|
464
|
-
Excel.close_all(:if_unsaved => :forget)
|
465
517
|
end
|
466
|
-
|
518
|
+
|
519
|
+
context "with one Excel instance" do
|
520
|
+
|
521
|
+
it "should save the unsaved workbook" do
|
522
|
+
book1 = Book.open(@simple_file, :visible => true)
|
523
|
+
book1.sheet(1)[1,1] = "bar"
|
524
|
+
book1.Saved.should be_false
|
525
|
+
Excel.close_all(:if_unsaved => :save)
|
526
|
+
end
|
527
|
+
|
528
|
+
it "should forget the unsaved workbook" do
|
529
|
+
book1 = Book.open(@simple_file, :visible => true)
|
530
|
+
excel1 = book1.excel
|
531
|
+
excel1.displayalerts = false
|
532
|
+
sheet1 = book1.sheet(1)
|
533
|
+
old_cell_value1 = sheet1[1,1].value
|
534
|
+
sheet1[1,1] = sheet1[1,1].value == "foo" ? "bar" : "foo"
|
535
|
+
book1.Saved.should be_false
|
536
|
+
Excel.close_all(:if_unsaved => :forget)
|
537
|
+
end
|
538
|
+
end
|
539
|
+
end
|
467
540
|
end
|
468
541
|
|
469
542
|
=begin
|
@@ -530,6 +603,7 @@ module RobustExcelOle
|
|
530
603
|
@excel.should be_alive
|
531
604
|
@book.should be_alive
|
532
605
|
@excel.close
|
606
|
+
sleep 0.2
|
533
607
|
@excel.should_not be_alive
|
534
608
|
@book.should_not be_alive
|
535
609
|
end
|
@@ -538,6 +612,7 @@ module RobustExcelOle
|
|
538
612
|
@excel.should be_alive
|
539
613
|
@book.should be_alive
|
540
614
|
@excel.close(:hard => true)
|
615
|
+
sleep 0.2
|
541
616
|
@excel.should_not be_alive
|
542
617
|
@book.should_not be_alive
|
543
618
|
end
|
@@ -546,6 +621,7 @@ module RobustExcelOle
|
|
546
621
|
@excel.should be_alive
|
547
622
|
excel2 = Excel.create
|
548
623
|
@excel.close
|
624
|
+
sleep 0.2
|
549
625
|
@excel.should_not be_alive
|
550
626
|
excel2.should be_alive
|
551
627
|
end
|
@@ -554,6 +630,7 @@ module RobustExcelOle
|
|
554
630
|
@excel.should be_alive
|
555
631
|
excel2 = Excel.create
|
556
632
|
@excel.close(:hard => true)
|
633
|
+
sleep 0.2
|
557
634
|
@excel.should_not be_alive
|
558
635
|
excel2.should be_alive
|
559
636
|
end
|
@@ -589,6 +666,7 @@ module RobustExcelOle
|
|
589
666
|
@excel.should be_alive
|
590
667
|
@excel.displayalerts = true
|
591
668
|
@excel.close(:if_unsaved => :forget)
|
669
|
+
sleep 0.2
|
592
670
|
@excel.should_not be_alive
|
593
671
|
new_book = Book.open(@simple_file)
|
594
672
|
new_sheet = new_book.sheet(1)
|
@@ -597,7 +675,7 @@ module RobustExcelOle
|
|
597
675
|
new_book2 = Book.open(@another_simple_file)
|
598
676
|
new_sheet2 = new_book2.sheet(1)
|
599
677
|
new_sheet2[1,1].value.should == @old_cell_value2
|
600
|
-
new_book2.close
|
678
|
+
new_book2.close(:if_unsaved => :forget)
|
601
679
|
end
|
602
680
|
|
603
681
|
it "should close the Excel without saving the workbook" do
|
@@ -605,6 +683,7 @@ module RobustExcelOle
|
|
605
683
|
@excel.should be_alive
|
606
684
|
@excel.displayalerts = false
|
607
685
|
@excel.close(:if_unsaved => :forget)
|
686
|
+
sleep 0.2
|
608
687
|
@excel.should_not be_alive
|
609
688
|
new_book = Book.open(@simple_file)
|
610
689
|
new_sheet = new_book.sheet(1)
|
@@ -613,12 +692,13 @@ module RobustExcelOle
|
|
613
692
|
new_book2 = Book.open(@another_simple_file)
|
614
693
|
new_sheet2 = new_book2.sheet(1)
|
615
694
|
new_sheet2[1,1].value.should == @old_cell_value2
|
616
|
-
new_book2.close
|
695
|
+
new_book2.close(:if_unsaved => :forget)
|
617
696
|
end
|
618
697
|
|
619
698
|
it "should close the Excel with saving the workbook" do
|
620
699
|
@excel.should be_alive
|
621
700
|
@excel.close(:if_unsaved => :save)
|
701
|
+
sleep 0.2
|
622
702
|
@excel.should_not be_alive
|
623
703
|
new_book = Book.open(@simple_file)
|
624
704
|
new_sheet = new_book.sheet(1)
|
@@ -633,6 +713,7 @@ module RobustExcelOle
|
|
633
713
|
it "should close the Excel with saving the workbook" do
|
634
714
|
@excel.should be_alive
|
635
715
|
@excel.close(:if_unsaved => :keep_open)
|
716
|
+
sleep 0.2
|
636
717
|
@excel.should be_alive
|
637
718
|
@excel.close(:if_unsaved => :forget)
|
638
719
|
end
|
@@ -655,6 +736,7 @@ module RobustExcelOle
|
|
655
736
|
@book.should be_alive
|
656
737
|
@book.saved.should be_false
|
657
738
|
@excel.close(:if_unsaved => :forget, :hard => true)
|
739
|
+
sleep 0.2
|
658
740
|
@excel.should_not be_alive
|
659
741
|
@book.should_not be_alive
|
660
742
|
new_book = Book.open(@simple_file)
|
@@ -662,6 +744,7 @@ module RobustExcelOle
|
|
662
744
|
new_sheet[1,1].value.should == @old_cell_value
|
663
745
|
new_book.close
|
664
746
|
new_book.excel.close(:hard => true)
|
747
|
+
sleep 0.2
|
665
748
|
procs = WIN32OLE.connect("winmgmts:\\\\.")
|
666
749
|
processes = procs.InstancesOf("win32_process")
|
667
750
|
result = []
|
@@ -777,6 +860,16 @@ module RobustExcelOle
|
|
777
860
|
|
778
861
|
end
|
779
862
|
|
863
|
+
describe "focus" do
|
864
|
+
|
865
|
+
it "should focus" do
|
866
|
+
excel = Excel.create
|
867
|
+
excel.focus
|
868
|
+
excel.Visible.should be_true
|
869
|
+
end
|
870
|
+
|
871
|
+
end
|
872
|
+
|
780
873
|
context "workbooks_visible" do
|
781
874
|
|
782
875
|
it "should not raise an error for an empty Excel instance" do
|
@@ -826,21 +919,62 @@ module RobustExcelOle
|
|
826
919
|
|
827
920
|
end
|
828
921
|
|
829
|
-
context "with Visible and DisplayAlerts,
|
922
|
+
context "with Visible and DisplayAlerts, focus" do
|
830
923
|
|
831
|
-
it "should
|
924
|
+
it "should bring Excel in focus" do
|
832
925
|
excel1 = Excel.create
|
833
926
|
excel2 = Excel.create
|
834
|
-
excel1.
|
927
|
+
excel1.focus
|
835
928
|
excel1.Visible.should be_true
|
836
929
|
excel1.visible.should be_true
|
837
930
|
end
|
838
931
|
|
932
|
+
it "should set default values" do
|
933
|
+
excel1 = Excel.new
|
934
|
+
excel1.Visible.should be_false
|
935
|
+
excel1.DisplayAlerts.should be_false
|
936
|
+
excel1.visible.should be_false
|
937
|
+
excel1.displayalerts.should == :if_visible
|
938
|
+
end
|
939
|
+
|
940
|
+
it "should set visible true" do
|
941
|
+
excel1 = Excel.new(:visible => true)
|
942
|
+
excel1.Visible.should be_true
|
943
|
+
excel1.DisplayAlerts.should be_true
|
944
|
+
excel1.visible.should be_true
|
945
|
+
excel1.displayalerts.should == :if_visible
|
946
|
+
end
|
947
|
+
|
948
|
+
it "should set visible false" do
|
949
|
+
excel1 = Excel.new(:visible => false)
|
950
|
+
excel1.Visible.should be_false
|
951
|
+
excel1.DisplayAlerts.should be_false
|
952
|
+
excel1.visible.should be_false
|
953
|
+
excel1.displayalerts.should == :if_visible
|
954
|
+
end
|
955
|
+
|
956
|
+
it "should set displayalerts true" do
|
957
|
+
excel1 = Excel.new(:displayalerts => true)
|
958
|
+
excel1.Visible.should be_false
|
959
|
+
excel1.DisplayAlerts.should be_true
|
960
|
+
excel1.visible.should be_false
|
961
|
+
excel1.displayalerts.should be_true
|
962
|
+
end
|
963
|
+
|
964
|
+
it "should set displayalerts false" do
|
965
|
+
excel1 = Excel.new(:displayalerts => false)
|
966
|
+
excel1.Visible.should be_false
|
967
|
+
excel1.DisplayAlerts.should be_false
|
968
|
+
excel1.visible.should be_false
|
969
|
+
excel1.displayalerts.should be_false
|
970
|
+
end
|
839
971
|
|
840
972
|
it "should use values of the current Excel when reusing" do
|
841
973
|
excel1 = Excel.create
|
842
974
|
excel1.Visible.should be_false
|
843
975
|
excel1.DisplayAlerts.should be_false
|
976
|
+
excel1.visible.should be_false
|
977
|
+
excel1.displayalerts.should == :if_visible
|
844
978
|
excel1.Visible = true
|
845
979
|
excel1.DisplayAlerts = true
|
846
980
|
excel1.Visible.should be_true
|
@@ -850,13 +984,22 @@ module RobustExcelOle
|
|
850
984
|
excel2.DisplayAlerts.should be_true
|
851
985
|
end
|
852
986
|
|
853
|
-
it "should
|
987
|
+
it "should take visible and displayalerts from Visible and DisplayAlerts of the connected Excel" do
|
988
|
+
excel1 = Excel.create
|
989
|
+
excel2 = Excel.current
|
990
|
+
excel2.Visible.should be_false
|
991
|
+
excel2.visible.should be_false
|
992
|
+
excel2.DisplayAlerts.should be_false
|
993
|
+
excel2.displayalerts.should == false
|
994
|
+
end
|
995
|
+
|
996
|
+
it "should take Visible and DisplayAlerts from the connected Excel" do
|
854
997
|
excel1 = Excel.create
|
855
998
|
excel2 = Excel.current(:visible => true)
|
856
999
|
excel2.Visible.should be_true
|
857
1000
|
excel2.visible.should be_true
|
858
|
-
excel2.DisplayAlerts.should
|
859
|
-
excel2.displayalerts.should
|
1001
|
+
excel2.DisplayAlerts.should be_false
|
1002
|
+
excel2.displayalerts.should be_false
|
860
1003
|
end
|
861
1004
|
|
862
1005
|
it "should set Excel visible and invisible with current" do
|
@@ -873,8 +1016,8 @@ module RobustExcelOle
|
|
873
1016
|
excel2 = Excel.current(:visible => true)
|
874
1017
|
excel2.Visible.should be_true
|
875
1018
|
excel2.visible.should be_true
|
876
|
-
excel2.displayalerts.should
|
877
|
-
excel2.DisplayAlerts.should
|
1019
|
+
excel2.displayalerts.should be_false
|
1020
|
+
excel2.DisplayAlerts.should be_false
|
878
1021
|
end
|
879
1022
|
|
880
1023
|
it "should set Excel visible and invisible" do
|
@@ -883,9 +1026,6 @@ module RobustExcelOle
|
|
883
1026
|
excel.visible.should be_true
|
884
1027
|
excel.DisplayAlerts.should be_true
|
885
1028
|
excel.displayalerts.should == :if_visible
|
886
|
-
excel6 = Excel.current
|
887
|
-
excel6.should === excel
|
888
|
-
excel6.Visible.should be_true
|
889
1029
|
excel.visible = false
|
890
1030
|
excel.Visible.should be_false
|
891
1031
|
excel.visible.should be_false
|
@@ -911,19 +1051,19 @@ module RobustExcelOle
|
|
911
1051
|
excel3.Visible.should be_false
|
912
1052
|
excel3.visible.should be_false
|
913
1053
|
excel3.DisplayAlerts.should be_false
|
914
|
-
excel3.displayalerts.should
|
1054
|
+
excel3.displayalerts.should be_false
|
915
1055
|
excel4 = Excel.current(:visible => true)
|
916
1056
|
excel4.should === excel
|
917
1057
|
excel4.Visible.should be_true
|
918
1058
|
excel4.visible.should be_true
|
919
|
-
excel4.DisplayAlerts.should
|
920
|
-
excel4.displayalerts.should
|
1059
|
+
excel4.DisplayAlerts.should be_false
|
1060
|
+
excel4.displayalerts.should be_false
|
921
1061
|
excel5 = Excel.current(:visible => false)
|
922
1062
|
excel5.should === excel
|
923
1063
|
excel5.Visible.should be_false
|
924
1064
|
excel5.visible.should be_false
|
925
1065
|
excel5.DisplayAlerts.should be_false
|
926
|
-
excel5.displayalerts.should
|
1066
|
+
excel5.displayalerts.should be_false
|
927
1067
|
end
|
928
1068
|
|
929
1069
|
it "should enable or disable Excel DispayAlerts" do
|
@@ -1328,11 +1468,16 @@ module RobustExcelOle
|
|
1328
1468
|
workbooks.Count.should == 2
|
1329
1469
|
end
|
1330
1470
|
|
1331
|
-
it "should raise error
|
1471
|
+
it "should raise error if filename is with wrong path" do
|
1332
1472
|
expect{
|
1333
1473
|
workbook = @excel1.generate_workbook(@invalid_name_file)
|
1334
|
-
|
1335
|
-
|
1474
|
+
}.to raise_error(FileNotFound, /could not save workbook with filename/)
|
1475
|
+
end
|
1476
|
+
|
1477
|
+
it "should raise error if filename is nil" do
|
1478
|
+
expect{
|
1479
|
+
workbook = @excel1.generate_workbook(@nil)
|
1480
|
+
}.to raise_error(FileNameNotGiven, "filename is nil")
|
1336
1481
|
end
|
1337
1482
|
|
1338
1483
|
end
|