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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog +47 -4
  3. data/README.rdoc +52 -47
  4. data/___dummy_workbook.xls +0 -0
  5. data/docs/README_excel.rdoc +9 -3
  6. data/docs/README_open.rdoc +86 -44
  7. data/docs/README_ranges.rdoc +90 -81
  8. data/docs/README_save_close.rdoc +9 -9
  9. data/docs/README_sheet.rdoc +17 -17
  10. data/examples/example_ruby_library.rb +27 -0
  11. data/extconf.rb +7 -0
  12. data/lib/robust_excel_ole.rb +7 -4
  13. data/lib/robust_excel_ole/{address.rb → address_tool.rb} +23 -22
  14. data/lib/robust_excel_ole/{reo_common.rb → base.rb} +3 -92
  15. data/lib/robust_excel_ole/bookstore.rb +14 -77
  16. data/lib/robust_excel_ole/cell.rb +30 -18
  17. data/lib/robust_excel_ole/excel.rb +138 -92
  18. data/lib/robust_excel_ole/general.rb +40 -15
  19. data/lib/robust_excel_ole/range.rb +42 -19
  20. data/lib/robust_excel_ole/range_owners.rb +40 -25
  21. data/lib/robust_excel_ole/vba_objects.rb +30 -0
  22. data/lib/robust_excel_ole/version.rb +1 -1
  23. data/lib/robust_excel_ole/workbook.rb +320 -319
  24. data/lib/robust_excel_ole/worksheet.rb +51 -25
  25. data/robust_excel_ole.gemspec +1 -0
  26. data/spec/address_tool_spec.rb +175 -0
  27. data/spec/{reo_common_spec.rb → base_spec.rb} +19 -34
  28. data/spec/bookstore_spec.rb +3 -3
  29. data/spec/cell_spec.rb +67 -25
  30. data/spec/data/more_data/workbook.xls +0 -0
  31. data/spec/excel_spec.rb +137 -369
  32. data/spec/general_spec.rb +21 -27
  33. data/spec/range_spec.rb +57 -3
  34. data/spec/workbook_spec.rb +11 -79
  35. data/spec/workbook_specs/workbook_misc_spec.rb +29 -40
  36. data/spec/workbook_specs/workbook_open_spec.rb +599 -31
  37. data/spec/workbook_specs/workbook_unobtr_spec.rb +760 -93
  38. data/spec/worksheet_spec.rb +36 -4
  39. metadata +12 -7
  40. data/spec/address_spec.rb +0 -174
@@ -35,7 +35,15 @@ describe Workbook do
35
35
  #@simple_file_via_network = File.join('N:/', 'data') + '/workbook.xls'
36
36
  @simple_file_network_path = "N:/data/workbook.xls"
37
37
  @simple_file_hostname_share_path = '//DESKTOP-A3C5CJ6/spec/data/workbook.xls'
38
-
38
+ @simple_file_network_path_other_path = "N:/data/more_data/workbook.xls"
39
+ @simple_file_hostname_share_path_other_path = '//DESKTOP-A3C5CJ6/spec/data/more_data/workbook.xls'
40
+ @simple_file_network_path1 = @simple_file_network_path
41
+ @simple_file_hostname_share_path1 = @simple_file_hostname_share_path
42
+ @simple_file_network_path_other_path1 = @simple_file_network_path_other_path
43
+ @simple_file_hostname_share_path_other_path1 = @simple_file_hostname_share_path_other_path
44
+ @simple_file_xlsm1 = @simple_file_xlsm
45
+ @simple_file_xlsx1 = @simple_file_xlsx
46
+ @error_message_excel = "provided Excel option value is neither an Excel object nor a valid option"
39
47
  end
40
48
 
41
49
  after do
@@ -43,6 +51,198 @@ describe Workbook do
43
51
  rm_tmp(@dir)
44
52
  end
45
53
 
