robust_excel_ole 1.11 → 1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog +11 -0
  3. data/README.rdoc +20 -8
  4. data/docs/README_open.rdoc +1 -0
  5. data/docs/README_ranges.rdoc +5 -11
  6. data/examples/{introducing_examples/example_introducing.rb → introductory_examples/example_introductory.rb} +10 -2
  7. data/examples/{introducing_examples → introductory_examples}/example_open.rb +18 -17
  8. data/examples/{introducing_examples → introductory_examples}/example_range.rb +29 -16
  9. data/examples/modifying_sheets/example_access_sheets_and_cells.rb +8 -7
  10. data/examples/modifying_sheets/example_add_names.rb +4 -8
  11. data/examples/modifying_sheets/example_adding_sheets.rb +7 -6
  12. data/examples/modifying_sheets/example_concating.rb +2 -2
  13. data/examples/modifying_sheets/example_copying.rb +3 -3
  14. data/examples/modifying_sheets/example_expanding.rb +2 -2
  15. data/examples/modifying_sheets/example_naming.rb +2 -2
  16. data/examples/modifying_sheets/example_ranges.rb +4 -4
  17. data/examples/modifying_sheets/example_saving.rb +3 -3
  18. data/examples/open_save_close/example_control_to_excel.rb +10 -11
  19. data/examples/open_save_close/example_default_excel.rb +13 -14
  20. data/examples/open_save_close/example_force_excel.rb +9 -10
  21. data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +7 -7
  22. data/examples/open_save_close/example_if_obstructed_forget.rb +5 -5
  23. data/examples/open_save_close/example_if_obstructed_save.rb +7 -7
  24. data/examples/open_save_close/example_if_unsaved_accept.rb +13 -13
  25. data/examples/open_save_close/example_if_unsaved_forget.rb +9 -10
  26. data/examples/open_save_close/example_if_unsaved_forget_more.rb +9 -10
  27. data/examples/open_save_close/example_read_only.rb +6 -6
  28. data/examples/open_save_close/example_rename_cells.rb +4 -5
  29. data/examples/open_save_close/example_reuse.rb +6 -6
  30. data/examples/open_save_close/example_simple.rb +5 -5
  31. data/examples/open_save_close/example_unobtrusively.rb +4 -4
  32. data/lib/robust_excel_ole/address.rb +0 -4
  33. data/lib/robust_excel_ole/bookstore.rb +4 -28
  34. data/lib/robust_excel_ole/excel.rb +17 -22
  35. data/lib/robust_excel_ole/general.rb +11 -18
  36. data/lib/robust_excel_ole/range_owners.rb +17 -27
  37. data/lib/robust_excel_ole/reo_common.rb +7 -3
  38. data/lib/robust_excel_ole/version.rb +1 -1
  39. data/lib/robust_excel_ole/workbook.rb +178 -180
  40. data/lib/robust_excel_ole/worksheet.rb +7 -4
  41. data/robust_excel_ole.gemspec +6 -4
  42. data/spec/bookstore_spec.rb +38 -34
  43. data/spec/data/more_data/workbook.xls +0 -0
  44. data/spec/excel_spec.rb +89 -44
  45. data/spec/general_spec.rb +1 -0
  46. data/spec/range_spec.rb +7 -4
  47. data/spec/workbook_specs/workbook_close_spec.rb +2 -1
  48. data/spec/workbook_specs/workbook_misc_spec.rb +34 -18
  49. data/spec/workbook_specs/workbook_open_spec.rb +112 -71
  50. data/spec/workbook_specs/workbook_save_spec.rb +173 -5
  51. data/spec/workbook_specs/workbook_sheet_spec.rb +6 -42
  52. data/spec/workbook_specs/workbook_unobtr_spec.rb +9 -246
  53. data/spec/worksheet_spec.rb +21 -5
  54. metadata +12 -11
@@ -198,6 +198,7 @@ describe Workbook do
198
198
  end
199
199
  end
200
200
 
201
+ =begin
201
202
  describe "default-visible" do
202
203
 
203
204
  it "should keep the visibility of the open workbook" do
@@ -288,28 +289,28 @@ describe Workbook do
288
289
  excel2 = book1.excel
289
290
  excel2.should == excel1
290
291
  excel2.Visible.should be false
