robust_excel_ole 1.13 → 1.18
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 +47 -4
- data/README.rdoc +52 -47
- data/___dummy_workbook.xls +0 -0
- data/docs/README_excel.rdoc +9 -3
- data/docs/README_open.rdoc +86 -44
- data/docs/README_ranges.rdoc +90 -81
- data/docs/README_save_close.rdoc +9 -9
- data/docs/README_sheet.rdoc +17 -17
- data/examples/example_ruby_library.rb +27 -0
- data/extconf.rb +7 -0
- data/lib/robust_excel_ole.rb +7 -4
- data/lib/robust_excel_ole/{address.rb → address_tool.rb} +23 -22
- data/lib/robust_excel_ole/{reo_common.rb → base.rb} +3 -92
- data/lib/robust_excel_ole/bookstore.rb +14 -77
- data/lib/robust_excel_ole/cell.rb +30 -18
- data/lib/robust_excel_ole/excel.rb +138 -92
- data/lib/robust_excel_ole/general.rb +40 -15
- data/lib/robust_excel_ole/range.rb +42 -19
- data/lib/robust_excel_ole/range_owners.rb +40 -25
- data/lib/robust_excel_ole/vba_objects.rb +30 -0
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +320 -319
- data/lib/robust_excel_ole/worksheet.rb +51 -25
- data/robust_excel_ole.gemspec +1 -0
- data/spec/address_tool_spec.rb +175 -0
- data/spec/{reo_common_spec.rb → base_spec.rb} +19 -34
- data/spec/bookstore_spec.rb +3 -3
- data/spec/cell_spec.rb +67 -25
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/excel_spec.rb +137 -369
- data/spec/general_spec.rb +21 -27
- data/spec/range_spec.rb +57 -3
- data/spec/workbook_spec.rb +11 -79
- data/spec/workbook_specs/workbook_misc_spec.rb +29 -40
- data/spec/workbook_specs/workbook_open_spec.rb +599 -31
- data/spec/workbook_specs/workbook_unobtr_spec.rb +760 -93
- data/spec/worksheet_spec.rb +36 -4
- metadata +12 -7
- data/spec/address_spec.rb +0 -174
@@ -35,8 +35,239 @@ describe Workbook do
|
|
35
35
|
rm_tmp(@dir)
|
36
36
|
end
|
37
37
|
|
38
|
+
describe "Workbook#for_reading, #for_modifying" do
|
39
|
+
|
40
|
+
context "with standard" do
|
41
|
+
|
42
|
+
before do
|
43
|
+
@book = Workbook.open(@simple_file1)
|
44
|
+
@old_value = @book.sheet(1)[1,1].Value
|
45
|
+
end
|
46
|
+
|
47
|
+
after do
|
48
|
+
@book.close(:if_unsaved => :forget) if @book && @book.alive?
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should not change the value" do
|
52
|
+
@book.for_reading do |book|
|
53
|
+
book.should be_a Workbook
|
54
|
+
book.should be_alive
|
55
|
+
book.Saved.should be true
|
56
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
57
|
+
book.Saved.should be false
|
58
|
+
end
|
59
|
+
@book.close(:if_unsaved => :forget)
|
60
|
+
new_book = Workbook.open(@simple_file1)
|
61
|
+
new_book.sheet(1)[1,1].Value.should == @old_value
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should change the value" do
|
65
|
+
@book.for_modifying do |book|
|
66
|
+
book.should be_a Workbook
|
67
|
+
book.should be_alive
|
68
|
+
book.Saved.should be true
|
69
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
70
|
+
book.Saved.should be false
|
71
|
+
end
|
72
|
+
@book.close(:if_unsaved => :forget)
|
73
|
+
new_book = Workbook.open(@simple_file1)
|
74
|
+
new_book.sheet(1)[1,1].Value.should_not == @old_value
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should not change the value and make visible" do
|
78
|
+
@book.for_reading(:visible => true) do |book|
|
79
|
+
book.should be_a Workbook
|
80
|
+
book.should be_alive
|
81
|
+
book.visible.should be true
|
82
|
+
book.Saved.should be true
|
83
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
84
|
+
book.Saved.should be false
|
85
|
+
end
|
86
|
+
@book.close(:if_unsaved => :forget)
|
87
|
+
new_book = Workbook.open(@simple_file1)
|
88
|
+
new_book.sheet(1)[1,1].Value.should == @old_value
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should change the value and make visible" do
|
92
|
+
@book.for_modifying(:visible => true) do |book|
|
93
|
+
book.should be_a Workbook
|
94
|
+
book.should be_alive
|
95
|
+
book.visible.should be true
|
96
|
+
book.Saved.should be true
|
97
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
98
|
+
book.Saved.should be false
|
99
|
+
end
|
100
|
+
@book.close(:if_unsaved => :forget)
|
101
|
+
new_book = Workbook.open(@simple_file1)
|
102
|
+
new_book.sheet(1)[1,1].Value.should_not == @old_value
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "Workbook#unobtrusively" do
|
110
|
+
|
111
|
+
context "with a writable saved workbook" do
|
112
|
+
|
113
|
+
before do
|
114
|
+
@book = Workbook.open(@simple_file1, :visible => true)
|
115
|
+
@old_value = @book.sheet(1)[1,1].Value
|
116
|
+
end
|
117
|
+
|
118
|
+
after do
|
119
|
+
@book.close(:if_unsaved => :forget) if @book && @book.alive?
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should unobtrusively open, modify, and retain the status" do
|
123
|
+
@book.unobtrusively do |book|
|
124
|
+
book.saved.should be true
|
125
|
+
book.visible.should be true
|
126
|
+
book.writable.should be true
|
127
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
128
|
+
end
|
129
|
+
@book.saved.should be true
|
130
|
+
@book.visible.should be true
|
131
|
+
@book.writable.should be true
|
132
|
+
@book.sheet(1)[1,1].Value.should_not == @old_value
|
133
|
+
@book.close
|
134
|
+
new_book = Workbook.open(@simple_file1)
|
135
|
+
new_book.sheet(1)[1,1].Value.should_not == @old_value
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should unobtrusively open, modify, and not save the changes" do
|
139
|
+
@book.unobtrusively(:writable => false) do |book|
|
140
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
141
|
+
end
|
142
|
+
@book.saved.should be true
|
143
|
+
@book.visible.should be true
|
144
|
+
@book.writable.should be true
|
145
|
+
@book.sheet(1)[1,1].Value.should_not == @old_value
|
146
|
+
@book.close
|
147
|
+
new_book = Workbook.open(@simple_file1)
|
148
|
+
new_book.sheet(1)[1,1].Value.should == @old_value
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should unobtrusively open, modify, and save the changes" do
|
152
|
+
@book.unobtrusively(:writable => true) do |book|
|
153
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
154
|
+
end
|
155
|
+
@book.saved.should be true
|
156
|
+
@book.visible.should be true
|
157
|
+
@book.writable.should be true
|
158
|
+
@book.sheet(1)[1,1].Value.should_not == @old_value
|
159
|
+
@book.close
|
160
|
+
new_book = Workbook.open(@simple_file1)
|
161
|
+
new_book.sheet(1)[1,1].Value.should_not == @old_value
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
context "with an writable unsaved workbook" do
|
167
|
+
|
168
|
+
before do
|
169
|
+
@book = Workbook.open(@simple_file1, :visible => true)
|
170
|
+
@old_value = @book.sheet(1)[1,1].Value
|
171
|
+
sheet = @book.sheet(1)
|
172
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
173
|
+
end
|
174
|
+
|
175
|
+
after do
|
176
|
+
@book.close(:if_unsaved => :forget) if @book && @book.alive?
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should unobtrusively open, modify, and retain the status" do
|
180
|
+
@book.unobtrusively do |book|
|
181
|
+
book.saved.should be false
|
182
|
+
book.visible.should be true
|
183
|
+
book.writable.should be true
|
184
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
185
|
+
end
|
186
|
+
@book.saved.should be false
|
187
|
+
@book.visible.should be true
|
188
|
+
@book.writable.should be true
|
189
|
+
@book.sheet(1)[1,1].Value.should == @old_value
|
190
|
+
@book.close(:if_unsaved => :forget)
|
191
|
+
@book = Workbook.open(@simple_file1)
|
192
|
+
@book.sheet(1)[1,1].Value.should == @old_value
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should unobtrusively open, modify, and not save the changes" do
|
196
|
+
@book.unobtrusively(:writable => false) do |book|
|
197
|
+
book.sheet(1)[1,1] = "bla"
|
198
|
+
end
|
199
|
+
@book.saved.should be false
|
200
|
+
@book.visible.should be true
|
201
|
+
@book.writable.should be true
|
202
|
+
@book.sheet(1)[1,1].Value.should == "bla"
|
203
|
+
@book.close(:if_unsaved => :forget)
|
204
|
+
new_book = Workbook.open(@simple_file1)
|
205
|
+
new_book.sheet(1)[1,1].Value.should == @old_value
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should unobtrusively open, modify, and save the changes" do
|
209
|
+
@book.unobtrusively(:writable => true) do |book|
|
210
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
211
|
+
end
|
212
|
+
@book.saved.should be false
|
213
|
+
@book.visible.should be true
|
214
|
+
@book.writable.should be true
|
215
|
+
@book.sheet(1)[1,1].Value.should == @old_value
|
216
|
+
@book.close(:if_unsaved => :forget)
|
217
|
+
new_book = Workbook.open(@simple_file1)
|
218
|
+
new_book.sheet(1)[1,1].Value.should == @old_value
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
context "with a closed workbook" do
|
224
|
+
|
225
|
+
before do
|
226
|
+
@book = Workbook.open(@simple_file1, :visible => true)
|
227
|
+
@old_value = @book.sheet(1)[1,1].Value
|
228
|
+
@book.close
|
229
|
+
end
|
230
|
+
|
231
|
+
after do
|
232
|
+
@book.close(:if_unsaved => :forget) if @book && @book.alive?
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should unobtrusively open and close the workbook" do
|
236
|
+
@book.unobtrusively do |book|
|
237
|
+
book.should be_alive
|
238
|
+
book.saved.should be true
|
239
|
+
book.visible.should be true
|
240
|
+
book.writable.should be true
|
241
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
242
|
+
end
|
243
|
+
@book.should_not be_alive
|
244
|
+
new_book = Workbook.open(@simple_file1)
|
245
|
+
new_book.sheet(1)[1,1].Value.should_not == @old_value
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should unobtrusively open and and not close the workbook" do
|
249
|
+
@book.unobtrusively(:visible => true, :keep_open => true) do |book|
|
250
|
+
book.should be_alive
|
251
|
+
book.saved.should be true
|
252
|
+
book.visible.should be true
|
253
|
+
book.writable.should be true
|
254
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
255
|
+
end
|
256
|
+
@book.should be_alive
|
257
|
+
@book.saved.should be true
|
258
|
+
@book.visible.should be true
|
259
|
+
@book.writable.should be true
|
260
|
+
@book.sheet(1)[1,1].Value.should_not == @old_value
|
261
|
+
@book.close
|
262
|
+
new_book = Workbook.open(@simple_file1)
|
263
|
+
new_book.sheet(1)[1,1].Value.should_not == @old_value
|
264
|
+
end
|
265
|
+
|
266
|
+
end
|
267
|
+
|
268
|
+
end
|
38
269
|
|
39
|
-
describe "unobtrusively" do
|
270
|
+
describe "Workbook.unobtrusively" do
|
40
271
|
|
41
272
|
# @private
|
42
273
|
def unobtrusively_ok?
|
@@ -80,6 +311,427 @@ describe Workbook do
|
|
80
311
|
|
81
312
|
end
|
82
313
|
|
314
|
+
describe "unknown workbooks" do
|
315
|
+
|
316
|
+
context "with one invisible saved writable workbook" do
|
317
|
+
|
318
|
+
before do
|
319
|
+
@ole_e1 = WIN32OLE.new('Excel.Application')
|
320
|
+
ws = @ole_e1.Workbooks
|
321
|
+
@abs_filename = General.absolute_path(@simple_file1)
|
322
|
+
@ole_wb = ws.Open(@abs_filename)
|
323
|
+
@old_value = @ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value
|
324
|
+
end
|
325
|
+
|
326
|
+
it "should connect" do
|
327
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
328
|
+
book.excel.Workbooks.Count.should == 1
|
329
|
+
Excel.excels_number.should == 1
|
330
|
+
book.FullName.should == General.absolute_path(@simple_file1)
|
331
|
+
book.saved.should be true
|
332
|
+
book.visible.should be false
|
333
|
+
book.writable.should be true
|
334
|
+
end
|
335
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
336
|
+
ole_wb.Saved.should be true
|
337
|
+
@ole_e1.Visible.should be false
|
338
|
+
ole_wb.ReadOnly.should be false
|
339
|
+
end
|
340
|
+
|
341
|
+
it "should set visible => true and remain invisiblity" do
|
342
|
+
Workbook.unobtrusively(@simple_file1, :visible => true) do |book|
|
343
|
+
book.saved.should be true
|
344
|
+
book.visible.should be true
|
345
|
+
book.writable.should be true
|
346
|
+
end
|
347
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
348
|
+
ole_wb.Saved.should be true
|
349
|
+
@ole_e1.Visible.should be true
|
350
|
+
ole_wb.Windows(ole_wb.Name).Visible.should be false
|
351
|
+
ole_wb.ReadOnly.should be false
|
352
|
+
end
|
353
|
+
|
354
|
+
it "should set read_only => true and remain writability" do
|
355
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book|
|
356
|
+
book.saved.should be true
|
357
|
+
book.visible.should be false
|
358
|
+
book.ReadOnly.should be true
|
359
|
+
book.writable.should be false
|
360
|
+
end
|
361
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
362
|
+
ole_wb.Saved.should be true
|
363
|
+
@ole_e1.Visible.should be false
|
364
|
+
ole_wb.ReadOnly.should be false
|
365
|
+
end
|
366
|
+
|
367
|
+
it "should set visible => true, read_only => true" do
|
368
|
+
Workbook.unobtrusively(@simple_file1, :visible => true, :read_only => true) do |book|
|
369
|
+
book.saved.should be true
|
370
|
+
book.visible.should be true
|
371
|
+
book.ReadOnly.should be true
|
372
|
+
book.writable.should be false
|
373
|
+
end
|
374
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
375
|
+
ole_wb.Saved.should be true
|
376
|
+
@ole_e1.Visible.should be true
|
377
|
+
ole_wb.Windows(ole_wb.Name).Visible.should be false
|
378
|
+
ole_wb.ReadOnly.should be false
|
379
|
+
end
|
380
|
+
|
381
|
+
it "should modify and remain saved-status" do
|
382
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
383
|
+
book.saved.should be true
|
384
|
+
book.visible.should be false
|
385
|
+
book.writable.should be true
|
386
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
387
|
+
@new_value = book.sheet(1)[1,1].Value
|
388
|
+
book.Saved.should be false
|
389
|
+
end
|
390
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
391
|
+
ole_wb.Saved.should be true
|
392
|
+
@ole_e1.Visible.should be false
|
393
|
+
ole_wb.ReadOnly.should be false
|
394
|
+
ole_wb.Close
|
395
|
+
book2 = Workbook.open(@simple_file1)
|
396
|
+
book2.sheet(1)[1,1].Value.should_not == @old_value
|
397
|
+
book2.sheet(1)[1,1].Value.should == @new_value
|
398
|
+
end
|
399
|
+
|
400
|
+
it "should modify and remain saved-status and not save the new value when writable => false" do
|
401
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
402
|
+
book.saved.should be true
|
403
|
+
book.visible.should be false
|
404
|
+
book.writable.should be true
|
405
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
406
|
+
@new_value = book.sheet(1)[1,1].Value
|
407
|
+
book.Saved.should be false
|
408
|
+
end
|
409
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
410
|
+
ole_wb.Saved.should be true
|
411
|
+
@ole_e1.Visible.should be false
|
412
|
+
ole_wb.ReadOnly.should be false
|
413
|
+
ole_wb.Close
|
414
|
+
book2 = Workbook.open(@simple_file1)
|
415
|
+
book2.sheet(1)[1,1].Value.should == @old_value
|
416
|
+
book2.sheet(1)[1,1].Value.should_not == @new_value
|
417
|
+
end
|
418
|
+
|
419
|
+
end
|
420
|
+
|
421
|
+
context "with one visible saved writable workbook" do
|
422
|
+
|
423
|
+
before do
|
424
|
+
@ole_e1 = WIN32OLE.new('Excel.Application')
|
425
|
+
ws = @ole_e1.Workbooks
|
426
|
+
@abs_filename = General.absolute_path(@simple_file1)
|
427
|
+
@ole_wb = ws.Open(@abs_filename)
|
428
|
+
@ole_e1.Visible = true
|
429
|
+
@ole_wb.Windows(@ole_wb.Name).Visible = true
|
430
|
+
end
|
431
|
+
|
432
|
+
it "should remain visibility" do
|
433
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
434
|
+
book.saved.should be true
|
435
|
+
book.visible.should be true
|
436
|
+
book.writable.should be true
|
437
|
+
end
|
438
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
439
|
+
ole_wb.Saved.should be true
|
440
|
+
@ole_e1.Visible.should be true
|
441
|
+
ole_wb.ReadOnly.should be false
|
442
|
+
end
|
443
|
+
|
444
|
+
it "should set visible => false and remain visibility" do
|
445
|
+
Workbook.unobtrusively(@simple_file1, :visible => false) do |book|
|
446
|
+
book.saved.should be true
|
447
|
+
book.visible.should be false
|
448
|
+
book.writable.should be true
|
449
|
+
end
|
450
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
451
|
+
ole_wb.Saved.should be true
|
452
|
+
@ole_e1.Visible.should be true
|
453
|
+
ole_wb.ReadOnly.should be false
|
454
|
+
end
|
455
|
+
|
456
|
+
end
|
457
|
+
|
458
|
+
context "with one unsaved writable workbook" do
|
459
|
+
|
460
|
+
before do
|
461
|
+
@ole_e1 = WIN32OLE.new('Excel.Application')
|
462
|
+
ws = @ole_e1.Workbooks
|
463
|
+
@abs_filename = General.absolute_path(@simple_file1)
|
464
|
+
@ole_wb = ws.Open(@abs_filename)
|
465
|
+
@ole_e1.Visible = true
|
466
|
+
@ole_wb.Windows(@ole_wb.Name).Visible = true
|
467
|
+
@old_value = @ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value
|
468
|
+
@ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value = @old_value = "foo" #== "foo" ? "bar" : "foo"
|
469
|
+
@new_value = @ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value
|
470
|
+
@ole_wb.Saved.should be false
|
471
|
+
end
|
472
|
+
|
473
|
+
it "should connect and remain unsaved" do
|
474
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
475
|
+
book.saved.should be false
|
476
|
+
book.visible.should be true
|
477
|
+
book.writable.should be true
|
478
|
+
end
|
479
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
480
|
+
ole_wb.Saved.should be false
|
481
|
+
@ole_e1.Visible.should be true
|
482
|
+
ole_wb.ReadOnly.should be false
|
483
|
+
end
|
484
|
+
|
485
|
+
it "should raise error" do
|
486
|
+
expect{
|
487
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book|
|
488
|
+
book.saved.should be false
|
489
|
+
book.visible.should be true
|
490
|
+
book.writable.should be false
|
491
|
+
end
|
492
|
+
}.to raise_error(WorkbookNotSaved)
|
493
|
+
end
|
494
|
+
|
495
|
+
it "should remain writable" do
|
496
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true, :if_unsaved => :save) do |book|
|
497
|
+
book.saved.should be true
|
498
|
+
book.visible.should be true
|
499
|
+
book.writable.should be false
|
500
|
+
end
|
501
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
502
|
+
ole_wb.Saved.should be false
|
503
|
+
@ole_e1.Visible.should be true
|
504
|
+
ole_wb.ReadOnly.should be false
|
505
|
+
end
|
506
|
+
|
507
|
+
it "should remain unsaved when modifying" do
|
508
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
509
|
+
book.sheet(1)[1,1] = "bar" #book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
510
|
+
@new_value = book.sheet(1)[1,1].Value
|
511
|
+
book.saved.should be false
|
512
|
+
book.visible.should be true
|
513
|
+
book.writable.should be true
|
514
|
+
end
|
515
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
516
|
+
ole_wb.Saved.should be false
|
517
|
+
@ole_e1.Visible.should be true
|
518
|
+
ole_wb.ReadOnly.should be false
|
519
|
+
Excel.kill_all
|
520
|
+
book2 = Workbook.open(@simple_file1)
|
521
|
+
book2.sheet(1)[1,1].Value.should_not == @old_value
|
522
|
+
book2.sheet(1)[1,1].Value.should == @new_value
|
523
|
+
end
|
524
|
+
|
525
|
+
it "should not write with :writable => false" do
|
526
|
+
@ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value = @old_value = "foo"
|
527
|
+
@ole_wb.Save
|
528
|
+
@ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value = @old_value = "foo"
|
529
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
530
|
+
book.sheet(1)[1,1] = "bar" #book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
531
|
+
@new_value = book.sheet(1)[1,1].Value
|
532
|
+
book.saved.should be false
|
533
|
+
book.visible.should be true
|
534
|
+
book.writable.should be true
|
535
|
+
end
|
536
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
537
|
+
ole_wb.Saved.should be false
|
538
|
+
@ole_e1.Visible.should be true
|
539
|
+
ole_wb.ReadOnly.should be false
|
540
|
+
Excel.kill_all
|
541
|
+
book2 = Workbook.open(@simple_file1)
|
542
|
+
book2.sheet(1)[1,1].Value.should == @old_value
|
543
|
+
book2.sheet(1)[1,1].Value.should_not == @new_value
|
544
|
+
end
|
545
|
+
|
546
|
+
end
|
547
|
+
|
548
|
+
context "with one read-only workbook" do
|
549
|
+
|
550
|
+
before do
|
551
|
+
@ole_e1 = WIN32OLE.new('Excel.Application')
|
552
|
+
ws = @ole_e1.Workbooks
|
553
|
+
@abs_filename = General.absolute_path(@simple_file1)
|
554
|
+
@ole_wb = ws.Open(@abs_filename, RobustExcelOle::XlUpdateLinksNever, true)
|
555
|
+
@old_value = @ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value
|
556
|
+
@ole_e1.Visible = true
|
557
|
+
@ole_wb.Windows(@ole_wb.Name).Visible = true
|
558
|
+
@ole_wb.ReadOnly.should be true
|
559
|
+
end
|
560
|
+
|
561
|
+
it "should connect and remain read-only" do
|
562
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
563
|
+
book.saved.should be true
|
564
|
+
book.visible.should be true
|
565
|
+
book.writable.should be false
|
566
|
+
end
|
567
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
568
|
+
ole_wb.Saved.should be true
|
569
|
+
@ole_e1.Visible.should be true
|
570
|
+
ole_wb.ReadOnly.should be true
|
571
|
+
end
|
572
|
+
|
573
|
+
it "should remain read-only" do
|
574
|
+
Workbook.unobtrusively(@simple_file1, :read_only => false) do |book|
|
575
|
+
book.saved.should be true
|
576
|
+
book.visible.should be true
|
577
|
+
book.writable.should be true
|
578
|
+
end
|
579
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
580
|
+
ole_wb.Saved.should be true
|
581
|
+
@ole_e1.Visible.should be true
|
582
|
+
ole_wb.ReadOnly.should be true
|
583
|
+
end
|
584
|
+
|
585
|
+
it "should remain read-only when modifying" do
|
586
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
587
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
588
|
+
@new_value = book.sheet(1)[1,1].Value
|
589
|
+
book.saved.should be false
|
590
|
+
book.visible.should be true
|
591
|
+
book.writable.should be false
|
592
|
+
end
|
593
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
594
|
+
ole_wb.Saved.should be true
|
595
|
+
@ole_e1.Visible.should be true
|
596
|
+
ole_wb.ReadOnly.should be true
|
597
|
+
ole_wb.Close
|
598
|
+
book2 = Workbook.open(@simple_file1)
|
599
|
+
book2.sheet(1)[1,1].Value.should == @old_value
|
600
|
+
book2.sheet(1)[1,1].Value.should_not == @new_value
|
601
|
+
end
|
602
|
+
|
603
|
+
it "should remain read-only when modifying" do
|
604
|
+
Workbook.unobtrusively(@simple_file1, :read_only => false) do |book|
|
605
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
606
|
+
@new_value = book.sheet(1)[1,1].Value
|
607
|
+
book.saved.should be false
|
608
|
+
book.visible.should be true
|
609
|
+
book.writable.should be true
|
610
|
+
end
|
611
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
612
|
+
ole_wb.Saved.should be true
|
613
|
+
@ole_e1.Visible.should be true
|
614
|
+
ole_wb.ReadOnly.should be true
|
615
|
+
ole_wb.Close
|
616
|
+
book2 = Workbook.open(@simple_file1)
|
617
|
+
book2.sheet(1)[1,1].Value.should_not == @old_value
|
618
|
+
book2.sheet(1)[1,1].Value.should == @new_value
|
619
|
+
end
|
620
|
+
|
621
|
+
it "should remain read-only when modifying" do
|
622
|
+
Workbook.unobtrusively(@simple_file1, :read_only => false, :writable => true) do |book|
|
623
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
624
|
+
@new_value = book.sheet(1)[1,1].Value
|
625
|
+
book.saved.should be false
|
626
|
+
book.visible.should be true
|
627
|
+
book.writable.should be true
|
628
|
+
end
|
629
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
630
|
+
ole_wb.Saved.should be true
|
631
|
+
@ole_e1.Visible.should be true
|
632
|
+
ole_wb.ReadOnly.should be true
|
633
|
+
ole_wb.Close
|
634
|
+
book2 = Workbook.open(@simple_file1)
|
635
|
+
book2.sheet(1)[1,1].Value.should_not == @old_value
|
636
|
+
book2.sheet(1)[1,1].Value.should == @new_value
|
637
|
+
end
|
638
|
+
|
639
|
+
it "should remain read-only when modifying and not save changes, when :writable => false" do
|
640
|
+
Workbook.unobtrusively(@simple_file1, :writable => false, :read_only => false) do |book|
|
641
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
642
|
+
@new_value = book.sheet(1)[1,1].Value
|
643
|
+
book.saved.should be false
|
644
|
+
book.visible.should be true
|
645
|
+
book.writable.should be true
|
646
|
+
end
|
647
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
648
|
+
ole_wb.Saved.should be true
|
649
|
+
@ole_e1.Visible.should be true
|
650
|
+
ole_wb.ReadOnly.should be true
|
651
|
+
ole_wb.Close
|
652
|
+
book2 = Workbook.open(@simple_file1)
|
653
|
+
book2.sheet(1)[1,1].Value.should == @old_value
|
654
|
+
book2.sheet(1)[1,1].Value.should_not == @new_value
|
655
|
+
end
|
656
|
+
|
657
|
+
it "should remain read-only when modifying and not save changes, when :writable => false" do
|
658
|
+
Workbook.unobtrusively(@simple_file1, :read_only => false, :writable => false) do |book|
|
659
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
660
|
+
@new_value = book.sheet(1)[1,1].Value
|
661
|
+
book.saved.should be false
|
662
|
+
book.visible.should be true
|
663
|
+
book.writable.should be true
|
664
|
+
end
|
665
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
666
|
+
ole_wb.Saved.should be true
|
667
|
+
@ole_e1.Visible.should be true
|
668
|
+
ole_wb.ReadOnly.should be true
|
669
|
+
ole_wb.Close
|
670
|
+
book2 = Workbook.open(@simple_file1)
|
671
|
+
book2.sheet(1)[1,1].Value.should == @old_value
|
672
|
+
book2.sheet(1)[1,1].Value.should_not == @new_value
|
673
|
+
end
|
674
|
+
|
675
|
+
|
676
|
+
it "should remain read-only when modifying and not save changes, when :writable => false" do
|
677
|
+
Workbook.unobtrusively(@simple_file1, :writable => false, :read_only => false) do |book|
|
678
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
679
|
+
@new_value = book.sheet(1)[1,1].Value
|
680
|
+
book.saved.should be false
|
681
|
+
book.visible.should be true
|
682
|
+
book.writable.should be true
|
683
|
+
end
|
684
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
685
|
+
ole_wb.Saved.should be true
|
686
|
+
@ole_e1.Visible.should be true
|
687
|
+
ole_wb.ReadOnly.should be true
|
688
|
+
ole_wb.Close
|
689
|
+
book2 = Workbook.open(@simple_file1)
|
690
|
+
book2.sheet(1)[1,1].Value.should == @old_value
|
691
|
+
book2.sheet(1)[1,1].Value.should_not == @new_value
|
692
|
+
end
|
693
|
+
|
694
|
+
it "should remain read-only when modifying and not save changes, even if :writable => true" do
|
695
|
+
Workbook.unobtrusively(@simple_file1, :writable => true) do |book|
|
696
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
697
|
+
@new_value = book.sheet(1)[1,1].Value
|
698
|
+
book.saved.should be false
|
699
|
+
book.visible.should be true
|
700
|
+
book.writable.should be false
|
701
|
+
end
|
702
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
703
|
+
ole_wb.Saved.should be true
|
704
|
+
@ole_e1.Visible.should be true
|
705
|
+
ole_wb.ReadOnly.should be true
|
706
|
+
ole_wb.Close
|
707
|
+
book2 = Workbook.open(@simple_file1)
|
708
|
+
book2.sheet(1)[1,1].Value.should == @old_value
|
709
|
+
book2.sheet(1)[1,1].Value.should_not == @new_value
|
710
|
+
end
|
711
|
+
|
712
|
+
it "should remain read-only when modifying and not save changes, when :writable => false" do
|
713
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
714
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
715
|
+
@new_value = book.sheet(1)[1,1].Value
|
716
|
+
book.saved.should be false
|
717
|
+
book.visible.should be true
|
718
|
+
book.writable.should be false
|
719
|
+
end
|
720
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
721
|
+
ole_wb.Saved.should be true
|
722
|
+
@ole_e1.Visible.should be true
|
723
|
+
ole_wb.ReadOnly.should be true
|
724
|
+
Excel.kill_all
|
725
|
+
book2 = Workbook.open(@simple_file1)
|
726
|
+
book2.sheet(1)[1,1].Value.should == @old_value
|
727
|
+
book2.sheet(1)[1,1].Value.should_not == @new_value
|
728
|
+
end
|
729
|
+
|
730
|
+
|
731
|
+
end
|
732
|
+
|
733
|
+
end
|
734
|
+
|
83
735
|
describe "excels number" do
|
84
736
|
|
85
737
|
it "should open one excel instance and workbook should be closed" do
|
@@ -135,7 +787,7 @@ describe Workbook do
|
|
135
787
|
end
|
136
788
|
Excel.current.Workbooks.Count.should == 0
|
137
789
|
b1 = Workbook.open(@simple_file1)
|
138
|
-
b1.sheet(1)[1,1].Value.
|
790
|
+
b1.sheet(1)[1,1].Value.should == @old_value
|
139
791
|
end
|
140
792
|
|
141
793
|
it "should open as read-write" do
|
@@ -166,8 +818,8 @@ describe Workbook do
|
|
166
818
|
Workbook.unobtrusively(@simple_file, :read_only => true) do |book|
|
167
819
|
book.ReadOnly.should be true
|
168
820
|
@old_value = book.sheet(1)[1,1].Value
|
169
|
-
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
170
|
-
book.Saved.should be false
|
821
|
+
#book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
822
|
+
#book.Saved.should be false
|
171
823
|
end
|
172
824
|
Excel.current.Workbooks.Count.should == 0
|
173
825
|
b1 = Workbook.open(@simple_file1)
|
@@ -188,7 +840,7 @@ describe Workbook do
|
|
188
840
|
|
189
841
|
it "should open not writable" do
|
190
842
|
Workbook.unobtrusively(@simple_file, :writable => false) do |book|
|
191
|
-
|
843
|
+
#
|
192
844
|
@old_value = book.sheet(1)[1,1].Value
|
193
845
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
194
846
|
book.Saved.should be false
|
@@ -248,7 +900,7 @@ describe Workbook do
|
|
248
900
|
end
|
249
901
|
@book.close
|
250
902
|
book2 = Workbook.open(@simple_file1)
|
251
|
-
book2.sheet(1)[1,1].Value.
|
903
|
+
book2.sheet(1)[1,1].Value.should == @old_value
|
252
904
|
end
|
253
905
|
|
254
906
|
it "should open as read-write" do
|
@@ -278,18 +930,20 @@ describe Workbook do
|
|
278
930
|
end
|
279
931
|
|
280
932
|
it "should force to read-only" do
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
book2.sheet(1)[1,1].Value.should == @old_value
|
933
|
+
expect{
|
934
|
+
Workbook.unobtrusively(@simple_file1, :if_unsaved => :forget, :read_only => true) do |book|
|
935
|
+
book.ReadOnly.should be true
|
936
|
+
book.should == @book
|
937
|
+
book.filename.should == @book.filename
|
938
|
+
book.excel.should_not == @book.excel
|
939
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
940
|
+
end
|
941
|
+
}.to raise_error(WorkbookReadOnly)
|
291
942
|
end
|
292
943
|
|
944
|
+
|
945
|
+
|
946
|
+
|
293
947
|
it "should force to read-only" do
|
294
948
|
Workbook.unobtrusively(@simple_file1, :read_only => true, :writable => false) do |book|
|
295
949
|
book.ReadOnly.should be true
|
@@ -330,6 +984,7 @@ describe Workbook do
|
|
330
984
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
331
985
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
332
986
|
end
|
987
|
+
@book.ReadOnly.should be true
|
333
988
|
@book.close
|
334
989
|
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
335
990
|
book.sheet(1)[1,1].Value.should == @old_value
|
@@ -347,6 +1002,7 @@ describe Workbook do
|
|
347
1002
|
book.excel.should == @book.excel
|
348
1003
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
349
1004
|
end
|
1005
|
+
@book.ReadOnly.should be true
|
350
1006
|
@book.close
|
351
1007
|
book2 = Workbook.open(@simple_file1)
|
352
1008
|
book2.sheet(1)[1,1].Value.should == @old_value
|
@@ -354,23 +1010,23 @@ describe Workbook do
|
|
354
1010
|
|
355
1011
|
it "should open as read-write" do
|
356
1012
|
Workbook.unobtrusively(@simple_file1, :read_only => false) do |book|
|
357
|
-
book.Readonly.should be
|
1013
|
+
book.Readonly.should be false
|
358
1014
|
book.should == @book
|
359
1015
|
book.filename.should == @book.filename
|
360
|
-
book.excel.
|
1016
|
+
book.excel.should_not == @book.excel
|
361
1017
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
362
1018
|
end
|
363
1019
|
@book.close
|
364
1020
|
book2 = Workbook.open(@simple_file1)
|
365
|
-
book2.sheet(1)[1,1].Value.
|
1021
|
+
book2.sheet(1)[1,1].Value.should_not == @old_value
|
366
1022
|
end
|
367
1023
|
|
368
1024
|
it "should open as read-write" do
|
369
1025
|
Workbook.unobtrusively(@simple_file1, :read_only => false, :writable => false) do |book|
|
370
|
-
book.Readonly.should be
|
1026
|
+
book.Readonly.should be false
|
371
1027
|
book.should == @book
|
372
1028
|
book.filename.should == @book.filename
|
373
|
-
book.excel.
|
1029
|
+
book.excel.should_not == @book.excel
|
374
1030
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
375
1031
|
end
|
376
1032
|
@book.close
|
@@ -378,9 +1034,9 @@ describe Workbook do
|
|
378
1034
|
book2.sheet(1)[1,1].Value.should == @old_value
|
379
1035
|
end
|
380
1036
|
|
381
|
-
it "should
|
1037
|
+
it "should remain read-only even if writeble => true" do
|
382
1038
|
Workbook.unobtrusively(@simple_file1, :writable => true) do |book|
|
383
|
-
book.ReadOnly.should be
|
1039
|
+
book.ReadOnly.should be true
|
384
1040
|
book.should == @book
|
385
1041
|
book.filename.should == @book.filename
|
386
1042
|
book.excel.should == @book.excel
|
@@ -388,7 +1044,7 @@ describe Workbook do
|
|
388
1044
|
end
|
389
1045
|
@book.close
|
390
1046
|
book2 = Workbook.open(@simple_file1)
|
391
|
-
book2.sheet(1)[1,1].Value.
|
1047
|
+
book2.sheet(1)[1,1].Value.should == @old_value
|
392
1048
|
end
|
393
1049
|
|
394
1050
|
it "should force to read-write" do
|
@@ -404,6 +1060,7 @@ describe Workbook do
|
|
404
1060
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
405
1061
|
end
|
406
1062
|
|
1063
|
+
=begin
|
407
1064
|
it "should force to read-write" do
|
408
1065
|
e1 = Excel.create
|
409
1066
|
Workbook.unobtrusively(@simple_file1, :writable => true, :rw_change_excel => e1) do |book|
|
@@ -441,6 +1098,7 @@ describe Workbook do
|
|
441
1098
|
book2 = Workbook.open(@simple_file1)
|
442
1099
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
443
1100
|
end
|
1101
|
+
=end
|
444
1102
|
|
445
1103
|
it "should force to read-write" do
|
446
1104
|
Workbook.unobtrusively(@simple_file1, :writable => true, :read_only => false) do |book|
|
@@ -563,16 +1221,22 @@ describe Workbook do
|
|
563
1221
|
@book.sheet(1)[1,1].Value.should_not == @old_value
|
564
1222
|
end
|
565
1223
|
|
566
|
-
it "should force to read-only
|
567
|
-
|
568
|
-
|
569
|
-
|
1224
|
+
it "should force to read-only" do
|
1225
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true, :if_unsaved => :save) do |book|
|
1226
|
+
book.ReadOnly.should be true
|
1227
|
+
end
|
1228
|
+
@book.Saved.should be false
|
1229
|
+
@book.ReadOnly.should be false
|
1230
|
+
@book.sheet(1)[1,1].Value.should == @old_value
|
570
1231
|
end
|
571
1232
|
|
572
|
-
it "should force to read-only
|
573
|
-
|
574
|
-
|
575
|
-
|
1233
|
+
it "should force to read-only with writable false" do
|
1234
|
+
Workbook.unobtrusively(@simple_file1, :if_unsaved => :save, :read_only => true, :writable => false) do |book|
|
1235
|
+
book.ReadOnly.should be true
|
1236
|
+
end
|
1237
|
+
@book.Saved.should be false
|
1238
|
+
@book.ReadOnly.should be false
|
1239
|
+
@book.sheet(1)[1,1].Value.should == @old_value
|
576
1240
|
end
|
577
1241
|
|
578
1242
|
it "should open not writable" do
|
@@ -616,48 +1280,23 @@ describe Workbook do
|
|
616
1280
|
end
|
617
1281
|
|
618
1282
|
it "should open as read-only" do
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
book.filename.should == @book.filename
|
623
|
-
book.excel.should == @book.excel
|
624
|
-
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
625
|
-
end
|
626
|
-
@book.Saved.should be false
|
627
|
-
@book.ReadOnly.should be true
|
628
|
-
@book.sheet(1)[1,1].Value.should_not == @old_value
|
629
|
-
@book.close
|
630
|
-
book2 = Workbook.open(@simple_file1)
|
631
|
-
book2.sheet(1)[1,1].Value.should_not == @old_value
|
1283
|
+
expect{
|
1284
|
+
Workbook.unobtrusively(@simple_file1, :if_unsaved => :accept, :read_only => false, :writable => false)
|
1285
|
+
}.to raise_error(OptionInvalid)
|
632
1286
|
end
|
633
1287
|
|
634
|
-
it "should
|
635
|
-
Workbook.unobtrusively(@simple_file1, :
|
1288
|
+
it "should remain read-only and not write, even with :writable => true" do
|
1289
|
+
Workbook.unobtrusively(@simple_file1, :writable => true) do |book|
|
636
1290
|
book.Readonly.should be true
|
637
|
-
book.should
|
638
|
-
book.filename.should == @book.filename
|
639
|
-
book.excel.should == @book.excel
|
1291
|
+
book.Saved.should be false
|
640
1292
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
641
1293
|
end
|
642
|
-
@book.Saved.should be false
|
643
1294
|
@book.ReadOnly.should be true
|
644
1295
|
@book.sheet(1)[1,1].Value.should_not == @old_value
|
645
1296
|
@book.close
|
646
1297
|
book2 = Workbook.open(@simple_file1)
|
647
1298
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
648
1299
|
end
|
649
|
-
|
650
|
-
it "should raise an error" do
|
651
|
-
expect{
|
652
|
-
Workbook.unobtrusively(@simple_file1, :writable => true)
|
653
|
-
}.to raise_error(NotImplementedREOError, "unsaved read-only workbook shall be written")
|
654
|
-
end
|
655
|
-
|
656
|
-
it "should raise an error" do
|
657
|
-
expect{
|
658
|
-
Workbook.unobtrusively(@simple_file1, :writable => true)
|
659
|
-
}.to raise_error(NotImplementedREOError, "unsaved read-only workbook shall be written")
|
660
|
-
end
|
661
1300
|
|
662
1301
|
it "should force to read-only" do
|
663
1302
|
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book|
|
@@ -758,22 +1397,20 @@ describe Workbook do
|
|
758
1397
|
book = Workbook.open(@simple_file1)
|
759
1398
|
book.sheet(1)[1,1].Value.should == @old_value
|
760
1399
|
end
|
761
|
-
|
1400
|
+
=begin
|
762
1401
|
it "should write in the outer and not in the inner block" do
|
763
|
-
|
764
|
-
Workbook.unobtrusively(@simple_file1) do |book|
|
1402
|
+
Workbook.unobtrusively(@simple_file1, :if_unsaved => :forget) do |book|
|
765
1403
|
@old_value = book.sheet(1)[1,1].Value
|
766
1404
|
book.ReadOnly.should be false
|
767
1405
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
768
1406
|
book.Saved.should be false
|
769
1407
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
770
|
-
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book2|
|
1408
|
+
Workbook.unobtrusively(@simple_file1, :if_unsaved => :forget, :read_only => true) do |book2|
|
771
1409
|
book2.should == book
|
772
1410
|
book2.ReadOnly.should be true
|
773
|
-
|
774
|
-
book2.sheet(1)[1,1].Value.should_not == @old_value
|
1411
|
+
book2.Saved.should be true
|
775
1412
|
book2.sheet(1)[1,1] = book2.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
776
|
-
book2.sheet(1)[1,1].Value.
|
1413
|
+
#book2.sheet(1)[1,1].Value.should_not == @old_value
|
777
1414
|
end
|
778
1415
|
book.should be_alive
|
779
1416
|
book.Saved.should be false
|
@@ -781,9 +1418,8 @@ describe Workbook do
|
|
781
1418
|
end
|
782
1419
|
book = Workbook.open(@simple_file1)
|
783
1420
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
784
|
-
}.to raise_error(NotImplementedREOError)
|
785
1421
|
end
|
786
|
-
|
1422
|
+
=end
|
787
1423
|
it "should write in the outer and not in the inner block" do
|
788
1424
|
Workbook.unobtrusively(@simple_file1) do |book|
|
789
1425
|
@old_value = book.sheet(1)[1,1].Value
|
@@ -806,15 +1442,15 @@ describe Workbook do
|
|
806
1442
|
book = Workbook.open(@simple_file1)
|
807
1443
|
book.sheet(1)[1,1].Value.should == @old_value
|
808
1444
|
end
|
809
|
-
|
1445
|
+
=begin
|
810
1446
|
it "should be read-only in the outer and write in the inner block" do
|
811
|
-
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book|
|
1447
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true, :if_unsaved => :save) do |book|
|
812
1448
|
@old_value = book.sheet(1)[1,1].Value
|
813
1449
|
book.ReadOnly.should be true
|
814
1450
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
815
1451
|
book.Saved.should be false
|
816
1452
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
817
|
-
Workbook.unobtrusively(@simple_file1) do |book2|
|
1453
|
+
Workbook.unobtrusively(@simple_file1, :if_unsaved => :save) do |book2|
|
818
1454
|
book2.should == book
|
819
1455
|
book2.ReadOnly.should be true
|
820
1456
|
book2.Saved.should be false
|
@@ -830,7 +1466,7 @@ describe Workbook do
|
|
830
1466
|
book = Workbook.open(@simple_file1)
|
831
1467
|
book.sheet(1)[1,1].Value.should == @old_value
|
832
1468
|
end
|
833
|
-
|
1469
|
+
=end
|
834
1470
|
end
|
835
1471
|
|
836
1472
|
end
|
@@ -890,7 +1526,7 @@ describe Workbook do
|
|
890
1526
|
book1 = Workbook.open(@simple_file1, :read_only => true)
|
891
1527
|
old_value = book1.sheet(1)[1,1].Value
|
892
1528
|
Workbook.unobtrusively(@simple_file1, :writable => true) do |book|
|
893
|
-
book.ReadOnly.should be
|
1529
|
+
book.ReadOnly.should be true
|
894
1530
|
sheet = book.sheet(1)
|
895
1531
|
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
896
1532
|
book.excel.should == book1.excel
|
@@ -898,7 +1534,7 @@ describe Workbook do
|
|
898
1534
|
book1.ReadOnly.should be true
|
899
1535
|
book1.close
|
900
1536
|
book2 = Workbook.open(@simple_file1)
|
901
|
-
book2.sheet(1)[1,1].Value.
|
1537
|
+
book2.sheet(1)[1,1].Value.should == old_value
|
902
1538
|
end
|
903
1539
|
|
904
1540
|
end
|
@@ -926,6 +1562,7 @@ describe Workbook do
|
|
926
1562
|
|
927
1563
|
it "should remain check-compatibility false" do
|
928
1564
|
book1 = Workbook.open(@simple_file1, :check_compatibility => false)
|
1565
|
+
book1.CheckCompatibility.should be false
|
929
1566
|
Workbook.unobtrusively(@simple_file1) do |book|
|
930
1567
|
end
|
931
1568
|
book1.CheckCompatibility.should be false
|
@@ -933,6 +1570,7 @@ describe Workbook do
|
|
933
1570
|
|
934
1571
|
it "should remain check-compatibility true" do
|
935
1572
|
book1 = Workbook.open(@simple_file1, :check_compatibility => true)
|
1573
|
+
book1.CheckCompatibility.should be true
|
936
1574
|
Workbook.unobtrusively(@simple_file1) do |book|
|
937
1575
|
end
|
938
1576
|
book1.CheckCompatibility.should be true
|
@@ -944,10 +1582,10 @@ describe Workbook do
|
|
944
1582
|
|
945
1583
|
it "should remain the calculation mode" do
|
946
1584
|
book1 = Workbook.open(@simple_file1)
|
947
|
-
old_calculation = book1.excel.calculation
|
1585
|
+
old_calculation = book1.excel.properties[:calculation]
|
948
1586
|
Workbook.unobtrusively(@simple_file1) do |book|
|
949
1587
|
end
|
950
|
-
book1.excel.calculation.should == old_calculation
|
1588
|
+
book1.excel.properties[:calculation].should == old_calculation
|
951
1589
|
end
|
952
1590
|
|
953
1591
|
it "should remain calculation manual" do
|
@@ -974,7 +1612,7 @@ describe Workbook do
|
|
974
1612
|
Workbook.unobtrusively(@simple_file) do |book|
|
975
1613
|
book.should be_a Workbook
|
976
1614
|
book.excel.Visible.should be false
|
977
|
-
book.CheckCompatibility.should be
|
1615
|
+
book.CheckCompatibility.should be true
|
978
1616
|
book.ReadOnly.should be false
|
979
1617
|
end
|
980
1618
|
end
|
@@ -1039,7 +1677,7 @@ describe Workbook do
|
|
1039
1677
|
expect{
|
1040
1678
|
Workbook.unobtrusively(@simple_file, :if_closed => :invalid_option) do |book|
|
1041
1679
|
end
|
1042
|
-
}.to raise_error(TypeREOError, "
|
1680
|
+
}.to raise_error(TypeREOError, "provided Excel option value is neither an Excel object nor a valid option")
|
1043
1681
|
end
|
1044
1682
|
|
1045
1683
|
end
|
@@ -1314,16 +1952,16 @@ describe Workbook do
|
|
1314
1952
|
Workbook.unobtrusively(@simple_file1, :if_closed => :new) do |book|
|
1315
1953
|
book.excel.should_not == @book.excel
|
1316
1954
|
book.excel.should_not == new_excel
|
1317
|
-
book.excel.visible.should be false
|
1318
|
-
book.excel.displayalerts.should == :if_visible
|
1955
|
+
book.excel.properties[:visible].should be false
|
1956
|
+
book.excel.properties[:displayalerts].should == :if_visible
|
1319
1957
|
@another_excel = book.excel
|
1320
1958
|
end
|
1321
1959
|
Workbook.unobtrusively(@simple_file1, :if_closed => :current) do |book|
|
1322
1960
|
book.excel.should_not == @book.excel
|
1323
1961
|
book.excel.should_not == new_excel
|
1324
1962
|
book.excel.should == @another_excel
|
1325
|
-
book.excel.visible.should be false
|
1326
|
-
book.excel.displayalerts.should == :if_visible
|
1963
|
+
book.excel.properties[:visible].should be false
|
1964
|
+
book.excel.properties[:displayalerts].should == :if_visible
|
1327
1965
|
end
|
1328
1966
|
end
|
1329
1967
|
|
@@ -1419,6 +2057,7 @@ describe Workbook do
|
|
1419
2057
|
book3.close
|
1420
2058
|
end
|
1421
2059
|
|
2060
|
+
=begin
|
1422
2061
|
it "should open unobtrusively the book in a new Excel to open the book writable" do
|
1423
2062
|
excel1 = Excel.new(:reuse => false)
|
1424
2063
|
excel2 = Excel.new(:reuse => false)
|
@@ -1475,6 +2114,7 @@ describe Workbook do
|
|
1475
2114
|
new_sheet[1,1].Value.should_not == cell_value
|
1476
2115
|
book3.close
|
1477
2116
|
end
|
2117
|
+
=end
|
1478
2118
|
|
1479
2119
|
it "should open unobtrusively the book in the Excel where it was opened most recently" do
|
1480
2120
|
book2 = Workbook.open(@simple_file1, :force_excel => :new, :read_only => true)
|
@@ -1672,6 +2312,30 @@ describe Workbook do
|
|
1672
2312
|
end
|
1673
2313
|
end
|
1674
2314
|
|
2315
|
+
describe "type-lifting" do
|
2316
|
+
|
2317
|
+
context "with standard" do
|
2318
|
+
|
2319
|
+
before do
|
2320
|
+
@book = Workbook.open(@simple_file1)
|
2321
|
+
@ole_workbook = @book.ole_workbook
|
2322
|
+
end
|
2323
|
+
|
2324
|
+
after do
|
2325
|
+
@book.close
|
2326
|
+
end
|
2327
|
+
|
2328
|
+
it "should type-lift" do
|
2329
|
+
Workbook.unobtrusively(@ole_workbook) do |book|
|
2330
|
+
book.should === @book
|
2331
|
+
book.equal?(@book).should be true
|
2332
|
+
end
|
2333
|
+
end
|
2334
|
+
|
2335
|
+
end
|
2336
|
+
|
2337
|
+
end
|
2338
|
+
|
1675
2339
|
describe "for_reading, for_modifying" do
|
1676
2340
|
|
1677
2341
|
context "open unobtrusively for reading and modifying" do
|
@@ -1694,7 +2358,8 @@ describe Workbook do
|
|
1694
2358
|
book.Saved.should be false
|
1695
2359
|
book.excel.should == @book.excel
|
1696
2360
|
end
|
1697
|
-
|
2361
|
+
Excel.kill_all
|
2362
|
+
new_book = Workbook.open(@simple_file1)
|
1698
2363
|
sheet = new_book.sheet(1)
|
1699
2364
|
sheet[1,1].Value.should == @old_cell_value
|
1700
2365
|
end
|
@@ -1708,7 +2373,8 @@ describe Workbook do
|
|
1708
2373
|
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1709
2374
|
book.excel.should == another_excel
|
1710
2375
|
end
|
1711
|
-
|
2376
|
+
Excel.kill_all
|
2377
|
+
new_book = Workbook.open(@simple_file1)
|
1712
2378
|
sheet = new_book.sheet(1)
|
1713
2379
|
sheet[1,1].Value.should == @old_cell_value
|
1714
2380
|
end
|
@@ -1721,10 +2387,11 @@ describe Workbook do
|
|
1721
2387
|
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1722
2388
|
book.excel.should_not == @book.excel
|
1723
2389
|
book.excel.should_not == new_excel
|
1724
|
-
book.excel.visible.should be false
|
1725
|
-
book.excel.displayalerts.should == :if_visible
|
2390
|
+
book.excel.properties[:visible].should be false
|
2391
|
+
book.excel.properties[:displayalerts].should == :if_visible
|
1726
2392
|
end
|
1727
|
-
|
2393
|
+
Excel.kill_all
|
2394
|
+
new_book = Workbook.open(@simple_file1)
|
1728
2395
|
sheet = new_book.sheet(1)
|
1729
2396
|
sheet[1,1].Value.should == @old_cell_value
|
1730
2397
|
end
|
@@ -1763,8 +2430,8 @@ describe Workbook do
|
|
1763
2430
|
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1764
2431
|
book.excel.should_not == @book.excel
|
1765
2432
|
book.excel.should_not == new_excel
|
1766
|
-
book.excel.visible.should be false
|
1767
|
-
book.excel.displayalerts.should == :if_visible
|
2433
|
+
book.excel.properties[:visible].should be false
|
2434
|
+
book.excel.properties[:displayalerts].should == :if_visible
|
1768
2435
|
end
|
1769
2436
|
new_book = Workbook.open(@simple_file1, :visible => true)
|
1770
2437
|
sheet = new_book.sheet(1)
|