robust_excel_ole 1.2 → 1.3
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.
- checksums.yaml +4 -4
- data/Changelog +20 -0
- data/README.rdoc +8 -1
- data/docs/README_excel.rdoc +6 -4
- data/docs/README_open.rdoc +25 -17
- data/docs/README_ranges.rdoc +182 -22
- data/docs/README_save_close.rdoc +6 -6
- data/docs/README_sheet.rdoc +5 -1
- data/examples/edit_sheets/example_concating.rb +1 -1
- data/examples/edit_sheets/example_copying.rb +1 -1
- data/examples/edit_sheets/example_expanding.rb +1 -1
- data/examples/edit_sheets/example_naming.rb +1 -1
- data/examples/open_save_close/example_rename_cells.rb +1 -1
- data/lib/robust_excel_ole/book.rb +5 -20
- data/lib/robust_excel_ole/excel.rb +8 -3
- data/lib/robust_excel_ole/range.rb +48 -6
- data/lib/robust_excel_ole/reo_common.rb +124 -10
- data/lib/robust_excel_ole/sheet.rb +45 -35
- data/lib/robust_excel_ole/version.rb +1 -1
- data/spec/book_spec.rb +11 -11
- data/spec/book_specs/book_misc_spec.rb +71 -27
- data/spec/book_specs/book_open_spec.rb +308 -147
- data/spec/book_specs/book_unobtr_spec.rb +2 -2
- data/spec/data/another_workbook.xls +0 -0
- data/spec/data/different_workbook.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +102 -57
- data/spec/general_spec.rb +2 -2
- data/spec/range_spec.rb +37 -1
- data/spec/reo_common_spec.rb +90 -3
- data/spec/sheet_spec.rb +79 -41
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
@@ -21,7 +21,8 @@ module RobustExcelOle
|
|
21
21
|
@workbook = book_class.new(self.Parent)
|
22
22
|
end
|
23
23
|
|
24
|
-
#
|
24
|
+
# sheet name
|
25
|
+
# @returns name of the sheet
|
25
26
|
def name
|
26
27
|
begin
|
27
28
|
@ole_worksheet.Name
|
@@ -30,7 +31,7 @@ module RobustExcelOle
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
#
|
34
|
+
# sets sheet name
|
34
35
|
# @param [String] new_name the new name of the sheet
|
35
36
|
def name= (new_name)
|
36
37
|
begin
|
@@ -44,7 +45,9 @@ module RobustExcelOle
|
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
47
|
-
#
|
48
|
+
# a cell given the defined name or row and column
|
49
|
+
# @params row, column, or name
|
50
|
+
# @returns cell, if row and column are given
|
48
51
|
def [] p1, p2 = :__not_provided
|
49
52
|
if p2 != :__not_provided
|
50
53
|
x, y = p1, p2
|
@@ -58,15 +61,15 @@ module RobustExcelOle
|
|
58
61
|
else
|
59
62
|
name = p1
|
60
63
|
begin
|
61
|
-
|
64
|
+
namevalue_glob(name)
|
62
65
|
rescue REOError
|
63
|
-
|
66
|
+
namevalue(name)
|
64
67
|
end
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
68
|
-
# sets the value of a cell
|
69
|
-
#
|
71
|
+
# sets the value of a cell
|
72
|
+
# @params row and column, or defined name
|
70
73
|
def []= (p1, p2, p3 = :__not_provided)
|
71
74
|
if p3 != :__not_provided
|
72
75
|
x, y, value = p1, p2, p3
|
@@ -74,18 +77,20 @@ module RobustExcelOle
|
|
74
77
|
else
|
75
78
|
name, value = p1, p2
|
76
79
|
begin
|
77
|
-
|
80
|
+
set_namevalue_glob(name, value, :color => 42) # aqua-marin, 4-green
|
78
81
|
rescue REOError
|
79
82
|
begin
|
80
|
-
workbook.
|
83
|
+
workbook.set_namevalue_glob(name, value)
|
81
84
|
rescue REOError
|
82
|
-
|
85
|
+
set_namevalue(name, value)
|
83
86
|
end
|
84
87
|
end
|
85
88
|
end
|
86
89
|
end
|
87
90
|
|
88
|
-
#
|
91
|
+
# value of a cell, if row and column are given
|
92
|
+
# @params row and column
|
93
|
+
# @returns value of the cell
|
89
94
|
def cellval(x,y)
|
90
95
|
xy = "#{x}_#{y}"
|
91
96
|
@cells = { }
|
@@ -98,6 +103,8 @@ module RobustExcelOle
|
|
98
103
|
end
|
99
104
|
|
100
105
|
# sets the value of a cell, if row, column and color of the cell are given
|
106
|
+
# @params [Fixnum] x,y row and column
|
107
|
+
# @option opts [Symbol] :color the color of the cell when set
|
101
108
|
def set_cellval(x,y,value, opts = {:color => 0})
|
102
109
|
begin
|
103
110
|
cell = @ole_worksheet.Cells.Item(x, y)
|
@@ -108,27 +115,24 @@ module RobustExcelOle
|
|
108
115
|
raise RangeNotEvaluatable, "cannot assign value #{value.inspect} to cell (#{y.inspect},#{x.inspect})"
|
109
116
|
end
|
110
117
|
end
|
111
|
-
|
112
|
-
#
|
113
|
-
# @
|
114
|
-
# @
|
115
|
-
#
|
116
|
-
|
118
|
+
|
119
|
+
# creates a range.
|
120
|
+
# @params [Fixnum,Range] row or range of the rows
|
121
|
+
# @params [Fixnum,Range] column or range of columns
|
122
|
+
# row and column of the bottum right cell of a rectangur range
|
123
|
+
# @return [Range] a range
|
124
|
+
def range(int_range1, int_range2)
|
125
|
+
int_range1 = int_range1 .. int_range1 if int_range1.is_a?(Fixnum)
|
126
|
+
int_range2 = int_range2 .. int_range2 if int_range2.is_a?(Fixnum)
|
117
127
|
begin
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
self.Names.Add("Name" => name, "RefersToR1C1" => "=" + address)
|
124
|
-
end
|
125
|
-
rescue WIN32OLERuntimeError => msg
|
126
|
-
#trace "WIN32OLERuntimeError: #{msg.message}"
|
127
|
-
raise RangeNotEvaluatable, "cannot add name #{name.inspect} to cell with row #{row.inspect} and column #{column.inspect}"
|
128
|
+
RobustExcelOle::Range.new(@ole_worksheet.Range(
|
129
|
+
@ole_worksheet.Cells(int_range1.min, int_range2.min),
|
130
|
+
@ole_worksheet.Cells(int_range1.max, int_range2.max)))
|
131
|
+
rescue WIN32OLERuntimeError
|
132
|
+
raise RangeNotCreated, "cannot create range (#{int_range1.inspect},#{int_range2.inspect})"
|
128
133
|
end
|
129
134
|
end
|
130
135
|
|
131
|
-
|
132
136
|
def each
|
133
137
|
each_row do |row_range|
|
134
138
|
row_range.each do |cell|
|
@@ -175,14 +179,14 @@ module RobustExcelOle
|
|
175
179
|
end
|
176
180
|
end
|
177
181
|
|
178
|
-
def row_range(row,
|
179
|
-
|
180
|
-
RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(row ,
|
182
|
+
def row_range(row, integer_range = nil)
|
183
|
+
integer_range ||= 1..@end_column
|
184
|
+
RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(row , integer_range.min ), @ole_worksheet.Cells(row , integer_range.max )))
|
181
185
|
end
|
182
186
|
|
183
|
-
def col_range(col,
|
184
|
-
|
185
|
-
RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(
|
187
|
+
def col_range(col, integer_range = nil)
|
188
|
+
integer_range ||= 1..@end_row
|
189
|
+
RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(integer_range.min , col ), @ole_worksheet.Cells(integer_range.max , col )))
|
186
190
|
end
|
187
191
|
|
188
192
|
|
@@ -238,6 +242,12 @@ module RobustExcelOle
|
|
238
242
|
|
239
243
|
special_last_column >= used_last_column ? special_last_column : used_last_column
|
240
244
|
end
|
245
|
+
|
241
246
|
end
|
242
|
-
|
247
|
+
|
248
|
+
public
|
249
|
+
|
250
|
+
Worksheet = Sheet
|
251
|
+
|
243
252
|
end
|
253
|
+
|
data/spec/book_spec.rb
CHANGED
@@ -1037,12 +1037,12 @@ describe Book do
|
|
1037
1037
|
end
|
1038
1038
|
|
1039
1039
|
it "should return value of a range" do
|
1040
|
-
@book1.
|
1041
|
-
@book1.
|
1042
|
-
@book1.
|
1043
|
-
@book1.
|
1044
|
-
@book1.
|
1045
|
-
@book1.
|
1040
|
+
@book1.namevalue_glob("new").should == "foo"
|
1041
|
+
@book1.namevalue_glob("one").should == 1
|
1042
|
+
@book1.namevalue_glob("firstrow").should == [[1,2]]
|
1043
|
+
@book1.namevalue_glob("four").should == [[1,2],[3,4]]
|
1044
|
+
@book1.namevalue_glob("firstrow").should_not == "12"
|
1045
|
+
@book1.namevalue_glob("firstcell").should == "foo"
|
1046
1046
|
end
|
1047
1047
|
|
1048
1048
|
it "should return value of a range via []" do
|
@@ -1055,17 +1055,17 @@ describe Book do
|
|
1055
1055
|
end
|
1056
1056
|
|
1057
1057
|
it "should set value of a range" do
|
1058
|
-
@book1.
|
1059
|
-
@book1.
|
1058
|
+
@book1.set_namevalue_glob("new", "bar")
|
1059
|
+
@book1.namevalue_glob("new").should == "bar"
|
1060
1060
|
end
|
1061
1061
|
|
1062
1062
|
it "should set value of a range via []=" do
|
1063
1063
|
@book1["new"] = "bar"
|
1064
|
-
@book1.
|
1064
|
+
@book1.namevalue_glob("new").should == "bar"
|
1065
1065
|
end
|
1066
1066
|
|
1067
1067
|
#it "should evaluate a formula" do
|
1068
|
-
# @book1.
|
1068
|
+
# @book1.namevalue_glob("named_formula").should == 4
|
1069
1069
|
#end
|
1070
1070
|
|
1071
1071
|
#it "should evaluate a formula via []" do
|
@@ -1073,7 +1073,7 @@ describe Book do
|
|
1073
1073
|
#end
|
1074
1074
|
|
1075
1075
|
#it "should return default value if name not defined" do
|
1076
|
-
# @book1.
|
1076
|
+
# @book1.namevalue_glob("foo", :default => 2).should == 2
|
1077
1077
|
#end
|
1078
1078
|
|
1079
1079
|
end
|
@@ -678,12 +678,12 @@ describe Book do
|
|
678
678
|
end
|
679
679
|
|
680
680
|
it "should return value of a range" do
|
681
|
-
@book1.
|
682
|
-
@book1.
|
683
|
-
@book1.
|
684
|
-
@book1.
|
685
|
-
@book1.
|
686
|
-
@book1.
|
681
|
+
@book1.namevalue_glob("new").should == "foo"
|
682
|
+
@book1.namevalue_glob("one").should == 1
|
683
|
+
@book1.namevalue_glob("firstrow").should == [[1,2]]
|
684
|
+
@book1.namevalue_glob("four").should == [[1,2],[3,4]]
|
685
|
+
@book1.namevalue_glob("firstrow").should_not == "12"
|
686
|
+
@book1.namevalue_glob("firstcell").should == "foo"
|
687
687
|
end
|
688
688
|
|
689
689
|
it "should return value of a range via []" do
|
@@ -696,17 +696,17 @@ describe Book do
|
|
696
696
|
end
|
697
697
|
|
698
698
|
it "should set value of a range" do
|
699
|
-
@book1.
|
700
|
-
@book1.
|
699
|
+
@book1.set_namevalue_glob("new", "bar")
|
700
|
+
@book1.namevalue_glob("new").should == "bar"
|
701
701
|
end
|
702
702
|
|
703
703
|
it "should set value of a range via []=" do
|
704
704
|
@book1["new"] = "bar"
|
705
|
-
@book1.
|
705
|
+
@book1.namevalue_glob("new").should == "bar"
|
706
706
|
end
|
707
707
|
|
708
708
|
#it "should evaluate a formula" do
|
709
|
-
# @book1.
|
709
|
+
# @book1.namevalue_glob("named_formula").should == 4
|
710
710
|
#end
|
711
711
|
|
712
712
|
#it "should evaluate a formula via []" do
|
@@ -715,28 +715,28 @@ describe Book do
|
|
715
715
|
|
716
716
|
it "should raise an error if name not defined and default value is not provided" do
|
717
717
|
expect {
|
718
|
-
@book1.
|
718
|
+
@book1.namevalue_glob("foo", :default => nil)
|
719
719
|
}.to_not raise_error
|
720
720
|
expect {
|
721
|
-
@book1.
|
721
|
+
@book1.namevalue_glob("foo", :default => :__not_provided)
|
722
722
|
}.to raise_error(NameNotFound, /name "foo" not in #<Book: another_workbook/)
|
723
723
|
expect {
|
724
|
-
@book1.
|
724
|
+
@book1.namevalue_glob("foo")
|
725
725
|
}.to raise_error(NameNotFound, /name "foo" not in #<Book: another_workbook/)
|
726
|
-
@book1.
|
727
|
-
@book1.
|
726
|
+
@book1.namevalue_glob("foo", :default => nil).should be_nil
|
727
|
+
@book1.namevalue_glob("foo", :default => 1).should == 1
|
728
728
|
expect {
|
729
|
-
@book1.
|
729
|
+
@book1.set_namevalue_glob("foo","bar")
|
730
730
|
}.to raise_error(NameNotFound, /name "foo" not in #<Book: another_workbook/)
|
731
731
|
expect {
|
732
732
|
@book1["foo"] = "bar"
|
733
733
|
}.to raise_error(NameNotFound, /name "foo" not in #<Book: another_workbook/)
|
734
|
-
@book1.
|
734
|
+
@book1.namevalue_glob("empty", :default => 1).should be_nil
|
735
735
|
end
|
736
736
|
|
737
737
|
it "should raise an error if name was defined but contents is calcuated" do
|
738
738
|
expect {
|
739
|
-
@book1.
|
739
|
+
@book1.set_namevalue_glob("named_formula","bar")
|
740
740
|
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "named_formula" in #<Book: another_workbook/)
|
741
741
|
expect {
|
742
742
|
@book1["named_formula"] = "bar"
|
@@ -745,19 +745,19 @@ describe Book do
|
|
745
745
|
|
746
746
|
# Excel Bug: for local names without uqifier: takes the first sheet as default even if another sheet is activated
|
747
747
|
it "should take the first sheet as default even if the second sheet is activated" do
|
748
|
-
@book1.
|
749
|
-
@book1.
|
750
|
-
@book1.
|
748
|
+
@book1.namevalue_glob("Sheet1!localname").should == "bar"
|
749
|
+
@book1.namevalue_glob("Sheet2!localname").should == "simple"
|
750
|
+
@book1.namevalue_glob("localname").should == "bar"
|
751
751
|
@book1.Worksheets.Item(2).Activate
|
752
|
-
@book1.
|
752
|
+
@book1.namevalue_glob("localname").should == "bar"
|
753
753
|
@book1.Worksheets.Item(1).Delete
|
754
|
-
@book1.
|
754
|
+
@book1.namevalue_glob("localname").should == "simple"
|
755
755
|
end
|
756
756
|
|
757
757
|
it "should color the cell" do
|
758
|
-
@book1.
|
758
|
+
@book1.set_namevalue_glob("new", "bar")
|
759
759
|
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
760
|
-
@book1.
|
760
|
+
@book1.set_namevalue_glob("new", "bar", :color => 4)
|
761
761
|
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
762
762
|
@book1["new"].should == "bar"
|
763
763
|
@book1["new"] = "bar"
|
@@ -769,7 +769,7 @@ describe Book do
|
|
769
769
|
end
|
770
770
|
|
771
771
|
it "should save without color" do
|
772
|
-
@book1.
|
772
|
+
@book1.set_namevalue_glob("new", "bar", :color => 4)
|
773
773
|
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
774
774
|
@book1.save(:discoloring => true)
|
775
775
|
@book1.close
|
@@ -791,7 +791,7 @@ describe Book do
|
|
791
791
|
|
792
792
|
it "should rename a range" do
|
793
793
|
@book1.rename_range("four","five")
|
794
|
-
@book1.
|
794
|
+
@book1.namevalue_glob("five").should == [[1,2],[3,4]]
|
795
795
|
expect {
|
796
796
|
@book1.rename_range("four","five")
|
797
797
|
}.to raise_error(NameNotFound, /name "four" not in "another_workbook.xls"/)
|
@@ -1078,6 +1078,50 @@ describe Book do
|
|
1078
1078
|
end
|
1079
1079
|
end
|
1080
1080
|
|
1081
|
+
context "adding and deleting the name of a range" do
|
1082
|
+
|
1083
|
+
before do
|
1084
|
+
@book1 = Book.open(@dir + '/another_workbook.xls', :read_only => true, :visible => true)
|
1085
|
+
@book1.excel.displayalerts = false
|
1086
|
+
end
|
1087
|
+
|
1088
|
+
after do
|
1089
|
+
@book1.close
|
1090
|
+
end
|
1091
|
+
|
1092
|
+
it "should name an unnamed range with a giving address" do
|
1093
|
+
@book1.add_name("foo",1,2)
|
1094
|
+
@book1.Names.Item("foo").Name.should == "foo"
|
1095
|
+
@book1.Names.Item("foo").Value.should == "=Sheet1!$B$1"
|
1096
|
+
end
|
1097
|
+
|
1098
|
+
it "should rename an already named range with a giving address" do
|
1099
|
+
@book1.add_name("foo",1,1)
|
1100
|
+
@book1.Names.Item("foo").Name.should == "foo"
|
1101
|
+
@book1.Names.Item("foo").Value.should == "=Sheet1!$A$1"
|
1102
|
+
end
|
1103
|
+
|
1104
|
+
it "should raise an error" do
|
1105
|
+
expect{
|
1106
|
+
@book1.add_name("foo", -2, 1)
|
1107
|
+
}.to raise_error(RangeNotEvaluatable, /cannot add name "foo" to cell with row -2 and column 1/)
|
1108
|
+
end
|
1109
|
+
|
1110
|
+
it "should delete a name of a range" do
|
1111
|
+
@book1.add_name("foo",1,1)
|
1112
|
+
@book1.delete_name("foo")
|
1113
|
+
expect{
|
1114
|
+
@book1.namevalue_glob("foo")
|
1115
|
+
}.to raise_error(NameNotFound, /name "foo"/)
|
1116
|
+
end
|
1117
|
+
|
1118
|
+
it "should add a name of a rectangular range" do
|
1119
|
+
@book1.add_name("foo",1,1,3,4)
|
1120
|
+
@book1["foo"].should == [["foo", "workbook", "sheet1", nil], ["foo", 1.0, 2.0, 4.0], ["matz", 3.0, 4.0, 4.0]]
|
1121
|
+
end
|
1122
|
+
|
1123
|
+
end
|
1124
|
+
|
1081
1125
|
context "with compatibility" do
|
1082
1126
|
|
1083
1127
|
it "should open with checking compatibility" do
|
@@ -30,6 +30,7 @@ describe Book do
|
|
30
30
|
@simple_file1 = @simple_file
|
31
31
|
@different_file1 = @different_file
|
32
32
|
@simple_file_other_path1 = @simple_file_other_path
|
33
|
+
@another_simple_file1 = @another_simple_file
|
33
34
|
end
|
34
35
|
|
35
36
|
after do
|
@@ -217,12 +218,12 @@ describe Book do
|
|
217
218
|
it "should set calculation mode" do
|
218
219
|
book1 = Book.open(@simple_file1, :visible => true)
|
219
220
|
book1.excel.calculation = :manual
|
220
|
-
book1.excel.Calculation.should ==
|
221
|
+
book1.excel.Calculation.should == XlCalculationManual
|
221
222
|
book1.save
|
222
223
|
book1.excel.close
|
223
224
|
book2 = Book.open(@simple_file1, :visible => true)
|
224
225
|
book2.excel.calculation = :automatic
|
225
|
-
book2.excel.Calculation.should ==
|
226
|
+
book2.excel.Calculation.should == XlCalculationAutomatic
|
226
227
|
book2.save
|
227
228
|
book2.excel.close
|
228
229
|
end
|
@@ -236,22 +237,22 @@ describe Book do
|
|
236
237
|
book1 = Book.open(@simple_file)
|
237
238
|
book1.excel.calculation = :automatic
|
238
239
|
book1.excel.calculation.should == :automatic
|
239
|
-
book1.excel.Calculation.should ==
|
240
|
+
book1.excel.Calculation.should == XlCalculationAutomatic
|
240
241
|
end
|
241
242
|
|
242
243
|
it "should set the calculation mode to manual" do
|
243
244
|
book1 = Book.open(@simple_file)
|
244
245
|
book1.excel.calculation = :manual
|
245
246
|
book1.excel.calculation.should == :manual
|
246
|
-
book1.excel.Calculation.should ==
|
247
|
+
book1.excel.Calculation.should == XlCalculationManual
|
247
248
|
end
|
248
249
|
|
249
250
|
it "should change the calculation mode from manual to automatic" do
|
250
251
|
book1 = Book.open(@simple_file, :visible => true)
|
251
252
|
excel1 = Excel.current(:calculation => :automatic)
|
252
253
|
book2 = Book.open(@different_file, :visible => true)
|
253
|
-
book2.excel.Calculation.should ==
|
254
|
-
book1.excel.Calculation.should ==
|
254
|
+
book2.excel.Calculation.should == XlCalculationAutomatic
|
255
|
+
book1.excel.Calculation.should == XlCalculationAutomatic
|
255
256
|
end
|
256
257
|
end
|
257
258
|
|
@@ -543,6 +544,48 @@ describe Book do
|
|
543
544
|
@book.close rescue nil
|
544
545
|
end
|
545
546
|
|
547
|
+
it "should open not in the reserved Excel instance" do
|
548
|
+
Excel.kill_all
|
549
|
+
sleep 1
|
550
|
+
book2 = Book.open(@simple_file1, :force => {:excel => :reserved_new})
|
551
|
+
Excel.current.should_not == book2.excel
|
552
|
+
book3 = Book.open(@different_file1, :default => {:excel => :current})
|
553
|
+
book3.excel.should_not == book2.excel
|
554
|
+
book4 = Book.open(@another_simple_file1, :default => {:excel => :new})
|
555
|
+
book4.excel.should_not == book2.excel
|
556
|
+
book4.close
|
557
|
+
sleep 1
|
558
|
+
book5 = Book.open(@another_simple_file1, :default => {:excel => :reserved_new})
|
559
|
+
book5.excel.should_not == book2.excel
|
560
|
+
end
|
561
|
+
|
562
|
+
it "should open in the reserved Excel instance" do
|
563
|
+
excel1 = @book.excel
|
564
|
+
@book.close
|
565
|
+
book2 = Book.open(@simple_file1, :force => {:excel => :reserved_new})
|
566
|
+
book2.excel.should_not == excel1
|
567
|
+
end
|
568
|
+
|
569
|
+
it "should open in the reserved Excel instance" do
|
570
|
+
book2 = Book.open(@simple_file1, :force => {:excel => :reserved_new})
|
571
|
+
book3 = Book.open(@different_file1, :force => {:excel => :reserved_new})
|
572
|
+
book4 = Book.open(@another_simple_file1, :force => {:excel => :new})
|
573
|
+
book5 = Book.open(@another_simple_file1, :force => {:excel => :current})
|
574
|
+
book2.excel.should_not == @book.excel
|
575
|
+
book3.excel.should_not == book2.excel
|
576
|
+
book4.excel.should_not == @book.excel
|
577
|
+
book4.excel.should_not == book2.excel
|
578
|
+
book5.excel.should == @book.excel
|
579
|
+
end
|
580
|
+
|
581
|
+
it "should open in the reserved Excel instance" do
|
582
|
+
book2 = Book.open(@another_simple_file1, :force => {:excel => :new})
|
583
|
+
book3 = Book.open(@different_file1, :force => {:excel => :reserved_new})
|
584
|
+
book2.excel.should_not == @book.excel
|
585
|
+
book3.excel.should_not == @book.excel
|
586
|
+
book3.excel.should_not == book2.excel
|
587
|
+
end
|
588
|
+
|
546
589
|
it "should open in a given Excel provided as Excel, Book, or WIN32OLE representing an Excel or Workbook" do
|
547
590
|
book2 = Book.open(@another_simple_file)
|
548
591
|
book3 = Book.open(@different_file)
|
@@ -686,7 +729,7 @@ describe Book do
|
|
686
729
|
book3.should be_a Book
|
687
730
|
book3.excel.should == @book.excel
|
688
731
|
end
|
689
|
-
|
732
|
+
|
690
733
|
end
|
691
734
|
|
692
735
|
context "with leaving out :force => {:excel}" do
|
@@ -1013,162 +1056,280 @@ describe Book do
|
|
1013
1056
|
@book.close rescue nil
|
1014
1057
|
end
|
1015
1058
|
|
1016
|
-
|
1017
|
-
book2 = Book.open(@simple_file1, :default => {:excel => :current})
|
1018
|
-
book2.excel.should == @book.excel
|
1019
|
-
book2.should be_alive
|
1020
|
-
book2.should be_a Book
|
1021
|
-
book2.should == @book
|
1022
|
-
book2.close
|
1023
|
-
end
|
1059
|
+
context "with :default => {:excel => :reserved_new}" do
|
1024
1060
|
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
book2.should be_alive
|
1030
|
-
book2.should be_a Book
|
1031
|
-
book2.excel.should == @book.excel
|
1032
|
-
book2.excel.should_not == excel
|
1033
|
-
book2.filename.should == @book.filename
|
1034
|
-
@book.should be_alive
|
1035
|
-
book2.should == @book
|
1036
|
-
book2.close
|
1037
|
-
end
|
1061
|
+
it "should open in the reserved Excel instance" do
|
1062
|
+
book3 = Book.open(@different_file1, :default => {:excel => :reserved_new})
|
1063
|
+
book3.excel.should_not == @book.excel
|
1064
|
+
end
|
1038
1065
|
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
@book.should be_alive
|
1050
|
-
book2.should == @book
|
1051
|
-
book2.close
|
1052
|
-
end
|
1066
|
+
it "should open in separate Excel instances" do
|
1067
|
+
Excel.kill_all
|
1068
|
+
sleep 1
|
1069
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :reserved_new})
|
1070
|
+
book3 = Book.open(@different_file1, :default => {:excel => :reserved_new})
|
1071
|
+
book2.excel.should_not == book3.excel
|
1072
|
+
book4 = Book.open(@another_simple_file1, :default => {:excel => :current})
|
1073
|
+
book4.excel.should_not == book2.excel
|
1074
|
+
book4.excel.should_not == book3.excel
|
1075
|
+
end
|
1053
1076
|
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
book2.excel.should_not == excel
|
1063
|
-
book2.excel.should_not == new_excel2
|
1064
|
-
book2.excel.should == new_excel
|
1065
|
-
@book.should be_alive
|
1066
|
-
book2.should == @book
|
1067
|
-
book2.close
|
1068
|
-
end
|
1077
|
+
it "should use the open book" do
|
1078
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :reserved_new})
|
1079
|
+
book2.excel.should == @book.excel
|
1080
|
+
book2.should be_alive
|
1081
|
+
book2.should be_a Book
|
1082
|
+
book2.should == @book
|
1083
|
+
book2.close
|
1084
|
+
end
|
1069
1085
|
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
book2.excel.should == excel1
|
1079
|
-
book2.excel.should_not == excel2
|
1080
|
-
book2.close
|
1081
|
-
end
|
1086
|
+
it "should open in the old Excel instance" do
|
1087
|
+
@book.close
|
1088
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :reserved_new})
|
1089
|
+
book2.should be_alive
|
1090
|
+
book2.should be_a Book
|
1091
|
+
book2.should == @book
|
1092
|
+
book2.excel.should == @book.excel
|
1093
|
+
end
|
1082
1094
|
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
book2.close
|
1090
|
-
book3 = Book.open(@simple_file1, :force => {:excel => excel2})
|
1091
|
-
book3.close
|
1092
|
-
book3 = Book.open(@simple_file1, :default => {:excel => :current})
|
1093
|
-
book3.excel.should == excel2
|
1094
|
-
book3.close
|
1095
|
-
end
|
1095
|
+
it "should open one book in the reserved Excel instance" do
|
1096
|
+
book3 = Book.open(@different_file1, :default => {:excel => :reserved_new})
|
1097
|
+
@book.close
|
1098
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :reserved_new})
|
1099
|
+
book2.excel.should_not == book3.excel
|
1100
|
+
end
|
1096
1101
|
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
book2.should be_a Book
|
1104
|
-
book3.excel.should == book2.excel
|
1105
|
-
book3.excel.should_not == @book.excel
|
1106
|
-
book3.should == book2
|
1107
|
-
book3.should_not == @book
|
1108
|
-
end
|
1102
|
+
it "should not use the reserved Excel instance" do
|
1103
|
+
book3 = Book.open(@different_file1, :default => {:excel => :reserved_new})
|
1104
|
+
@book.close
|
1105
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :new})
|
1106
|
+
book2.excel.should_not == book3.excel
|
1107
|
+
end
|
1109
1108
|
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1109
|
+
it "should not reopen in the reserved Excel instance" do
|
1110
|
+
book3 = Book.open(@different_file1, :default => {:excel => :reserved_new})
|
1111
|
+
@book.close
|
1112
|
+
@book.reopen
|
1113
|
+
@book.excel.should_not == book3.excel
|
1114
|
+
end
|
1116
1115
|
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1116
|
+
it "should reopen in the reserved Excel instance" do
|
1117
|
+
book3 = Book.open(@different_file1, :default => {:excel => :reserved_new})
|
1118
|
+
@book.close
|
1119
|
+
book3.close
|
1120
|
+
@book.reopen
|
1121
|
+
book3.reopen
|
1122
|
+
@book.excel.should_not == book3.excel
|
1123
|
+
end
|
1125
1124
|
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1125
|
+
it "should not reopen in the reserved Excel instance when opened the reserved Excel instance first" do
|
1126
|
+
Excel.kill_all
|
1127
|
+
sleep 1
|
1128
|
+
book1 = Book.open(@simple_file1, :default => {:excel => :reserved_new})
|
1129
|
+
book2 = Book.open(@different_file1, :default => {:excel => :new})
|
1130
|
+
book2.excel.should_not == book1.excel
|
1131
|
+
book3 = Book.open(@another_simple_file1, :default => {:excel => :current})
|
1132
|
+
book3.excel.should_not == book1.excel
|
1133
|
+
book2.close
|
1134
|
+
book2.reopen
|
1135
|
+
book2.excel.should_not == book1.excel
|
1136
|
+
book3.close
|
1137
|
+
book3.reopen
|
1138
|
+
book3.excel.should_not == book1.excel
|
1139
|
+
book1.close
|
1140
|
+
book1.reopen
|
1141
|
+
book1.excel.should_not == book2.excel
|
1142
|
+
book1.excel.should_not == book3.excel
|
1143
|
+
end
|
1144
|
+
|
1145
|
+
it "should open several workbooks in the reserved Excel instance" do
|
1146
|
+
book2 = Book.open(@different_file1, :default => {:excel => :reserved_new})
|
1147
|
+
book3 = Book.open(@another_simple_file1, :default => {:excel => :reserved_new})
|
1148
|
+
book2.excel.should_not == @book.excel
|
1149
|
+
book3.excel.should_not == @book.excel
|
1150
|
+
book2.excel.should_not == book3.excel
|
1151
|
+
end
|
1152
|
+
|
1153
|
+
it "should open several workbooks in the reserved Excel instance" do
|
1154
|
+
Excel.kill_all
|
1155
|
+
book1 = Book.open(@simple_file1, :default => {:excel => :reserved_new})
|
1156
|
+
book2 = Book.open(@different_file1, :default => {:excel => :current})
|
1157
|
+
book3 = Book.open(@another_simple_file1, :default => {:excel => :current})
|
1158
|
+
book2.excel.should_not == book1.excel
|
1159
|
+
book3.excel.should_not == book1.excel
|
1160
|
+
book2.excel.should == book3.excel
|
1161
|
+
end
|
1133
1162
|
|
1134
|
-
it "should open the book in a given excel if the book was opened before but the excel has been closed" do
|
1135
|
-
excel2 = Excel.new(:reuse => false, :visible => true)
|
1136
|
-
@book.excel.close
|
1137
|
-
book2 = Book.open(@simple_file1, :default => {:excel => excel2, :visible => true})
|
1138
|
-
book2.excel.should == excel2
|
1139
1163
|
end
|
1140
1164
|
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1165
|
+
context "with :default => {:excel => :current}" do
|
1166
|
+
|
1167
|
+
it "should use the open book" do
|
1168
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :current})
|
1169
|
+
book2.excel.should == @book.excel
|
1170
|
+
book2.should be_alive
|
1171
|
+
book2.should be_a Book
|
1172
|
+
book2.should == @book
|
1173
|
+
book2.close
|
1174
|
+
end
|
1175
|
+
|
1176
|
+
it "should reopen the book in the excel instance where it was opened before" do
|
1177
|
+
excel = Excel.new(:reuse => false)
|
1178
|
+
@book.close
|
1179
|
+
book2 = Book.open(@simple_file1)
|
1180
|
+
book2.should be_alive
|
1181
|
+
book2.should be_a Book
|
1182
|
+
book2.excel.should == @book.excel
|
1183
|
+
book2.excel.should_not == excel
|
1184
|
+
book2.filename.should == @book.filename
|
1185
|
+
@book.should be_alive
|
1186
|
+
book2.should == @book
|
1187
|
+
book2.close
|
1188
|
+
end
|
1189
|
+
|
1190
|
+
it "should reopen a book in a new Excel if all Excel instances are closed" do
|
1191
|
+
excel = Excel.new(:reuse => false)
|
1192
|
+
excel2 = @book.excel
|
1193
|
+
fn = @book.filename
|
1194
|
+
@book.close
|
1195
|
+
Excel.close_all
|
1196
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :current})
|
1197
|
+
book2.should be_alive
|
1198
|
+
book2.should be_a Book
|
1199
|
+
book2.filename.should == fn
|
1200
|
+
@book.should be_alive
|
1201
|
+
book2.should == @book
|
1202
|
+
book2.close
|
1203
|
+
end
|
1204
|
+
|
1205
|
+
it "should reopen a book in the first opened Excel if the old Excel is closed" do
|
1206
|
+
excel = @book.excel
|
1207
|
+
Excel.close_all
|
1208
|
+
new_excel = Excel.new(:reuse => false)
|
1209
|
+
new_excel2 = Excel.new(:reuse => false)
|
1210
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :current})
|
1211
|
+
book2.should be_alive
|
1212
|
+
book2.should be_a Book
|
1213
|
+
book2.excel.should_not == excel
|
1214
|
+
book2.excel.should_not == new_excel2
|
1215
|
+
book2.excel.should == new_excel
|
1216
|
+
@book.should be_alive
|
1217
|
+
book2.should == @book
|
1218
|
+
book2.close
|
1219
|
+
end
|
1220
|
+
|
1221
|
+
it "should reopen a book in the first opened excel, if the book cannot be reopened" do
|
1222
|
+
@book.close
|
1223
|
+
Excel.close_all
|
1224
|
+
excel1 = Excel.new(:reuse => false)
|
1225
|
+
excel2 = Excel.new(:reuse => false)
|
1226
|
+
book2 = Book.open(@different_file, :default => {:excel => :current})
|
1227
|
+
book2.should be_alive
|
1228
|
+
book2.should be_a Book
|
1229
|
+
book2.excel.should == excel1
|
1230
|
+
book2.excel.should_not == excel2
|
1231
|
+
book2.close
|
1232
|
+
end
|
1233
|
+
|
1234
|
+
it "should reopen the book in the Excel where it was opened most recently" do
|
1235
|
+
excel1 = @book.excel
|
1236
|
+
excel2 = Excel.new(:reuse => false)
|
1237
|
+
@book.close
|
1238
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :current})
|
1239
|
+
book2.excel.should == excel1
|
1240
|
+
book2.close
|
1241
|
+
book3 = Book.open(@simple_file1, :force => {:excel => excel2})
|
1242
|
+
book3.close
|
1243
|
+
book3 = Book.open(@simple_file1, :default => {:excel => :current})
|
1244
|
+
book3.excel.should == excel2
|
1245
|
+
book3.close
|
1246
|
+
end
|
1247
|
+
|
1150
1248
|
end
|
1151
1249
|
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1250
|
+
context "with :default => {:excel => :new}" do
|
1251
|
+
|
1252
|
+
it "should reopen a book in the excel instance where it was opened most recently" do
|
1253
|
+
book2 = Book.open(@simple_file, :force => {:excel => :new})
|
1254
|
+
@book.close
|
1255
|
+
book2.close
|
1256
|
+
book3 = Book.open(@simple_file1)
|
1257
|
+
book2.should be_alive
|
1258
|
+
book2.should be_a Book
|
1259
|
+
book3.excel.should == book2.excel
|
1260
|
+
book3.excel.should_not == @book.excel
|
1261
|
+
book3.should == book2
|
1262
|
+
book3.should_not == @book
|
1263
|
+
end
|
1264
|
+
|
1265
|
+
it "should open the book in a new excel if the book was not opened before" do
|
1266
|
+
book2 = Book.open(@different_file, :default => {:excel => :current})
|
1267
|
+
book2.excel.should == @book.excel
|
1268
|
+
book3 = Book.open(@another_simple_file, :default => {:excel => :new})
|
1269
|
+
book3.excel.should_not == @book.excel
|
1270
|
+
end
|
1271
|
+
|
1272
|
+
it "should open the book in a new excel if the book was opened before but the excel has been closed" do
|
1273
|
+
excel = @book.excel
|
1274
|
+
excel2 = Excel.new(:reuse => false)
|
1275
|
+
excel.close
|
1276
|
+
book2 = Book.open(@simple_file1, :default => {:excel => :new})
|
1277
|
+
book2.excel.should_not == excel2
|
1278
|
+
book2.close
|
1279
|
+
end
|
1280
|
+
|
1161
1281
|
end
|
1162
1282
|
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1283
|
+
context "with :default => {:excel => <excel-instance>}" do
|
1284
|
+
|
1285
|
+
it "should open the book in a given excel if the book was not opened before" do
|
1286
|
+
book2 = Book.open(@different_file, :default => {:excel => :current})
|
1287
|
+
book2.excel.should == @book.excel
|
1288
|
+
excel = Excel.new(:reuse => false)
|
1289
|
+
book3 = Book.open(@another_simple_file, :default => {:excel => excel})
|
1290
|
+
book3.excel.should == excel
|
1291
|
+
end
|
1292
|
+
|
1293
|
+
it "should open the book in a given excel if the book was opened before but the excel has been closed" do
|
1294
|
+
excel2 = Excel.new(:reuse => false, :visible => true)
|
1295
|
+
@book.excel.close
|
1296
|
+
book2 = Book.open(@simple_file1, :default => {:excel => excel2, :visible => true})
|
1297
|
+
book2.excel.should == excel2
|
1298
|
+
end
|
1299
|
+
|
1300
|
+
it "should open a new excel, if the book cannot be reopened" do
|
1301
|
+
@book.close
|
1302
|
+
new_excel = Excel.new(:reuse => false)
|
1303
|
+
book2 = Book.open(@different_file, :default => {:excel => :new})
|
1304
|
+
book2.should be_alive
|
1305
|
+
book2.should be_a Book
|
1306
|
+
book2.excel.should_not == new_excel
|
1307
|
+
book2.excel.should_not == @book.excel
|
1308
|
+
book2.close
|
1309
|
+
end
|
1310
|
+
|
1311
|
+
it "should open a given excel, if the book cannot be reopened" do
|
1312
|
+
@book.close
|
1313
|
+
new_excel = Excel.new(:reuse => false)
|
1314
|
+
book2 = Book.open(@different_file, :default => {:excel => @book.excel})
|
1315
|
+
book2.should be_alive
|
1316
|
+
book2.should be_a Book
|
1317
|
+
book2.excel.should_not == new_excel
|
1318
|
+
book2.excel.should == @book.excel
|
1319
|
+
book2.close
|
1320
|
+
end
|
1321
|
+
|
1322
|
+
it "should open a given excel, if the book cannot be reopened" do
|
1323
|
+
@book.close
|
1324
|
+
new_excel = Excel.new(:reuse => false)
|
1325
|
+
book2 = Book.open(@different_file, :default => {:excel => @book})
|
1326
|
+
book2.should be_alive
|
1327
|
+
book2.should be_a Book
|
1328
|
+
book2.excel.should_not == new_excel
|
1329
|
+
book2.excel.should == @book.excel
|
1330
|
+
book2.close
|
1331
|
+
end
|
1332
|
+
|
1172
1333
|
end
|
1173
1334
|
|
1174
1335
|
it "should reuse an open book by default" do
|