robust_excel_ole 1.31 → 1.32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog +20 -1
  3. data/README.rdoc +118 -18
  4. data/___dummy_workbook.xls +0 -0
  5. data/benchmarking/creek_example.rb +1 -1
  6. data/benchmarking/roo_example.rb +1 -1
  7. data/benchmarking/simple_xlsx_reader_example.rb +1 -1
  8. data/benchmarking/spreadsheet_example.rb +1 -1
  9. data/docs/README_excel.rdoc +16 -24
  10. data/docs/README_listobjects.rdoc +176 -0
  11. data/docs/README_open.rdoc +12 -12
  12. data/docs/README_ranges.rdoc +72 -55
  13. data/docs/README_save_close.rdoc +3 -3
  14. data/docs/README_sheet.rdoc +18 -13
  15. data/examples/example_ruby_library.rb +2 -2
  16. data/examples/introductory_examples/example_range.rb +2 -2
  17. data/examples/modifying_sheets/example_access_sheets_and_cells.rb +6 -6
  18. data/examples/modifying_sheets/example_add_names.rb +1 -1
  19. data/examples/modifying_sheets/example_concating.rb +1 -1
  20. data/examples/modifying_sheets/example_copying.rb +2 -2
  21. data/examples/modifying_sheets/example_listobjects.rb +86 -0
  22. data/examples/modifying_sheets/example_naming.rb +1 -1
  23. data/examples/modifying_sheets/example_ranges.rb +1 -1
  24. data/examples/open_save_close/example_control_to_excel.rb +1 -1
  25. data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +1 -1
  26. data/examples/open_save_close/example_if_obstructed_save.rb +3 -3
  27. data/examples/open_save_close/example_if_unsaved_accept.rb +1 -1
  28. data/examples/open_save_close/example_if_unsaved_forget.rb +3 -3
  29. data/examples/open_save_close/example_if_unsaved_forget_more.rb +4 -4
  30. data/examples/open_save_close/example_read_only.rb +1 -1
  31. data/examples/open_save_close/example_simple.rb +1 -1
  32. data/examples/open_save_close/example_unobtrusively.rb +3 -3
  33. data/lib/robust_excel_ole/address_tool.rb +54 -44
  34. data/lib/robust_excel_ole/base.rb +4 -6
  35. data/lib/robust_excel_ole/bookstore.rb +2 -16
  36. data/lib/robust_excel_ole/cell.rb +16 -21
  37. data/lib/robust_excel_ole/excel.rb +131 -186
  38. data/lib/robust_excel_ole/general.rb +82 -55
  39. data/lib/robust_excel_ole/list_object.rb +182 -109
  40. data/lib/robust_excel_ole/list_row.rb +65 -38
  41. data/lib/robust_excel_ole/range.rb +125 -93
  42. data/lib/robust_excel_ole/range_owners.rb +52 -66
  43. data/lib/robust_excel_ole/version.rb +1 -1
  44. data/lib/robust_excel_ole/workbook.rb +168 -176
  45. data/lib/robust_excel_ole/worksheet.rb +177 -141
  46. data/robust_excel_ole.gemspec +4 -3
  47. data/spec/bookstore_spec.rb +2 -3
  48. data/spec/cell_spec.rb +9 -9
  49. data/spec/data/more_data/workbook.xls +0 -0
  50. data/spec/excel_spec.rb +132 -85
  51. data/spec/general_spec.rb +47 -15
  52. data/spec/list_object_spec.rb +258 -145
  53. data/spec/list_row_spec.rb +218 -0
  54. data/spec/range_spec.rb +76 -29
  55. data/spec/spec_helper.rb +15 -1
  56. data/spec/workbook_spec.rb +75 -34
  57. data/spec/workbook_specs/workbook_all_spec.rb +2 -1
  58. data/spec/workbook_specs/workbook_misc_spec.rb +20 -13
  59. data/spec/workbook_specs/workbook_open_spec.rb +47 -45
  60. data/spec/workbook_specs/workbook_save_spec.rb +21 -22
  61. data/spec/workbook_specs/workbook_sheet_spec.rb +3 -3
  62. data/spec/workbook_specs/workbook_unobtr_spec.rb +303 -303
  63. data/spec/worksheet_spec.rb +522 -318
  64. metadata +37 -2
@@ -33,8 +33,9 @@ Gem::Specification.new do |s|
33
33
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
34
34
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
35
35
  s.require_paths = ["lib"]