54
+ describe "basic tests with xlsx-workbooks" do
55
+
56
+ context "with simple file" do
57
+
58
+ it "should simply create a new workbook given a file" do
59
+ book = Workbook.new(@simple_file_xlsx1)
60
+ book.should be_alive
61
+ book.should be_a Workbook
62
+ book.filename.should == @simple_file_xlsx1
63
+ end
64
+
65
+ end
66
+
67
+ context "with transparency identity" do
68
+
69
+ before do
70
+ @book = Workbook.open(@simple_file_xlsx1)
71
+ end
72
+
73
+ after do
74
+ @book.close
75
+ end
76
+
77
+ it "should yield identical Workbook objects referring to identical WIN32OLE objects" do
78
+ book2 = Workbook.new(@book.ole_workbook)
79
+ book2.equal?(@book).should be true
80
+ end
81
+
82
+ end
83
+
84
+ context "with connecting to one unknown workbook" do
85
+
86
+ before do
87
+ ole_e1 = WIN32OLE.new('Excel.Application')
88
+ ws = ole_e1.Workbooks
89
+ abs_filename = General.absolute_path(@simple_file_xlsx1)
90
+ @ole_wb = ws.Open(abs_filename)
91
+ end
92
+
93
+ it "should connect to an unknown workbook" do
94
+ Workbook.open(@simple_file_xlsx1) do |book|
95
+ book.filename.should == @simple_file_xlsx1
96
+ book.should be_alive
97
+ book.should be_a Workbook
98
+ book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
99
+ Excel.excels_number.should == 1
100
+ end
101
+ end
102
+ end
103
+
104
+ context "with :force => excel" do
105
+
106
+ before do
107
+ @book = Workbook.open(@simple_file_xlsx1)
108
+ end
109
+
110
+ it "should open in a new Excel" do
111
+ book2 = Workbook.open(@simple_file_xlsx1, :force => {:excel => :new})
112
+ book2.should be_alive
113
+ book2.should be_a Workbook
114
+ book2.excel.should_not == @book.excel
115
+ book2.should_not == @book
116
+ @book.Readonly.should be false
117
+ book2.Readonly.should be true
118
+ book2.close
119
+ end
120
+
121
+ end
122
+
123
+ context "with :if_unsaved" do
124
+
125
+ before do
126
+ @book = Workbook.open(@simple_file_xlsx1)
127
+ @sheet = @book.sheet(1)
128
+ @book.add_sheet(@sheet, :as => 'a_name')
129
+ @book.visible = true
130
+ end
131
+
132
+ after do
133
+ @book.close(:if_unsaved => :forget)
134
+ @new_book.close rescue nil
135
+ end
136
+
137
+ it "should let the book open, if :if_unsaved is :accept" do
138
+ expect {
139
+ @new_book = Workbook.open(@simple_file_xlsx1, :if_unsaved => :accept)
140
+ }.to_not raise_error
141
+ @book.should be_alive
142
+ @new_book.should be_alive
143
+ @new_book.should == @book
144
+ end
145
+
146
+ end
147
+
148
+ end
149
+
150
+ describe "basic tests with xlsm-workbooks" do
151
+
152
+ context "with simple file" do
153
+
154
+ it "should simply create a new workbook given a file" do
155
+ book = Workbook.new(@simple_file_xlsm1)
156
+ book.should be_alive
157
+ book.should be_a Workbook
158
+ book.filename.should == @simple_file_xlsm1
159
+ end
160
+
161
+ end
162
+
163
+ context "with transparency identity" do
164
+
165
+ before do
166
+ @book = Workbook.open(@simple_file_xlsm1)
167
+ end
168
+
169
+ after do
170
+ @book.close
171
+ end
172
+
173
+ it "should yield identical Workbook objects referring to identical WIN32OLE objects" do
174
+ book2 = Workbook.new(@book.ole_workbook)
175
+ book2.equal?(@book).should be true
176
+ end
177
+
178
+ end
179
+
180
+ context "connecting to one unknown workbook" do
181
+
182
+ before do
183
+ ole_e1 = WIN32OLE.new('Excel.Application')
184
+ ws = ole_e1.Workbooks
185
+ abs_filename = General.absolute_path(@simple_file_xlsm1)
186
+ @ole_wb = ws.Open(abs_filename)
187
+ end
188
+
189
+ it "should connect to an unknown workbook" do
190
+ Workbook.open(@simple_file_xlsm1) do |book|
191
+ book.filename.should == @simple_file_xlsm1
192
+ book.should be_alive
193
+ book.should be_a Workbook
194
+ book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
195
+ Excel.excels_number.should == 1
196
+ end
197
+ end
198
+ end
199
+
200
+ context "with :force => excel" do
201
+
202
+ before do
203
+ @book = Workbook.open(@simple_file_xlsm1)
204
+ end
205
+
206
+ it "should open in a new Excel" do
207
+ book2 = Workbook.open(@simple_file_xlsm1, :force => {:excel => :new})
208
+ book2.should be_alive
209
+ book2.should be_a Workbook
210
+ book2.excel.should_not == @book.excel
211
+ book2.should_not == @book
212
+ @book.Readonly.should be false
213
+ book2.Readonly.should be true
214
+ book2.close
215
+ end
216
+
217
+ end
218
+
219
+ context "with :if_unsaved" do
220
+
221
+ before do
222
+ @book = Workbook.open(@simple_file_xlsm1)
223
+ @sheet = @book.sheet(1)
224
+ @book.add_sheet(@sheet, :as => 'a_name')
225
+ @book.visible = true
226
+ end
227
+
228
+ after do
229
+ @book.close(:if_unsaved => :forget)
230
+ @new_book.close rescue nil
231
+ end
232
+
233
+ it "should let the book open, if :if_unsaved is :accept" do
234
+ expect {
235
+ @new_book = Workbook.open(@simple_file_xlsm1, :if_unsaved => :accept)
236
+ }.to_not raise_error
237
+ @book.should be_alive
238
+ @new_book.should be_alive
239
+ @new_book.should == @book
240
+ end
241
+
242
+ end
243
+
244
+ end
245
+
46
246
  describe "open and new" do