291
- book2.Windows(book2.Name).Visible.should be true
292
+ book2.Windows(book2.Name).Visible.should be true
292
293
  end
293
294
 
294
295
  it "should open the workbook visible if the workbook is new" do
295
296
  book1 = Workbook.open(@simple_file1, :default => {:visible => true})
296
- book1.visible.should be true
297
297
  book1.excel.Visible.should be true
298
298
  book1.Windows(book1.Name).Visible.should be true
299
+ book1.visible.should be true
299
300
  end
300
301
 
301
302
  it "should open the workbook invisible if the workbook is new" do
302
303
  book1 = Workbook.open(@simple_file1, :default => {:visible => false})
303
- book1.visible.should be false
304
304
  book1.excel.Visible.should be false
305
305
  book1.Windows(book1.Name).Visible.should be false
306
+ book1.visible.should be false
306
307
  end
307
308
 
308
309
  it "should open the workbook invisible per default if the workbook is new" do
309
310
  book1 = Workbook.open(@simple_file1)
310
- book1.visible.should be false
311
311
  book1.excel.Visible.should be false
312
312
  book1.Windows(book1.Name).Visible.should be true
313
+ book1.visible.should be false
313
314
  end
314
315
 
315
316
  it "should open the workbook visible if the old Excel is closed" do
@@ -322,9 +323,9 @@ describe Workbook do
322
323
  excel1.close
323
324
  book2 = Workbook.open(@simple_file1, :default => {:visible => true})
324
325
  excel2 = book2.excel
325
- book2.visible.should be true
326
- excel2.Visible.should be true
327
326
  book1.Windows(book1.Name).Visible.should be true
327
+ excel2.Visible.should be true
328
+ book2.visible.should be true
328
329
  end
329
330
 
330
331
  it "should open the workbook invisible if the old Excel is closed" do
@@ -337,13 +338,15 @@ describe Workbook do
337
338
  excel1.close
338
339
  book2 = Workbook.open(@simple_file1, :default => {:visible => false})
339
340
  excel2 = book2.excel
340
- book2.visible.should be false
341
341
  excel2.Visible.should be false
342
342
  book1.Windows(book1.Name).Visible.should be false
343
+ book2.visible.should be false
343
344
  end
344
345
 
345
346
  end
346
347
 
348
+ =end
349
+
347
350
  describe "force-visible" do
348
351
 
349
352
  it "should change the visibility of the workbooks" do
@@ -386,7 +389,7 @@ describe Workbook do
386
389
  it "should set :visible to false" do
387
390
  book1 = Workbook.open(@simple_file, :visible => false)
388
391
  book1.excel.Visible.should be false
389
- book1.Windows(book1.Name).Visible.should be false
392
+ book1.Windows(book1.Name).Visible.should be true
390
393
  book1.visible.should be false
391
394
  end
392
395
 
@@ -418,7 +421,7 @@ describe Workbook do
418
421
  excel1 = Excel.create
419
422
  book1 = Workbook.open(@simple_file, :visible => false)
420
423
  book1.excel.Visible.should be false
421
- book1.Windows(book1.Name).Visible.should be false
424
+ book1.Windows(book1.Name).Visible.should be true
422
425
  book1.visible.should be false
423
426
  end
424
427
 
@@ -469,7 +472,7 @@ describe Workbook do
469
472
  book1 = Workbook.open(@simple_file)
470
473
  book2 = Workbook.open(@different_file, :default_excel => :new, :visible => false)
471
474
  book2.excel.Visible.should be false
472
- book2.Windows(book2.Name).Visible.should be false
475
+ book2.Windows(book2.Name).Visible.should be true
473
476
  book2.visible.should be false
474
477
  end
475
478
 
@@ -667,7 +670,7 @@ describe Workbook do
667
670
  end
668
671
  end
669
672
 
670
- describe "nameval, set_nameval, [], []=" do
673
+ describe "namevalue_glob, set_namevalue_glob, [], []=" do
671
674
 
672
675
  before do
673
676
  @book1 = Workbook.open(@another_simple_file)
@@ -727,10 +730,10 @@ describe Workbook do
727
730
  @book1.namevalue_glob("foo", :default => 1).should == 1