36
- s.add_runtime_dependency "pry", '>= 0.12.1'
37
- s.add_runtime_dependency "pry-bond", '>=0.0.1'
38
- s.add_development_dependency "rspec", '>= 2.6.0'
36
+ s.add_runtime_dependency 'win32api', '~> 0.1'
37
+ s.add_runtime_dependency 'pry', '~> 0.12', '>= 0.12.1'
38
+ s.add_runtime_dependency 'pry-bond', '~> 0.0', '>= 0.0.1'
39
+ s.add_development_dependency 'rspec', '~> 2.6', '>= 2.6.0'
39
40
  s.required_ruby_version = '>= 2.1'
40
41
  end
@@ -419,7 +419,7 @@ describe Bookstore do
419
419
  @bookstore.store(@book2)
420
420
  @bookstore.store(@book3)
421
421
  sheet = @book3.sheet(1)
422
- sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
422
+ sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
423
423
  @book.ReadOnly.should be true
424
424
  @book2.ReadOnly.should be false
425
425
  @book3.ReadOnly.should be true
@@ -560,8 +560,7 @@ describe Bookstore do
560
560
  end
561
561
 
562
562
  it "should show books" do
563
- expect{
564
- @bookstore.books}.to_not raise_error
563
+ @bookstore.books.should == [@book, @book2]
565
564
  end
566
565
 
567
566
  end
data/spec/cell_spec.rb CHANGED
@@ -19,7 +19,7 @@ describe Cell do
19
19
  @merge_cells_file = @dir + '/merge_cells.xls'
20
20
  @book = Workbook.open(@simple_file)
21
21
  @sheet = @book.sheet(1)
22
- @cell = @sheet[1, 1]
22
+ @cell = @sheet.range([1, 1])
23
23
  end
24
24
 
25
25
  after do
@@ -55,7 +55,7 @@ describe Cell do
55
55
  before do
56
56
  @book1 = Workbook.open(@dir + '/workbook.xls')
57
57
  @sheet1 = @book1.sheet(1)
58
- @cell1 = @sheet1[1,1]
58
+ @cell1 = @sheet1.range([1,1])
59
59
  end
60
60
 
61
61
  after do
@@ -76,22 +76,22 @@ describe Cell do
76
76
  end
77
77
 
78
78
  it "merged cell get same value" do
79
- @sheet[1, 1].Value.should be_nil
80
- @sheet[2, 1].Value.should eq 'first merged'
79
+ @sheet[1, 1].should be_nil
80
+ @sheet[2, 1].should eq 'first merged'
81
81
  end
82
82
 
83
83
  it "set merged cell" do
84
- @sheet[2, 1].Value = "set merge cell"
85
- @sheet[2, 1].Value.should eq "set merge cell"
86
- @sheet[2, 2].Value.should eq "set merge cell"
84
+ @sheet[2, 1] = "set merge cell"
85
+ @sheet[2, 1].should eq "set merge cell"
86
+ @sheet[2, 2].should eq "set merge cell"
87
87
  end
88
88
  end
89
89
 
90
90
  describe "==" do
91
91
 
92
92
  it "should check equality of cells" do
93
- @cell.should == @sheet[1,1]
94
- @cell.should_not == @sheet[1,2]
93
+ @cell.should == @sheet.range([1,1])
94
+ @cell.should_not == @sheet.range([1,2])
95
95
  end
96
96
 
97
97
  end
Binary file
data/spec/excel_spec.rb CHANGED
@@ -154,7 +154,7 @@ module RobustExcelOle
154
154
  excel1.should_not be_alive
155
155
  excel2.should be_alive
156
156
  excel2.ole_excel.Hwnd.should == @ole_excel1.Hwnd
157
- Excel.excels_number.should == 2
157
+ Excel.instance_count.should == 2
158
158
  end
159
159
 
160
160
  it "should make the Excel instance not alive if the Excel that was connected with was closed" do
@@ -219,7 +219,7 @@ module RobustExcelOle
219
219
  excel1.should be_alive
220
220
  excel1.ole_excel.Hwnd.should_not == @ole_excel1.Hwnd
221
221
  excel1.ole_excel.Hwnd.should_not == @ole_excel2.Hwnd
222
- Excel.excels_number.should == 3
222
+ Excel.instance_count.should == 3
223
223
  end
224
224
 
225
225
  end
@@ -378,7 +378,7 @@ module RobustExcelOle
378
378
  excel2 = Excel.current
