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
@@ -9,6 +9,7 @@ module My # :nodoc: #
|
|
9
9
|
|
10
10
|
class Book < RobustExcelOle::Book # :nodoc: #
|
11
11
|
end
|
12
|
+
|
12
13
|
end
|
13
14
|
|
14
15
|
describe "subclassed Book" do
|
@@ -17,7 +18,7 @@ describe "subclassed Book" do
|
|
17
18
|
excel = RobustExcelOle::Excel.new(:reuse => true)
|
18
19
|
open_books = excel == nil ? 0 : excel.Workbooks.Count
|
19
20
|
puts "*** open books *** : #{open_books}" if open_books > 0
|
20
|
-
RobustExcelOle::Excel.
|
21
|
+
RobustExcelOle::Excel.kill_all
|
21
22
|
end
|
22
23
|
|
23
24
|
before do
|
@@ -14,7 +14,7 @@ describe Book do
|
|
14
14
|
excel = Excel.new(:reuse => true)
|
15
15
|
open_books = excel == nil ? 0 : excel.Workbooks.Count
|
16
16
|
puts "*** open books *** : #{open_books}" if open_books > 0
|
17
|
-
Excel.
|
17
|
+
Excel.kill_all
|
18
18
|
end
|
19
19
|
|
20
20
|
before do
|
@@ -27,6 +27,7 @@ describe Book do
|
|
27
27
|
@linked_file = @dir + '/workbook_linked.xlsm'
|
28
28
|
@simple_file_xlsm = @dir + '/workbook.xls'
|
29
29
|
@simple_file_xlsx = @dir + '/workbook.xlsx'
|
30
|
+
@simple_file1 = @simple_file
|
30
31
|
end
|
31
32
|
|
32
33
|
after do
|
@@ -71,20 +72,11 @@ describe Book do
|
|
71
72
|
end
|
72
73
|
|
73
74
|
after do
|
74
|
-
|
75
|
-
begin
|
76
|
-
@excel1.close
|
77
|
-
@excel2.close
|
78
|
-
rescue RuntimeError => msg
|
79
|
-
#puts "RuntimeError: #{msg.message}" if msg.message =~ /Excel instance not alive or damaged/
|
80
|
-
nil
|
81
|
-
end
|
75
|
+
Excel.kill_all
|
82
76
|
end
|
83
77
|
|
84
78
|
it "should open unobtrusively in the first opened Excel" do
|
85
79
|
Book.unobtrusively(@simple_file) do |book|
|
86
|
-
book.should be_a Book
|
87
|
-
book.should be_alive
|
88
80
|
book.excel.should == @excel1
|
89
81
|
book.excel.should_not == @excel2
|
90
82
|
end
|
@@ -113,7 +105,7 @@ describe Book do
|
|
113
105
|
expect{
|
114
106
|
Book.unobtrusively(@simple_file, @excel2) do |book|
|
115
107
|
end
|
116
|
-
}.
|
108
|
+
}.to_not raise_error
|
117
109
|
end
|
118
110
|
end
|
119
111
|
|
@@ -124,12 +116,11 @@ describe Book do
|
|
124
116
|
}.to raise_error(ExcelErrorOpen, "given object is neither an Excel, a Workbook, nor a Win32ole")
|
125
117
|
end
|
126
118
|
|
127
|
-
it "should be visible
|
128
|
-
Book.unobtrusively(@simple_file, :visible => true
|
119
|
+
it "should be visible" do
|
120
|
+
Book.unobtrusively(@simple_file, :visible => true) do |book|
|
129
121
|
book.should be_a Book
|
130
122
|
book.should be_alive
|
131
123
|
book.excel.visible.should be_true
|
132
|
-
book.excel.displayalerts.should be_true
|
133
124
|
end
|
134
125
|
end
|
135
126
|
|
@@ -148,7 +139,7 @@ describe Book do
|
|
148
139
|
context "with an open book" do
|
149
140
|
|
150
141
|
before do
|
151
|
-
@book = Book.open(@
|
142
|
+
@book = Book.open(@simple_file1)
|
152
143
|
end
|
153
144
|
|
154
145
|
after do
|
@@ -169,7 +160,7 @@ describe Book do
|
|
169
160
|
it "should let an open Book open if it has been closed and opened again" do
|
170
161
|
@book.close
|
171
162
|
@book.reopen
|
172
|
-
Book.unobtrusively(@
|
163
|
+
Book.unobtrusively(@simple_file1) do |book|
|
173
164
|
book.should be_a Book
|
174
165
|
book.should be_alive
|
175
166
|
book.excel.should == @book.excel
|
@@ -183,7 +174,7 @@ describe Book do
|
|
183
174
|
@book.close
|
184
175
|
book2.close
|
185
176
|
@book.reopen
|
186
|
-
Book.unobtrusively(@
|
177
|
+
Book.unobtrusively(@simple_file1) do |book|
|
187
178
|
book.should be_a Book
|
188
179
|
book.should be_alive
|
189
180
|
book.excel.should == @book.excel
|
@@ -241,8 +232,8 @@ describe Book do
|
|
241
232
|
@book2.Saved.should be_false
|
242
233
|
@book2.close(:if_unsaved => :forget)
|
243
234
|
@book.close
|
244
|
-
|
245
|
-
sheet2 =
|
235
|
+
new_book = Book.open(@simple_file1)
|
236
|
+
sheet2 = new_book.sheet(1)
|
246
237
|
sheet2[1,1].value.should_not == old_cell_value
|
247
238
|
end
|
248
239
|
|
@@ -289,8 +280,8 @@ describe Book do
|
|
289
280
|
@book.should_not be_alive
|
290
281
|
unobtrusively_ok?
|
291
282
|
@book.should_not be_alive
|
292
|
-
|
293
|
-
sheet =
|
283
|
+
new_book = Book.open(@simple_file1)
|
284
|
+
sheet = new_book.sheet(1)
|
294
285
|
sheet[1,1].Value.should_not == old_cell_value
|
295
286
|
end
|
296
287
|
|
@@ -312,7 +303,7 @@ describe Book do
|
|
312
303
|
end
|
313
304
|
@book.should be_alive
|
314
305
|
@book.close
|
315
|
-
new_book = Book.open(@
|
306
|
+
new_book = Book.open(@simple_file1)
|
316
307
|
sheet = new_book.sheet(1)
|
317
308
|
sheet[1,1].value.should_not == old_cell_value
|
318
309
|
end
|
@@ -349,7 +340,7 @@ describe Book do
|
|
349
340
|
book.Saved.should be_false
|
350
341
|
end
|
351
342
|
@book.should_not be_alive
|
352
|
-
new_book = Book.open(@
|
343
|
+
new_book = Book.open(@simple_file1)
|
353
344
|
sheet = new_book.sheet(1)
|
354
345
|
sheet[1,1].value.should_not == old_cell_value
|
355
346
|
end
|
@@ -372,7 +363,7 @@ describe Book do
|
|
372
363
|
end
|
373
364
|
@book.should be_alive
|
374
365
|
@book.close
|
375
|
-
new_book = Book.open(@
|
366
|
+
new_book = Book.open(@simple_file1)
|
376
367
|
sheet = new_book.sheet(1)
|
377
368
|
sheet[1,1].value.should_not == old_cell_value
|
378
369
|
end
|
@@ -394,7 +385,7 @@ describe Book do
|
|
394
385
|
book.Saved.should be_false
|
395
386
|
end
|
396
387
|
@book.should_not be_alive
|
397
|
-
new_book = Book.open(@
|
388
|
+
new_book = Book.open(@simple_file1)
|
398
389
|
sheet = new_book.sheet(1)
|
399
390
|
sheet[1,1].value.should_not == old_cell_value
|
400
391
|
end
|
@@ -410,7 +401,7 @@ describe Book do
|
|
410
401
|
cell = sheet[1,1]
|
411
402
|
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
412
403
|
end
|
413
|
-
old_book = Book.open(@
|
404
|
+
old_book = Book.open(@simple_file1)
|
414
405
|
old_sheet = old_book.sheet(1)
|
415
406
|
old_sheet[1,1].Value.should == old_cell_value
|
416
407
|
old_book.close
|
@@ -424,7 +415,7 @@ describe Book do
|
|
424
415
|
context "with a visible book" do
|
425
416
|
|
426
417
|
before do
|
427
|
-
@book = Book.open(@
|
418
|
+
@book = Book.open(@simple_file1, :visible => true)
|
428
419
|
end
|
429
420
|
|
430
421
|
after do
|
@@ -433,7 +424,7 @@ describe Book do
|
|
433
424
|
end
|
434
425
|
|
435
426
|
it "should let an open Book open" do
|
436
|
-
Book.unobtrusively(@
|
427
|
+
Book.unobtrusively(@simple_file1) do |book|
|
437
428
|
book.should be_a Book
|
438
429
|
book.should be_alive
|
439
430
|
book.excel.should == @book.excel
|
@@ -449,14 +440,14 @@ describe Book do
|
|
449
440
|
context "with various options for an Excel instance in which to open a closed book" do
|
450
441
|
|
451
442
|
before do
|
452
|
-
@book = Book.open(@
|
443
|
+
@book = Book.open(@simple_file1)
|
453
444
|
@book.close
|
454
445
|
end
|
455
446
|
|
456
447
|
it "should use a given Excel" do
|
457
448
|
new_excel = Excel.new(:reuse => false)
|
458
449
|
another_excel = Excel.new(:reuse => false)
|
459
|
-
Book.unobtrusively(@
|
450
|
+
Book.unobtrusively(@simple_file1, another_excel) do |book|
|
460
451
|
book.excel.should_not == @book.excel
|
461
452
|
book.excel.should_not == new_excel
|
462
453
|
book.excel.should == another_excel
|
@@ -465,25 +456,25 @@ describe Book do
|
|
465
456
|
|
466
457
|
it "should use the hidden Excel" do
|
467
458
|
new_excel = Excel.new(:reuse => false)
|
468
|
-
Book.unobtrusively(@
|
459
|
+
Book.unobtrusively(@simple_file1, :hidden) do |book|
|
469
460
|
book.excel.should_not == @book.excel
|
470
461
|
book.excel.should_not == new_excel
|
471
462
|
book.excel.visible.should be_false
|
472
|
-
book.excel.displayalerts.should
|
463
|
+
book.excel.displayalerts.should == :if_visible
|
473
464
|
@hidden_excel = book.excel
|
474
465
|
end
|
475
|
-
Book.unobtrusively(@
|
466
|
+
Book.unobtrusively(@simple_file1, :hidden) do |book|
|
476
467
|
book.excel.should_not == @book.excel
|
477
468
|
book.excel.should_not == new_excel
|
478
469
|
book.excel.visible.should be_false
|
479
|
-
book.excel.displayalerts.should
|
470
|
+
book.excel.displayalerts.should == :if_visible
|
480
471
|
book.excel.should == @hidden_excel
|
481
472
|
end
|
482
473
|
end
|
483
474
|
|
484
475
|
it "should reuse Excel" do
|
485
476
|
new_excel = Excel.new(:reuse => false)
|
486
|
-
Book.unobtrusively(@
|
477
|
+
Book.unobtrusively(@simple_file1, :reuse) do |book|
|
487
478
|
book.excel.should == @book.excel
|
488
479
|
book.excel.should_not == new_excel
|
489
480
|
end
|
@@ -491,7 +482,7 @@ describe Book do
|
|
491
482
|
|
492
483
|
it "should reuse Excel by default" do
|
493
484
|
new_excel = Excel.new(:reuse => false)
|
494
|
-
Book.unobtrusively(@
|
485
|
+
Book.unobtrusively(@simple_file1) do |book|
|
495
486
|
book.excel.should == @book.excel
|
496
487
|
book.excel.should_not == new_excel
|
497
488
|
end
|
@@ -502,7 +493,7 @@ describe Book do
|
|
502
493
|
context "with a read_only book" do
|
503
494
|
|
504
495
|
before do
|
505
|
-
@book = Book.open(@
|
496
|
+
@book = Book.open(@simple_file1, :read_only => true)
|
506
497
|
end
|
507
498
|
|
508
499
|
after do
|
@@ -519,7 +510,7 @@ describe Book do
|
|
519
510
|
@book.Saved.should be_true
|
520
511
|
@book.ReadOnly.should be_true
|
521
512
|
@book.close
|
522
|
-
book2 = Book.open(@
|
513
|
+
book2 = Book.open(@simple_file1)
|
523
514
|
sheet2 = book2.sheet(1)
|
524
515
|
sheet2[1,1].value.should_not == old_cell_value
|
525
516
|
end
|
@@ -530,7 +521,7 @@ describe Book do
|
|
530
521
|
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
531
522
|
@book.Saved.should be_false
|
532
523
|
@book.should be_alive
|
533
|
-
Book.unobtrusively(@
|
524
|
+
Book.unobtrusively(@simple_file1) do |book|
|
534
525
|
book.should be_a Book
|
535
526
|
sheet = book.sheet(1)
|
536
527
|
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
@@ -542,7 +533,7 @@ describe Book do
|
|
542
533
|
@book.Saved.should be_false
|
543
534
|
@book.ReadOnly.should be_true
|
544
535
|
@book.close
|
545
|
-
book2 = Book.open(@
|
536
|
+
book2 = Book.open(@simple_file1)
|
546
537
|
sheet2 = book2.sheet(1)
|
547
538
|
# modifies unobtrusively the saved version, not the unsaved version
|
548
539
|
sheet2[1,1].value.should == @cell_value
|
@@ -554,7 +545,7 @@ describe Book do
|
|
554
545
|
book2.Readonly.should be_false
|
555
546
|
sheet = @book.sheet(1)
|
556
547
|
cell_value = sheet[1,1].value
|
557
|
-
Book.unobtrusively(@
|
548
|
+
Book.unobtrusively(@simple_file1, :hidden) do |book|
|
558
549
|
book.should be_a Book
|
559
550
|
book.excel.should == book2.excel
|
560
551
|
book.excel.should_not == @book.excel
|
@@ -567,14 +558,14 @@ describe Book do
|
|
567
558
|
@book.ReadOnly.should be_true
|
568
559
|
@book.close
|
569
560
|
book2.close
|
570
|
-
book3 = Book.open(@
|
561
|
+
book3 = Book.open(@simple_file1)
|
571
562
|
new_sheet = book3.sheet(1)
|
572
563
|
new_sheet[1,1].value.should_not == cell_value
|
573
564
|
book3.close
|
574
565
|
end
|
575
566
|
|
576
567
|
it "should open unobtrusively by default the book in a new Excel such that the book is writable" do
|
577
|
-
book2 = Book.open(@
|
568
|
+
book2 = Book.open(@simple_file1, :force_excel => :new, :read_only => true)
|
578
569
|
@book.ReadOnly.should be_true
|
579
570
|
book2.Readonly.should be_true
|
580
571
|
sheet = @book.sheet(1)
|
@@ -592,14 +583,14 @@ describe Book do
|
|
592
583
|
@book.ReadOnly.should be_true
|
593
584
|
@book.close
|
594
585
|
book2.close
|
595
|
-
book3 = Book.open(@
|
586
|
+
book3 = Book.open(@simple_file1)
|
596
587
|
new_sheet = book3.sheet(1)
|
597
588
|
new_sheet[1,1].value.should_not == cell_value
|
598
589
|
book3.close
|
599
590
|
end
|
600
591
|
|
601
592
|
it "should open unobtrusively the book in a new Excel such that the book is writable" do
|
602
|
-
book2 = Book.open(@
|
593
|
+
book2 = Book.open(@simple_file1, :force_excel => :new, :read_only => true)
|
603
594
|
@book.ReadOnly.should be_true
|
604
595
|
book2.Readonly.should be_true
|
605
596
|
sheet = @book.sheet(1)
|
@@ -617,7 +608,7 @@ describe Book do
|
|
617
608
|
@book.ReadOnly.should be_true
|
618
609
|
@book.close
|
619
610
|
book2.close
|
620
|
-
book3 = Book.open(@
|
611
|
+
book3 = Book.open(@simple_file1)
|
621
612
|
new_sheet = book3.sheet(1)
|
622
613
|
new_sheet[1,1].value.should_not == cell_value
|
623
614
|
book3.close
|
@@ -626,12 +617,12 @@ describe Book do
|
|
626
617
|
it "should open unobtrusively the book in a new Excel to open the book writable" do
|
627
618
|
excel1 = Excel.new(:reuse => false)
|
628
619
|
excel2 = Excel.new(:reuse => false)
|
629
|
-
book2 = Book.open(@
|
620
|
+
book2 = Book.open(@simple_file1, :force_excel => :new, :read_only => true)
|
630
621
|
@book.ReadOnly.should be_true
|
631
622
|
book2.Readonly.should be_true
|
632
623
|
sheet = @book.sheet(1)
|
633
624
|
cell_value = sheet[1,1].value
|
634
|
-
Book.unobtrusively(@
|
625
|
+
Book.unobtrusively(@simple_file1, :hidden, :readonly_excel => false) do |book|
|
635
626
|
book.should be_a Book
|
636
627
|
book.ReadOnly.should be_false
|
637
628
|
book.excel.should_not == book2.excel
|
@@ -647,7 +638,7 @@ describe Book do
|
|
647
638
|
@book.ReadOnly.should be_true
|
648
639
|
@book.close
|
649
640
|
book2.close
|
650
|
-
book3 = Book.open(@
|
641
|
+
book3 = Book.open(@simple_file1)
|
651
642
|
new_sheet = book3.sheet(1)
|
652
643
|
new_sheet[1,1].value.should_not == cell_value
|
653
644
|
book3.close
|
@@ -656,12 +647,12 @@ describe Book do
|
|
656
647
|
it "should open unobtrusively the book in the same Excel to open the book writable" do
|
657
648
|
excel1 = Excel.new(:reuse => false)
|
658
649
|
excel2 = Excel.new(:reuse => false)
|
659
|
-
book2 = Book.open(@
|
650
|
+
book2 = Book.open(@simple_file1, :force_excel => :new, :read_only => true)
|
660
651
|
@book.ReadOnly.should be_true
|
661
652
|
book2.Readonly.should be_true
|
662
653
|
sheet = @book.sheet(1)
|
663
654
|
cell_value = sheet[1,1].value
|
664
|
-
Book.unobtrusively(@
|
655
|
+
Book.unobtrusively(@simple_file1, :hidden, :readonly_excel => true) do |book|
|
665
656
|
book.should be_a Book
|
666
657
|
book.excel.should == book2.excel
|
667
658
|
book.ReadOnly.should be_false
|
@@ -674,19 +665,19 @@ describe Book do
|
|
674
665
|
book2.ReadOnly.should be_false
|
675
666
|
@book.close
|
676
667
|
book2.close
|
677
|
-
book3 = Book.open(@
|
668
|
+
book3 = Book.open(@simple_file1)
|
678
669
|
new_sheet = book3.sheet(1)
|
679
670
|
new_sheet[1,1].value.should_not == cell_value
|
680
671
|
book3.close
|
681
672
|
end
|
682
673
|
|
683
674
|
it "should open unobtrusively the book in the Excel where it was opened most recently" do
|
684
|
-
book2 = Book.open(@
|
675
|
+
book2 = Book.open(@simple_file1, :force_excel => :new, :read_only => true)
|
685
676
|
@book.ReadOnly.should be_true
|
686
677
|
book2.Readonly.should be_true
|
687
678
|
sheet = @book.sheet(1)
|
688
679
|
cell_value = sheet[1,1].value
|
689
|
-
Book.unobtrusively(@
|
680
|
+
Book.unobtrusively(@simple_file1, :hidden, :read_only => true) do |book|
|
690
681
|
book.should be_a Book
|
691
682
|
book.excel.should == book2.excel
|
692
683
|
book.excel.should_not == @book.excel
|
@@ -727,7 +718,7 @@ describe Book do
|
|
727
718
|
context "with a saved book" do
|
728
719
|
|
729
720
|
before do
|
730
|
-
@book1 = Book.open(@
|
721
|
+
@book1 = Book.open(@simple_file1)
|
731
722
|
end
|
732
723
|
|
733
724
|
after do
|
@@ -736,7 +727,7 @@ describe Book do
|
|
736
727
|
|
737
728
|
it "should save if the book was modified during unobtrusively" do
|
738
729
|
m_time = File.mtime(@book1.stored_filename)
|
739
|
-
Book.unobtrusively(@
|
730
|
+
Book.unobtrusively(@simple_file1, :hidden) do |book|
|
740
731
|
@book1.Saved.should be_true
|
741
732
|
book.Saved.should be_true
|
742
733
|
sheet = book.sheet(1)
|
@@ -753,7 +744,7 @@ describe Book do
|
|
753
744
|
|
754
745
|
it "should not save the book if it was not modified during unobtrusively" do
|
755
746
|
m_time = File.mtime(@book1.stored_filename)
|
756
|
-
Book.unobtrusively(@
|
747
|
+
Book.unobtrusively(@simple_file1) do |book|
|
757
748
|
@book1.Saved.should be_true
|
758
749
|
book.Saved.should be_true
|
759
750
|
sleep 1
|
@@ -765,7 +756,7 @@ describe Book do
|
|
765
756
|
|
766
757
|
context "with block result" do
|
767
758
|
before do
|
768
|
-
@book1 = Book.open(@
|
759
|
+
@book1 = Book.open(@simple_file1)
|
769
760
|
end
|
770
761
|
|
771
762
|
after do
|
@@ -774,7 +765,7 @@ describe Book do
|
|
774
765
|
|
775
766
|
it "should yield the block result true" do
|
776
767
|
result =
|
777
|
-
Book.unobtrusively(@
|
768
|
+
Book.unobtrusively(@simple_file1) do |book|
|
778
769
|
@book1.Saved.should be_true
|
779
770
|
end
|
780
771
|
result.should == true
|
@@ -782,7 +773,7 @@ describe Book do
|
|
782
773
|
|
783
774
|
it "should yield the block result nil" do
|
784
775
|
result =
|
785
|
-
Book.unobtrusively(@
|
776
|
+
Book.unobtrusively(@simple_file1) do |book|
|
786
777
|
end
|
787
778
|
result.should == nil
|
788
779
|
end
|
@@ -791,7 +782,7 @@ describe Book do
|
|
791
782
|
sheet1 = @book1.sheet(1)
|
792
783
|
cell1 = sheet1[1,1].value
|
793
784
|
result =
|
794
|
-
Book.unobtrusively(@
|
785
|
+
Book.unobtrusively(@simple_file1) do |book|
|
795
786
|
sheet = book.sheet(1)
|
796
787
|
cell = sheet[1,1].value
|
797
788
|
end
|
@@ -802,7 +793,7 @@ describe Book do
|
|
802
793
|
sheet1 = @book1.sheet(1)
|
803
794
|
@book1.save
|
804
795
|
result =
|
805
|
-
Book.unobtrusively(@
|
796
|
+
Book.unobtrusively(@simple_file1) do |book|
|
806
797
|
sheet = book.sheet(1)
|
807
798
|
sheet[1,1] = 22
|
808
799
|
@book1.Saved.should be_false
|
@@ -816,8 +807,8 @@ describe Book do
|
|
816
807
|
context "with several Excel instances" do
|
817
808
|
|
818
809
|
before do
|
819
|
-
@book1 = Book.open(@
|
820
|
-
@book2 = Book.open(@
|
810
|
+
@book1 = Book.open(@simple_file1)
|
811
|
+
@book2 = Book.open(@simple_file1, :force_excel => :new)
|
821
812
|
@book1.Readonly.should == false
|
822
813
|
@book2.Readonly.should == true
|
823
814
|
old_sheet = @book1.sheet(1)
|
@@ -829,7 +820,7 @@ describe Book do
|
|
829
820
|
end
|
830
821
|
|
831
822
|
it "should open unobtrusively the closed book in the most recent Excel where it was open before" do
|
832
|
-
Book.unobtrusively(@
|
823
|
+
Book.unobtrusively(@simple_file1) do |book|
|
833
824
|
book.excel.should == @book2.excel
|
834
825
|
book.excel.should_not == @book1.excel
|
835
826
|
book.ReadOnly.should == false
|
@@ -838,13 +829,13 @@ describe Book do
|
|
838
829
|
sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
|
839
830
|
book.Saved.should be_false
|
840
831
|
end
|
841
|
-
new_book = Book.open(@
|
832
|
+
new_book = Book.open(@simple_file1)
|
842
833
|
sheet = new_book.sheet(1)
|
843
834
|
sheet[1,1].value.should_not == @old_cell_value
|
844
835
|
end
|
845
836
|
|
846
837
|
it "should open unobtrusively the closed book in the new hidden Excel" do
|
847
|
-
Book.unobtrusively(@
|
838
|
+
Book.unobtrusively(@simple_file1, :hidden) do |book|
|
848
839
|
book.excel.should_not == @book2.excel
|
849
840
|
book.excel.should_not == @book1.excel
|
850
841
|
book.ReadOnly.should == false
|
@@ -853,14 +844,14 @@ describe Book do
|
|
853
844
|
sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
|
854
845
|
book.Saved.should be_false
|
855
846
|
end
|
856
|
-
new_book = Book.open(@
|
847
|
+
new_book = Book.open(@simple_file1)
|
857
848
|
sheet = new_book.sheet(1)
|
858
849
|
sheet[1,1].Value.should_not == @old_cell_value
|
859
850
|
end
|
860
851
|
|
861
852
|
it "should open unobtrusively the closed book in a new Excel if the Excel is not alive anymore" do
|
862
|
-
Excel.
|
863
|
-
Book.unobtrusively(@
|
853
|
+
Excel.kill_all
|
854
|
+
Book.unobtrusively(@simple_file1, :hidden) do |book|
|
864
855
|
book.ReadOnly.should == false
|
865
856
|
book.excel.should_not == @book1.excel
|
866
857
|
book.excel.should_not == @book2.excel
|
@@ -869,7 +860,7 @@ describe Book do
|
|
869
860
|
sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
|
870
861
|
book.Saved.should be_false
|
871
862
|
end
|
872
|
-
new_book = Book.open(@
|
863
|
+
new_book = Book.open(@simple_file1)
|
873
864
|
sheet = new_book.sheet(1)
|
874
865
|
sheet[1,1].Value.should_not == @old_cell_value
|
875
866
|
end
|
@@ -878,12 +869,12 @@ describe Book do
|
|
878
869
|
context "with :hidden" do
|
879
870
|
|
880
871
|
before do
|
881
|
-
@book1 = Book.open(@
|
872
|
+
@book1 = Book.open(@simple_file1)
|
882
873
|
@book1.close
|
883
874
|
end
|
884
875
|
|
885
876
|
it "should create a new hidden Excel instance" do
|
886
|
-
Book.unobtrusively(@
|
877
|
+
Book.unobtrusively(@simple_file1, :hidden) do |book|
|
887
878
|
book.should be_a Book
|
888
879
|
book.should be_alive
|
889
880
|
book.excel.Visible.should be_false
|
@@ -893,7 +884,7 @@ describe Book do
|
|
893
884
|
|
894
885
|
it "should create a new hidden Excel instance and use this afterwards" do
|
895
886
|
hidden_excel = nil
|
896
|
-
Book.unobtrusively(@
|
887
|
+
Book.unobtrusively(@simple_file1, :hidden) do |book|
|
897
888
|
book.should be_a Book
|
898
889
|
book.should be_alive
|
899
890
|
book.excel.Visible.should be_false
|
@@ -911,7 +902,7 @@ describe Book do
|
|
911
902
|
|
912
903
|
it "should create a new hidden Excel instance if the Excel is closed" do
|
913
904
|
Excel.close_all
|
914
|
-
Book.unobtrusively(@
|
905
|
+
Book.unobtrusively(@simple_file1, :hidden) do |book|
|
915
906
|
book.should be_a Book
|
916
907
|
book.should be_alive
|
917
908
|
book.excel.Visible.should be_false
|
@@ -922,7 +913,7 @@ describe Book do
|
|
922
913
|
|
923
914
|
it "should exclude hidden Excel when reuse in unobtrusively" do
|
924
915
|
hidden_excel = nil
|
925
|
-
Book.unobtrusively(@
|
916
|
+
Book.unobtrusively(@simple_file1, :hidden) do |book|
|
926
917
|
book.should be_a Book
|
927
918
|
book.should be_alive
|
928
919
|
book.excel.Visible.should be_false
|
@@ -930,7 +921,7 @@ describe Book do
|
|
930
921
|
book.excel.should_not == @book1.excel
|
931
922
|
hidden_excel = book.excel
|
932
923
|
end
|
933
|
-
Book.unobtrusively(@
|
924
|
+
Book.unobtrusively(@simple_file1) do |book|
|
934
925
|
book.should be_a Book
|
935
926
|
book.should be_alive
|
936
927
|
book.excel.Visible.should be_false
|
@@ -941,7 +932,7 @@ describe Book do
|
|
941
932
|
|
942
933
|
it "should exclude hidden Excel when reuse in open" do
|
943
934
|
hidden_excel = nil
|
944
|
-
Book.unobtrusively(@
|
935
|
+
Book.unobtrusively(@simple_file1, :hidden) do |book|
|
945
936
|
book.should be_a Book
|
946
937
|
book.should be_alive
|
947
938
|
book.excel.Visible.should be_false
|
@@ -949,14 +940,14 @@ describe Book do
|
|
949
940
|
book.excel.should_not == @book1.excel
|
950
941
|
hidden_excel = book.excel
|
951
942
|
end
|
952
|
-
book2 = Book.open(@
|
943
|
+
book2 = Book.open(@simple_file1, :default_excel => :current)
|
953
944
|
book2.excel.should_not == hidden_excel
|
954
945
|
end
|
955
946
|
|
956
947
|
it "should exclude hidden Excel when reuse in open" do
|
957
|
-
book1 = Book.open(@
|
948
|
+
book1 = Book.open(@simple_file1)
|
958
949
|
book1.close
|
959
|
-
book2 = Book.open(@
|
950
|
+
book2 = Book.open(@simple_file1, :default_excel => :current)
|
960
951
|
book2.excel.should == book1.excel
|
961
952
|
book1.should be_alive
|
962
953
|
book2.close
|
@@ -969,14 +960,14 @@ describe Book do
|
|
969
960
|
context "open unobtrusively for reading and modifying" do
|
970
961
|
|
971
962
|
before do
|
972
|
-
@book = Book.open(@
|
963
|
+
@book = Book.open(@simple_file1)
|
973
964
|
sheet = @book.sheet(1)
|
974
965
|
@old_cell_value = sheet[1,1].value
|
975
966
|
@book.close
|
976
967
|
end
|
977
968
|
|
978
969
|
it "should not change the value" do
|
979
|
-
Book.for_reading(@
|
970
|
+
Book.for_reading(@simple_file1) do |book|
|
980
971
|
book.should be_a Book
|
981
972
|
book.should be_alive
|
982
973
|
book.Saved.should be_true
|
@@ -986,7 +977,7 @@ describe Book do
|
|
986
977
|
book.Saved.should be_false
|
987
978
|
book.excel.should == @book.excel
|
988
979
|
end
|
989
|
-
new_book = Book.open(@
|
980
|
+
new_book = Book.open(@simple_file1, :visible => true)
|
990
981
|
sheet = new_book.sheet(1)
|
991
982
|
sheet[1,1].Value.should == @old_cell_value
|
992
983
|
end
|
@@ -994,35 +985,35 @@ describe Book do
|
|
994
985
|
it "should not change the value and use a given Excel" do
|
995
986
|
new_excel = Excel.new(:reuse => false)
|
996
987
|
another_excel = Excel.new(:reuse => false)
|
997
|
-
Book.for_reading(@
|
988
|
+
Book.for_reading(@simple_file1, another_excel) do |book|
|
998
989
|
sheet = book.sheet(1)
|
999
990
|
cell = sheet[1,1]
|
1000
991
|
sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
|
1001
992
|
book.excel.should == another_excel
|
1002
993
|
end
|
1003
|
-
new_book = Book.open(@
|
994
|
+
new_book = Book.open(@simple_file1, :visible => true)
|
1004
995
|
sheet = new_book.sheet(1)
|
1005
996
|
sheet[1,1].Value.should == @old_cell_value
|
1006
997
|
end
|
1007
998
|
|
1008
999
|
it "should not change the value and use the hidden Excel instance" do
|
1009
1000
|
new_excel = Excel.new(:reuse => false)
|
1010
|
-
Book.for_reading(@
|
1001
|
+
Book.for_reading(@simple_file1, :hidden) do |book|
|
1011
1002
|
sheet = book.sheet(1)
|
1012
1003
|
cell = sheet[1,1]
|
1013
1004
|
sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
|
1014
1005
|
book.excel.should_not == @book.excel
|
1015
1006
|
book.excel.should_not == new_excel
|
1016
1007
|
book.excel.visible.should be_false
|
1017
|
-
book.excel.displayalerts.should
|
1008
|
+
book.excel.displayalerts.should == :if_visible
|
1018
1009
|
end
|
1019
|
-
new_book = Book.open(@
|
1010
|
+
new_book = Book.open(@simple_file1, :visible => true)
|
1020
1011
|
sheet = new_book.sheet(1)
|
1021
1012
|
sheet[1,1].Value.should == @old_cell_value
|
1022
1013
|
end
|
1023
1014
|
|
1024
1015
|
it "should change the value" do
|
1025
|
-
Book.for_modifying(@
|
1016
|
+
Book.for_modifying(@simple_file1) do |book|
|
1026
1017
|
sheet = book.sheet(1)
|
1027
1018
|
cell = sheet[1,1]
|
1028
1019
|
sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
|
@@ -1036,29 +1027,29 @@ describe Book do
|
|
1036
1027
|
it "should change the value and use a given Excel" do
|
1037
1028
|
new_excel = Excel.new(:reuse => false)
|
1038
1029
|
another_excel = Excel.new(:reuse => false)
|
1039
|
-
Book.for_modifying(@
|
1030
|
+
Book.for_modifying(@simple_file1, another_excel) do |book|
|
1040
1031
|
sheet = book.sheet(1)
|
1041
1032
|
cell = sheet[1,1]
|
1042
1033
|
sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
|
1043
1034
|
book.excel.should == another_excel
|
1044
1035
|
end
|
1045
|
-
new_book = Book.open(@
|
1036
|
+
new_book = Book.open(@simple_file1, :visible => true)
|
1046
1037
|
sheet = new_book.sheet(1)
|
1047
1038
|
sheet[1,1].Value.should_not == @old_cell_value
|
1048
1039
|
end
|
1049
1040
|
|
1050
1041
|
it "should change the value and use the hidden Excel instance" do
|
1051
1042
|
new_excel = Excel.new(:reuse => false)
|
1052
|
-
Book.for_modifying(@
|
1043
|
+
Book.for_modifying(@simple_file1, :hidden) do |book|
|
1053
1044
|
sheet = book.sheet(1)
|
1054
1045
|
cell = sheet[1,1]
|
1055
1046
|
sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
|
1056
1047
|
book.excel.should_not == @book.excel
|
1057
1048
|
book.excel.should_not == new_excel
|
1058
1049
|
book.excel.visible.should be_false
|
1059
|
-
book.excel.displayalerts.should
|
1050
|
+
book.excel.displayalerts.should == :if_visible
|
1060
1051
|
end
|
1061
|
-
new_book = Book.open(@
|
1052
|
+
new_book = Book.open(@simple_file1, :visible => true)
|
1062
1053
|
sheet = new_book.sheet(1)
|
1063
1054
|
sheet[1,1].Value.should_not == @old_cell_value
|
1064
1055
|
end
|