47
247
 
48
248
  context "with standard" do
@@ -67,8 +267,340 @@ describe Workbook do
67
267
 
68
268
  end
69
269
 
270
+ describe "fetching workbooks with network and hostname share paths" do
271
+
272
+ before do
273
+ bookstore = Bookstore.new
274
+ end
275
+
276
+ it "should fetch a network path file given a hostname share file" do
277
+ book1 = Workbook.open(@simple_file_hostname_share_path)
278
+ book2 = Workbook.open(@simple_file_network_path)
279
+ book2.should === book1
280
+ book2.Fullname.should == book1.Fullname
281
+ book1.excel.Workbooks.Count.should == 1
282
+ end
283
+
284
+ it "should fetch a hostname share file given a network path file" do
285
+ book1 = Workbook.open(@simple_file_network_path)
286
+ book2 = Workbook.open(@simple_file_hostname_share_path)
287
+ book2.should === book1
288
+ book2.Fullname.should == book1.Fullname
289
+ book1.excel.Workbooks.Count.should == 1
290
+ end
291
+
292
+ it "should raise WorkbookBlocked" do
293
+ book1 = Workbook.open(@simple_file_hostname_share_path)
294
+ expect{
295
+ book2 = Workbook.open(@simple_file)
296
+ }.to raise_error(WorkbookBlocked)
297
+ end
298
+
299
+ it "should raise an error fetching an hostname share file having opened a local path file" do
300
+ book1 = Workbook.open(@simple_file)
301
+ expect{
302
+ Workbook.open(@simple_file_hostname_share_path)
303
+ }.to raise_error(WorkbookBlocked)
304
+ end
305
+
306
+ it "should raise an error fetching a local path file having opened a network path file" do
307
+ book1 = Workbook.open(@simple_file_network_path)
308
+ expect{
309
+ Workbook.open(@simple_file)
310
+ }.to raise_error(WorkbookBlocked)
311
+ end
312
+
313
+ it "should raise an error fetching a network path file having opened a local path file" do
314
+ book1 = Workbook.open(@simple_file)
315
+ expect{
316
+ Workbook.open(@simple_file_network_path)
317
+ }.to raise_error(WorkbookBlocked)
318
+ end
319
+
320
+ it "should raise an error fetching a local path file having opened a hostname share path file" do
321
+ book1 = Workbook.open(@simple_file_hostname_share_path)
322
+ expect{
323
+ Workbook.open(@simple_file)
324
+ }.to raise_error(WorkbookBlocked)
325
+ end
326
+
327
+ it "should raise an WorkbookBlockederror" do
328
+ book1 = Workbook.open(@simple_file_network_path1)
329
+ expect{
330
+ Workbook.open(@simple_file_network_path_other_path1)
331
+ }.to raise_error(WorkbookBlocked)
332
+ end
333
+
334
+ it "should raise an WorkbookBlockederror" do
335
+ book1 = Workbook.open(@simple_file_network_path_other_path1)
336
+ expect{
337
+ Workbook.open(@simple_file_network_path1)
338
+ }.to raise_error(WorkbookBlocked)
339
+ end
340
+
341
+ it "should raise an WorkbookBlockederror" do
342
+ book1 = Workbook.open(@simple_file_hostname_share_path1)
343
+ expect{
344
+ Workbook.open(@simple_file_hostname_share_path_other_path1)
345
+ }.to raise_error(WorkbookBlocked)
346
+ end
347
+
348
+ it "should raise an WorkbookBlockederror" do
349
+ book1 = Workbook.open(@simple_file_hostname_share_path_other_path1)
350
+ expect{
351
+ Workbook.open(@simple_file_hostname_share_path1)
352
+ }.to raise_error(WorkbookBlocked)
353
+ end
354
+
355
+ it "should raise an WorkbookBlockederror" do
356
+ book1 = Workbook.open(@simple_file_hostname_share_path1)
357
+ expect{
358
+ Workbook.open(@simple_file_network_path_other_path1)
359
+ }.to raise_error(WorkbookBlocked)
360
+ end
361
+
362
+ it "should raise an WorkbookBlockederror" do
363
+ book1 = Workbook.open(@simple_file_hostname_share_path_other_path1)
364
+ expect{
365
+ Workbook.open(@simple_file_network_path1)
366
+ }.to raise_error(WorkbookBlocked)
367
+ end
368
+
369
+ it "should raise an WorkbookBlockederror" do
370
+ book1 = Workbook.open(@simple_file_network_path1)
371
+ expect{
372
+ Workbook.open(@simple_file_hostname_share_path_other_path1)
373
+ }.to raise_error(WorkbookBlocked)
374
+ end
375
+
376
+ it "should raise an WorkbookBlockederror" do
377
+ book1 = Workbook.open(@simple_file_network_path_other_path1)
378
+ expect{
379
+ Workbook.open(@simple_file_hostname_share_path1)
380
+ }.to raise_error(WorkbookBlocked)
381
+ end
382
+
383
+ end
384
+
385
+
70
386
  describe "connecting to unknown workbooks" do