379
379
  excel1.should_not be_alive
380
380
  excel2.should be_alive
381
- Excel.excels_number.should == 1
381
+ Excel.instance_count.should == 1
382
382
  end
383
383
 
384
384
  it "should make the Excel instance not alive if the Excel that was connected with was closed" do
@@ -389,7 +389,7 @@ module RobustExcelOle
389
389
  excel1.should_not be_alive
390
390
  excel2.should_not be_alive
391
391
  sleep 0.2
392
- Excel.excels_number.should == 0
392
+ Excel.instance_count.should == 0
393
393
  end
394
394
 
395
395
  it "should reuse the first opened Excel instance if not the first opened Excel instance was closed" do
@@ -417,11 +417,11 @@ module RobustExcelOle
417
417
  it "should return right number of excel instances" do
418
418
  Excel.kill_all
419
419
  sleep 0.2
420
- n1 = Excel.excels_number
420
+ n1 = Excel.instance_count
421
421
  e1 = Excel.create
422
- Excel.excels_number.should == n1 + 1
422
+ Excel.instance_count.should == n1 + 1
423
423
  e2 = Excel.create
424
- Excel.excels_number.should == n1 + 2
424
+ Excel.instance_count.should == n1 + 2
425
425
  end
426
426
  end
427
427
 
@@ -611,8 +611,8 @@ module RobustExcelOle
611
611
  book1 = Workbook.open(@simple_file1, :visible => true)
612
612
  @excel1 = book1.excel
613
613
  sheet1 = book1.sheet(1)
614
- @old_cell_value1 = sheet1[1,1].Value
615
- sheet1[1,1] = sheet1[1,1].Value == "foo" ? "bar" : "foo"
614
+ @old_cell_value1 = sheet1[1,1]
615
+ sheet1[1,1] = sheet1[1,1] == "foo" ? "bar" : "foo"
616
616
  book1.Saved.should be false
617
617
  end
618
618
 
@@ -622,7 +622,7 @@ module RobustExcelOle
622
622
  @excel1.should_not be_alive
623
623
  new_book1 = Workbook.open(@simple_file1)
624
624
  new_sheet1 = new_book1.sheet(1)
625
- new_sheet1[1,1].Value.should_not == @old_cell_value1
625
+ new_sheet1[1,1].should_not == @old_cell_value1
626
626
  new_book1.close
627
627
  result.should == [1,0]
628
628
  end
@@ -633,7 +633,7 @@ module RobustExcelOle
633
633
  @excel1.should_not be_alive
634
634
  new_book1 = Workbook.open(@simple_file1)
635
635
  new_sheet1 = new_book1.sheet(1)
636
- new_sheet1[1,1].Value.should == @old_cell_value1
636
+ new_sheet1[1,1].should == @old_cell_value1
637
637
  new_book1.close
638
638
  result.should == [1,0]
639
639
  end
@@ -647,8 +647,8 @@ module RobustExcelOle
647
647
  @excel1 = book1.excel
648
648
  @excel2 = book2.excel
649
649
  sheet2 = book2.sheet(1)
650
- @old_cell_value2 = sheet2[1,1].Value
651
- sheet2[1,1] = sheet2[1,1].Value == "foo" ? "bar" : "foo"
650
+ @old_cell_value2 = sheet2[1,1]
651
+ sheet2[1,1] = sheet2[1,1] == "foo" ? "bar" : "foo"
652
652
  end
653
653
 
654
654
  it "should close the first Excel without unsaved workbooks and then raise an error" do
@@ -684,7 +684,7 @@ module RobustExcelOle
684
684
  @excel2.should_not be_alive
685
685
  new_book2 = Workbook.open(@different_file1)
686
686
  new_sheet2 = new_book2.sheet(1)
687
- new_sheet2[1,1].Value.should_not == @old_cell_value2
687
+ new_sheet2[1,1].should_not == @old_cell_value2
688
688
  new_book2.close
689
689
  result.should == [2,0]
690
690
  end
@@ -696,7 +696,7 @@ module RobustExcelOle
696
696
  @excel2.should_not be_alive
697
697
  new_book2 = Workbook.open(@different_file1)
698
698
  new_sheet2 = new_book2.sheet(1)
699
- new_sheet2[1,1].Value.should == @old_cell_value2
699
+ new_sheet2[1,1].should == @old_cell_value2
700
700
  new_book2.close