728
731
  expect {
729
732
  @book1.set_namevalue_glob("foo","bar")
730
- }.to raise_error(NameNotFound, /name "foo" not in #<Workbook: another_workbook/)
733
+ }.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo"/)
731
734
  expect {
732
735
  @book1["foo"] = "bar"
733
- }.to raise_error(NameNotFound, /name "foo" not in #<Workbook: another_workbook/)
736
+ }.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo"/)
734
737
  @book1.namevalue_glob("empty", :default => 1).should be_nil
735
738
  end
736
739
 
@@ -754,7 +757,7 @@ describe Workbook do
754
757
  @book1.namevalue_glob("localname").should == "simple"
755
758
  end
756
759
 
757
- it "should color the cell" do
760
+ it "should color the cell (deprecated)" do
758
761
  @book1.set_namevalue_glob("new", "bar")
759
762
  @book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
760
763
  @book1.set_namevalue_glob("new", "bar", :color => 4)
@@ -768,7 +771,20 @@ describe Workbook do
768
771
  #book2.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 42
769
772
  end
770
773
 
771
- it "should save without color" do
774
+ it "should color the cell" do
775
+ @book1.set_namevalue_glob("new", "bar")
776
+ @book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
777
+ @book1.color_if_modified = 4
778
+ @book1.set_namevalue_glob("new", "bar")
779
+ @book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
780
+ @book1["new"].should == "bar"
781
+ @book1["new"] = "bar"
782
+ @book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 42
783
+ @book1.save
784
+ @book1.close
785
+ end
786
+
787
+ it "should save without color (deprecated)" do
772
788
  @book1.set_namevalue_glob("new", "bar", :color => 4)
773
789
  @book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
774
790
  @book1.save(:discoloring => true)
@@ -916,7 +932,7 @@ describe Workbook do
916
932
  excel1 = Excel.new(:reuse => false, :visible => false)
917
933
  book1 = Workbook.open(@simple_file, :visible => false)
918
934
  excel1.Visible.should be false
919
- book1.Windows(book1.Name).Visible.should be false
935
+ book1.Windows(book1.Name).Visible.should be true
920
936
  book1.visible.should be false
921
937
  end
922
938
 
@@ -985,7 +1001,7 @@ describe Workbook do
985
1001
  excel1 = Excel.new(:reuse => false, :visible => false)
986
1002
  book1 = Workbook.open(@simple_file, :visible => false)
987
1003
  excel1.Visible.should be false
988
- book1.Windows(book1.Name).Visible.should be false
1004
+ book1.Windows(book1.Name).Visible.should be true
989
1005
  book1.visible.should be false
990
1006
  excel1.visible = true
991
1007
  book2 = Workbook.open(@different_file)
@@ -1035,7 +1051,7 @@ describe Workbook do
1035
1051
  @book2.visible = false
1036
1052
  @book2.Saved.should be true
1037
1053
  @book2.excel.Visible.should be false
1038
- @book2.Windows(@book2.Name).Visible.should be false
1054
+ @book2.Windows(@book2.Name).Visible.should be true
1039
1055
  @book2.visible.should be false
1040
1056
  end
1041
1057
 
@@ -32,7 +32,9 @@ describe Workbook do
32
32
  @simple_file_other_path1 = @simple_file_other_path
33
33
  @another_simple_file1 = @another_simple_file
34
34
  @simple_file_direct = File.join(File.dirname(__FILE__), 'data') + '/workbook.xls'
35
- @simple_file_via_network = File.join('N:/', 'data') + '/workbook.xls'
35
+ #@simple_file_via_network = File.join('N:/', 'data') + '/workbook.xls'
36
+ @simple_file_network_path = "N:/data/workbook.xls"
37
+ @simple_file_hostname_share_path = '//DESKTOP-A3C5CJ6/spec/data/workbook.xls'
36
38
 
37
39
  end
38
40
 
@@ -43,7 +45,7 @@ describe Workbook do
43
45
 
44
46
  describe "connecting to unknown workbooks" do
45
47
 
46
- context "with none workbook" do
48
+ context "with none workbook" do
47
49
 
48
50
  it "should open one new Excel with the worbook" do
49
51
  book1 = Workbook.open(@simple_file1)
@@ -114,7 +116,7 @@ describe Workbook do
114
116
  before do
115
117
  ole_e1 = WIN32OLE.new('Excel.Application')
116
118
  ws = ole_e1.Workbooks
