robust_excel_ole 0.5.1 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +13 -0
- data/README.rdoc +70 -21
- data/README_detail.rdoc +60 -27
- data/examples/edit_sheets/example_access_sheets_and_cells.rb +2 -2
- data/examples/edit_sheets/example_adding_sheets.rb +2 -2
- data/examples/edit_sheets/example_concating.rb +2 -3
- data/examples/edit_sheets/example_copying.rb +2 -3
- data/examples/edit_sheets/example_expanding.rb +2 -3
- data/examples/edit_sheets/example_naming.rb +2 -3
- data/examples/edit_sheets/example_ranges.rb +2 -2
- data/examples/edit_sheets/example_saving.rb +2 -3
- data/examples/open_save_close/example_control_to_excel.rb +3 -3
- data/examples/open_save_close/example_default_excel.rb +4 -4
- data/examples/open_save_close/example_force_excel.rb +2 -2
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +2 -2
- data/examples/open_save_close/example_if_obstructed_forget.rb +2 -2
- data/examples/open_save_close/example_if_obstructed_save.rb +2 -2
- data/examples/open_save_close/example_if_unsaved_accept.rb +2 -2
- data/examples/open_save_close/example_if_unsaved_forget.rb +2 -2
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +4 -5
- data/examples/open_save_close/example_read_only.rb +2 -2
- data/examples/open_save_close/example_rename_cells.rb +3 -3
- data/examples/open_save_close/example_reuse.rb +2 -2
- data/examples/open_save_close/example_simple.rb +3 -4
- data/examples/open_save_close/example_unobtrusively.rb +2 -2
- data/lib/robust_excel_ole/book.rb +84 -78
- data/lib/robust_excel_ole/bookstore.rb +5 -1
- data/lib/robust_excel_ole/excel.rb +165 -188
- data/lib/robust_excel_ole/reo_common.rb +4 -0
- data/lib/robust_excel_ole/sheet.rb +15 -6
- data/lib/robust_excel_ole/version.rb +1 -1
- data/spec/book_spec.rb +104 -77
- data/spec/book_specs/book_close_spec.rb +9 -8
- data/spec/book_specs/book_misc_spec.rb +367 -26
- data/spec/book_specs/book_open_spec.rb +375 -94
- data/spec/book_specs/book_save_spec.rb +137 -112
- data/spec/book_specs/book_sheet_spec.rb +1 -1
- data/spec/book_specs/book_subclass_spec.rb +2 -1
- data/spec/book_specs/book_unobtr_spec.rb +87 -96
- data/spec/bookstore_spec.rb +8 -5
- data/spec/cell_spec.rb +1 -1
- data/spec/data/another_workbook.xls +0 -0
- data/spec/data/book_with_blank.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +484 -72
- data/spec/range_spec.rb +1 -1
- data/spec/sheet_spec.rb +47 -1
- metadata +4 -5
data/spec/bookstore_spec.rb
CHANGED
@@ -41,7 +41,7 @@ describe Bookstore do
|
|
41
41
|
excel = Excel.new(:reuse => true)
|
42
42
|
open_books = excel == nil ? 0 : excel.Workbooks.Count
|
43
43
|
puts "*** open books *** : #{open_books}" if open_books > 0
|
44
|
-
Excel.
|
44
|
+
Excel.kill_all
|
45
45
|
end
|
46
46
|
|
47
47
|
before do
|
@@ -391,16 +391,19 @@ describe Bookstore do
|
|
391
391
|
end
|
392
392
|
|
393
393
|
it "should have forgotten some books if they have no reference anymore" do
|
394
|
-
|
394
|
+
different_file1 = @different_file
|
395
|
+
simple_file1 = @simple_file
|
396
|
+
book_new = Book.open(different_file1)
|
395
397
|
@bookstore.store(book_new)
|
396
398
|
@book = nil
|
397
399
|
@book = "Bla"
|
398
|
-
@book = Book.open(
|
400
|
+
@book = Book.open(simple_file1)
|
399
401
|
@bookstore.store(@book)
|
400
402
|
@book = nil
|
401
403
|
GC.start
|
402
|
-
|
403
|
-
|
404
|
+
sleep 1
|
405
|
+
#@bookstore.fetch(simple_file1).should == nil
|
406
|
+
@bookstore.fetch(different_file1).should == book_new
|
404
407
|
end
|
405
408
|
end
|
406
409
|
end
|
data/spec/cell_spec.rb
CHANGED
Binary file
|
Binary file
|
data/spec/data/workbook.xls
CHANGED
Binary file
|
data/spec/excel_spec.rb
CHANGED
@@ -24,7 +24,22 @@ module RobustExcelOle
|
|
24
24
|
|
25
25
|
after do
|
26
26
|
Excel.kill_all
|
27
|
-
rm_tmp(@dir)
|
27
|
+
#rm_tmp(@dir)
|
28
|
+
end
|
29
|
+
|
30
|
+
context "Illegal Refrence" do
|
31
|
+
|
32
|
+
before do
|
33
|
+
|
34
|
+
book1 = Book.open(@simple_file)
|
35
|
+
book2 = Book.open(@simple_file, :force_excel => :new)
|
36
|
+
a = book1.saved
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should not cause warning 'Illegal Reference probably recycled'" do
|
40
|
+
Excel.close_all
|
41
|
+
book = Book.open(@simple_file)
|
42
|
+
end
|
28
43
|
end
|
29
44
|
|
30
45
|
context "excel creation" do
|
@@ -134,7 +149,32 @@ module RobustExcelOle
|
|
134
149
|
end
|
135
150
|
|
136
151
|
context "current" do
|
137
|
-
|
152
|
+
|
153
|
+
it "should connect to the Excel" do
|
154
|
+
excel1 = Excel.create
|
155
|
+
excel2 = Excel.current
|
156
|
+
excel2.should === excel1
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should create a new Excel if there is no Excel to connect with" do
|
160
|
+
excel1 = Excel.create
|
161
|
+
excel1.close
|
162
|
+
excel2 = Excel.current
|
163
|
+
excel1.should_not be_alive
|
164
|
+
excel2.should be_alive
|
165
|
+
Excel.excels_number.should == 1
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should make the Excel instance not alive if the Excel that was connected with was closed" do
|
169
|
+
excel1 = Excel.create
|
170
|
+
excel2 = Excel.current
|
171
|
+
excel1.close
|
172
|
+
excel1.should_not be_alive
|
173
|
+
excel2.should_not be_alive
|
174
|
+
sleep 0.2
|
175
|
+
Excel.excels_number.should == 0
|
176
|
+
end
|
177
|
+
|
138
178
|
it "should reuse the first opened Excel instance if not the first opened Excel instance was closed" do
|
139
179
|
excel1 = Excel.create
|
140
180
|
excel2 = Excel.create
|
@@ -143,30 +183,26 @@ module RobustExcelOle
|
|
143
183
|
excel3.should === excel1
|
144
184
|
end
|
145
185
|
|
146
|
-
it "should
|
186
|
+
it "should reuse the Excel that was not closed" do
|
147
187
|
excel1 = Excel.create
|
148
|
-
excel1_hwnd = excel1.hwnd
|
149
188
|
excel2 = Excel.create
|
150
189
|
excel1.close
|
190
|
+
sleep 0.2
|
151
191
|
excel3 = Excel.current
|
152
|
-
excel3.
|
153
|
-
excel3.
|
192
|
+
excel3.should === excel2
|
193
|
+
excel3.Hwnd.should == excel2.Hwnd
|
154
194
|
end
|
155
195
|
end
|
156
196
|
|
157
|
-
context "
|
197
|
+
context "excels_number" do
|
158
198
|
|
159
|
-
|
160
|
-
|
161
|
-
|
199
|
+
it "should return right number of excel instances" do
|
200
|
+
Excel.excels_number.should == 0
|
201
|
+
e1 = Excel.create
|
202
|
+
Excel.excels_number.should == 1
|
203
|
+
e2 = Excel.create
|
204
|
+
Excel.excels_number.should == 2
|
162
205
|
end
|
163
|
-
|
164
|
-
it "should yield Excel objects" do
|
165
|
-
excels = Excel.excel_processes
|
166
|
-
excels[0].should == @excel1
|
167
|
-
excels[1].should == @excel2
|
168
|
-
end
|
169
|
-
|
170
206
|
end
|
171
207
|
|
172
208
|
context "kill Excel processes hard" do
|
@@ -181,7 +217,6 @@ module RobustExcelOle
|
|
181
217
|
@excel1.alive?.should be_false
|
182
218
|
@excel2.alive?.should be_false
|
183
219
|
end
|
184
|
-
|
185
220
|
end
|
186
221
|
|
187
222
|
context "recreating Excel instances" do
|
@@ -272,15 +307,15 @@ module RobustExcelOle
|
|
272
307
|
@excel1.recreate(:reopen_workbooks => true, :displayalerts => true)
|
273
308
|
@excel1.should be_alive
|
274
309
|
@excel1.should be_a Excel
|
275
|
-
@excel1.
|
276
|
-
@excel1.
|
310
|
+
@excel1.Visible.should be_true
|
311
|
+
@excel1.DisplayAlerts.should be_true
|
277
312
|
@book1.should be_alive
|
278
313
|
@book2.should be_alive
|
279
314
|
@excel3.recreate(:visible => true)
|
280
315
|
@excel3.should be_alive
|
281
316
|
@excel3.should be_a Excel
|
282
|
-
@excel3.
|
283
|
-
@excel3.
|
317
|
+
@excel3.Visible.should be_true
|
318
|
+
@excel3.DisplayAlerts.should be_true
|
284
319
|
@book3.reopen
|
285
320
|
@book3.should be_alive
|
286
321
|
@book3.excel.should == @excel3
|
@@ -292,20 +327,24 @@ module RobustExcelOle
|
|
292
327
|
end
|
293
328
|
end
|
294
329
|
|
330
|
+
# Error
|
295
331
|
context "close excel instances" do
|
296
332
|
def direct_excel_creation_helper # :nodoc: #
|
297
333
|
expect { WIN32OLE.connect("Excel.Application") }.to raise_error
|
298
334
|
sleep 0.1
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
335
|
+
ole_excel1 = WIN32OLE.new("Excel.Application")
|
336
|
+
ole_excel1.Workbooks.Add
|
337
|
+
ole_excel2 = WIN32OLE.new("Excel.Application")
|
338
|
+
ole_excel2.Workbooks.Add
|
303
339
|
expect { WIN32OLE.connect("Excel.Application") }.to_not raise_error
|
304
340
|
end
|
305
341
|
|
306
342
|
it "simple file with default" do
|
307
343
|
Excel.close_all
|
308
344
|
direct_excel_creation_helper
|
345
|
+
sleep 3
|
346
|
+
puts "excels_number: #{Excel.excels_number}"
|
347
|
+
sleep 1
|
309
348
|
Excel.close_all
|
310
349
|
sleep 0.1
|
311
350
|
expect { WIN32OLE.connect("Excel.Application") }.to raise_error
|
@@ -316,19 +355,26 @@ module RobustExcelOle
|
|
316
355
|
|
317
356
|
context "with saved workbooks" do
|
318
357
|
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
@excel2 = book2.excel
|
358
|
+
it "should do with no Excel instances" do
|
359
|
+
expect{
|
360
|
+
Excel.close_all
|
361
|
+
}.to_not raise_error
|
324
362
|
end
|
325
363
|
|
326
|
-
it "should close
|
327
|
-
|
328
|
-
@excel2.should be_alive
|
364
|
+
it "should close one Excel instance" do
|
365
|
+
excel1 = Excel.create
|
329
366
|
Excel.close_all
|
330
|
-
|
331
|
-
|
367
|
+
excel1.should_not be_alive
|
368
|
+
Excel.excels_number.should == 0
|
369
|
+
end
|
370
|
+
|
371
|
+
it "should close two Excel instances" do
|
372
|
+
excel1 = Excel.create
|
373
|
+
excel2 = Excel.create
|
374
|
+
Excel.close_all
|
375
|
+
excel1.should_not be_alive
|
376
|
+
excel2.should_not be_alive
|
377
|
+
Excel.excels_number.should == 0
|
332
378
|
end
|
333
379
|
end
|
334
380
|
|
@@ -351,41 +397,55 @@ module RobustExcelOle
|
|
351
397
|
end
|
352
398
|
|
353
399
|
it "should close the first Excel without unsaved workbooks and then raise an error" do
|
400
|
+
expect{
|
401
|
+
Excel.close_all(:if_unsaved => :raise)
|
402
|
+
}.to raise_error(ExcelErrorClose, "Excel contains unsaved workbooks")
|
403
|
+
@excel1.should_not be_alive
|
404
|
+
@excel2.should be_alive
|
405
|
+
@excel4.should be_alive
|
406
|
+
end
|
407
|
+
|
408
|
+
it "should close the first Excel without unsaved workbooks and then raise an error per default" do
|
354
409
|
expect{
|
355
410
|
Excel.close_all
|
356
411
|
}.to raise_error(ExcelErrorClose, "Excel contains unsaved workbooks")
|
357
412
|
@excel1.should_not be_alive
|
413
|
+
@excel2.should be_alive
|
414
|
+
@excel4.should be_alive
|
358
415
|
end
|
359
416
|
|
360
|
-
|
361
|
-
|
417
|
+
# Error
|
418
|
+
it "should close the Excel instances with saving the unsaved workbooks" do
|
419
|
+
Excel.close_all(:if_unsaved => :save)
|
362
420
|
@excel1.should_not be_alive
|
363
421
|
@excel2.should_not be_alive
|
364
422
|
@excel4.should_not be_alive
|
365
423
|
new_book2 = Book.open(@simple_file)
|
366
424
|
new_sheet2 = new_book2.sheet(1)
|
367
|
-
new_sheet2[1,1].value.
|
425
|
+
new_sheet2[1,1].value.should_not == @old_cell_value2
|
368
426
|
new_book2.close
|
369
427
|
new_book3 = Book.open(@another_simple_file)
|
370
428
|
new_sheet3 = new_book3.sheet(1)
|
371
|
-
new_sheet3[1,1].value.
|
372
|
-
new_book3.close
|
429
|
+
new_sheet3[1,1].value.should_not == @old_cell_value3
|
430
|
+
new_book3.close
|
373
431
|
end
|
374
432
|
|
375
|
-
|
376
|
-
|
433
|
+
# Error
|
434
|
+
it "should close the Excel instances without saving the unsaved workbooks" do
|
435
|
+
@excel1.displayalerts = @excel2.displayalerts = @excel4.displayalerts = false
|
436
|
+
Excel.close_all(:if_unsaved => :forget)
|
377
437
|
@excel1.should_not be_alive
|
378
438
|
@excel2.should_not be_alive
|
379
439
|
@excel4.should_not be_alive
|
380
440
|
new_book2 = Book.open(@simple_file)
|
381
441
|
new_sheet2 = new_book2.sheet(1)
|
382
|
-
new_sheet2[1,1].value.
|
442
|
+
new_sheet2[1,1].value.should == @old_cell_value2
|
383
443
|
new_book2.close
|
384
444
|
new_book3 = Book.open(@another_simple_file)
|
385
445
|
new_sheet3 = new_book3.sheet(1)
|
386
|
-
new_sheet3[1,1].value.
|
387
|
-
new_book3.close
|
388
|
-
end
|
446
|
+
new_sheet3[1,1].value.should == @old_cell_value3
|
447
|
+
new_book3.close
|
448
|
+
end
|
389
449
|
|
390
450
|
it "should raise an error for invalid option" do
|
391
451
|
expect {
|
@@ -393,14 +453,34 @@ module RobustExcelOle
|
|
393
453
|
}.to raise_error(ExcelErrorClose, ":if_unsaved: invalid option: :invalid_option")
|
394
454
|
end
|
395
455
|
|
396
|
-
it "should raise an error by default" do
|
397
|
-
expect{
|
398
|
-
Excel.close_all
|
399
|
-
}.to raise_error(ExcelErrorClose, "Excel contains unsaved workbooks")
|
400
|
-
@excel1.should_not be_alive
|
401
|
-
end
|
402
456
|
end
|
403
457
|
|
458
|
+
context "unsaved_workbooks" do
|
459
|
+
|
460
|
+
# Error
|
461
|
+
it "should save the unsaved workbook" do
|
462
|
+
book1 = Book.open(@simple_file, :visible => true)
|
463
|
+
excel1 = book1.excel
|
464
|
+
book1.sheet(1)[1,1] = "bar"
|
465
|
+
book1.Saved.should be_false
|
466
|
+
Excel.close_all(:if_unsaved => :save)
|
467
|
+
end
|
468
|
+
|
469
|
+
# Error
|
470
|
+
it "should forget the unsaved workbook" do
|
471
|
+
book1 = Book.open(@simple_file, :visible => true)
|
472
|
+
excel1 = book1.excel
|
473
|
+
excel1.displayalerts = false
|
474
|
+
sheet1 = book1.sheet(1)
|
475
|
+
old_cell_value1 = sheet1[1,1].value
|
476
|
+
sheet1[1,1] = sheet1[1,1].value == "foo" ? "bar" : "foo"
|
477
|
+
book1.Saved.should be_false
|
478
|
+
Excel.close_all(:if_unsaved => :forget)
|
479
|
+
end
|
480
|
+
end
|
481
|
+
end
|
482
|
+
|
483
|
+
=begin
|
404
484
|
context "with :if_unsaved => :alert" do
|
405
485
|
before do
|
406
486
|
@key_sender = IO.popen 'ruby "' + File.join(File.dirname(__FILE__), '/helpers/key_sender.rb') + '" "Microsoft Excel" ' , "w"
|
@@ -419,6 +499,7 @@ module RobustExcelOle
|
|
419
499
|
it "should save if user answers 'yes'" do
|
420
500
|
@key_sender.puts "{enter}"
|
421
501
|
Excel.close_all(:if_unsaved => :alert)
|
502
|
+
@excel2.should_not be_alive
|
422
503
|
new_book2 = Book.open(@simple_file)
|
423
504
|
new_sheet2 = new_book2.sheet(1)
|
424
505
|
new_sheet2[1,1].value.should_not == @old_cell_value2
|
@@ -444,9 +525,33 @@ module RobustExcelOle
|
|
444
525
|
# Excel.close_all(:if_unsaved => :alert)
|
445
526
|
# }.to raise_error(ExcelUserCanceled, "close: canceled by user")
|
446
527
|
# end
|
528
|
+
|
529
|
+
it "should save if user answers 'yes'" do
|
530
|
+
@excel1.displayalerts = @excel2.displayalerts = @excel4.displayalerts = true
|
531
|
+
@key_sender.puts "{enter}"
|
532
|
+
Excel.close_all(:if_unsaved => :forget)
|
533
|
+
@excel2.should_not be_alive
|
534
|
+
new_book2 = Book.open(@simple_file)
|
535
|
+
new_sheet2 = new_book2.sheet(1)
|
536
|
+
new_sheet2[1,1].value.should_not == @old_cell_value2
|
537
|
+
new_book2.close
|
538
|
+
end
|
539
|
+
|
540
|
+
it "should not save if user answers 'no'" do
|
541
|
+
@excel1.displayalerts = @excel2.displayalerts = @excel4.displayalerts = true
|
542
|
+
@key_sender.puts "{right}{enter}"
|
543
|
+
@key_sender.puts "{right}{enter}"
|
544
|
+
Excel.close_all(:if_unsaved => :forget)
|
545
|
+
@excel2.should_not be_alive
|
546
|
+
new_book2 = Book.open(@simple_file)
|
547
|
+
new_sheet2 = new_book2.sheet(1)
|
548
|
+
new_sheet2[1,1].value.should == @old_cell_value2
|
549
|
+
new_book2.close
|
550
|
+
end
|
447
551
|
end
|
448
552
|
end
|
449
|
-
|
553
|
+
=end
|
554
|
+
|
450
555
|
describe "close" do
|
451
556
|
|
452
557
|
context "with a saved workbook" do
|
@@ -515,7 +620,9 @@ module RobustExcelOle
|
|
515
620
|
end
|
516
621
|
|
517
622
|
it "should close the Excel without saving the workbook" do
|
623
|
+
@excel.displayalerts = false
|
518
624
|
@excel.should be_alive
|
625
|
+
@excel.displayalerts = false
|
519
626
|
@excel.close(:if_unsaved => :forget)
|
520
627
|
@excel.should_not be_alive
|
521
628
|
new_book = Book.open(@simple_file)
|
@@ -637,7 +744,48 @@ module RobustExcelOle
|
|
637
744
|
@excel.close(:if_unsaved => :alert)
|
638
745
|
}.to raise_error(ExcelUserCanceled, "close: canceled by user")
|
639
746
|
end
|
747
|
+
|
748
|
+
it "should save if user answers 'yes'" do
|
749
|
+
# "Yes" is to the left of "No", which is the default. --> language independent
|
750
|
+
@excel.should be_alive
|
751
|
+
@excel.displayalerts = true
|
752
|
+
@key_sender.puts "{enter}"
|
753
|
+
@excel.close(:if_unsaved => :forget)
|
754
|
+
@excel.should_not be_alive
|
755
|
+
new_book = Book.open(@simple_file)
|
756
|
+
new_sheet = new_book.sheet(1)
|
757
|
+
new_sheet[1,1].value.should_not == @old_cell_value
|
758
|
+
new_book.close
|
759
|
+
end
|
760
|
+
|
761
|
+
it "should not save if user answers 'no'" do
|
762
|
+
@excel.should be_alive
|
763
|
+
@excel.displayalerts = true
|
764
|
+
@book.should be_alive
|
765
|
+
@book.saved.should be_false
|
766
|
+
@key_sender.puts "{right}{enter}"
|
767
|
+
@excel.close(:if_unsaved => :forget)
|
768
|
+
@excel.should_not be_alive
|
769
|
+
@book.should_not be_alive
|
770
|
+
new_book = Book.open(@simple_file)
|
771
|
+
new_sheet = new_book.sheet(1)
|
772
|
+
new_sheet[1,1].value.should == @old_cell_value
|
773
|
+
new_book.close
|
774
|
+
end
|
775
|
+
|
776
|
+
it "should not save if user answers 'cancel'" do
|
777
|
+
# strangely, in the "cancel" case, the question will sometimes be repeated twice
|
778
|
+
@excel.should be_alive
|
779
|
+
@excel.displayalerts = true
|
780
|
+
@book.should be_alive
|
781
|
+
@book.saved.should be_false
|
782
|
+
@key_sender.puts "{left}{enter}"
|
783
|
+
@key_sender.puts "{left}{enter}"
|
784
|
+
@excel.close(:if_unsaved => :forget)
|
785
|
+
end
|
786
|
+
|
640
787
|
end
|
788
|
+
|
641
789
|
end
|
642
790
|
|
643
791
|
describe "alive" do
|
@@ -676,64 +824,301 @@ module RobustExcelOle
|
|
676
824
|
@excel1.should_not == nil
|
677
825
|
end
|
678
826
|
|
827
|
+
# Error
|
679
828
|
it "should be false with dead Excel objects" do
|
680
829
|
excel2 = Excel.current
|
830
|
+
sleep 3
|
681
831
|
Excel.close_all
|
832
|
+
sleep 2
|
682
833
|
excel2.should_not == @excel1
|
683
834
|
end
|
684
835
|
|
685
836
|
end
|
686
837
|
|
838
|
+
context "workbooks_visible" do
|
839
|
+
|
840
|
+
it "should not raise an error for an empty Excel instance" do
|
841
|
+
excel = Excel.create
|
842
|
+
expect{
|
843
|
+
excel.workbooks_visible = true
|
844
|
+
}.to_not raise_error
|
845
|
+
end
|
846
|
+
|
847
|
+
it "should make visible a workbook" do
|
848
|
+
book1 = Book.open(@simple_file)
|
849
|
+
book1.excel.workbooks_visible = true
|
850
|
+
book1.excel.Visible.should be_true
|
851
|
+
book1.Windows(book1.Name).Visible.should be_true
|
852
|
+
book1.visible.should be_true
|
853
|
+
end
|
854
|
+
|
855
|
+
it "should make visible and invisible two workbooks" do
|
856
|
+
book1 = Book.open(@simple_file)
|
857
|
+
book2 = Book.open(@different_file)
|
858
|
+
excel = book1.excel
|
859
|
+
excel.workbooks_visible = true
|
860
|
+
excel.Visible.should be_true
|
861
|
+
book1.Windows(book1.Name).Visible.should be_true
|
862
|
+
book1.visible.should be_true
|
863
|
+
book2.Windows(book2.Name).Visible.should be_true
|
864
|
+
book2.visible.should be_true
|
865
|
+
excel.workbooks_visible = false
|
866
|
+
excel.Visible.should be_true
|
867
|
+
book1.Windows(book1.Name).Visible.should be_false
|
868
|
+
book1.visible.should be_false
|
869
|
+
book2.Windows(book2.Name).Visible.should be_false
|
870
|
+
book2.visible.should be_false
|
871
|
+
end
|
872
|
+
|
873
|
+
it "should make visible all workbooks" do
|
874
|
+
book1 = Book.open(@simple_file, :visible => true)
|
875
|
+
book2 = Book.open(@different_file)
|
876
|
+
excel = book1.excel
|
877
|
+
excel.workbooks_visible = true
|
878
|
+
excel.Visible.should be_true
|
879
|
+
book1.Windows(book1.Name).Visible.should be_true
|
880
|
+
book1.visible.should be_true
|
881
|
+
book2.Windows(book2.Name).Visible.should be_true
|
882
|
+
book2.visible.should be_true
|
883
|
+
end
|
884
|
+
|
885
|
+
end
|
886
|
+
|
687
887
|
context "with Visible and DisplayAlerts" do
|
688
888
|
|
689
|
-
it "should
|
690
|
-
|
889
|
+
it "should set Excel visible and invisible with current" do
|
890
|
+
excel1 = Excel.create
|
891
|
+
excel2 = Excel.current(:visible => true)
|
892
|
+
excel2.Visible.should be_true
|
893
|
+
excel2.visible.should be_true
|
894
|
+
excel2.DisplayAlerts.should be_true
|
895
|
+
excel2.displayalerts.should == :if_visible
|
896
|
+
end
|
897
|
+
|
898
|
+
it "should set Excel visible and invisible with current" do
|
899
|
+
excel1 = Excel.new(:reuse => false, :visible => true)
|
900
|
+
excel1.Visible.should be_true
|
901
|
+
excel1.visible.should be_true
|
902
|
+
excel1.DisplayAlerts.should be_true
|
903
|
+
excel1.displayalerts.should == :if_visible
|
904
|
+
excel1.visible = false
|
905
|
+
excel1.Visible.should be_false
|
906
|
+
excel1.visible.should be_false
|
907
|
+
excel1.DisplayAlerts.should be_false
|
908
|
+
excel1.displayalerts.should == :if_visible
|
909
|
+
excel2 = Excel.current(:visible => true)
|
910
|
+
excel2.Visible.should be_true
|
911
|
+
excel2.visible.should be_true
|
912
|
+
excel2.displayalerts.should == :if_visible
|
913
|
+
excel2.DisplayAlerts.should be_true
|
914
|
+
end
|
915
|
+
|
916
|
+
it "should set Excel visible and invisible" do
|
917
|
+
excel = Excel.new(:reuse => false, :visible => true)
|
691
918
|
excel.Visible.should be_true
|
692
919
|
excel.visible.should be_true
|
693
|
-
excel.DisplayAlerts.should
|
694
|
-
excel.displayalerts.should
|
920
|
+
excel.DisplayAlerts.should be_true
|
921
|
+
excel.displayalerts.should == :if_visible
|
922
|
+
excel6 = Excel.current
|
923
|
+
excel6.should === excel
|
924
|
+
excel6.Visible.should be_true
|
695
925
|
excel.visible = false
|
696
926
|
excel.Visible.should be_false
|
697
927
|
excel.visible.should be_false
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
928
|
+
excel.DisplayAlerts.should be_false
|
929
|
+
excel.displayalerts.should == :if_visible
|
930
|
+
excel7 = Excel.current
|
931
|
+
excel7.should === excel
|
932
|
+
excel7.Visible.should be_false
|
933
|
+
excel7.DisplayAlerts.should be_false
|
934
|
+
excel1 = Excel.create(:visible => true)
|
935
|
+
excel1.should_not == excel
|
936
|
+
excel1.Visible.should be_true
|
937
|
+
excel1.visible.should be_true
|
938
|
+
excel1.DisplayAlerts.should be_true
|
939
|
+
excel1.displayalerts.should == :if_visible
|
940
|
+
excel2 = Excel.create(:visible => false)
|
941
|
+
excel2.Visible.should be_false
|
942
|
+
excel2.visible.should be_false
|
943
|
+
excel2.DisplayAlerts.should be_false
|
944
|
+
excel2.displayalerts.should == :if_visible
|
945
|
+
excel3 = Excel.current
|
946
|
+
excel3.should === excel
|
947
|
+
excel3.Visible.should be_false
|
948
|
+
excel3.visible.should be_false
|
949
|
+
excel3.DisplayAlerts.should be_false
|
950
|
+
excel3.displayalerts.should == :if_visible
|
951
|
+
excel4 = Excel.current(:visible => true)
|
952
|
+
excel4.should === excel
|
953
|
+
excel4.Visible.should be_true
|
954
|
+
excel4.visible.should be_true
|
955
|
+
#Error:
|
956
|
+
#excel4.DisplayAlerts.should be_true
|
957
|
+
excel4.displayalerts.should == :if_visible
|
958
|
+
excel5 = Excel.current(:visible => false)
|
959
|
+
excel5.should === excel
|
960
|
+
excel5.Visible.should be_false
|
961
|
+
excel5.visible.should be_false
|
962
|
+
excel5.DisplayAlerts.should be_false
|
963
|
+
excel5.displayalerts.should == :if_visible
|
964
|
+
end
|
965
|
+
|
966
|
+
it "should enable or disable Excel DispayAlerts" do
|
967
|
+
excel = Excel.new(:reuse => false, :displayalerts => true)
|
702
968
|
excel.DisplayAlerts.should be_true
|
703
969
|
excel.displayalerts.should be_true
|
704
970
|
excel.Visible.should be_false
|
705
971
|
excel.visible.should be_false
|
972
|
+
excel6 = Excel.current
|
973
|
+
excel6.should === excel
|
974
|
+
excel6.DisplayAlerts.should be_true
|
975
|
+
excel6.displayalerts.should be_true
|
976
|
+
excel6.Visible.should be_false
|
977
|
+
excel6.visible.should be_false
|
706
978
|
excel.displayalerts = false
|
707
979
|
excel.DisplayAlerts.should be_false
|
708
980
|
excel.displayalerts.should be_false
|
981
|
+
excel.Visible.should be_false
|
982
|
+
excel.visible.should be_false
|
983
|
+
excel7 = Excel.current
|
984
|
+
excel7.should === excel
|
985
|
+
excel7.DisplayAlerts.should be_false
|
986
|
+
excel7.displayalerts.should be_false
|
987
|
+
excel7.Visible.should be_false
|
988
|
+
excel7.visible.should be_false
|
989
|
+
excel1 = Excel.create(:displayalerts => true)
|
990
|
+
excel1.should_not == excel
|
991
|
+
excel1.DisplayAlerts.should be_true
|
992
|
+
excel1.displayalerts.should be_true
|
993
|
+
excel1.Visible.should be_false
|
994
|
+
excel1.visible.should be_false
|
995
|
+
excel2 = Excel.create(:displayalerts => false)
|
996
|
+
excel2.DisplayAlerts.should be_false
|
997
|
+
excel2.displayalerts.should be_false
|
998
|
+
excel2.Visible.should be_false
|
999
|
+
excel2.visible.should be_false
|
1000
|
+
excel3 = Excel.current
|
1001
|
+
excel3.should === excel
|
1002
|
+
excel3.DisplayAlerts.should be_false
|
1003
|
+
excel3.displayalerts.should be_false
|
1004
|
+
excel3.Visible.should be_false
|
1005
|
+
excel3.visible.should be_false
|
1006
|
+
excel4 = Excel.current(:displayalerts => true)
|
1007
|
+
excel4.should === excel
|
1008
|
+
excel4.DisplayAlerts.should be_true
|
1009
|
+
excel4.displayalerts.should be_true
|
1010
|
+
excel4.Visible.should be_false
|
1011
|
+
excel4.visible.should be_false
|
1012
|
+
excel5 = Excel.current(:displayalerts => false)
|
1013
|
+
excel5.should === excel
|
1014
|
+
excel5.DisplayAlerts.should be_false
|
1015
|
+
excel5.displayalerts.should be_false
|
1016
|
+
excel5.Visible.should be_false
|
1017
|
+
excel5.visible.should be_false
|
1018
|
+
end
|
1019
|
+
|
1020
|
+
it "should set Excel visible and displayalerts" do
|
1021
|
+
excel = Excel.new(:reuse => false, :visible => true, :displayalerts => true)
|
1022
|
+
excel.DisplayAlerts.should be_true
|
1023
|
+
excel.displayalerts.should be_true
|
1024
|
+
excel.Visible.should be_true
|
1025
|
+
excel.visible.should be_true
|
1026
|
+
excel6 = Excel.current
|
1027
|
+
excel6.should === excel
|
1028
|
+
excel6.DisplayAlerts.should be_true
|
1029
|
+
excel6.displayalerts.should be_true
|
1030
|
+
excel6.Visible.should be_true
|
1031
|
+
excel6.visible.should be_true
|
1032
|
+
excel.displayalerts = false
|
1033
|
+
excel.DisplayAlerts.should be_false
|
1034
|
+
excel.displayalerts.should be_false
|
1035
|
+
excel.Visible.should be_true
|
1036
|
+
excel.visible.should be_true
|
1037
|
+
excel7 = Excel.current
|
1038
|
+
excel7.should === excel
|
1039
|
+
excel7.DisplayAlerts.should be_false
|
1040
|
+
excel7.displayalerts.should be_false
|
1041
|
+
excel7.Visible.should be_true
|
1042
|
+
excel7.visible.should be_true
|
1043
|
+
excel2 = Excel.new(:reuse => false, :visible => true, :displayalerts => true)
|
1044
|
+
excel2.visible = false
|
1045
|
+
excel2.DisplayAlerts.should be_true
|
1046
|
+
excel2.displayalerts.should be_true
|
1047
|
+
excel2.Visible.should be_false
|
1048
|
+
excel2.visible.should be_false
|
1049
|
+
excel3 = Excel.new(:reuse => false, :visible => true, :displayalerts => false)
|
1050
|
+
excel3.Visible.should be_true
|
1051
|
+
excel3.DisplayAlerts.should be_false
|
1052
|
+
excel3 = Excel.new(:reuse => false, :visible => false, :displayalerts => true)
|
1053
|
+
excel3.Visible.should be_false
|
1054
|
+
excel3.DisplayAlerts.should be_true
|
1055
|
+
excel3 = Excel.new(:reuse => false, :visible => false, :displayalerts => false)
|
1056
|
+
excel3.Visible.should be_false
|
1057
|
+
excel3.DisplayAlerts.should be_false
|
1058
|
+
excel4 = Excel.create(:visible => true, :displayalerts => true)
|
1059
|
+
excel4.DisplayAlerts.should be_true
|
1060
|
+
excel4.displayalerts.should be_true
|
1061
|
+
excel4.Visible.should be_true
|
1062
|
+
excel4.visible.should be_true
|
1063
|
+
excel5 = Excel.current(:visible => true, :displayalerts => false)
|
1064
|
+
excel5.should === excel
|
1065
|
+
excel5.DisplayAlerts.should be_false
|
1066
|
+
excel5.displayalerts.should be_false
|
1067
|
+
excel5.Visible.should be_true
|
1068
|
+
excel5.visible.should be_true
|
1069
|
+
excel6 = Excel.current(:visible => false, :displayalerts => true)
|
1070
|
+
excel6.should === excel
|
1071
|
+
excel6.DisplayAlerts.should be_true
|
1072
|
+
excel6.displayalerts.should be_true
|
1073
|
+
excel6.Visible.should be_false
|
1074
|
+
excel6.visible.should be_false
|
1075
|
+
end
|
1076
|
+
|
1077
|
+
it "should work with displayalerts == if_visible" do
|
1078
|
+
excel = Excel.new(:reuse => false, :visible => true, :displayalerts => :if_visible)
|
1079
|
+
excel.Visible.should be_true
|
1080
|
+
excel.DisplayAlerts.should be_true
|
1081
|
+
excel2 = Excel.new(:reuse => false, :visible => false, :displayalerts => :if_visible)
|
1082
|
+
excel2.Visible.should be_false
|
1083
|
+
excel2.DisplayAlerts.should be_false
|
1084
|
+
excel3 = Excel.new(:reuse => false, :displayalerts => :if_visible)
|
1085
|
+
excel3.Visible.should be_false
|
1086
|
+
excel3.DisplayAlerts.should be_false
|
1087
|
+
excel3.visible = true
|
1088
|
+
excel3.Visible.should be_true
|
1089
|
+
excel3.DisplayAlerts.should be_true
|
1090
|
+
excel3.visible = false
|
1091
|
+
excel3.Visible.should be_false
|
1092
|
+
excel3.DisplayAlerts.should be_false
|
709
1093
|
end
|
710
1094
|
|
711
1095
|
it "should keep visible and displayalerts values when reusing Excel" do
|
712
1096
|
excel = Excel.new(:visible => true)
|
713
|
-
excel.
|
714
|
-
excel.
|
715
|
-
excel2 = Excel.new(:displayalerts =>
|
1097
|
+
excel.Visible.should be_true
|
1098
|
+
excel.DisplayAlerts.should be_true
|
1099
|
+
excel2 = Excel.new(:displayalerts => false)
|
716
1100
|
excel2.should == excel
|
717
|
-
excel.
|
718
|
-
excel.
|
1101
|
+
excel.Visible.should be_true
|
1102
|
+
excel.DisplayAlerts.should be_false
|
719
1103
|
end
|
720
1104
|
|
721
1105
|
it "should keep displayalerts and visible values when reusing Excel" do
|
722
1106
|
excel = Excel.new(:displayalerts => true)
|
723
|
-
excel.
|
724
|
-
excel.
|
1107
|
+
excel.Visible.should be_false
|
1108
|
+
excel.DisplayAlerts.should be_true
|
725
1109
|
excel2 = Excel.new(:visible => true)
|
726
1110
|
excel2.should == excel
|
727
|
-
excel.
|
728
|
-
excel.
|
1111
|
+
excel.Visible.should be_true
|
1112
|
+
excel.DisplayAlerts.should be_true
|
729
1113
|
end
|
730
1114
|
|
731
1115
|
end
|
732
1116
|
|
733
|
-
context "with displayalerts" do
|
1117
|
+
context "with resetting displayalerts values" do
|
734
1118
|
before do
|
735
1119
|
@excel1 = Excel.new(:displayalerts => true)
|
736
1120
|
@excel2 = Excel.new(:displayalerts => false, :reuse => false)
|
1121
|
+
@excel3 = Excel.new(:displayalerts => false, :visible => true, :reuse => false)
|
737
1122
|
end
|
738
1123
|
|
739
1124
|
it "should turn off displayalerts" do
|
@@ -759,6 +1144,33 @@ module RobustExcelOle
|
|
759
1144
|
@excel2.DisplayAlerts.should be_false
|
760
1145
|
end
|
761
1146
|
end
|
1147
|
+
|
1148
|
+
it "should set displayalerts to :if_visible" do
|
1149
|
+
@excel1.DisplayAlerts.should be_true
|
1150
|
+
begin
|
1151
|
+
@excel1.with_displayalerts :if_visible do
|
1152
|
+
@excel1.DisplayAlerts.should be_false
|
1153
|
+
@excel1.Visible.should be_false
|
1154
|
+
raise TestError, "any_error"
|
1155
|
+
end
|
1156
|
+
rescue TestError
|
1157
|
+
@excel1.DisplayAlerts.should be_true
|
1158
|
+
end
|
1159
|
+
end
|
1160
|
+
|
1161
|
+
it "should set displayalerts to :if_visible" do
|
1162
|
+
@excel3.DisplayAlerts.should be_false
|
1163
|
+
begin
|
1164
|
+
@excel3.with_displayalerts :if_visible do
|
1165
|
+
@excel3.DisplayAlerts.should be_true
|
1166
|
+
@excel3.Visible.should be_true
|
1167
|
+
raise TestError, "any_error"
|
1168
|
+
end
|
1169
|
+
rescue TestError
|
1170
|
+
@excel3.DisplayAlerts.should be_false
|
1171
|
+
end
|
1172
|
+
end
|
1173
|
+
|
762
1174
|
end
|
763
1175
|
|
764
1176
|
context "with calculation" do
|