701
701
  result.should == [2,0]
702
702
  end
@@ -714,7 +714,7 @@ module RobustExcelOle
714
714
  @book1 = Workbook.open(@simple_file1, :force_excel => :new)
715
715
  @book2 = Workbook.open(@another_simple_file, :force_excel => :new)
716
716
  @book3 = Workbook.open(@different_file, :force_excel => :new)
717
- old_cell_value1 = @book2.sheet(1)[1,1].Value
717
+ old_cell_value1 = @book2.sheet(1)[1,1]
718
718
  @book2.sheet(1)[1,1] = old_cell_value1 == "foo" ? "bar" : "foo"
719
719
  end
720
720
 
@@ -739,7 +739,7 @@ module RobustExcelOle
739
739
  @book1 = Workbook.open(@simple_file1, :force_excel => :new)
740
740
  @book2 = Workbook.open(@another_simple_file, :force_excel => :new)
741
741
  @book3 = Workbook.open(@different_file, :force_excel => :new)
742
- old_cell_value1 = @book2.sheet(1)[1,1].Value
742
+ old_cell_value1 = @book2.sheet(1)[1,1]
743
743
  @book2.sheet(1)[1,1] = old_cell_value1 == "foo" ? "bar" : "foo"
744
744
  end
745
745
 
@@ -808,12 +808,12 @@ module RobustExcelOle
808
808
  @excel = Excel.create
809
809
  @book = Workbook.open(@simple_file)
810
810
  sheet = @book.sheet(1)
811
- @old_cell_value = sheet[1,1].Value
812
- sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
811
+ @old_cell_value = sheet[1,1]
812
+ sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
813
813
  @book2 = Workbook.open(@another_simple_file)
814
814
  sheet2 = @book2.sheet(1)
815
- @old_cell_value2 = sheet2[1,1].Value
816
- sheet2[1,1] = sheet2[1,1].Value == "foo" ? "bar" : "foo"
815
+ @old_cell_value2 = sheet2[1,1]
816
+ sheet2[1,1] = sheet2[1,1] == "foo" ? "bar" : "foo"
817
817
  @excel.should be_alive
818
818
  @book.should be_alive
819
819
  @book.saved.should be false
@@ -840,7 +840,7 @@ module RobustExcelOle
840
840
  result.should == 1
841
841
  new_book = Workbook.open(@simple_file)
842
842
  new_sheet = new_book.sheet(1)
843
- new_sheet[1,1].Value.should == @old_cell_value
843
+ new_sheet[1,1].should == @old_cell_value
844
844
  new_book.close
845
845
  end
846
846
 
@@ -854,7 +854,7 @@ module RobustExcelOle
854
854
  @excel.should_not be_alive
855
855
  new_book = Workbook.open(@simple_file)
856
856
  new_sheet = new_book.sheet(1)
857
- new_sheet[1,1].Value.should == @old_cell_value
857
+ new_sheet[1,1].should == @old_cell_value
858
858
  new_book.close
859
859
  end
860
860
 
@@ -866,7 +866,7 @@ module RobustExcelOle
866
866
  @excel.should_not be_alive
867
867
  new_book = Workbook.open(@simple_file)
868
868
  new_sheet = new_book.sheet(1)
869
- new_sheet[1,1].Value.should_not == @old_cell_value
869
+ new_sheet[1,1].should_not == @old_cell_value
870
870
  new_book.close
871
871
  end
872
872
 
@@ -884,8 +884,8 @@ module RobustExcelOle
884
884
  @excel = Excel.create(:visible => true)
885
885
  @book = Workbook.open(@simple_file, :visible => true)
886
886
  sheet = @book.sheet(1)
887
- @old_cell_value = sheet[1,1].Value
888
- sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
887
+ @old_cell_value = sheet[1,1]
888
+ sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
889
889
  end
890
890
 
891
891
  after do
@@ -903,7 +903,7 @@ module RobustExcelOle
903
903
  result.should == 1
904
904
  new_book = Workbook.open(@simple_file)
905
905
  new_sheet = new_book.sheet(1)
906
- new_sheet[1,1].Value.should_not == @old_cell_value
906
+ new_sheet[1,1].should_not == @old_cell_value
907
907
  new_book.close
908
908
  end
909
909
 
@@ -918,7 +918,7 @@ module RobustExcelOle
918
918
  @book.should_not be_alive
919
919
  new_book = Workbook.open(@simple_file)