117
- abs_filename = General.absolute_path(@simple_file1).tr('/','\\')
119
+ abs_filename = General.absolute_path(@simple_file1)
118
120
  @ole_wb = ws.Open(abs_filename)
119
121
  end
120
122
 
@@ -124,6 +126,7 @@ describe Workbook do
124
126
  book.should be_alive
125
127
  book.should be_a Workbook
126
128
  book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
129
+ Excel.excels_number.should == 1
127
130
  end
128
131
  end
129
132
 
@@ -150,6 +153,18 @@ describe Workbook do
150
153
  }.to raise_error(WorkbookNotSaved, /workbook is already open but not saved: "workbook.xls"/)
151
154
  end
152
155
 
156
+ it "should let the workbook open, if :if_unsaved is :save" do
157
+ @ole_wb.Worksheets.Add
158
+ sheet_num = @ole_wb.Worksheets.Count
159
+ new_book = Workbook.open(@simple_file1, :if_unsaved => :save)
160
+ new_book.should be_alive
161
+ new_book.should be_a Workbook
162
+ new_book.Worksheets.Count.should == sheet_num
163
+ new_book.close
164
+ new_book2 = Workbook.open(@simple_file1)
165
+ new_book2.Worksheets.Count.should == sheet_num
166
+ end
167
+
153
168
  it "should let the workbook open, if :if_unsaved is :accept" do
154
169
  @ole_wb.Worksheets.Add
155
170
  sheet_num = @ole_wb.Worksheets.Count
@@ -157,6 +172,10 @@ describe Workbook do
157
172
  new_book.should be_alive
158
173
  new_book.should be_a Workbook
159
174
  new_book.Worksheets.Count.should == sheet_num
175
+ new_book.Saved.should be false
176
+ new_book.close(:if_unsaved => :forget)
177
+ new_book2 = Workbook.open(@simple_file1)
178
+ new_book2.Worksheets.Count.should == sheet_num - 1
160
179
  end
161
180
 
162
181
  it "should close the workbook, if :if_unsaved is :forget" do
@@ -175,11 +194,11 @@ describe Workbook do
175
194
  before do
176
195
  ole_e1 = WIN32OLE.new('Excel.Application')
177
196
  ws1 = ole_e1.Workbooks
178
- abs_filename1 = General.absolute_path(@simple_file1).tr('/','\\')
197
+ abs_filename1 = General.absolute_path(@simple_file1)
179
198
  @ole_wb1 = ws1.Open(abs_filename1)
180
199
  ole_e2 = WIN32OLE.new('Excel.Application')
181
200
  ws2 = ole_e2.Workbooks
182
- abs_filename2 = General.absolute_path(@different_file1).tr('/','\\')
201
+ abs_filename2 = General.absolute_path(@different_file1)
183
202
  @ole_wb2 = ws2.Open(abs_filename2)
184
203
  end
185
204
 
@@ -187,6 +206,7 @@ describe Workbook do
187
206
  Workbook.open(@simple_file1) do |book|
188
207
  book.filename.should == @simple_file1
189
208
  book.excel.ole_excel.Hwnd.should == @ole_wb1.Application.Hwnd
209
+ Excel.excels_number.should == 2
190
210
  end
191
211
  end
192
212
 
@@ -194,13 +214,12 @@ describe Workbook do
194
214
  Workbook.open(@different_file1) do |book|
195
215
  book.filename.should == @different_file1
196
216
  book.excel.ole_excel.Hwnd.should == @ole_wb2.Application.Hwnd
217
+ Excel.excels_number.should == 2
197
218
  end
198
219
  end
199
220
 
200
221
  end
201
222
 
202
-
203
-
204
223
  end
205
224
 
206
225
  describe "with already open Excel instances and an open unsaved workbook" do
@@ -209,7 +228,7 @@ describe Workbook do
209
228
  @ole_excel1 = WIN32OLE.new('Excel.Application')
210
229
  @ole_excel2 = WIN32OLE.new('Excel.Application')
211
230
  #@ole_workbook1 = @ole_excel1.Workbooks.Open(@simple_file1, { 'ReadOnly' => false })
212
- abs_filename = General.absolute_path(@simple_file1).tr('/','\\')
231
+ abs_filename = General.absolute_path(@simple_file1)
213
232
  @ole_workbook1 = @ole_excel1.Workbooks.Open(abs_filename, nil, false)