71
387
 
388
+ context "with one unknown network path or hostname share file" do
389
+
390
+ it "should connect to a network path workbook from a network path file" do
391
+ ole_e1 = WIN32OLE.new('Excel.Application')
392
+ ws = ole_e1.Workbooks
393
+ abs_filename = General.absolute_path(@simple_file_network_path1)
394
+ @ole_wb = ws.Open(abs_filename)
395
+ Workbook.open(@simple_file_network_path1) do |book|
396
+ book.should be_alive
397
+ book.should be_a Workbook
398
+ book.filename.should == @simple_file_network_path1
399
+ book.Fullname.should == @ole_wb.Fullname
400
+ book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
401
+ Excel.excels_number.should == 1
402
+ book.excel.Workbooks.Count.should == 1
403
+ end
404
+ end
405
+
406
+ it "should connect to a hostname share workbook from a network path file" do
407
+ ole_e1 = WIN32OLE.new('Excel.Application')
408
+ ws = ole_e1.Workbooks
409
+ abs_filename = General.absolute_path(@simple_file_hostname_share_path1)
410
+ @ole_wb = ws.Open(abs_filename)
411
+ Workbook.open(@simple_file_network_path1) do |book|
412
+ book.should be_alive
413
+ book.should be_a Workbook
414
+ book.filename.should == @simple_file_hostname_share_path1.downcase
415
+ book.Fullname.should == @ole_wb.Fullname
416
+ book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
417
+ Excel.excels_number.should == 1
418
+ book.excel.Workbooks.Count.should == 1
419
+ end
420
+ end
421
+
422
+ it "should raise WorkbookBlocked trying to connect to a local path file from a network path file" do
423
+ ole_e1 = WIN32OLE.new('Excel.Application')
424
+ ws = ole_e1.Workbooks
425
+ abs_filename = General.absolute_path(@simple_file1)
426
+ @ole_wb = ws.Open(abs_filename)
427
+ expect{
428
+ Workbook.open(@simple_file_network_path1)
429
+ }.to raise_error(WorkbookBlocked)
430
+ end
431
+
432
+ it "should raise WorkbookBlocked trying to connect to a network path file from a local path file" do
433
+ ole_e1 = WIN32OLE.new('Excel.Application')
434
+ ws = ole_e1.Workbooks
435
+ abs_filename = General.absolute_path(@simple_file_network_path1)
436
+ @ole_wb = ws.Open(abs_filename)
437
+ expect{
438
+ Workbook.open(@simple_file1)
439
+ }.to raise_error(WorkbookBlocked)
440
+ end
441
+
442
+ it "should raise WorkbookBlocked trying to connect a hostname share file from a local path file" do
443
+ ole_e1 = WIN32OLE.new('Excel.Application')
444
+ ws = ole_e1.Workbooks
445
+ abs_filename = General.absolute_path(@simple_file_hostname_share_path1)
446
+ @ole_wb = ws.Open(abs_filename)
447
+ expect{
448
+ Workbook.open(@simple_file1)
449
+ }.to raise_error(WorkbookBlocked)
450
+ end
451
+
452
+ it "should raise WorkbookBlocked trying to connect to a local path workbook from a hostname share file" do
453
+ ole_e1 = WIN32OLE.new('Excel.Application')
454
+ ws = ole_e1.Workbooks
455
+ abs_filename = General.absolute_path(@simple_file1)
456
+ @ole_wb = ws.Open(abs_filename)
457
+ expect{
458
+ Workbook.open(@simple_file_hostname_share_path1)
459
+ }.to raise_error(WorkbookBlocked)
460
+ end
461
+
462
+ it "should connect to a network path workbook from a hostname share file" do
463
+ ole_e1 = WIN32OLE.new('Excel.Application')
464
+ ws = ole_e1.Workbooks
465
+ abs_filename = General.absolute_path(@simple_file_network_path1)
466
+ @ole_wb = ws.Open(abs_filename)
467
+ Workbook.open(@simple_file_hostname_share_path1) do |book|
468
+ book.should be_alive
469
+ book.should be_a Workbook
470
+ book.filename.should == @simple_file_network_path1
471
+ book.Fullname.should == @ole_wb.Fullname
472
+ book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
473
+ Excel.excels_number.should == 1
474
+ book.excel.Workbooks.Count.should == 1
475
+ end
476
+ end
477
+
478
+ it "should connect to a hostname share workbook from a hostname share file" do
479
+ ole_e1 = WIN32OLE.new('Excel.Application')
480
+ ws = ole_e1.Workbooks
481
+ abs_filename = General.absolute_path(@simple_file_hostname_share_path1)
482
+ @ole_wb = ws.Open(abs_filename)
483
+ Workbook.open(@simple_file_hostname_share_path1) do |book|
484
+ book.should be_alive
485
+ book.should be_a Workbook
486
+ book.filename.should == @simple_file_hostname_share_path1.downcase
487
+ book.Fullname.should == @ole_wb.Fullname
488
+ book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
489
+ Excel.excels_number.should == 1
490
+ book.excel.Workbooks.Count.should == 1
491
+ end
492
+ end
493
+
494
+ it "should raise WorkbookBlocked error" do
495
+ ole_e1 = WIN32OLE.new('Excel.Application')
496
+ ws = ole_e1.Workbooks
497
+ abs_filename = General.absolute_path(@simple_file_network_path1)
498
+ @ole_wb = ws.Open(abs_filename)
499
+ expect{
500
+ Workbook.open(@simple_file_network_path_other_path1)
501
+ }.to raise_error(WorkbookBlocked)
502
+ end
503
+
504
+ it "should raise WorkbookBlocked error" do
505
+ ole_e1 = WIN32OLE.new('Excel.Application')
506
+ ws = ole_e1.Workbooks
507
+ abs_filename = General.absolute_path(@simple_file_network_path_other_path1)
508
+ @ole_wb = ws.Open(abs_filename)
509
+ expect{
510
+ Workbook.open(@simple_file_network_path1)
511
+ }.to raise_error(WorkbookBlocked)
512
+ end
513
+
514
+ it "should raise WorkbookBlocked error" do
515
+ ole_e1 = WIN32OLE.new('Excel.Application')
516
+ ws = ole_e1.Workbooks
517
+ abs_filename = General.absolute_path(@simple_file_hostname_share_path1)
518
+ @ole_wb = ws.Open(abs_filename)
519
+ expect{
520
+ Workbook.open(@simple_file_hostname_share_path_other_path1)
521
+ }.to raise_error(WorkbookBlocked)
522
+ end
523
+
524
+ it "should raise WorkbookBlocked error" do
525
+ ole_e1 = WIN32OLE.new('Excel.Application')
526
+ ws = ole_e1.Workbooks
527
+ abs_filename = General.absolute_path(@simple_file_hostname_share_path_other_path1)
528
+ @ole_wb = ws.Open(abs_filename)
529
+ expect{
530
+ Workbook.open(@simple_file_hostname_share_path1)
531
+ }.to raise_error(WorkbookBlocked)
532
+ end
533
+
534
+ it "should raise WorkbookBlocked error" do
535
+ ole_e1 = WIN32OLE.new('Excel.Application')
536
+ ws = ole_e1.Workbooks
537
+ abs_filename = General.absolute_path(@simple_file_hostname_share_path1)
538
+ @ole_wb = ws.Open(abs_filename)
539
+ expect{
540
+ Workbook.open(@simple_file_network_path_other_path1)
541
+ }.to raise_error(WorkbookBlocked)
542
+ end
543
+
544
+ it "should raise WorkbookBlocked error" do
545
+ ole_e1 = WIN32OLE.new('Excel.Application')
546
+ ws = ole_e1.Workbooks
547
+ abs_filename = General.absolute_path(@simple_file_network_path_other_path1)
548
+ @ole_wb = ws.Open(abs_filename)
549
+ expect{
550
+ Workbook.open(@simple_file_hostname_share_path1)
551
+ }.to raise_error(WorkbookBlocked)
552
+ end
553
+
554
+ it "should raise WorkbookBlocked error" do
555
+ ole_e1 = WIN32OLE.new('Excel.Application')
556
+ ws = ole_e1.Workbooks
557
+ abs_filename = General.absolute_path(@simple_file_network_path1)
558
+ @ole_wb = ws.Open(abs_filename)
559
+ expect{
560
+ Workbook.open(@simple_file_hostname_share_path_other_path1)
561
+ }.to raise_error(WorkbookBlocked)
562
+ end
563
+
564
+ it "should raise WorkbookBlocked error" do
565
+ ole_e1 = WIN32OLE.new('Excel.Application')
566
+ ws = ole_e1.Workbooks
567
+ abs_filename = General.absolute_path(@simple_file_hostname_share_path_other_path1)
568
+ @ole_wb = ws.Open(abs_filename)
569
+ expect{
570
+ Workbook.open(@simple_file_network_path1)
571
+ }.to raise_error(WorkbookBlocked)
572
+ end
573
+
574
+ end
575
+
576
+ context "with one unknown hostname share path file" do
577
+
578
+ before do
579
+ ole_e1 = WIN32OLE.new('Excel.Application')
580
+ ws = ole_e1.Workbooks
581
+ abs_filename = General.absolute_path( @simple_file_hostname_share_path1)
582
+ @ole_wb = ws.Open(abs_filename)
583
+ end
584
+
585
+ it "should connect to an unknown hostname share path workbook" do
586
+ Workbook.open(@simple_file_hostname_share_path1) do |book|
587
+ book.filename.should == @simple_file_hostname_share_path1.downcase
588
+ book.should be_alive
589
+ book.should be_a Workbook
590
+ book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
591
+ Excel.excels_number.should == 1
592
+ book.excel.Workbooks.Count.should == 1
593
+ end
594
+ end
595
+
596
+ it "should raise error because blocking" do
597
+ expect{
598
+ Workbook.open(@simple_file1)
599
+ }.to raise_error(WorkbookBlocked)
600
+ end
601
+
602
+ end
603
+
72
604
  context "with none workbook" do