920
920
  new_sheet = new_book.sheet(1)
921
- new_sheet[1,1].Value.should == @old_cell_value
921
+ new_sheet[1,1].should == @old_cell_value
922
922
  new_book.close
923
923
  end
924
924
 
@@ -944,11 +944,11 @@ module RobustExcelOle
944
944
  before do
945
945
  @book = Workbook.open(@simple_file)
946
946
  sheet = @book.sheet(1)
947
- @old_cell_value = sheet[1,1].Value
948
- sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
947
+ @old_cell_value = sheet[1,1]
948
+ sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
949
949
  @book3 = Workbook.open(@different_file, :read_only => true)
950
950
  sheet3 = @book3.sheet(1)
951
- sheet3[1,1] = sheet3[1,1].Value == "foo" ? "bar" : "foo"
951
+ sheet3[1,1] = sheet3[1,1] == "foo" ? "bar" : "foo"
952
952
  @excel = @book.excel
953
953
  @book2 = Workbook.open(@another_simple_file, :force_excel => :new)
954
954
  end
@@ -978,7 +978,7 @@ module RobustExcelOle
978
978
  @excel.Workbooks.Count.should == 0
979
979
  new_book = Workbook.open(@simple_file)
980
980
  new_sheet = new_book.sheet(1)
981
- new_sheet[1,1].Value.should == @old_cell_value
981
+ new_sheet[1,1].should == @old_cell_value
982
982
  new_book.close
983
983
  end
984
984
 
@@ -989,7 +989,7 @@ module RobustExcelOle
989
989
  @excel.Workbooks.Count.should == 0
990
990
  new_book = Workbook.open(@simple_file)
991
991
  new_sheet = new_book.sheet(1)
992
- new_sheet[1,1].Value.should_not == @old_cell_value
992
+ new_sheet[1,1].should_not == @old_cell_value
993
993
  new_book.close
994
994
  end
995
995
 
@@ -1038,10 +1038,10 @@ module RobustExcelOle
1038
1038
  before do
1039
1039
  @book = Workbook.open(@simple_file)
1040
1040
  sheet = @book.sheet(1)
1041
- sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
1041
+ sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
1042
1042
  @book3 = Workbook.open(@different_file, :read_only => true)
1043
1043
  sheet3 = @book3.sheet(1)
1044
- sheet3[1,1] = sheet3[1,1].Value == "foo" ? "bar" : "foo"
1044
+ sheet3[1,1] = sheet3[1,1] == "foo" ? "bar" : "foo"
1045
1045
  @book.Saved.should be false
1046
1046
  @book3.Saved.should be false
1047
1047
  end
@@ -1060,20 +1060,39 @@ module RobustExcelOle
1060
1060
  end
1061
1061
  end
1062
1062
 
1063
- describe "workbooks, each, each_with_index" do
1063
+ describe "each, each_with_index, workbooks" do
1064
1064
 
1065
- before do
1065
+ before do
1066
1066
  @excel = Excel.create
1067
- @book1 = Workbook.open(@simple_file)
1068
- @book2 = Workbook.open(@different_file)
1067
+ end
1068
+
1069
+ it "should yield empty list" do
1070
+ @excel.count.should == 0
1071
+ @excel.workbooks.should be_empty
1069
1072
  end
1070
1073
 
1071
1074
  it "should list workbooks" do
1075
+ @book1 = Workbook.open(@simple_file)
1076
+ @book2 = Workbook.open(@different_file)
1072
1077
  workbooks = @excel.workbooks
1073
1078
  workbooks.should == [@book1,@book2]
1074
1079
  end
1075
1080
 
1081
+ it "should concatenate" do
1082
+ @book1 = Workbook.open(@simple_file)
1083
+ @book2 = Workbook.open(@different_file)
1084
+ i = 0
1085
+ @excel.each.with_index do |workbook,i|
1086
+ workbook.should be_alive
1087
+ workbook.should be_a Workbook
1088
+ workbook.filename.should == @simple_file if i == 0
1089
+ workbook.filename.should == @different_file if i == 1
1090
+ end
1091
+ end
1092
+
1076
1093
  it "should each_workbook" do
1094
+ @book1 = Workbook.open(@simple_file)
1095
+ @book2 = Workbook.open(@different_file)
1077
1096
  i = 0
1078
1097
  @excel.each_workbook do |workbook|
1079
1098
  workbook.should be_alive
@@ -1085,6 +1104,9 @@ module RobustExcelOle
1085
1104
  end