214
233
  @ole_workbook1.Worksheets.Add
215
234
  end
@@ -332,6 +351,14 @@ describe Workbook do
332
351
 
333
352
  context "with :force => {:excel}" do
334
353
 
354
+ it "should raise if excel is not alive" do
355
+ excel1 = Excel.create
356
+ excel1.close
357
+ expect{
358
+ book1 = Workbook.open(@simple_file1, :force => {:excel => excel1})
359
+ }.to raise_error(ExcelREOError, "excel is not alive")
360
+ end
361
+
335
362
  it "should open in a provided Excel" do
336
363
  book1 = Workbook.open(@simple_file1, :force => {:excel => :new})
337
364
  book2 = Workbook.open(@simple_file1, :force => {:excel => :new})
@@ -354,11 +381,9 @@ describe Workbook do
354
381
 
355
382
  describe "network paths" do
356
383
 
357
- it "should open the workbokk via network path" do
358
- book1 = Workbook.open(@simple_file)
359
- expect{
360
- book2 = Workbook.open(@simple_file_via_network)
361
- }.to_not raise_error
384
+ it "should open the workbook via network path" do
385
+ book1 = Workbook.open(@simple_file_hostname_share_path)
386
+ book2 = Workbook.open(@simple_file_network_path)
362
387
  book1.should === book2
363
388
  book1.Fullname.should == book2.Fullname
364
389
  end
@@ -371,7 +396,7 @@ describe Workbook do
371
396
 
372
397
  before do
373
398
  @book = Workbook.open(@simple_file1)
374
- abs_filename = General.absolute_path(@simple_file1).tr('/','\\')
399
+ abs_filename = General.absolute_path(@simple_file1)
375
400
  @ole_book = WIN32OLE.connect(abs_filename)
376
401
  end
377
402
 
@@ -387,7 +412,7 @@ describe Workbook do
387
412
 
388
413
  it "should yield different Workbook objects for different Excel books" do
389
414
  book3 = Workbook.open(@different_file1)
390
- abs_filename2 = General.absolute_path(@different_file1).tr('/','\\')
415
+ abs_filename2 = General.absolute_path(@different_file1)
391
416
  ole_book2 = WIN32OLE.connect(abs_filename2)
392
417
  book2 = Workbook.new(ole_book2)
393
418
  book2.should_not === @book
@@ -483,7 +508,7 @@ describe Workbook do
483
508
  it "should uplift an open unknown workbook" do
484
509
  ole_excel = WIN32OLE.new('Excel.Application')
485
510
  ws = ole_excel.Workbooks
486
- abs_filename = General.absolute_path(@simple_file1).tr('/','\\')
511
+ abs_filename = General.absolute_path(@simple_file1)
487
512
  ole_workbook = ws.Open(abs_filename)
488
513
  new_book = Workbook.new(ole_workbook)
489
514
  new_book.Fullname.should == ole_workbook.Fullname
@@ -493,7 +518,7 @@ describe Workbook do
493
518
  it "should uplift an open unknown workbook and make it visible" do
494
519
  ole_excel = WIN32OLE.new('Excel.Application')
495
520
  ws = ole_excel.Workbooks
496
- abs_filename = General.absolute_path(@simple_file1).tr('/','\\')
521
+ abs_filename = General.absolute_path(@simple_file1)
497
522
  ole_workbook = ws.Open(abs_filename)
498
523
  new_book = Workbook.new(ole_workbook, :visible => true)
499
524
  new_book.Fullname.should == ole_workbook.Fullname
@@ -505,7 +530,7 @@ describe Workbook do
505
530
  it "should uplift an open unknown workbook and make it visible and readonly" do
506
531
  ole_excel = WIN32OLE.new('Excel.Application')
507
532
  ws = ole_excel.Workbooks
508
- abs_filename = General.absolute_path(@simple_file1).tr('/','\\')
533
+ abs_filename = General.absolute_path(@simple_file1)
509
534
  ole_workbook = ws.Open(abs_filename)
510
535
  new_book = Workbook.new(ole_workbook, :visible => true)
511
536
  new_book.Fullname.should == ole_workbook.Fullname
@@ -607,22 +632,22 @@ describe Workbook do
607
632
  end
608
633
 
609
634
  it "should fetch the workbook" do