73
605
 
74
606
  it "should open one new Excel with the worbook" do
@@ -78,7 +610,7 @@ describe Workbook do
78
610
  Excel.excels_number.should == 1
79
611
  book1.ReadOnly.should be false
80
612
  book1.excel.Visible.should be false
81
- book1.CheckCompatibility.should be false
613
+ book1.CheckCompatibility.should be true
82
614
  book1.Saved.should be true
83
615
  end
84
616
 
@@ -380,7 +912,7 @@ describe Workbook do
380
912
  excel1.close
381
913
  expect{
382
914
  book1 = Workbook.open(@simple_file1, :force => {:excel => excel1})
383
- }.to raise_error(ExcelREOError, "excel is not alive")
915
+ }.to raise_error(ExcelREOError, "Excel is not alive")
384
916
  end
385
917
 
386
918
  it "should open in a provided Excel" do
@@ -402,18 +934,7 @@ describe Workbook do
402
934
  end
403
935
 
404
936
  end
405
-
406
- describe "network paths" do
407
-
408
- it "should open the workbook via network path" do
409
- book1 = Workbook.open(@simple_file_hostname_share_path)
410
- book2 = Workbook.open(@simple_file_network_path)
411
- book1.should === book2
412
- book1.Fullname.should == book2.Fullname
413
- end
414
-
415
- end
416
-
937
+
417
938
  describe "new" do