1086
1105
 
1087
1106
  it "should each_workbook_with_index" do
1107
+ @book1 = Workbook.open(@simple_file)
1108
+ @book2 = Workbook.open(@different_file)
1109
+ i = 0
1088
1110
  @excel.each_workbook_with_index do |workbook,i|
1089
1111
  workbook.should be_alive
1090
1112
  workbook.should be_a Workbook
@@ -1094,6 +1116,8 @@ module RobustExcelOle
1094
1116
  end
1095
1117
 
1096
1118
  it "should each_workbook with options" do
1119
+ @book1 = Workbook.open(@simple_file)
1120
+ @book2 = Workbook.open(@different_file)
1097
1121
  i = 0
1098
1122
  @excel.each_workbook(:visible => true) do |workbook|
1099
1123
  workbook.should be_alive
@@ -1106,6 +1130,8 @@ module RobustExcelOle
1106
1130
  end
1107
1131
 
1108
1132
  it "should set options" do
1133
+ @book1 = Workbook.open(@simple_file)
1134
+ @book2 = Workbook.open(@different_file)
1109
1135
  @excel.each_workbook(:visible => true)
1110
1136
  [1,2].each do |i|
1111
1137
  ole_workbook = @excel.Workbooks.Item(i)
@@ -1113,7 +1139,6 @@ module RobustExcelOle
1113
1139
  end
1114
1140
  end
1115
1141
 
1116
-
1117
1142
  end
1118
1143
 
1119
1144
  describe "unsaved_known_workbooks" do
@@ -1124,32 +1149,24 @@ module RobustExcelOle
1124
1149
 
1125
1150
  it "should return empty list for first Excel instance" do
1126
1151
  book = Workbook.open(@simple_file)
1127
- Excel.unsaved_known_workbooks.should == [[]]
1152
+ Excel.unsaved_known_workbooks.should be_empty
1128
1153
  book.close
1129
1154
  end
1130
1155
 
1131
1156
  it "should return one unsaved book" do
1132
1157
  book = Workbook.open(@simple_file)
1133
1158
  sheet = book.sheet(1)
1134
- sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
1135
- # Excel.unsaved_known_workbooks.should == [[book.ole_workbook]]
1159
+ sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
1136
1160
  unsaved_known_wbs = Excel.unsaved_known_workbooks
1137
1161
  unsaved_known_wbs.size.should == 1
1138
- unsaved_known_wbs.each do |ole_wb_list|
1139
- ole_wb_list.size.should == 1
1140
- ole_wb_list.each do |ole_workbook|
1141
- ole_workbook.Fullname.tr('\\','/').should == @simple_file
1142
- end
1162
+ unsaved_known_wbs.each do |ole_wb|
1163
+ ole_wb.Fullname.tr('\\','/').should == @simple_file
1143
1164
  end
1144
1165
  book2 = Workbook.open(@another_simple_file)
1145
- # Excel.unsaved_known_workbooks.should == [[book.ole_workbook]]
1146
1166
  unsaved_known_wbs = Excel.unsaved_known_workbooks
1147
1167
  unsaved_known_wbs.size.should == 1
1148
- unsaved_known_wbs.each do |ole_wb_list|
1149
- ole_wb_list.size.should == 1
1150
- ole_wb_list.each do |ole_workbook|
1151
- ole_workbook.Fullname.tr('\\','/').should == @simple_file
1152
- end
1168
+ unsaved_known_wbs.each do |ole_wb|
1169
+ ole_wb.Fullname.tr('\\','/').should == @simple_file
1153
1170
  end
1154
1171
  book2.close
1155
1172
  book.close(:if_unsaved => :forget)
@@ -1158,18 +1175,15 @@ module RobustExcelOle
1158
1175
  it "should return two unsaved books" do
1159
1176
  book = Workbook.open(@simple_file)
1160
1177
  sheet = book.sheet(1)
1161
- sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
1178
+ sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
1162
1179
  book2 = Workbook.open(@another_simple_file)
1163
1180
  sheet2 = book2.sheet(1)
1164
- sheet2[1,1] = sheet2[1,1].Value == "foo" ? "bar" : "foo"
1165
- #Excel.unsaved_known_workbooks.should == [[book.ole_workbook, book2.ole_workbook]]
1181
+ sheet2[1,1] = sheet2[1,1] == "foo" ? "bar" : "foo"
1166
1182
  unsaved_known_wbs = Excel.unsaved_known_workbooks