610
- workbook = @book.ole_workbook
611
- new_book = Workbook.new(workbook)
635
+ ole_workbook = @book.ole_workbook
636
+ new_book = Workbook.new(ole_workbook)
612
637
  new_book.should be_a Workbook
613
638
  new_book.should be_alive
614
639
  new_book.should == @book
615
640
  new_book.filename.should == @book.filename
616
641
  new_book.excel.should == @book.excel
617
642
  new_book.excel.Visible.should be false
618
- new_book.excel.DisplayAlerts.should be false
643
+ #new_book.excel.DisplayAlerts.should be false
619
644
  new_book.should === @book
620
645
  new_book.close
621
646
  end
622
647
 
623
648
  it "should fetch the workbook" do
624
- workbook = @book.ole_workbook
625
- new_book = Workbook.new(workbook, :visible => true)
649
+ ole_workbook = @book.ole_workbook
650
+ new_book = Workbook.new(ole_workbook, :visible => true)
626
651
  new_book.should be_a Workbook
627
652
  new_book.should be_alive
628
653
  new_book.should == @book
@@ -635,8 +660,8 @@ describe Workbook do
635
660
  end
636
661
 
637
662
  it "should yield an identical Workbook and set visible value" do
638
- workbook = @book.ole_workbook
639
- new_book = Workbook.new(workbook, :visible => true)
663
+ ole_workbook = @book.ole_workbook
664
+ new_book = Workbook.new(ole_workbook, :visible => true)
640
665
  new_book.excel.displayalerts = true
641
666
  new_book.should be_a Workbook
642
667
  new_book.should be_alive
@@ -703,6 +728,26 @@ describe Workbook do
703
728
  book2.close
704
729
  end
705
730
 
731
+ it "should yield identical Workbook objects for identical Excel books when reopening with current excel" do
732
+ @book.should be_alive
733
+ @book.close
734
+ @book.should_not be_alive
735
+ book2 = Workbook.open(@simple_file1, :default => {:excel => :current})
736
+ book2.should === @book
737
+ book2.should be_alive
738
+ book2.close
739
+ end
740
+
741
+ it "should yield identical Workbook objects for identical Excel books when reopening with current excel" do
742
+ @book.should be_alive
743
+ @book.close
744
+ @book.should_not be_alive
745
+ book2 = Workbook.open(@simple_file1, :force => {:excel => :current})
746
+ book2.should === @book
747
+ book2.should be_alive
748
+ book2.close
749
+ end
750
+
706
751
  it "should yield identical Workbook objects when reopening and the Excel is closed" do
707
752
  @book.should be_alive
708
753
  @book.close
@@ -887,14 +932,14 @@ describe Workbook do
887
932
  book4.should be_alive
888
933
  book4.should be_a Workbook
889
934
  book4.excel.should == book2.excel
890
- #book4.Readonly.should == true
935
+ book4.Readonly.should == true
891
936
  book4.should_not == book2
892
937
  book4.close
893
938
  book5 = Workbook.open(@simple_file1, :force => {:excel => book2})
894
939
  book5.should be_alive
895
940
  book5.should be_a Workbook
896
941
  book5.excel.should == book2.excel
897
- #book5.Readonly.should == true
942
+ book5.Readonly.should == true
898
943
  book5.should_not == book2
899
944
  book5.close
900
945
  book3.close
@@ -1043,14 +1088,14 @@ describe Workbook do
1043
1088
  book4.should be_alive
1044
1089
  book4.should be_a Workbook
1045
1090
  book4.excel.should == book2.excel
1046
- #book4.Readonly.should == true
1091
+ book4.Readonly.should == true
1047
1092
  book4.should_not == book2
1048
1093
  book4.close
1049
1094
  book5 = Workbook.open(@simple_file1, :excel => book2)
1050
1095
  book5.should be_alive
1051
1096
  book5.should be_a Workbook
1052
1097
  book5.excel.should == book2.excel
1053
- #book5.Readonly.should == true
1098
+ book5.Readonly.should == true
1054
1099
  book5.should_not == book2
1055
1100
  book5.close
1056
1101
  book3.close
@@ -1201,14 +1246,14 @@ describe Workbook do
1201
1246
  book4.should be_alive
1202
1247
  book4.should be_a Workbook
1203
1248
  book4.excel.should == book2.excel
1204
- #book4.Readonly.should == false
1249
+ book4.Readonly.should == true
1205
1250
  book4.should_not == book2