418
939
 
419
940
  context "with transparency identity" do
@@ -428,9 +949,32 @@ describe Workbook do
428
949
  @book.close
429
950
  end
430
951
 
431
- it "should yield identical Workbook objects for identical Excel books after uplifting" do
952
+ it "should yield identical Workbook objects referring to identical WIN32OLE objects" do
953
+ book2 = Workbook.new(@book.ole_workbook)
954
+ book2.equal?(@book).should be true
955
+ end
956
+
957
+ it "should yield identical Workbook objects referring to identical WIN32OLE objects with open" do
958
+ book2 = Workbook.open(@book.ole_workbook)
959
+ book2.equal?(@book).should be true
960
+ end
961
+
962
+ it "should yield identical Workbook objects created with help of their filenames" do
963
+ book2 = Workbook.open(@simple_file1)
964
+ book2.equal?(@book).should be true
965
+ end
966
+
967
+ it "should yield identical Workbook objects created with help of their WIN32OLE objects" do
968
+ book2 = Workbook.new(@book.ole_workbook)
969
+ book3 = Workbook.open(@book.ole_workbook)
970
+ book3.equal?(book2).should be true
971
+ end
972
+
973
+
974
+ it "should yield identical Workbook objects for identical Excel books after prmoting" do
432
975
  book2 = Workbook.new(@ole_book)