1167
- unsaved_known_wbs.size.should == 1
1168
- unsaved_known_wbs.each do |ole_wb_list|
1169
- ole_wb_list.size.should == 2
1170
- ole_workbook1, ole_workbook2 = ole_wb_list
1171
- ole_workbook1.Fullname.tr('\\','/').should == @simple_file
1172
- ole_workbook2.Fullname.tr('\\','/').should == @another_simple_file
1183
+ unsaved_known_wbs.size.should == 2
1184
+ unsaved_known_wbs.each_with_index do |ole_wb, ind|
1185
+ ole_wb.Fullname.tr('\\','/').should == @simple_file if ind == 0
1186
+ ole_wb.Fullname.tr('\\','/').should == @another_simple_file if ind == 1
1173
1187
  end
1174
1188
  book2.close(:if_unsaved => :forget)
1175
1189
  book.close(:if_unsaved => :forget)
@@ -1182,9 +1196,8 @@ module RobustExcelOle
1182
1196
  begin
1183
1197
  open_books.each do |wb|
1184
1198
  sheet = wb.sheet(1)
1185
- sheet[1,1] = (sheet[1,1].Value == "foo") ? "bar" : "foo"
1199
+ sheet[1,1] = (sheet[1,1] == "foo") ? "bar" : "foo"
1186
1200
  end
1187
- #Excel.unsaved_known_workbooks.should == [[book.ole_workbook], [book2.ole_workbook]]
1188
1201
  unsaved_known_wbs = Excel.unsaved_known_workbooks
1189
1202
  unsaved_known_wbs.size.should == 2
1190
1203
  unsaved_known_wbs.flatten.map{|ole_wb| ole_wb.Fullname.tr('\\','/') }.sort.should == open_books.map{|b| b.filename}.sort
@@ -1809,7 +1822,7 @@ module RobustExcelOle
1809
1822
 
1810
1823
  end
1811
1824
 
1812
- describe "for_this_instance" do
1825
+ describe "set_options" do
1813
1826
 
1814
1827
  before do
1815
1828
  @excel = Excel.new(:reuse => false)
@@ -1819,7 +1832,7 @@ module RobustExcelOle
1819
1832
  end
1820
1833
 
1821
1834
  it "should set options in the Excel instance" do
1822
- @excel.for_this_instance(:displayalerts => true, :visible => true, :screenupdating => true, :calculation => :manual)
1835
+ @excel.set_options(:displayalerts => true, :visible => true, :screenupdating => true, :calculation => :manual)
1823
1836
  @excel.DisplayAlerts.should be true
1824
1837
  @excel.Visible.should be true
1825
1838
  @excel.ScreenUpdating.should be true
@@ -1832,25 +1845,25 @@ module RobustExcelOle
1832
1845
 
1833
1846
  end
1834
1847
 
1835
- context "for_all_workbooks" do
1848
+ context "each_workbook" do
1836
1849
 
1837
1850
  it "should not raise an error for an empty Excel instance" do
1838
1851
  excel = Excel.create
1839
1852
  expect{
1840
- excel.for_all_workbooks(:visible => true, :read_only => true, :check_compatibility => true)
1853
+ excel.each_workbook(:visible => true, :read_only => true, :check_compatibility => true)
1841
1854
  }.to_not raise_error
1842
1855
  end
1843
1856
 
1844
1857
  it "should set options to true for a workbook" do
1845
1858
  book1 = Workbook.open(@simple_file1)
1846
1859
  excel1 = book1.excel
1847
- excel1.for_all_workbooks(:visible => true, :read_only => true, :check_compatibility => true)
1860
+ excel1.each_workbook(:visible => true, :read_only => true, :check_compatibility => true)
1848
1861
  excel1.Visible.should be true
1849
1862
  ole_workbook1 = book1.ole_workbook
1850
1863
  ole_workbook1.Windows(ole_workbook1.Name).Visible.should be true
1851
1864
  ole_workbook1.ReadOnly.should be true
1852
1865
  ole_workbook1.CheckCompatibility.should be true
1853
- excel1.for_all_workbooks(:visible => false, :read_only => false, :check_compatibility => false)
1866
+ excel1.each_workbook(:visible => false, :read_only => false, :check_compatibility => false)
1854
1867
  excel1.Visible.should be true
1855
1868
  ole_workbook1 = book1.ole_workbook