1206
1251
  book4.close
1207
1252
  book5 = Workbook.open(@simple_file1, :force_excel => book2)
1208
1253
  book5.should be_alive
1209
1254
  book5.should be_a Workbook
1210
1255
  book5.excel.should == book2.excel
1211
- #book5.Readonly.should == false
1256
+ book5.Readonly.should == true
1212
1257
  book5.should_not == book2
1213
1258
  book5.close
1214
1259
  book3.close
@@ -1920,6 +1965,7 @@ describe Workbook do
1920
1965
  @book = Workbook.open(@simple_file)
1921
1966
  @sheet = @book.sheet(1)
1922
1967
  @book.add_sheet(@sheet, :as => 'a_name')
1968
+ @book.visible = true
1923
1969
  end
1924
1970
 
1925
1971
  after do
@@ -1953,13 +1999,22 @@ describe Workbook do
1953
1999
 
1954
2000
  it "should open the new book and close the unsaved book, if user answers 'yes'" do
1955
2001
  # "Yes" is the default. --> language independent
1956
- @key_sender.puts "{enter}"
2002
+ #@key_sender.puts "{enter}"
1957
2003
  @new_book = Workbook.open(@simple_file1, :if_unsaved => :alert)
1958
2004
  @new_book.should be_alive
1959
2005
  @new_book.filename.downcase.should == @simple_file1.downcase
1960
2006
  @book.should_not be_alive
1961
2007
  end
1962
2008
 
2009
+ it "should open the new book and close the unsaved book, if user answers 'yes'" do
2010
+ # "Yes" is the default. --> language independent
2011
+ @key_sender.puts "{enter}"
2012
+ @new_book = Workbook.open(@simple_file1, :if_unsaved => :excel)
2013
+ @new_book.should be_alive
2014
+ @new_book.filename.downcase.should == @simple_file1.downcase
2015
+ @book.should_not be_alive
2016
+ end
2017
+
1963
2018
  it "should not open the new book and not close the unsaved book, if user answers 'no'" do
1964
2019
  # "No" is right to "Yes" (the default). --> language independent
1965
2020
  # strangely, in the "no" case, the question will sometimes be repeated three times
@@ -1973,19 +2028,11 @@ describe Workbook do
1973
2028
  @book.should be_alive
1974
2029
  end
1975
2030
 
1976
- it "should open the new book and close the unsaved book, if user answers 'yes'" do
1977
- # "Yes" is the default. --> language independent
1978
- @key_sender.puts "{enter}"
1979
- @new_book = Workbook.open(@simple_file1, :if_unsaved => :excel)
1980
- @new_book.should be_alive
1981
- @new_book.filename.downcase.should == @simple_file1.downcase
1982
- #@book.should_not be_alive
1983
- end
2031
+
1984
2032
 
1985
2033
  it "should not open the new book and not close the unsaved book, if user answers 'no'" do
1986
2034
  # "No" is right to "Yes" (the default). --> language independent
1987
- # strangely, in the "no" case, the question will sometimes be repeated three times
1988
- #@book.excel.Visible = true
2035
+ # strangely, in the "no" case, the question will sometimes be repeated three time
1989
2036
  @key_sender.puts "{right}{enter}"
1990
2037
  @key_sender.puts "{right}{enter}"
1991
2038
  @key_sender.puts "{right}{enter}"
@@ -2055,7 +2102,7 @@ describe Workbook do
2055
2102
  if :if_obstructed is :close_if_saved" do
2056
2103
  expect{
2057
2104
  new_book = Workbook.open(@simple_file1, :if_obstructed => :close_if_saved)
2058
- }.to raise_error(WorkbookBlocked, /workbook with the same name in a different path is unsaved/)
2105
+ }.to raise_error(WorkbookBlocked, /same name in a different path/)
2059
2106
  @book.save
2060
2107
  new_book = Workbook.open(@simple_file1, :if_obstructed => :close_if_saved)
2061
2108
  @book.should_not be_alive
@@ -2222,7 +2269,7 @@ describe Workbook do
2222
2269
 
2223
2270
  context "with :read_only" do
2224
2271
 
2225
- it "should reopen the book with writable (unsaved changes from readonly will not be saved)" do
2272
+ it "should not reopen the book with writable" do
2226
2273
  book = Workbook.open(@simple_file1, :read_only => true)