433
976
  book2.should === @book
977
+ book2.equal?(@book).should be true
434
978
  book2.close
435
979
  end
436
980
 
@@ -440,6 +984,7 @@ describe Workbook do
440
984
  ole_book2 = WIN32OLE.connect(abs_filename2)
441
985
  book2 = Workbook.new(ole_book2)
442
986
  book2.should_not === @book
987
+ book2.equal?(@book).should be false
443
988
  book2.close
444
989
  book3.close
445
990
  end
@@ -486,31 +1031,53 @@ describe Workbook do
486
1031
  book2.excel.should_not == book.excel
487
1032
  end
488
1033
 
489
- it "should uplift an open known workbook" do
1034
+ it "should type-lift an workbook" do
1035
+ book = Workbook.open(@simple_file)
1036
+ new_book = Workbook.new(book)
1037
+ new_book.should == book
1038
+ new_book.equal?(book).should be true
1039
+ new_book.Fullname.should == book.Fullname
1040
+ new_book.excel.should == book.excel
1041
+ end
1042
+
1043
+ it "should type-lift an workbook and supply option" do
1044
+ book = Workbook.open(@simple_file)
1045
+ new_book = Workbook.new(book, :visible => true)
1046
+ new_book.should == book
1047
+ new_book.equal?(book).should be true
1048
+ new_book.Fullname.should == book.Fullname
1049
+ new_book.excel.should == book.excel
1050
+ new_book.visible.should be true
1051
+ end
1052
+
1053
+ it "should type-lift an open known win32ole workbook" do
490
1054
  book = Workbook.open(@simple_file)
491
1055
  ole_workbook = book.ole_workbook
492
1056
  new_book = Workbook.new(ole_workbook)
493
1057
  new_book.should == book
1058
+ new_book.equal?(book).should be true
494
1059
  new_book.Fullname.should == book.Fullname
495
1060
  new_book.excel.should == book.excel
496
1061
  end
497
1062
 
498
- it "should uplift an open known workbook and let it be visible" do
1063
+ it "should type-lift an open known win32ole workbook and let it be visible" do
499
1064
  book = Workbook.open(@simple_file, :visible => true)
500
1065
  ole_workbook = book.ole_workbook
501
1066
  new_book = Workbook.new(ole_workbook)
502
1067
  new_book.should == book
1068
+ new_book.equal?(book).should be true
503
1069
  new_book.Fullname.should == book.Fullname
504
1070
  new_book.excel.should == book.excel
505
1071
  new_book.excel.Visible.should == true
506
1072
  new_book.Windows(new_book.ole_workbook.Name).Visible.should == true
507
1073
  end
508
1074
 
509
- it "should uplift an open known workbook and let it be visible and readonly" do
1075
+ it "should type-lift an open known win32ole workbook and let it be visible and readonly" do
510
1076
  book = Workbook.open(@simple_file, :visible => true, :read_only => true)
511
1077
  ole_workbook = book.ole_workbook
512
1078
  new_book = Workbook.new(ole_workbook)
513
1079
  new_book.should == book
1080
+ new_book.equal?(book).should be true
514
1081
  new_book.Fullname.should == book.Fullname
515
1082
  new_book.excel.should == book.excel
516
1083
  new_book.excel.Visible.should == true
@@ -518,18 +1085,19 @@ describe Workbook do
518
1085
  new_book.ReadOnly.should == true
519
1086
  end
520
1087
 
521
- it "should uplift an open known workbook and make it visible" do
1088
+ it "should type-lift an open known win32ole workbook and make it visible" do
522
1089
  book = Workbook.open(@simple_file)
523
1090
  ole_workbook = book.ole_workbook
524
1091
  new_book = Workbook.new(ole_workbook, :visible => true)
525
1092
  new_book.should == book
1093
+ new_book.equal?(book).should be true
526
1094
  new_book.Fullname.should == book.Fullname
527
1095
  new_book.excel.should == book.excel
528
1096
  new_book.excel.Visible.should == true
529
1097
  new_book.Windows(new_book.ole_workbook.Name).Visible.should == true
530
1098
  end
531
1099
 
532
- it "should uplift an open unknown workbook" do
1100
+ it "should type-lift an open unknown win32ole workbook" do
533
1101
  ole_excel = WIN32OLE.new('Excel.Application')
534
1102
  ws = ole_excel.Workbooks
535
1103
  abs_filename = General.absolute_path(@simple_file1)
@@ -539,7 +1107,7 @@ describe Workbook do
539
1107
  new_book.excel.Hwnd.should == ole_excel.Hwnd
540
1108
  end
541
1109
 
