robust_excel_ole 1.13 → 1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +14 -4
- data/README.rdoc +34 -43
- data/___dummy_workbook.xls +0 -0
- data/docs/README_excel.rdoc +2 -2
- data/docs/README_open.rdoc +51 -34
- data/docs/README_ranges.rdoc +80 -80
- data/docs/README_save_close.rdoc +9 -9
- data/docs/README_sheet.rdoc +17 -17
- data/lib/robust_excel_ole.rb +3 -1
- data/lib/robust_excel_ole/excel.rb +38 -33
- data/lib/robust_excel_ole/reo_common.rb +1 -2
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +110 -83
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/workbook_spec.rb +2 -2
- data/spec/workbook_specs/workbook_open_spec.rb +36 -8
- data/spec/workbook_specs/workbook_unobtr_spec.rb +379 -16
- metadata +3 -2
Binary file
|
data/spec/workbook_spec.rb
CHANGED
@@ -669,7 +669,7 @@ describe Workbook do
|
|
669
669
|
end
|
670
670
|
end
|
671
671
|
|
672
|
-
describe "
|
672
|
+
describe "promoting" do
|
673
673
|
|
674
674
|
context "with standard" do
|
675
675
|
|
@@ -681,7 +681,7 @@ describe Workbook do
|
|
681
681
|
@book.close
|
682
682
|
end
|
683
683
|
|
684
|
-
it "should
|
684
|
+
it "should promote a win32ole workbook object to a workbook object with an open workbook" do
|
685
685
|
workbook = @book.ole_workbook
|
686
686
|
book1 = Workbook.new(workbook)
|
687
687
|
book1.should be_a Workbook
|
@@ -428,9 +428,32 @@ describe Workbook do
|
|
428
428
|
@book.close
|
429
429
|
end
|
430
430
|
|
431
|
-
it "should yield identical Workbook objects
|
431
|
+
it "should yield identical Workbook objects referring to identical WIN32OLE objects" do
|
432
|
+
book2 = Workbook.new(@book.ole_workbook)
|
433
|
+
book2.equal?(@book).should be true
|
434
|
+
end
|
435
|
+
|
436
|
+
it "should yield identical Workbook objects referring to identical WIN32OLE objects with open" do
|
437
|
+
book2 = Workbook.open(@book.ole_workbook)
|
438
|
+
book2.equal?(@book).should be true
|
439
|
+
end
|
440
|
+
|
441
|
+
it "should yield identical Workbook objects created with help of their filenames" do
|
442
|
+
book2 = Workbook.open(@simple_file1)
|
443
|
+
book2.equal?(@book).should be true
|
444
|
+
end
|
445
|
+
|
446
|
+
it "should yield identical Workbook objects created with help of their WIN32OLE objects" do
|
447
|
+
book2 = Workbook.new(@book.ole_workbook)
|
448
|
+
book3 = Workbook.open(@book.ole_workbook)
|
449
|
+
book3.equal?(book2).should be true
|
450
|
+
end
|
451
|
+
|
452
|
+
|
453
|
+
it "should yield identical Workbook objects for identical Excel books after prmoting" do
|
432
454
|
book2 = Workbook.new(@ole_book)
|
433
455
|
book2.should === @book
|
456
|
+
book2.equal?(@book).should be true
|
434
457
|
book2.close
|
435
458
|
end
|
436
459
|
|
@@ -440,6 +463,7 @@ describe Workbook do
|
|
440
463
|
ole_book2 = WIN32OLE.connect(abs_filename2)
|
441
464
|
book2 = Workbook.new(ole_book2)
|
442
465
|
book2.should_not === @book
|
466
|
+
book2.equal?(@book).should be false
|
443
467
|
book2.close
|
444
468
|
book3.close
|
445
469
|
end
|
@@ -486,31 +510,34 @@ describe Workbook do
|
|
486
510
|
book2.excel.should_not == book.excel
|
487
511
|
end
|
488
512
|
|
489
|
-
it "should
|
513
|
+
it "should promote an open known workbook" do
|
490
514
|
book = Workbook.open(@simple_file)
|
491
515
|
ole_workbook = book.ole_workbook
|
492
516
|
new_book = Workbook.new(ole_workbook)
|
493
517
|
new_book.should == book
|
518
|
+
new_book.equal?(book).should be true
|
494
519
|
new_book.Fullname.should == book.Fullname
|
495
520
|
new_book.excel.should == book.excel
|
496
521
|
end
|
497
522
|
|
498
|
-
it "should
|
523
|
+
it "should promote an open known workbook and let it be visible" do
|
499
524
|
book = Workbook.open(@simple_file, :visible => true)
|
500
525
|
ole_workbook = book.ole_workbook
|
501
526
|
new_book = Workbook.new(ole_workbook)
|
502
527
|
new_book.should == book
|
528
|
+
new_book.equal?(book).should be true
|
503
529
|
new_book.Fullname.should == book.Fullname
|
504
530
|
new_book.excel.should == book.excel
|
505
531
|
new_book.excel.Visible.should == true
|
506
532
|
new_book.Windows(new_book.ole_workbook.Name).Visible.should == true
|
507
533
|
end
|
508
534
|
|
509
|
-
it "should
|
535
|
+
it "should promote an open known workbook and let it be visible and readonly" do
|
510
536
|
book = Workbook.open(@simple_file, :visible => true, :read_only => true)
|
511
537
|
ole_workbook = book.ole_workbook
|
512
538
|
new_book = Workbook.new(ole_workbook)
|
513
539
|
new_book.should == book
|
540
|
+
new_book.equal?(book).should be true
|
514
541
|
new_book.Fullname.should == book.Fullname
|
515
542
|
new_book.excel.should == book.excel
|
516
543
|
new_book.excel.Visible.should == true
|
@@ -518,18 +545,19 @@ describe Workbook do
|
|
518
545
|
new_book.ReadOnly.should == true
|
519
546
|
end
|
520
547
|
|
521
|
-
it "should
|
548
|
+
it "should promote an open known workbook and make it visible" do
|
522
549
|
book = Workbook.open(@simple_file)
|
523
550
|
ole_workbook = book.ole_workbook
|
524
551
|
new_book = Workbook.new(ole_workbook, :visible => true)
|
525
552
|
new_book.should == book
|
553
|
+
new_book.equal?(book).should be true
|
526
554
|
new_book.Fullname.should == book.Fullname
|
527
555
|
new_book.excel.should == book.excel
|
528
556
|
new_book.excel.Visible.should == true
|
529
557
|
new_book.Windows(new_book.ole_workbook.Name).Visible.should == true
|
530
558
|
end
|
531
559
|
|
532
|
-
it "should
|
560
|
+
it "should promote an open unknown workbook" do
|
533
561
|
ole_excel = WIN32OLE.new('Excel.Application')
|
534
562
|
ws = ole_excel.Workbooks
|
535
563
|
abs_filename = General.absolute_path(@simple_file1)
|
@@ -539,7 +567,7 @@ describe Workbook do
|
|
539
567
|
new_book.excel.Hwnd.should == ole_excel.Hwnd
|
540
568
|
end
|
541
569
|
|
542
|
-
it "should
|
570
|
+
it "should promote an open unknown workbook and make it visible" do
|
543
571
|
ole_excel = WIN32OLE.new('Excel.Application')
|
544
572
|
ws = ole_excel.Workbooks
|
545
573
|
abs_filename = General.absolute_path(@simple_file1)
|
@@ -551,7 +579,7 @@ describe Workbook do
|
|
551
579
|
new_book.Windows(new_book.ole_workbook.Name).Visible.should == true
|
552
580
|
end
|
553
581
|
|
554
|
-
it "should
|
582
|
+
it "should promote an open unknown workbook and make it visible and readonly" do
|
555
583
|
ole_excel = WIN32OLE.new('Excel.Application')
|
556
584
|
ws = ole_excel.Workbooks
|
557
585
|
abs_filename = General.absolute_path(@simple_file1)
|
@@ -80,6 +80,335 @@ describe Workbook do
|
|
80
80
|
|
81
81
|
end
|
82
82
|
|
83
|
+
describe "unknown workbooks" do
|
84
|
+
|
85
|
+
context "with one invisible saved writable workbook" do
|
86
|
+
|
87
|
+
before do
|
88
|
+
@ole_e1 = WIN32OLE.new('Excel.Application')
|
89
|
+
ws = @ole_e1.Workbooks
|
90
|
+
@abs_filename = General.absolute_path(@simple_file1)
|
91
|
+
@ole_wb = ws.Open(abs_filename)
|
92
|
+
@old_value = @ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should connect" do
|
96
|
+
Workbooks.unobtrusively(@simple_file1) do |book|
|
97
|
+
book.excel.Workbook.Count.should == 1
|
98
|
+
Excel.excels_number.should == 1
|
99
|
+
book.FullName.should == General.absolute_path(@simple_file1)
|
100
|
+
book.saved.should be true
|
101
|
+
book.visible.should be false
|
102
|
+
book.writable.should be true
|
103
|
+
end
|
104
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
105
|
+
ole_wb.Saved.should be true
|
106
|
+
@ole_e1.Visible.should be false
|
107
|
+
ole_wb.ReadOnly.should be false
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should set visible => true and remain invisiblity" do
|
111
|
+
Workbooks.unobtrusively(@simple_file1, :visible => true) do |book|
|
112
|
+
book.saved.should be true
|
113
|
+
book.visible.should be true
|
114
|
+
book.writable.should be true
|
115
|
+
end
|
116
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
117
|
+
ole_wb.Saved.should be true
|
118
|
+
@ole_e1.Visible.should be false
|
119
|
+
ole_wb.ReadOnly.should be false
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should set read_only => true and remain writability" do
|
123
|
+
Workbooks.unobtrusively(@simple_file1, :read_only => true) do |book|
|
124
|
+
book.saved.should be true
|
125
|
+
book.visible.should be false
|
126
|
+
book.writable.should be false
|
127
|
+
end
|
128
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
129
|
+
ole_wb.Saved.should be true
|
130
|
+
@ole_e1.Visible.should be false
|
131
|
+
ole_wb.ReadOnly.should be false
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should set visible => true, read_only => true" do
|
135
|
+
Workbooks.unobtrusively(@simple_file1, :visible => true, :read_only => true) do |book|
|
136
|
+
book.saved.should be true
|
137
|
+
book.visible.should be true
|
138
|
+
book.writable.should be false
|
139
|
+
end
|
140
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
141
|
+
ole_wb.Saved.should be true
|
142
|
+
@ole_e1.Visible.should be false
|
143
|
+
ole_wb.ReadOnly.should be false
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should modify and remain saved-status" do
|
147
|
+
Workbooks.unobtrusively(@simple_file1) do |book|
|
148
|
+
book.saved.should be true
|
149
|
+
book.visible.should be false
|
150
|
+
book.writable.should be true
|
151
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
152
|
+
@new_value = book.sheet(1)[1,1].value
|
153
|
+
book.Saved.should be false
|
154
|
+
end
|
155
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
156
|
+
ole_wb.Saved.should be true
|
157
|
+
@ole_e1.Visible.should be false
|
158
|
+
ole_wb.ReadOnly.should be false
|
159
|
+
ole_wb.Close
|
160
|
+
book2 = Workbook.open(@simple_file1)
|
161
|
+
book2.sheet(1)[1,1].value.should_not == @old_value
|
162
|
+
book2.sheet(1)[1,1].value.should == @new_value
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should modify and remain saved-status and not save the new value when writable => false" do
|
166
|
+
Workbooks.unobtrusively(@simple_file1, :writable => false) do |book|
|
167
|
+
book.saved.should be true
|
168
|
+
book.visible.should be false
|
169
|
+
book.writable.should be true
|
170
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
171
|
+
@new_value = book.sheet(1)[1,1].value
|
172
|
+
book.Saved.should be false
|
173
|
+
end
|
174
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
175
|
+
ole_wb.Saved.should be true
|
176
|
+
@ole_e1.Visible.should be false
|
177
|
+
ole_wb.ReadOnly.should be false
|
178
|
+
ole_wb.Close
|
179
|
+
book2 = Workbook.open(@simple_file1)
|
180
|
+
book2.sheet(1)[1,1].value.should == @old_value
|
181
|
+
book2.sheet(1)[1,1].value.should_not == @new_value
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
context "with one visible saved writable workbook" do
|
187
|
+
|
188
|
+
before do
|
189
|
+
@ole_e1 = WIN32OLE.new('Excel.Application')
|
190
|
+
ws = @ole_e1.Workbooks
|
191
|
+
@abs_filename = General.absolute_path(@simple_file1)
|
192
|
+
@ole_wb = ws.Open(abs_filename)
|
193
|
+
@ole_e1.Visible = true
|
194
|
+
@ole_wb.Windows(@ole_wb.Name).Visible = true
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should remain visibility" do
|
198
|
+
Workbooks.unobtrusively(@simple_file1) do |book|
|
199
|
+
book.saved.should be true
|
200
|
+
book.visible.should be true
|
201
|
+
book.writable.should be true
|
202
|
+
end
|
203
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
204
|
+
ole_wb.Saved.should be true
|
205
|
+
@ole_e1.Visible.should be true
|
206
|
+
ole_wb.ReadOnly.should be false
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should set visible => false and remain visibility" do
|
210
|
+
Workbooks.unobtrusively(@simple_file1, :visible => false) do |book|
|
211
|
+
book.saved.should be true
|
212
|
+
book.visible.should be false
|
213
|
+
book.writable.should be true
|
214
|
+
end
|
215
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
216
|
+
ole_wb.Saved.should be true
|
217
|
+
@ole_e1.Visible.should be true
|
218
|
+
ole_wb.ReadOnly.should be false
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
context "with one unsaved writable workbook" do
|
224
|
+
|
225
|
+
before do
|
226
|
+
@ole_e1 = WIN32OLE.new('Excel.Application')
|
227
|
+
ws = @ole_e1.Workbooks
|
228
|
+
@abs_filename = General.absolute_path(@simple_file1)
|
229
|
+
@ole_wb = ws.Open(abs_filename)
|
230
|
+
@ole_e1.Visible = true
|
231
|
+
@ole_wb.Windows(@ole_wb.Name).Visible = true
|
232
|
+
@old_value = @ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value
|
233
|
+
@ole_wb.Worksheets.Item(name).Cells.Item(1,1).Value = @old_value == "foo" ? "bar" : "foo"
|
234
|
+
@new_value = @ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value
|
235
|
+
@ole_wb.Saved.should be false
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should connect and remain unsaved" do
|
239
|
+
Workbooks.unobtrusively(@simple_file1) do |book|
|
240
|
+
book.saved.should be false
|
241
|
+
book.visible.should be true
|
242
|
+
book.writable.should be true
|
243
|
+
end
|
244
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
245
|
+
ole_wb.Saved.should be false
|
246
|
+
@ole_e1.Visible.should be true
|
247
|
+
ole_wb.ReadOnly.should be false
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should remain writable" do
|
251
|
+
Workbooks.unobtrusively(@simple_file1, :read_only => true) do |book|
|
252
|
+
book.saved.should be false
|
253
|
+
book.visible.should be true
|
254
|
+
book.writable.should be false
|
255
|
+
end
|
256
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
257
|
+
ole_wb.Saved.should be false
|
258
|
+
@ole_e1.Visible.should be true
|
259
|
+
ole_wb.ReadOnly.should be false
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should remain unsaved when modifying" do
|
263
|
+
Workbooks.unobtrusively(@simple_file1) do |book|
|
264
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
265
|
+
@new_value = book.sheet(1)[1,1].Value
|
266
|
+
book.saved.should be false
|
267
|
+
book.visible.should be true
|
268
|
+
book.writable.should be true
|
269
|
+
end
|
270
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
271
|
+
ole_wb.Saved.should be false
|
272
|
+
@ole_e1.Visible.should be true
|
273
|
+
ole_wb.ReadOnly.should be false
|
274
|
+
ole_wb.Close
|
275
|
+
book2 = Workbook.open(@simple_file1)
|
276
|
+
book2.sheet(1)[1,1].value.should_not == @old_value
|
277
|
+
book2.sheet(1)[1,1].value.should == @new_value
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should not write with :writable => false" do
|
281
|
+
Workbooks.unobtrusively(@simple_file1, :writable => false) do |book|
|
282
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
283
|
+
@new_value = book.sheet(1)[1,1].Value
|
284
|
+
book.saved.should be false
|
285
|
+
book.visible.should be true
|
286
|
+
book.writable.should be true
|
287
|
+
end
|
288
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
289
|
+
ole_wb.Saved.should be false
|
290
|
+
@ole_e1.Visible.should be true
|
291
|
+
ole_wb.ReadOnly.should be false
|
292
|
+
ole_wb.Close
|
293
|
+
book2 = Workbook.open(@simple_file1)
|
294
|
+
book2.sheet(1)[1,1].value.should == @old_value
|
295
|
+
book2.sheet(1)[1,1].value.should_not == @new_value
|
296
|
+
end
|
297
|
+
|
298
|
+
end
|
299
|
+
|
300
|
+
context "with one read-only workbook" do
|
301
|
+
|
302
|
+
before do
|
303
|
+
@ole_e1 = WIN32OLE.new('Excel.Application')
|
304
|
+
ws = @ole_e1.Workbooks
|
305
|
+
@abs_filename = General.absolute_path(@simple_file1)
|
306
|
+
@ole_wb = ws.Open(abs_filename, RobustExcelOle::XlUpdateLinksNever, true)
|
307
|
+
@ole_e1.Visible = true
|
308
|
+
@ole_wb.Windows(@ole_wb.Name).Visible = true
|
309
|
+
@ole_wb.ReadOnly.should be true
|
310
|
+
end
|
311
|
+
|
312
|
+
it "should connect and remain read-only" do
|
313
|
+
Workbooks.unobtrusively(@simple_file1) do |book|
|
314
|
+
book.saved.should be true
|
315
|
+
book.visible.should be true
|
316
|
+
book.writable.should be false
|
317
|
+
end
|
318
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
319
|
+
ole_wb.Saved.should be true
|
320
|
+
@ole_e1.Visible.should be true
|
321
|
+
ole_wb.ReadOnly.should be true
|
322
|
+
end
|
323
|
+
|
324
|
+
it "should remain read-only" do
|
325
|
+
Workbooks.unobtrusively(@simple_file1, :read_only => false) do |book|
|
326
|
+
book.saved.should be false
|
327
|
+
book.visible.should be true
|
328
|
+
book.writable.should be true
|
329
|
+
end
|
330
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
331
|
+
ole_wb.Saved.should be true
|
332
|
+
@ole_e1.Visible.should be true
|
333
|
+
ole_wb.ReadOnly.should be true
|
334
|
+
end
|
335
|
+
|
336
|
+
it "should remain read-only when modifying" do
|
337
|
+
Workbooks.unobtrusively(@simple_file1) do |book|
|
338
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
339
|
+
@new_value = book.sheet(1)[1,1].Value
|
340
|
+
book.saved.should be false
|
341
|
+
book.visible.should be true
|
342
|
+
book.writable.should be true
|
343
|
+
end
|
344
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
345
|
+
ole_wb.Saved.should be true
|
346
|
+
@ole_e1.Visible.should be true
|
347
|
+
ole_wb.ReadOnly.should be true
|
348
|
+
ole_wb.Close
|
349
|
+
book2 = Workbook.open(@simple_file1)
|
350
|
+
book2.sheet(1)[1,1].value.should_not == @old_value
|
351
|
+
book2.sheet(1)[1,1].value.should == @new_value
|
352
|
+
end
|
353
|
+
|
354
|
+
it "should remain read-only when modifying" do
|
355
|
+
Workbooks.unobtrusively(@simple_file1, :read_only => false, :writable => true) do |book|
|
356
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
357
|
+
@new_value = book.sheet(1)[1,1].Value
|
358
|
+
book.saved.should be false
|
359
|
+
book.visible.should be true
|
360
|
+
book.writable.should be true
|
361
|
+
end
|
362
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
363
|
+
ole_wb.Saved.should be true
|
364
|
+
@ole_e1.Visible.should be true
|
365
|
+
ole_wb.ReadOnly.should be true
|
366
|
+
ole_wb.Close
|
367
|
+
book2 = Workbook.open(@simple_file1)
|
368
|
+
book2.sheet(1)[1,1].value.should_not == @old_value
|
369
|
+
book2.sheet(1)[1,1].value.should == @new_value
|
370
|
+
end
|
371
|
+
|
372
|
+
it "should remain read-only when modifying and not save changes, when :writable => false" do
|
373
|
+
Workbooks.unobtrusively(@simple_file1, :writable => false) do |book|
|
374
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
375
|
+
@new_value = book.sheet(1)[1,1].Value
|
376
|
+
book.saved.should be false
|
377
|
+
book.visible.should be true
|
378
|
+
book.writable.should be true
|
379
|
+
end
|
380
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
381
|
+
ole_wb.Saved.should be true
|
382
|
+
@ole_e1.Visible.should be true
|
383
|
+
ole_wb.ReadOnly.should be true
|
384
|
+
ole_wb.Close
|
385
|
+
book2 = Workbook.open(@simple_file1)
|
386
|
+
book2.sheet(1)[1,1].value.should == @old_value
|
387
|
+
book2.sheet(1)[1,1].value.should_not == @new_value
|
388
|
+
end
|
389
|
+
|
390
|
+
it "should remain read-only when modifying and not save changes, when :writable => false" do
|
391
|
+
Workbooks.unobtrusively(@simple_file1, :read_only => false, :writable => false) do |book|
|
392
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
393
|
+
@new_value = book.sheet(1)[1,1].Value
|
394
|
+
book.saved.should be false
|
395
|
+
book.visible.should be true
|
396
|
+
book.writable.should be true
|
397
|
+
end
|
398
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
399
|
+
ole_wb.Saved.should be true
|
400
|
+
@ole_e1.Visible.should be true
|
401
|
+
ole_wb.ReadOnly.should be true
|
402
|
+
ole_wb.Close
|
403
|
+
book2 = Workbook.open(@simple_file1)
|
404
|
+
book2.sheet(1)[1,1].value.should == @old_value
|
405
|
+
book2.sheet(1)[1,1].value.should_not == @new_value
|
406
|
+
end
|
407
|
+
|
408
|
+
end
|
409
|
+
|
410
|
+
end
|
411
|
+
|
83
412
|
describe "excels number" do
|
84
413
|
|
85
414
|
it "should open one excel instance and workbook should be closed" do
|
@@ -188,7 +517,7 @@ describe Workbook do
|
|
188
517
|
|
189
518
|
it "should open not writable" do
|
190
519
|
Workbook.unobtrusively(@simple_file, :writable => false) do |book|
|
191
|
-
|
520
|
+
#
|
192
521
|
@old_value = book.sheet(1)[1,1].Value
|
193
522
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
194
523
|
book.Saved.should be false
|
@@ -330,6 +659,7 @@ describe Workbook do
|
|
330
659
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
331
660
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
332
661
|
end
|
662
|
+
@book.ReadOnly.should be true
|
333
663
|
@book.close
|
334
664
|
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
335
665
|
book.sheet(1)[1,1].Value.should == @old_value
|
@@ -347,6 +677,7 @@ describe Workbook do
|
|
347
677
|
book.excel.should == @book.excel
|
348
678
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
349
679
|
end
|
680
|
+
@book.ReadOnly.should be true
|
350
681
|
@book.close
|
351
682
|
book2 = Workbook.open(@simple_file1)
|
352
683
|
book2.sheet(1)[1,1].Value.should == @old_value
|
@@ -367,7 +698,7 @@ describe Workbook do
|
|
367
698
|
|
368
699
|
it "should open as read-write" do
|
369
700
|
Workbook.unobtrusively(@simple_file1, :read_only => false, :writable => false) do |book|
|
370
|
-
book.Readonly.should be
|
701
|
+
book.Readonly.should be false
|
371
702
|
book.should == @book
|
372
703
|
book.filename.should == @book.filename
|
373
704
|
book.excel.should == @book.excel
|
@@ -404,6 +735,7 @@ describe Workbook do
|
|
404
735
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
405
736
|
end
|
406
737
|
|
738
|
+
=begin
|
407
739
|
it "should force to read-write" do
|
408
740
|
e1 = Excel.create
|
409
741
|
Workbook.unobtrusively(@simple_file1, :writable => true, :rw_change_excel => e1) do |book|
|
@@ -441,6 +773,7 @@ describe Workbook do
|
|
441
773
|
book2 = Workbook.open(@simple_file1)
|
442
774
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
443
775
|
end
|
776
|
+
=end
|
444
777
|
|
445
778
|
it "should force to read-write" do
|
446
779
|
Workbook.unobtrusively(@simple_file1, :writable => true, :read_only => false) do |book|
|
@@ -563,16 +896,22 @@ describe Workbook do
|
|
563
896
|
@book.sheet(1)[1,1].Value.should_not == @old_value
|
564
897
|
end
|
565
898
|
|
566
|
-
it "should force to read-only
|
567
|
-
|
568
|
-
|
569
|
-
|
899
|
+
it "should force to read-only" do
|
900
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book|
|
901
|
+
book.ReadOnly.should be true
|
902
|
+
end
|
903
|
+
@book.Saved.should be false
|
904
|
+
@book.ReadOnly.should be false
|
905
|
+
@book.sheet(1)[1,1].Value.should == @old_value
|
570
906
|
end
|
571
907
|
|
572
|
-
it "should force to read-only
|
573
|
-
|
574
|
-
|
575
|
-
|
908
|
+
it "should force to read-only with writable false" do
|
909
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true, :writable => false) do |book|
|
910
|
+
book.ReadOnly.should be true
|
911
|
+
end
|
912
|
+
@book.Saved.should be false
|
913
|
+
@book.ReadOnly.should be false
|
914
|
+
@book.sheet(1)[1,1].Value.should == @old_value
|
576
915
|
end
|
577
916
|
|
578
917
|
it "should open not writable" do
|
@@ -617,7 +956,7 @@ describe Workbook do
|
|
617
956
|
|
618
957
|
it "should open as read-only" do
|
619
958
|
Workbook.unobtrusively(@simple_file1, :read_only => false) do |book|
|
620
|
-
book.Readonly.should be
|
959
|
+
book.Readonly.should be false
|
621
960
|
book.should == @book
|
622
961
|
book.filename.should == @book.filename
|
623
962
|
book.excel.should == @book.excel
|
@@ -633,7 +972,7 @@ describe Workbook do
|
|
633
972
|
|
634
973
|
it "should open as read-only" do
|
635
974
|
Workbook.unobtrusively(@simple_file1, :read_only => false, :writable => false) do |book|
|
636
|
-
book.Readonly.should be
|
975
|
+
book.Readonly.should be false
|
637
976
|
book.should == @book
|
638
977
|
book.filename.should == @book.filename
|
639
978
|
book.excel.should == @book.excel
|
@@ -760,7 +1099,6 @@ describe Workbook do
|
|
760
1099
|
end
|
761
1100
|
|
762
1101
|
it "should write in the outer and not in the inner block" do
|
763
|
-
expect{
|
764
1102
|
Workbook.unobtrusively(@simple_file1) do |book|
|
765
1103
|
@old_value = book.sheet(1)[1,1].Value
|
766
1104
|
book.ReadOnly.should be false
|
@@ -770,7 +1108,7 @@ describe Workbook do
|
|
770
1108
|
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book2|
|
771
1109
|
book2.should == book
|
772
1110
|
book2.ReadOnly.should be true
|
773
|
-
|
1111
|
+
book2.Saved.should be false
|
774
1112
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
775
1113
|
book2.sheet(1)[1,1] = book2.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
776
1114
|
book2.sheet(1)[1,1].Value.should == @old_value
|
@@ -781,7 +1119,6 @@ describe Workbook do
|
|
781
1119
|
end
|
782
1120
|
book = Workbook.open(@simple_file1)
|
783
1121
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
784
|
-
}.to raise_error(NotImplementedREOError)
|
785
1122
|
end
|
786
1123
|
|
787
1124
|
it "should write in the outer and not in the inner block" do
|
@@ -890,7 +1227,7 @@ describe Workbook do
|
|
890
1227
|
book1 = Workbook.open(@simple_file1, :read_only => true)
|
891
1228
|
old_value = book1.sheet(1)[1,1].Value
|
892
1229
|
Workbook.unobtrusively(@simple_file1, :writable => true) do |book|
|
893
|
-
book.ReadOnly.should be
|
1230
|
+
book.ReadOnly.should be true
|
894
1231
|
sheet = book.sheet(1)
|
895
1232
|
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
896
1233
|
book.excel.should == book1.excel
|
@@ -1419,6 +1756,7 @@ describe Workbook do
|
|
1419
1756
|
book3.close
|
1420
1757
|
end
|
1421
1758
|
|
1759
|
+
=begin
|
1422
1760
|
it "should open unobtrusively the book in a new Excel to open the book writable" do
|
1423
1761
|
excel1 = Excel.new(:reuse => false)
|
1424
1762
|
excel2 = Excel.new(:reuse => false)
|
@@ -1475,6 +1813,7 @@ describe Workbook do
|
|
1475
1813
|
new_sheet[1,1].Value.should_not == cell_value
|
1476
1814
|
book3.close
|
1477
1815
|
end
|
1816
|
+
=end
|
1478
1817
|
|
1479
1818
|
it "should open unobtrusively the book in the Excel where it was opened most recently" do
|
1480
1819
|
book2 = Workbook.open(@simple_file1, :force_excel => :new, :read_only => true)
|
@@ -1672,6 +2011,30 @@ describe Workbook do
|
|
1672
2011
|
end
|
1673
2012
|
end
|
1674
2013
|
|
2014
|
+
describe "promoting" do
|
2015
|
+
|
2016
|
+
context "with standard" do
|
2017
|
+
|
2018
|
+
before do
|
2019
|
+
@book = Workbook.open(@simple_file1)
|
2020
|
+
@ole_workbook = @book.ole_workbook
|
2021
|
+
end
|
2022
|
+
|
2023
|
+
after do
|
2024
|
+
@book.close
|
2025
|
+
end
|
2026
|
+
|
2027
|
+
it "should promote" do
|
2028
|
+
Workbook.unobtrusively(@ole_workbook) do |book|
|
2029
|
+
book.should === @book
|
2030
|
+
book.equal?(@book).should be true
|
2031
|
+
end
|
2032
|
+
end
|
2033
|
+
|
2034
|
+
end
|
2035
|
+
|
2036
|
+
end
|
2037
|
+
|
1675
2038
|
describe "for_reading, for_modifying" do
|
1676
2039
|
|
1677
2040
|
context "open unobtrusively for reading and modifying" do
|