1856
1869
  ole_workbook1.Windows(ole_workbook1.Name).Visible.should be false
@@ -1862,7 +1875,7 @@ module RobustExcelOle
1862
1875
  book1 = Workbook.open(@simple_file1)
1863
1876
  book2 = Workbook.open(@different_file1)
1864
1877
  excel = book1.excel
1865
- excel.for_all_workbooks(:visible => true, :check_compatibility => true, :read_only => true)
1878
+ excel.each_workbook(:visible => true, :check_compatibility => true, :read_only => true)
1866
1879
  excel.Visible.should be true
1867
1880
  ole_workbook1 = book1.ole_workbook
1868
1881
  ole_workbook2 = book2.ole_workbook
@@ -1872,7 +1885,7 @@ module RobustExcelOle
1872
1885
  ole_workbook2.CheckCompatibility.should be true
1873
1886
  ole_workbook1.ReadOnly.should be true
1874
1887
  ole_workbook2.ReadOnly.should be true
1875
- excel.for_all_workbooks(:visible => false, :check_compatibility => false, :read_only => false)
1888
+ excel.each_workbook(:visible => false, :check_compatibility => false, :read_only => false)
1876
1889
  excel.Visible.should be true
1877
1890
  ole_workbook1 = book1.ole_workbook
1878
1891
  ole_workbook2 = book2.ole_workbook
@@ -1886,29 +1899,46 @@ module RobustExcelOle
1886
1899
 
1887
1900
  end
1888
1901
 
1889
- describe "known_excel_instances" do
1902
+ describe "known_running_instance" do
1903
+
1904
+ before do
1905
+ @excel1 = Excel.create
1906
+ @excel2 = Excel.create
1907
+ end
1908
+
1909
+ it "should yield an Excel instance" do
1910
+ Excel.known_running_instance.should == @excel1
1911
+ end
1912
+
1913
+ end
1914
+
1915
+ describe "known_running_instances" do
1890
1916
 
1891
1917
  it "should return empty list" do
1892
- Excel.known_excel_instances.should be_empty
1918
+ Excel.known_running_instances.size.should == 0
1893
1919
  end
1894
1920
 
1895
1921
  it "should return list of one Excel process" do
1896
1922
  excel = Excel.new
1897
- Excel.known_excel_instances.should == [excel]
1898
- excel.close
1923
+ excel_instances = Excel.known_running_instances
1924
+ excel_instances.size.should == 1
1925
+ excel_instances.first.should == excel
1926
+ excel_instances.to_a.should == [excel]
1927
+ res = []
1928
+ excel_instances.each.with_index{|e,i| res << [e,i]}
1929
+ res.should == [[excel,0]]
1899
1930
  end
1900
1931
 
1901
1932
  it "should return list of two Excel processes" do
1902
1933
  excel1 = Excel.create
1903
1934
  excel2 = Excel.create
1904
- Excel.known_excel_instances.should == [excel1,excel2]
1905
- end
1906
-
1907
- it "should return list of two Excel processes" do
1908
- excel1 = Excel.new
1909
- excel2 = Excel.current
1910
- excel3 = Excel.create
1911
- Excel.known_excel_instances.should == [excel1,excel3]
1935
+ excel_instances = Excel.known_running_instances
1936
+ excel_instances.size.should == 2
1937
+ excel_instances.first.should == excel1
1938
+ excel_instances.to_a.should == [excel1, excel2]
1939
+ res = []
1940
+ excel_instances.each.with_index{|e,i| res << [e,i]}
1941
+ res.should == [[excel1,0],[excel2,1]]
1912
1942
  end
1913
1943
 
1914
1944
  end
@@ -1969,6 +1999,23 @@ module RobustExcelOle
1969
1999
  end
1970
2000
  =end
1971
2001
  end
2002
+
2003
+ describe "set_options" do
2004
+
2005
+ before do
2006
+ workbook = Workbook.open(@simple_file1, visible: false)
2007
+ @excel1 = workbook.excel
2008
+ end
2009
+
2010
+ it "should set options" do
2011
+ @excel1.DisplayAlerts.should be false
2012
+ @excel1.Visible.should be false
2013
+ @excel1.set_options(displayalerts: true, visible: true)
2014
+ @excel1.DisplayAlerts.should be true
2015
+ @excel1.Visible.should be true
2016
+ end
2017
+
2018
+ end
1972
2019
 
1973
2020
  describe "generate workbook" do
1974
2021