robust_excel_ole 1.29 → 1.30
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 +8 -0
- data/docs/README_open.rdoc +8 -4
- data/lib/robust_excel_ole/address_tool.rb +0 -2
- data/lib/robust_excel_ole/bookstore.rb +1 -1
- data/lib/robust_excel_ole/excel.rb +5 -15
- data/lib/robust_excel_ole/general.rb +239 -223
- data/lib/robust_excel_ole/list_object.rb +5 -1
- data/lib/robust_excel_ole/range.rb +5 -1
- data/lib/robust_excel_ole/range_owners.rb +4 -71
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +26 -17
- data/lib/robust_excel_ole/worksheet.rb +72 -4
- data/spec/base_spec.rb +17 -15
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/general_spec.rb +3 -0
- data/spec/workbook_spec.rb +11 -11
- data/spec/workbook_specs/workbook_misc_spec.rb +30 -30
- data/spec/workbook_specs/workbook_open_spec.rb +11 -0
- data/spec/workbook_specs/workbook_unobtr_spec.rb +289 -109
- data/spec/worksheet_spec.rb +18 -18
- metadata +2 -2
Binary file
|
data/spec/general_spec.rb
CHANGED
data/spec/workbook_spec.rb
CHANGED
@@ -1103,12 +1103,12 @@ describe Workbook do
|
|
1103
1103
|
end
|
1104
1104
|
|
1105
1105
|
it "should return value of a range" do
|
1106
|
-
@book1.
|
1107
|
-
@book1.
|
1108
|
-
@book1.
|
1109
|
-
@book1.
|
1110
|
-
@book1.
|
1111
|
-
@book1.
|
1106
|
+
@book1.namevalue_global("new").should == "foo"
|
1107
|
+
@book1.namevalue_global("one").should == 1
|
1108
|
+
@book1.namevalue_global("firstrow").should == [[1,2]]
|
1109
|
+
@book1.namevalue_global("four").should == [[1,2],[3,4]]
|
1110
|
+
@book1.namevalue_global("firstrow").should_not == "12"
|
1111
|
+
@book1.namevalue_global("firstcell").should == "foo"
|
1112
1112
|
end
|
1113
1113
|
|
1114
1114
|
it "should return value of a range via []" do
|
@@ -1121,17 +1121,17 @@ describe Workbook do
|
|
1121
1121
|
end
|
1122
1122
|
|
1123
1123
|
it "should set value of a range" do
|
1124
|
-
@book1.
|
1125
|
-
@book1.
|
1124
|
+
@book1.set_namevalue_global("new", "bar")
|
1125
|
+
@book1.namevalue_global("new").should == "bar"
|
1126
1126
|
end
|
1127
1127
|
|
1128
1128
|
it "should set value of a range via []=" do
|
1129
1129
|
@book1["new"] = "bar"
|
1130
|
-
@book1.
|
1130
|
+
@book1.namevalue_global("new").should == "bar"
|
1131
1131
|
end
|
1132
1132
|
|
1133
1133
|
#it "should evaluate a formula" do
|
1134
|
-
# @book1.
|
1134
|
+
# @book1.namevalue_global("named_formula").should == 4
|
1135
1135
|
#end
|
1136
1136
|
|
1137
1137
|
#it "should evaluate a formula via []" do
|
@@ -1139,7 +1139,7 @@ describe Workbook do
|
|
1139
1139
|
#end
|
1140
1140
|
|
1141
1141
|
#it "should return default value if name not defined" do
|
1142
|
-
# @book1.
|
1142
|
+
# @book1.namevalue_global("foo", :default => 2).should == 2
|
1143
1143
|
#end
|
1144
1144
|
|
1145
1145
|
end
|
@@ -669,7 +669,7 @@ describe Workbook do
|
|
669
669
|
end
|
670
670
|
end
|
671
671
|
|
672
|
-
describe "
|
672
|
+
describe "namevalue_global, set_namevalue_global, [], []=" do
|
673
673
|
|
674
674
|
before do
|
675
675
|
@book1 = Workbook.open(@another_simple_file)
|
@@ -680,12 +680,12 @@ describe Workbook do
|
|
680
680
|
end
|
681
681
|
|
682
682
|
it "should return value of a range" do
|
683
|
-
@book1.
|
684
|
-
@book1.
|
685
|
-
@book1.
|
686
|
-
@book1.
|
687
|
-
@book1.
|
688
|
-
@book1.
|
683
|
+
@book1.namevalue_global("new").should == "foo"
|
684
|
+
@book1.namevalue_global("one").should == 1
|
685
|
+
@book1.namevalue_global("firstrow").should == [[1,2]]
|
686
|
+
@book1.namevalue_global("four").should == [[1,2],[3,4]]
|
687
|
+
@book1.namevalue_global("firstrow").should_not == "12"
|
688
|
+
@book1.namevalue_global("firstcell").should == "foo"
|
689
689
|
end
|
690
690
|
|
691
691
|
it "should return value of a range via []" do
|
@@ -698,17 +698,17 @@ describe Workbook do
|
|
698
698
|
end
|
699
699
|
|
700
700
|
it "should set value of a range" do
|
701
|
-
@book1.
|
702
|
-
@book1.
|
701
|
+
@book1.set_namevalue_global("new", "bar")
|
702
|
+
@book1.namevalue_global("new").should == "bar"
|
703
703
|
end
|
704
704
|
|
705
705
|
it "should set value of a range via []=" do
|
706
706
|
@book1["new"] = "bar"
|
707
|
-
@book1.
|
707
|
+
@book1.namevalue_global("new").should == "bar"
|
708
708
|
end
|
709
709
|
|
710
710
|
#it "should evaluate a formula" do
|
711
|
-
# @book1.
|
711
|
+
# @book1.namevalue_global("named_formula").should == 4
|
712
712
|
#end
|
713
713
|
|
714
714
|
#it "should evaluate a formula via []" do
|
@@ -717,28 +717,28 @@ describe Workbook do
|
|
717
717
|
|
718
718
|
it "should raise an error if name not defined and default value is not provided" do
|
719
719
|
expect {
|
720
|
-
@book1.
|
720
|
+
@book1.namevalue_global("foo", :default => nil)
|
721
721
|
}.to_not raise_error
|
722
722
|
expect {
|
723
|
-
@book1.
|
723
|
+
@book1.namevalue_global("foo", :default => :__not_provided)
|
724
724
|
}.to raise_error(NameNotFound, /name "foo" not in #<Workbook: another_workbook/)
|
725
725
|
expect {
|
726
|
-
@book1.
|
726
|
+
@book1.namevalue_global("foo")
|
727
727
|
}.to raise_error(NameNotFound, /name "foo" not in #<Workbook: another_workbook/)
|
728
|
-
@book1.
|
729
|
-
@book1.
|
728
|
+
@book1.namevalue_global("foo", :default => nil).should be_nil
|
729
|
+
@book1.namevalue_global("foo", :default => 1).should == 1
|
730
730
|
expect {
|
731
|
-
@book1.
|
731
|
+
@book1.set_namevalue_global("foo","bar")
|
732
732
|
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo"/)
|
733
733
|
expect {
|
734
734
|
@book1["foo"] = "bar"
|
735
735
|
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo"/)
|
736
|
-
@book1.
|
736
|
+
@book1.namevalue_global("empty", :default => 1).should be_nil
|
737
737
|
end
|
738
738
|
|
739
739
|
it "should raise an error if name was defined but contents is calcuated" do
|
740
740
|
expect {
|
741
|
-
@book1.
|
741
|
+
@book1.set_namevalue_global("named_formula","bar")
|
742
742
|
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "named_formula" in #<Workbook: another_workbook/)
|
743
743
|
expect {
|
744
744
|
@book1["named_formula"] = "bar"
|
@@ -747,19 +747,19 @@ describe Workbook do
|
|
747
747
|
|
748
748
|
# Excel Bug: for local names without uqifier: takes the first sheet as default even if another sheet is activated
|
749
749
|
it "should take the first sheet as default even if the second sheet is activated" do
|
750
|
-
@book1.
|
751
|
-
@book1.
|
752
|
-
@book1.
|
750
|
+
@book1.namevalue_global("Sheet1!localname").should == "bar"
|
751
|
+
@book1.namevalue_global("Sheet2!localname").should == "simple"
|
752
|
+
@book1.namevalue_global("localname").should == "bar"
|
753
753
|
@book1.Worksheets.Item(2).Activate
|
754
|
-
@book1.
|
754
|
+
@book1.namevalue_global("localname").should == "bar"
|
755
755
|
@book1.Worksheets.Item(1).Delete
|
756
|
-
@book1.
|
756
|
+
@book1.namevalue_global("localname").should == "simple"
|
757
757
|
end
|
758
758
|
|
759
759
|
it "should color the cell (deprecated)" do
|
760
|
-
@book1.
|
760
|
+
@book1.set_namevalue_global("new", "bar")
|
761
761
|
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
762
|
-
@book1.
|
762
|
+
@book1.set_namevalue_global("new", "bar", :color => 4)
|
763
763
|
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
764
764
|
@book1["new"].should == "bar"
|
765
765
|
@book1["new"] = "bar"
|
@@ -771,9 +771,9 @@ describe Workbook do
|
|
771
771
|
end
|
772
772
|
|
773
773
|
it "should color the cell" do
|
774
|
-
@book1.
|
774
|
+
@book1.set_namevalue_global("new", "bar")
|
775
775
|
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
776
|
-
@book1.
|
776
|
+
@book1.set_namevalue_global("new", "bar", :color => 4)
|
777
777
|
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
778
778
|
@book1["new"].should == "bar"
|
779
779
|
@book1["new"] = "bar"
|
@@ -796,7 +796,7 @@ describe Workbook do
|
|
796
796
|
|
797
797
|
it "should rename a range" do
|
798
798
|
@book1.rename_range("four","five")
|
799
|
-
@book1.
|
799
|
+
@book1.namevalue_global("five").should == [[1,2],[3,4]]
|
800
800
|
expect {
|
801
801
|
@book1.rename_range("four","five")
|
802
802
|
}.to raise_error(NameNotFound, /name "four" not in "another_workbook.xls"/)
|
@@ -1165,7 +1165,7 @@ describe Workbook do
|
|
1165
1165
|
@book1.add_name("foo",[1,1])
|
1166
1166
|
@book1.delete_name("foo")
|
1167
1167
|
expect{
|
1168
|
-
@book1.
|
1168
|
+
@book1.namevalue_global("foo")
|
1169
1169
|
}.to raise_error(NameNotFound, /name "foo"/)
|
1170
1170
|
end
|
1171
1171
|
|
@@ -273,6 +273,17 @@ describe Workbook do
|
|
273
273
|
bookstore = Bookstore.new
|
274
274
|
end
|
275
275
|
|
276
|
+
it "should fetch a network path file given a not via Reo opened hostname share file" do
|
277
|
+
ole_e1 = WIN32OLE.new('Excel.Application')
|
278
|
+
ws = ole_e1.Workbooks
|
279
|
+
abs_filename = General.absolute_path(@simple_file_hostname_share_path)
|
280
|
+
@ole_wb = ws.Open(abs_filename)
|
281
|
+
book2 = Workbook.open(@simple_file_network_path)
|
282
|
+
#book2.should === @ole_wb.to_reo
|
283
|
+
book2.Fullname.should == @ole_wb.Fullname
|
284
|
+
book2.excel.Workbooks.Count.should == 1
|
285
|
+
end
|
286
|
+
|
276
287
|
it "should fetch a network path file given a hostname share file" do
|
277
288
|
book1 = Workbook.open(@simple_file_hostname_share_path)
|
278
289
|
book2 = Workbook.open(@simple_file_network_path)
|
@@ -25,6 +25,7 @@ describe Workbook do
|
|
25
25
|
@simple_file_other_path = @dir + '/more_data/workbook.xls'
|
26
26
|
@another_simple_file = @dir + '/another_workbook.xls'
|
27
27
|
@linked_file = @dir + '/workbook_linked.xlsm'
|
28
|
+
@linked_sub_file = @dir + '/workbook_linked_sub.xlsm'
|
28
29
|
@simple_file_xlsm = @dir + '/workbook.xlsm'
|
29
30
|
@simple_file_xlsx = @dir + '/workbook.xlsx'
|
30
31
|
@simple_file1 = @simple_file
|
@@ -35,9 +36,237 @@ describe Workbook do
|
|
35
36
|
rm_tmp(@dir)
|
36
37
|
end
|
37
38
|
|
38
|
-
describe "
|
39
|
+
describe "writable" do
|
40
|
+
|
41
|
+
context "with no book" do
|
42
|
+
|
43
|
+
it "should open in read-only mode" do
|
44
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
45
|
+
book.ReadOnly.should be true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should open in writable mode" do
|
50
|
+
Workbook.unobtrusively(@simple_file1, :writable => true) do |book|
|
51
|
+
book.ReadOnly.should be false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
context "with open writable book" do
|
58
|
+
|
59
|
+
before do
|
60
|
+
@book = Workbook.open(@simple_file1)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should keep the read-only mode" do
|
64
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
65
|
+
book.ReadOnly.should be false
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
context "with open read-only book" do
|
72
|
+
|
73
|
+
before do
|
74
|
+
@book = Workbook.open(@simple_file1, :read_only => true)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should keep the read-only mode" do
|
78
|
+
Workbook.unobtrusively(@simple_file1, :writable => true) do |book|
|
79
|
+
book.ReadOnly.should be true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "for_reading, for_modifying" do
|
88
|
+
|
89
|
+
context "with no workbook" do
|
90
|
+
|
91
|
+
it "should open with read-only" do
|
92
|
+
Workbook.for_reading(@simple_file1) do |book|
|
93
|
+
book.should be_a Workbook
|
94
|
+
book.should be_alive
|
95
|
+
book.ReadOnly.should be true
|
96
|
+
book.Saved.should be true
|
97
|
+
sheet = book.sheet(1)
|
98
|
+
cell = sheet[1,1]
|
99
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
100
|
+
@new_cell_value = sheet[1,1].Value
|
101
|
+
book.Saved.should be false
|
102
|
+
end
|
103
|
+
Excel.kill_all
|
104
|
+
new_book = Workbook.open(@simple_file1)
|
105
|
+
sheet = new_book.sheet(1)
|
106
|
+
sheet[1,1].Value.should_not == @new_cell_value
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should change the value" do
|
110
|
+
Workbook.for_modifying(@simple_file1) do |book|
|
111
|
+
book.should be_a Workbook
|
112
|
+
book.should be_alive
|
113
|
+
book.ReadOnly.should be false
|
114
|
+
book.Saved.should be true
|
115
|
+
sheet = book.sheet(1)
|
116
|
+
cell = sheet[1,1]
|
117
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
118
|
+
@new_cell_value = sheet[1,1].Value
|
119
|
+
book.Saved.should be false
|
120
|
+
end
|
121
|
+
Excel.kill_all
|
122
|
+
new_book = Workbook.open(@simple_file1)
|
123
|
+
sheet = new_book.sheet(1)
|
124
|
+
sheet[1,1].Value.should == @new_cell_value
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
context "with closed writable workbook" do
|
130
|
+
|
131
|
+
before do
|
132
|
+
@book = Workbook.open(@simple_file1)
|
133
|
+
sheet = @book.sheet(1)
|
134
|
+
@old_cell_value = sheet[1,1].Value
|
135
|
+
@book.close
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should not change the value" do
|
139
|
+
Workbook.for_reading(@simple_file1) do |book|
|
140
|
+
book.should be_a Workbook
|
141
|
+
book.should be_alive
|
142
|
+
book.ReadOnly.should be true
|
143
|
+
book.Saved.should be true
|
144
|
+
sheet = book.sheet(1)
|
145
|
+
cell = sheet[1,1]
|
146
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
147
|
+
book.Saved.should be false
|
148
|
+
book.excel.should == @book.excel
|
149
|
+
end
|
150
|
+
Excel.kill_all
|
151
|
+
new_book = Workbook.open(@simple_file1)
|
152
|
+
sheet = new_book.sheet(1)
|
153
|
+
sheet[1,1].Value.should == @old_cell_value
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should not change the value and use a given Excel" do
|
157
|
+
new_excel = Excel.new(:reuse => false)
|
158
|
+
another_excel = Excel.new(:reuse => false)
|
159
|
+
Workbook.for_reading(@simple_file1, :if_closed => another_excel) do |book|
|
160
|
+
sheet = book.sheet(1)
|
161
|
+
cell = sheet[1,1]
|
162
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
163
|
+
book.excel.should == another_excel
|
164
|
+
end
|
165
|
+
Excel.kill_all
|
166
|
+
new_book = Workbook.open(@simple_file1)
|
167
|
+
sheet = new_book.sheet(1)
|
168
|
+
sheet[1,1].Value.should == @old_cell_value
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should not change the value and use the new Excel instance" do
|
172
|
+
new_excel = Excel.new(:reuse => false)
|
173
|
+
Workbook.for_reading(@simple_file1, :if_closed => :new) do |book|
|
174
|
+
sheet = book.sheet(1)
|
175
|
+
cell = sheet[1,1]
|
176
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
177
|
+
book.excel.should_not == @book.excel
|
178
|
+
book.excel.should_not == new_excel
|
179
|
+
book.excel.properties[:visible].should be false
|
180
|
+
book.excel.properties[:displayalerts].should == :if_visible
|
181
|
+
end
|
182
|
+
Excel.kill_all
|
183
|
+
new_book = Workbook.open(@simple_file1)
|
184
|
+
sheet = new_book.sheet(1)
|
185
|
+
sheet[1,1].Value.should == @old_cell_value
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should change the value" do
|
189
|
+
Workbook.for_modifying(@simple_file1) do |book|
|
190
|
+
sheet = book.sheet(1)
|
191
|
+
cell = sheet[1,1]
|
192
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
193
|
+
book.excel.should == @book.excel
|
194
|
+
end
|
195
|
+
new_book = Workbook.open(@simple_file, :visible => true)
|
196
|
+
sheet = new_book.sheet(1)
|
197
|
+
sheet[1,1].Value.should_not == @old_cell_value
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should change the value and use a given Excel" do
|
201
|
+
@book.close
|
202
|
+
new_excel = Excel.new(:reuse => false)
|
203
|
+
another_excel = Excel.new(:reuse => false)
|
204
|
+
Workbook.for_modifying(@simple_file1, :if_closed => another_excel) do |book|
|
205
|
+
sheet = book.sheet(1)
|
206
|
+
cell = sheet[1,1]
|
207
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
208
|
+
book.excel.should == another_excel
|
209
|
+
end
|
210
|
+
new_book = Workbook.open(@simple_file1, :visible => true)
|
211
|
+
sheet = new_book.sheet(1)
|
212
|
+
sheet[1,1].Value.should_not == @old_cell_value
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should change the value and use the new Excel instance" do
|
216
|
+
new_excel = Excel.new(:reuse => false)
|
217
|
+
Workbook.for_modifying(@simple_file1, :if_closed => :new) do |book|
|
218
|
+
sheet = book.sheet(1)
|
219
|
+
cell = sheet[1,1]
|
220
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
221
|
+
book.excel.should_not == @book.excel
|
222
|
+
book.excel.should_not == new_excel
|
223
|
+
book.excel.properties[:visible].should be false
|
224
|
+
book.excel.properties[:displayalerts].should == :if_visible
|
225
|
+
end
|
226
|
+
new_book = Workbook.open(@simple_file1, :visible => true)
|
227
|
+
sheet = new_book.sheet(1)
|
228
|
+
sheet[1,1].Value.should_not == @old_cell_value
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe "Workbook.for_reading, for_modifying" do
|
234
|
+
|
235
|
+
|
236
|
+
|
39
237
|
|
40
|
-
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
context "with open writable book" do
|
41
270
|
|
42
271
|
before do
|
43
272
|
@book = Workbook.open(@simple_file1)
|
@@ -52,6 +281,7 @@ describe Workbook do
|
|
52
281
|
@book.for_reading do |book|
|
53
282
|
book.should be_a Workbook
|
54
283
|
book.should be_alive
|
284
|
+
book.ReadOnly.should be false
|
55
285
|
book.Saved.should be true
|
56
286
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
57
287
|
book.Saved.should be false
|
@@ -106,6 +336,60 @@ describe Workbook do
|
|
106
336
|
|
107
337
|
end
|
108
338
|
|
339
|
+
describe "with referenced book" do
|
340
|
+
|
341
|
+
context "with no books" do
|
342
|
+
|
343
|
+
it "should open in read-only" do
|
344
|
+
Workbook.unobtrusively(@linked_sub_file, :writable => false) do |book|
|
345
|
+
book.ReadOnly.should be true
|
346
|
+
book.filename.should == @linked_sub_file
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should raise error when trying to change" do
|
351
|
+
|
352
|
+
expect{
|
353
|
+
Workbook.unobtrusively(@linked_sub_file, :writable => false) do |book|
|
354
|
+
book.ReadOnly.should be true
|
355
|
+
book.filename.should == @linked_sub_file
|
356
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
357
|
+
end
|
358
|
+
}.to raise_error(WorkbookReadOnly)
|
359
|
+
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
context "with open books" do
|
364
|
+
|
365
|
+
before do
|
366
|
+
@book_main = Workbook.open(@linked_file)
|
367
|
+
@book_sub = Workbook.open(@linked_sub_file)
|
368
|
+
end
|
369
|
+
|
370
|
+
it "should leave the read-only mode" do
|
371
|
+
Workbook.unobtrusively(@linked_sub_file, :read_only_default => true) do |book|
|
372
|
+
book.ReadOnly.should be false
|
373
|
+
book.should == @book_sub
|
374
|
+
book.filename.should == @book_sub.filename
|
375
|
+
book.excel.should == @book_sub.excel
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
it "should force to read-only" do
|
380
|
+
expect{
|
381
|
+
Workbook.unobtrusively(@linked_sub_file, :if_unsaved => :forget, :read_only => true) do |book|
|
382
|
+
book.ReadOnly.should be true
|
383
|
+
book.should == @book_sub
|
384
|
+
book.filename.should == @book_sub.filename
|
385
|
+
book.excel.should == @book_sub.excel
|
386
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
387
|
+
end
|
388
|
+
}.to raise_error(WorkbookReadOnly)
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
109
393
|
describe "Workbook#unobtrusively" do
|
110
394
|
|
111
395
|
context "with a writable saved workbook" do
|
@@ -778,7 +1062,7 @@ describe Workbook do
|
|
778
1062
|
b1.sheet(1)[1,1].Value.should_not == @old_value
|
779
1063
|
end
|
780
1064
|
|
781
|
-
it "should open as read-write" do
|
1065
|
+
it "should open as read-write but not save changes" do
|
782
1066
|
Workbook.unobtrusively(@simple_file, :read_only => false, :writable => false) do |book|
|
783
1067
|
book.ReadOnly.should be false
|
784
1068
|
@old_value = book.sheet(1)[1,1].Value
|
@@ -838,9 +1122,9 @@ describe Workbook do
|
|
838
1122
|
b1.sheet(1)[1,1].Value.should == @old_value
|
839
1123
|
end
|
840
1124
|
|
841
|
-
it "should open not writable" do
|
1125
|
+
it "should open not writable and read-only" do
|
842
1126
|
Workbook.unobtrusively(@simple_file, :writable => false) do |book|
|
843
|
-
|
1127
|
+
book.ReadOnly.should be true
|
844
1128
|
@old_value = book.sheet(1)[1,1].Value
|
845
1129
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
846
1130
|
book.Saved.should be false
|
@@ -2336,108 +2620,4 @@ describe Workbook do
|
|
2336
2620
|
|
2337
2621
|
end
|
2338
2622
|
|
2339
|
-
describe "for_reading, for_modifying" do
|
2340
|
-
|
2341
|
-
context "open unobtrusively for reading and modifying" do
|
2342
|
-
|
2343
|
-
before do
|
2344
|
-
@book = Workbook.open(@simple_file1)
|
2345
|
-
sheet = @book.sheet(1)
|
2346
|
-
@old_cell_value = sheet[1,1].Value
|
2347
|
-
@book.close
|
2348
|
-
end
|
2349
|
-
|
2350
|
-
it "should not change the value" do
|
2351
|
-
Workbook.for_reading(@simple_file1) do |book|
|
2352
|
-
book.should be_a Workbook
|
2353
|
-
book.should be_alive
|
2354
|
-
book.Saved.should be true
|
2355
|
-
sheet = book.sheet(1)
|
2356
|
-
cell = sheet[1,1]
|
2357
|
-
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
2358
|
-
book.Saved.should be false
|
2359
|
-
book.excel.should == @book.excel
|
2360
|
-
end
|
2361
|
-
Excel.kill_all
|
2362
|
-
new_book = Workbook.open(@simple_file1)
|
2363
|
-
sheet = new_book.sheet(1)
|
2364
|
-
sheet[1,1].Value.should == @old_cell_value
|
2365
|
-
end
|
2366
|
-
|
2367
|
-
it "should not change the value and use a given Excel" do
|
2368
|
-
new_excel = Excel.new(:reuse => false)
|
2369
|
-
another_excel = Excel.new(:reuse => false)
|
2370
|
-
Workbook.for_reading(@simple_file1, :if_closed => another_excel) do |book|
|
2371
|
-
sheet = book.sheet(1)
|
2372
|
-
cell = sheet[1,1]
|
2373
|
-
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
2374
|
-
book.excel.should == another_excel
|
2375
|
-
end
|
2376
|
-
Excel.kill_all
|
2377
|
-
new_book = Workbook.open(@simple_file1)
|
2378
|
-
sheet = new_book.sheet(1)
|
2379
|
-
sheet[1,1].Value.should == @old_cell_value
|
2380
|
-
end
|
2381
|
-
|
2382
|
-
it "should not change the value and use the new Excel instance" do
|
2383
|
-
new_excel = Excel.new(:reuse => false)
|
2384
|
-
Workbook.for_reading(@simple_file1, :if_closed => :new) do |book|
|
2385
|
-
sheet = book.sheet(1)
|
2386
|
-
cell = sheet[1,1]
|
2387
|
-
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
2388
|
-
book.excel.should_not == @book.excel
|
2389
|
-
book.excel.should_not == new_excel
|
2390
|
-
book.excel.properties[:visible].should be false
|
2391
|
-
book.excel.properties[:displayalerts].should == :if_visible
|
2392
|
-
end
|
2393
|
-
Excel.kill_all
|
2394
|
-
new_book = Workbook.open(@simple_file1)
|
2395
|
-
sheet = new_book.sheet(1)
|
2396
|
-
sheet[1,1].Value.should == @old_cell_value
|
2397
|
-
end
|
2398
|
-
|
2399
|
-
it "should change the value" do
|
2400
|
-
Workbook.for_modifying(@simple_file1) do |book|
|
2401
|
-
sheet = book.sheet(1)
|
2402
|
-
cell = sheet[1,1]
|
2403
|
-
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
2404
|
-
book.excel.should == @book.excel
|
2405
|
-
end
|
2406
|
-
new_book = Workbook.open(@simple_file, :visible => true)
|
2407
|
-
sheet = new_book.sheet(1)
|
2408
|
-
sheet[1,1].Value.should_not == @old_cell_value
|
2409
|
-
end
|
2410
|
-
|
2411
|
-
it "should change the value and use a given Excel" do
|
2412
|
-
new_excel = Excel.new(:reuse => false)
|
2413
|
-
another_excel = Excel.new(:reuse => false)
|
2414
|
-
Workbook.for_modifying(@simple_file1, :if_closed => another_excel) do |book|
|
2415
|
-
sheet = book.sheet(1)
|
2416
|
-
cell = sheet[1,1]
|
2417
|
-
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
2418
|
-
book.excel.should == another_excel
|
2419
|
-
end
|
2420
|
-
new_book = Workbook.open(@simple_file1, :visible => true)
|
2421
|
-
sheet = new_book.sheet(1)
|
2422
|
-
sheet[1,1].Value.should_not == @old_cell_value
|
2423
|
-
end
|
2424
|
-
|
2425
|
-
it "should change the value and use the new Excel instance" do
|
2426
|
-
new_excel = Excel.new(:reuse => false)
|
2427
|
-
Workbook.for_modifying(@simple_file1, :if_closed => :new) do |book|
|
2428
|
-
sheet = book.sheet(1)
|
2429
|
-
cell = sheet[1,1]
|
2430
|
-
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
2431
|
-
book.excel.should_not == @book.excel
|
2432
|
-
book.excel.should_not == new_excel
|
2433
|
-
book.excel.properties[:visible].should be false
|
2434
|
-
book.excel.properties[:displayalerts].should == :if_visible
|
2435
|
-
end
|
2436
|
-
new_book = Workbook.open(@simple_file1, :visible => true)
|
2437
|
-
sheet = new_book.sheet(1)
|
2438
|
-
sheet[1,1].Value.should_not == @old_cell_value
|
2439
|
-
end
|
2440
|
-
end
|
2441
|
-
end
|
2442
|
-
|
2443
2623
|
end
|