542
- it "should uplift an open unknown workbook and make it visible" do
1110
+ it "should type-lift an open unknown win32ole workbook and make it visible" do
543
1111
  ole_excel = WIN32OLE.new('Excel.Application')
544
1112
  ws = ole_excel.Workbooks
545
1113
  abs_filename = General.absolute_path(@simple_file1)
@@ -551,7 +1119,7 @@ describe Workbook do
551
1119
  new_book.Windows(new_book.ole_workbook.Name).Visible.should == true
552
1120
  end
553
1121
 
554
- it "should uplift an open unknown workbook and make it visible and readonly" do
1122
+ it "should type-lift an open unknown win32ole workbook and make it visible and readonly" do
555
1123
  ole_excel = WIN32OLE.new('Excel.Application')
556
1124
  ws = ole_excel.Workbooks
557
1125
  abs_filename = General.absolute_path(@simple_file1)
@@ -584,20 +1152,20 @@ describe Workbook do
584
1152
 
585
1153
  it "should not set the default value" do
586
1154
  book1 = Workbook.open(@simple_file)
587
- book1.excel.calculation.should == nil
1155
+ book1.excel.properties[:calculation].should == nil
588
1156
  end
589
1157
 
590
1158
  it "should set the calculation mode to automatic" do
591
1159
  book1 = Workbook.open(@simple_file)
592
1160
  book1.excel.calculation = :automatic
593
- book1.excel.calculation.should == :automatic
1161
+ book1.excel.properties[:calculation].should == :automatic
594
1162
  book1.excel.Calculation.should == XlCalculationAutomatic
595
1163
  end
596
1164
 
597
1165
  it "should set the calculation mode to manual" do
598
1166
  book1 = Workbook.open(@simple_file)
599
1167
  book1.excel.calculation = :manual
600
- book1.excel.calculation.should == :manual
1168
+ book1.excel.properties[:calculation].should == :manual
601
1169
  book1.excel.Calculation.should == XlCalculationManual
602
1170
  end
603
1171
 
@@ -1012,7 +1580,7 @@ describe Workbook do
1012
1580
  it "should raise an error if no Excel or Workbook is given" do
1013
1581
  expect{
1014
1582
  Workbook.open(@simple_file1, :force => {:excel => :b})
1015
- }.to raise_error(TypeREOError, "given object is neither an Excel, a Workbook, nor a Win32ole")
1583
+ }.to raise_error(TypeREOError, @error_message_excel)
1016
1584
  end
1017
1585
 
1018
1586
  it "should do force_excel even if both force_ and default_excel is given" do
@@ -1168,7 +1736,7 @@ describe Workbook do
1168
1736
  it "should raise an error if no Excel or Workbook is given" do
1169
1737
  expect{
1170
1738
  Workbook.open(@simple_file1, :excel => :b)
1171
- }.to raise_error(TypeREOError, "given object is neither an Excel, a Workbook, nor a Win32ole")
1739
+ }.to raise_error(TypeREOError, @error_message_excel)
1172
1740
  end
1173
1741
 
1174
1742
  it "should do force_excel even if both force_ and default_excel is given" do
@@ -1326,7 +1894,7 @@ describe Workbook do
1326
1894
  it "should raise an error if no Excel or Workbook is given" do
1327
1895
  expect{
1328
1896
  Workbook.open(@simple_file1, :force_excel => :b)
1329
- }.to raise_error(TypeREOError, "given object is neither an Excel, a Workbook, nor a Win32ole")
1897
+ }.to raise_error(TypeREOError, @error_message_excel)
1330
1898
  end
1331
1899
 
1332
1900
  it "should do force_excel even if both force_ and default_excel is given" do
@@ -1567,7 +2135,7 @@ describe Workbook do
1567
2135
  it "should raise an error if no Excel or Workbook is given" do
1568
2136
  expect{
1569
2137
  Workbook.open(@different_file, :default => {:excel => :a})
1570
- }.to raise_error(TypeREOError, "given object is neither an Excel, a Workbook, nor a Win32ole")
2138
+ }.to raise_error(TypeREOError, @error_message_excel)
1571
2139
  end
1572
2140
 
1573
2141
  end
@@ -1749,7 +2317,7 @@ describe Workbook do
1749
2317
  it "should raise an error if no Excel or Workbook is given" do
1750
2318
  expect{
1751
2319
  Workbook.open(@different_file, :default_excel => :a)
1752
- }.to raise_error(TypeREOError, "given object is neither an Excel, a Workbook, nor a Win32ole")
2320
+ }.to raise_error(TypeREOError, @error_message_excel)
1753
2321
  end
1754
2322
 
1755
2323
  end