2227
2274
  book.ReadOnly.should be true
2228
2275
  book.should be_alive
@@ -2234,27 +2281,10 @@ describe Workbook do
2234
2281
  new_book.ReadOnly.should be false
2235
2282
  new_book.should be_alive
2236
2283
  book.should be_alive
2237
- new_book.should == book
2238
- new_sheet = new_book.sheet(1)
2239
- new_cell_value = new_sheet[1,1].Value
2240
- new_cell_value.should == old_cell_value
2284
+ new_book.should == book
2241
2285
  end
2242
2286
 
2243
- it "should not raise an error when trying to reopen the book as read_only while the writable book had unsaved changes" do
2244
- book = Workbook.open(@simple_file1, :read_only => false)
2245
- book.ReadOnly.should be false
2246
- book.should be_alive
2247
- sheet = book.sheet(1)
2248
- old_cell_value = sheet[1,1].Value
2249
- sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
2250
- book.Saved.should be false
2251
- new_book = Workbook.open(@simple_file1, :read_only => true, :if_unsaved => :accept)
2252
- new_book.ReadOnly.should be true
2253
- new_book.Saved.should be true
2254
- new_book.should == book
2255
- end
2256
-
2257
- it "should reopen the book with writable in the same Excel instance (unsaved changes from readonly will not be saved)" do
2287
+ it "should not reopen the book with writable" do
2258
2288
  book = Workbook.open(@simple_file1, :read_only => true)
2259
2289
  book.ReadOnly.should be true
2260
2290
  book.should be_alive
@@ -2262,28 +2292,39 @@ describe Workbook do
2262
2292
  old_cell_value = sheet[1,1].Value
2263
2293
  sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
2264
2294
  book.Saved.should be false
2265
- new_book = Workbook.open(@simple_file1, :if_unsaved => :accept, :force => {:excel => book.excel}, :read_only => false)
2295
+ new_book = Workbook.open(@simple_file1, :read_only => false, :if_unsaved => :forget)
2266
2296
  new_book.ReadOnly.should be false
2267
2297
  new_book.should be_alive
2268
- book.should be_alive
2269
- new_book.should == book
2298
+ book.should_not be_alive
2299
+ new_book.should_not == book
2270
2300
  new_sheet = new_book.sheet(1)
2271
2301
  new_cell_value = new_sheet[1,1].Value
2272
2302
  new_cell_value.should == old_cell_value
2273
2303
  end
2274
2304
 
2275
- it "should reopen the book with readonly (unsaved changes of the writable should be saved)" do
2276
- book = Workbook.open(@simple_file1, :force => {:excel => :new}, :read_only => false)
2305
+ it "should raise an error when trying to reopen the book as read_only while the writable book had unsaved changes" do
2306
+ book = Workbook.open(@simple_file1, :read_only => false)
2277
2307
  book.ReadOnly.should be false
2278
2308
  book.should be_alive
2279
2309
  sheet = book.sheet(1)
2280
2310
  old_cell_value = sheet[1,1].Value
2281
2311
  sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
2282
2312
  book.Saved.should be false
2283
- new_book = Workbook.open(@simple_file1, :force => {:excel => book.excel}, :read_only => true, :if_unsaved => :accept)
2313
+ expect{
2314
+ Workbook.open(@simple_file1, :read_only => true, :if_unsaved => :accept)
2315
+ }.to raise_error(OptionInvalid)
2316
+ end
2317
+
2318
+ it "should not raise an error when trying to reopen the book as read_only while the writable book had unsaved changes" do
2319
+ book = Workbook.open(@simple_file1, :read_only => false)
2320
+ book.ReadOnly.should be false
2321
+ book.should be_alive
2322
+ sheet = book.sheet(1)
2323
+ old_cell_value = sheet[1,1].Value
2324
+ sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
2325
+ book.Saved.should be false
2326
+ new_book = Workbook.open(@simple_file1, :read_only => true, :if_unsaved => :save)
2284
2327
  new_book.ReadOnly.should be true
2285
- new_book.Saved.should be true
2286
- new_book.should == book
2287
2328
  new_sheet = new_book.sheet(1)
2288
2329
  new_cell_value = new_sheet[1,1].Value
2289
2330
  new_cell_value.should_not == old_cell_value