robust_excel_ole 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog +13 -0
  3. data/README.rdoc +107 -73
  4. data/{README_excel.rdoc → docs/README_excel.rdoc} +2 -0
  5. data/{README_open.rdoc → docs/README_open.rdoc} +12 -16
  6. data/{README_ranges.rdoc → docs/README_ranges.rdoc} +1 -1
  7. data/{README_save_close.rdoc → docs/README_save_close.rdoc} +0 -0
  8. data/{README_sheet.rdoc → docs/README_sheet.rdoc} +0 -0
  9. data/examples/open_save_close/example_control_to_excel.rb +3 -3
  10. data/examples/open_save_close/example_default_excel.rb +2 -2
  11. data/examples/open_save_close/example_force_excel.rb +2 -2
  12. data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +2 -2
  13. data/examples/open_save_close/example_if_obstructed_forget.rb +2 -2
  14. data/examples/open_save_close/example_if_obstructed_save.rb +2 -2
  15. data/examples/open_save_close/example_if_unsaved_accept.rb +3 -3
  16. data/examples/open_save_close/example_if_unsaved_forget.rb +7 -3
  17. data/examples/open_save_close/example_if_unsaved_forget_more.rb +1 -1
  18. data/examples/open_save_close/example_read_only.rb +2 -2
  19. data/examples/open_save_close/example_rename_cells.rb +2 -2
  20. data/examples/open_save_close/example_reuse.rb +2 -2
  21. data/examples/open_save_close/example_simple.rb +1 -1
  22. data/examples/open_save_close/example_unobtrusively.rb +2 -2
  23. data/lib/robust_excel_ole/book.rb +75 -76
  24. data/lib/robust_excel_ole/bookstore.rb +9 -9
  25. data/lib/robust_excel_ole/excel.rb +5 -5
  26. data/lib/robust_excel_ole/general.rb +11 -4
  27. data/lib/robust_excel_ole/reo_common.rb +3 -0
  28. data/lib/robust_excel_ole/version.rb +1 -1
  29. data/robust_excel_ole.gemspec +2 -2
  30. data/spec/book_spec.rb +67 -63
  31. data/spec/book_specs/book_close_spec.rb +12 -10
  32. data/spec/book_specs/book_misc_spec.rb +279 -279
  33. data/spec/book_specs/book_open_spec.rb +258 -105
  34. data/spec/book_specs/book_save_spec.rb +28 -28
  35. data/spec/book_specs/book_unobtr_spec.rb +862 -164
  36. data/spec/bookstore_spec.rb +22 -22
  37. data/spec/data/another_workbook.xls +0 -0
  38. data/spec/data/different_workbook.xls +0 -0
  39. data/spec/data/workbook.xls +0 -0
  40. data/spec/excel_spec.rb +256 -254
  41. data/spec/general_spec.rb +7 -7
  42. data/spec/ruby1.8.6_rspec2.14/book_spec.rb +1421 -0
  43. data/spec/ruby1.8.6_rspec2.14/book_specs/book_all_spec.rb +22 -0
  44. data/spec/ruby1.8.6_rspec2.14/book_specs/book_close_spec.rb +252 -0
  45. data/spec/ruby1.8.6_rspec2.14/book_specs/book_misc_spec.rb +1070 -0
  46. data/spec/ruby1.8.6_rspec2.14/book_specs/book_open_spec.rb +1855 -0
  47. data/spec/ruby1.8.6_rspec2.14/book_specs/book_save_spec.rb +514 -0
  48. data/spec/ruby1.8.6_rspec2.14/book_specs/book_sheet_spec.rb +395 -0
  49. data/spec/ruby1.8.6_rspec2.14/book_specs/book_subclass_spec.rb +51 -0
  50. data/spec/ruby1.8.6_rspec2.14/book_specs/book_unobtr_spec.rb +1737 -0
  51. data/spec/ruby1.8.6_rspec2.14/bookstore_spec.rb +495 -0
  52. data/spec/ruby1.8.6_rspec2.14/cell_spec.rb +76 -0
  53. data/spec/ruby1.8.6_rspec2.14/cygwin_spec.rb +42 -0
  54. data/spec/ruby1.8.6_rspec2.14/excel_spec.rb +1820 -0
  55. data/spec/ruby1.8.6_rspec2.14/general_spec.rb +212 -0
  56. data/spec/ruby1.8.6_rspec2.14/range_spec.rb +131 -0
  57. data/spec/ruby1.8.6_rspec2.14/reo_common_spec.rb +130 -0
  58. data/spec/ruby1.8.6_rspec2.14/sheet_spec.rb +663 -0
  59. data/spec/ruby1.8.6_rspec2.14/spec_helper.rb +35 -0
  60. data/spec/sheet_spec.rb +2 -2
  61. metadata +28 -12
  62. data/README_detail.rdoc +0 -852
  63. data/README_development.rdoc +0 -5
@@ -29,6 +29,7 @@ describe Book do
29
29
  @simple_file_xlsx = @dir + '/workbook.xlsx'
30
30
  @simple_file1 = @simple_file
31
31
  @different_file1 = @different_file
32
+ @simple_file_other_path1 = @simple_file_other_path
32
33
  end
33
34
 
34
35
  after do
@@ -36,6 +37,40 @@ describe Book do
36
37
  #rm_tmp(@dir)
37
38
  end
38
39
 
40
+ describe "simple open" do
41
+
42
+ it "should simply open" do
43
+ book = Workbook.open(@simple_file, :v => true, :f => {:e => :new})
44
+ end
45
+
46
+ end
47
+
48
+ describe "new" do
49
+
50
+ it "should simply create a new one" do
51
+ book = Workbook.new(@simple_file)
52
+ book.should be_alive
53
+ book.should be_a Book
54
+ end
55
+
56
+ it "should set options" do
57
+ book = Workbook.new(@simple_file, :visible => true, :read_only => true, :force => {:excel => :new})
58
+ book.should be_alive
59
+ book.should be_a Book
60
+ book.excel.Visible.should be true
61
+ book.Windows(book.Name).Visible.should be true
62
+ book.ReadOnly.should be true
63
+ book2 = Workbook.new(@different_file, :force => {:excel => :new}, :v => true)
64
+ book2.should be_alive
65
+ book2.should be_a Book
66
+ book2.excel.Visible.should be true
67
+ book2.Windows(book2.Name).Visible.should be true
68
+ book2.ReadOnly.should be false
69
+ book2.excel.should_not == book.excel
70
+ end
71
+
72
+ end
73
+
39
74
  describe "open" do
40
75
 
41
76
  context "with calculation mode" do
@@ -111,8 +146,8 @@ describe Book do
111
146
  book2.should be_a Book
112
147
  book2.excel.should_not == @book.excel
113
148
  book2.should_not == @book
114
- @book.Readonly.should be_false
115
- book2.Readonly.should be_true
149
+ @book.Readonly.should be false
150
+ book2.Readonly.should be true
116
151
  book2.close
117
152
  end
118
153
  end
@@ -135,8 +170,8 @@ describe Book do
135
170
  new_book.should == @book
136
171
  new_book.filename.should == @book.filename
137
172
  new_book.excel.should == @book.excel
138
- new_book.excel.Visible.should be_false
139
- new_book.excel.DisplayAlerts.should be_false
173
+ new_book.excel.Visible.should be false
174
+ new_book.excel.DisplayAlerts.should be false
140
175
  new_book.should === @book
141
176
  new_book.close
142
177
  end
@@ -149,8 +184,8 @@ describe Book do
149
184
  new_book.should == @book
150
185
  new_book.filename.should == @book.filename
151
186
  new_book.excel.should == @book.excel
152
- new_book.excel.Visible.should be_true
153
- new_book.excel.DisplayAlerts.should be_true
187
+ new_book.excel.Visible.should be true
188
+ new_book.excel.DisplayAlerts.should be true
154
189
  new_book.should === @book
155
190
  new_book.close
156
191
  end
@@ -165,8 +200,8 @@ describe Book do
165
200
  new_book.filename.should == @book.filename
166
201
  new_book.excel.should == @book.excel
167
202
  new_book.should === @book
168
- new_book.excel.Visible.should be_true
169
- new_book.excel.DisplayAlerts.should be_true
203
+ new_book.excel.Visible.should be true
204
+ new_book.excel.DisplayAlerts.should be true
170
205
  new_book.close
171
206
  end
172
207
 
@@ -252,7 +287,8 @@ describe Book do
252
287
  @book.close
253
288
  @book.should_not be_alive
254
289
  book2 = Book.open(@simple_file1, :force => {:excel => new_excel})
255
- book2.should_not === @book
290
+ #@book.should be_alive
291
+ #book2.should === @book
256
292
  book2.should be_alive
257
293
  book2.excel.should == new_excel
258
294
  book2.excel.should_not == old_excel
@@ -274,6 +310,91 @@ describe Book do
274
310
 
275
311
  end
276
312
 
313
+ context "with abbrevations" do
314
+
315
+ before do
316
+ @book = Book.open(@simple_file1)
317
+ end
318
+
319
+ after do
320
+ @book.close rescue nil
321
+ end
322
+
323
+ it "should work as force" do
324
+ book2 = Book.open(@another_simple_file, :excel => :new)
325
+ book2.excel.should_not == @book.excel
326
+ book3 = Book.open(@different_file, :excel => book2.excel)
327
+ book3.excel.should == book2.excel
328
+ end
329
+
330
+ it "should work with abbrevation of force and excel" do
331
+ book2 = Book.open(@another_simple_file, :f => {:e => :new})
332
+ book2.excel.should_not == @book.excel
333
+ book3 = Book.open(@different_file, :f => {:e => book2.excel})
334
+ book3.excel.should == book2.excel
335
+ end
336
+
337
+ it "should work with abbrevation of force" do
338
+ book2 = Book.open(@another_simple_file, :f => {:excel => :new})
339
+ book2.excel.should_not == @book.excel
340
+ book3 = Book.open(@different_file, :f => {:excel => book2.excel})
341
+ book3.excel.should == book2.excel
342
+ end
343
+
344
+ it "should work with abbrevation of force" do
345
+ book2 = Book.open(@another_simple_file, :force => {:e => :new})
346
+ book2.excel.should_not == @book.excel
347
+ book3 = Book.open(@different_file, :force => {:e => book2.excel})
348
+ book3.excel.should == book2.excel
349
+ end
350
+
351
+ it "should open in a given Excel provided as Excel, Book, or WIN32OLE representing an Excel or Workbook" do
352
+ book2 = Book.open(@another_simple_file)
353
+ book3 = Book.open(@different_file)
354
+ book3 = Book.open(@simple_file1, :excel => book2.excel)
355
+ book3.excel.should === book2.excel
356
+ book4 = Book.open(@simple_file1, :excel => @book)
357
+ book4.excel.should === @book.excel
358
+ book3.close
359
+ book4.close
360
+ book5 = Book.open(@simple_file1, :excel => book2.ole_workbook)
361
+ book5.excel.should === book2.excel
362
+ win32ole_excel1 = WIN32OLE.connect(@book.ole_workbook.Fullname).Application
363
+ book6 = Book.open(@simple_file1, :excel => win32ole_excel1)
364
+ book6.excel.should === @book.excel
365
+ end
366
+
367
+ it "should use abbreviations of default" do
368
+ book2 = Book.open(@simple_file1, :d => {:excel => :current})
369
+ book2.excel.should == @book.excel
370
+ end
371
+
372
+ it "should use abbreviations of default" do
373
+ book2 = Book.open(@simple_file1, :d => {:e => :current})
374
+ book2.excel.should == @book.excel
375
+ end
376
+
377
+ it "should use abbreviations of default" do
378
+ book2 = Book.open(@simple_file1, :default => {:e => :current})
379
+ book2.excel.should == @book.excel
380
+ end
381
+
382
+ it "should reopen the book in the Excel where it was opened most recently" do
383
+ excel1 = @book.excel
384
+ excel2 = Excel.new(:reuse => false)
385
+ @book.close
386
+ book2 = Book.open(@simple_file1, :d => {:e => :current})
387
+ book2.excel.should == excel1
388
+ book2.close
389
+ book3 = Book.open(@simple_file1, :e => excel2)
390
+ book3.close
391
+ book3 = Book.open(@simple_file1, :d => {:e => :current})
392
+ book3.excel.should == excel2
393
+ book3.close
394
+ end
395
+
396
+ end
397
+
277
398
  context "with :force => {:excel}" do
278
399
 
279
400
  before do
@@ -300,15 +421,14 @@ describe Book do
300
421
  book6.excel.should === @book.excel
301
422
  end
302
423
 
303
-
304
424
  it "should open in a new Excel" do
305
425
  book2 = Book.open(@simple_file1, :force => {:excel => :new})
306
426
  book2.should be_alive
307
427
  book2.should be_a Book
308
428
  book2.excel.should_not == @book.excel
309
429
  book2.should_not == @book
310
- @book.Readonly.should be_false
311
- book2.Readonly.should be_true
430
+ @book.Readonly.should be false
431
+ book2.Readonly.should be true
312
432
  book2.close
313
433
  end
314
434
 
@@ -323,14 +443,14 @@ describe Book do
323
443
  book4.should be_alive
324
444
  book4.should be_a Book
325
445
  book4.excel.should == book2.excel
326
- book4.Readonly.should == true
446
+ #book4.Readonly.should == true
327
447
  book4.should_not == book2
328
448
  book4.close
329
449
  book5 = Book.open(@simple_file1, :force => {:excel => book2})
330
450
  book5.should be_alive
331
451
  book5.should be_a Book
332
452
  book5.excel.should == book2.excel
333
- book5.Readonly.should == true
453
+ #book5.Readonly.should == true
334
454
  book5.should_not == book2
335
455
  book5.close
336
456
  book3.close
@@ -349,14 +469,14 @@ describe Book do
349
469
  book4.should be_alive
350
470
  book4.should be_a Book
351
471
  book4.excel.should == book2.excel
352
- book4.ReadOnly.should be_true
472
+ book4.ReadOnly.should be true
353
473
  book4.should == book2
354
474
  book4.close
355
475
  book5 = Book.open(@simple_file1, :force => {:excel => book2}, :read_only => true)
356
476
  book5.should be_alive
357
477
  book5.should be_a Book
358
478
  book5.excel.should == book2.excel
359
- book5.ReadOnly.should be_true
479
+ book5.ReadOnly.should be true
360
480
  book5.should == book2
361
481
  book5.close
362
482
  book3.close
@@ -371,7 +491,7 @@ describe Book do
371
491
  book4.should be_alive
372
492
  book4.should be_a Book
373
493
  book4.excel.should == book2.excel
374
- book4.ReadOnly.should be_true
494
+ book4.ReadOnly.should be true
375
495
  book4.should == book2
376
496
  book4.close
377
497
  end
@@ -465,8 +585,8 @@ describe Book do
465
585
  book2.should be_a Book
466
586
  book2.excel.should_not == @book.excel
467
587
  book2.should_not == @book
468
- @book.Readonly.should be_false
469
- book2.Readonly.should be_true
588
+ @book.Readonly.should be false
589
+ book2.Readonly.should be true
470
590
  book2.close
471
591
  end
472
592
 
@@ -481,14 +601,14 @@ describe Book do
481
601
  book4.should be_alive
482
602
  book4.should be_a Book
483
603
  book4.excel.should == book2.excel
484
- book4.Readonly.should == true
604
+ #book4.Readonly.should == false
485
605
  book4.should_not == book2
486
606
  book4.close
487
607
  book5 = Book.open(@simple_file1, :force_excel => book2)
488
608
  book5.should be_alive
489
609
  book5.should be_a Book
490
610
  book5.excel.should == book2.excel
491
- book5.Readonly.should == true
611
+ #book5.Readonly.should == false
492
612
  book5.should_not == book2
493
613
  book5.close
494
614
  book3.close
@@ -507,14 +627,14 @@ describe Book do
507
627
  book4.should be_alive
508
628
  book4.should be_a Book
509
629
  book4.excel.should == book2.excel
510
- book4.ReadOnly.should be_true
630
+ book4.ReadOnly.should be true
511
631
  book4.should == book2
512
632
  book4.close
513
633
  book5 = Book.open(@simple_file1, :force_excel => book2, :read_only => true)
514
634
  book5.should be_alive
515
635
  book5.should be_a Book
516
636
  book5.excel.should == book2.excel
517
- book5.ReadOnly.should be_true
637
+ book5.ReadOnly.should be true
518
638
  book5.should == book2
519
639
  book5.close
520
640
  book3.close
@@ -529,7 +649,7 @@ describe Book do
529
649
  book4.should be_alive
530
650
  book4.should be_a Book
531
651
  book4.excel.should == book2.excel
532
- book4.ReadOnly.should be_true
652
+ book4.ReadOnly.should be true
533
653
  book4.should == book2
534
654
  book4.close
535
655
  end
@@ -1175,40 +1295,65 @@ describe Book do
1175
1295
 
1176
1296
  end
1177
1297
 
1298
+ it "should new_excel" do
1299
+ book = Book.open(@simple_file1)
1300
+ book.sheet(1)[1,1].Value = "f"
1301
+ book.Saved.should be false
1302
+ book2 = Book.open(@simple_file1, :if_unsaved => :new_excel)
1303
+ end
1304
+
1178
1305
  context "with :if_unsaved" do
1179
1306
 
1180
1307
  before do
1181
1308
  @book = Book.open(@simple_file1)
1182
- #@book.Windows(@book.Name).Visible = true
1183
- @sheet = @book.sheet(1)
1184
- @book.add_sheet(@sheet, :as => 'a_name')
1309
+ sheet = @book.sheet(1)
1310
+ #@book.add_sheet(@sheet, :as => 'a_name')
1311
+ @old_value = sheet[1,1].Value
1312
+ sheet[1,1] = (sheet[1,1].value == "foo" ? "bar" : "foo")
1313
+ @new_value = sheet[1,1].Value
1314
+ @book.Saved.should be false
1185
1315
  end
1186
1316
 
1187
1317
  after do
1188
1318
  @book.close(:if_unsaved => :forget)
1189
- @new_book.close rescue nil
1319
+ end
1320
+
1321
+ it "should open the book in a new excel instance, if :if_unsaved is :new_excel" do
1322
+ new_book = Book.open(@simple_file1, :if_unsaved => :new_excel)
1323
+ new_book.excel.should_not == @book.excel
1324
+ @book.should be_alive
1325
+ @book.Saved.should be false
1326
+ new_book.should be_alive
1327
+ new_book.Saved.should be true
1328
+ new_book.sheet(1)[1,1].Value.should == @old_value
1329
+ #new_book.filename.should == @book.filename
1330
+ new_book.excel.should_not == @book.excel
1331
+ new_book.close
1190
1332
  end
1191
1333
 
1192
1334
  it "should raise an error, if :if_unsaved is :raise" do
1193
1335
  expect {
1194
- @new_book = Book.open(@simple_file1, :if_unsaved => :raise)
1336
+ new_book = Book.open(@simple_file1, :if_unsaved => :raise)
1195
1337
  }.to raise_error(WorkbookNotSaved, /workbook is already open but not saved: "workbook.xls"/)
1196
1338
  end
1197
1339
 
1198
1340
  it "should let the book open, if :if_unsaved is :accept" do
1199
- expect {
1200
- @new_book = Book.open(@simple_file1, :if_unsaved => :accept)
1201
- }.to_not raise_error
1341
+ new_book = Book.open(@simple_file1, :if_unsaved => :accept)
1202
1342
  @book.should be_alive
1203
- @new_book.should be_alive
1204
- @new_book.should == @book
1343
+ new_book.should be_alive
1344
+ new_book.Saved.should be false
1345
+ @book.Saved.should be false
1346
+ new_book.sheet(1)[1,1].Value.should == @new_value
1347
+ new_book.should == @book
1205
1348
  end
1206
1349
 
1207
1350
  it "should open book and close old book, if :if_unsaved is :forget" do
1208
- @new_book = Book.open(@simple_file1, :if_unsaved => :forget)
1351
+ new_book = Book.open(@simple_file1, :if_unsaved => :forget)
1209
1352
  @book.should_not be_alive
1210
- @new_book.should be_alive
1211
- @new_book.filename.downcase.should == @simple_file.downcase
1353
+ new_book.should be_alive
1354
+ new_book.Saved.should be true
1355
+ new_book.sheet(1)[1,1].Value.should == @old_value
1356
+ #@new_book.filename.downcase.should == @simple_file.downcase
1212
1357
  end
1213
1358
 
1214
1359
  context "with :if_unsaved => :alert" do
@@ -1223,10 +1368,12 @@ describe Book do
1223
1368
  it "should open the new book and close the unsaved book, if user answers 'yes'" do
1224
1369
  # "Yes" is the default. --> language independent
1225
1370
  @key_sender.puts "{enter}"
1226
- @new_book = Book.open(@simple_file1, :if_unsaved => :alert)
1227
- @new_book.should be_alive
1228
- @new_book.filename.downcase.should == @simple_file.downcase
1229
- @book.should_not be_alive
1371
+ new_book = Book.open(@simple_file1, :if_unsaved => :alert)
1372
+ new_book.should be_alive
1373
+ #@book.should_not be_alive
1374
+ #new_book.filename.downcase.should == @simple_file.downcase
1375
+ new_book.Saved.should be true
1376
+ new_book.sheet(1)[1,1].Value.should == @old_value
1230
1377
  end
1231
1378
  end
1232
1379
  =begin
@@ -1258,10 +1405,11 @@ describe Book do
1258
1405
  it "should open the new book and close the unsaved book, if user answers 'yes'" do
1259
1406
  # "Yes" is the default. --> language independent
1260
1407
  @key_sender.puts "{enter}"
1261
- @new_book = Book.open(@simple_file1, :if_unsaved => :excel)
1262
- @new_book.should be_alive
1263
- @new_book.filename.downcase.should == @simple_file1.downcase
1264
- @book.should_not be_alive
1408
+ new_book = Book.open(@simple_file1, :if_unsaved => :excel)
1409
+ new_book.should be_alive
1410
+ #@book.should_not be_alive
1411
+ new_book.Saved.should be true
1412
+ new_book.sheet(1)[1,1].Value.should == @old_value
1265
1413
  end
1266
1414
 
1267
1415
  =begin
@@ -1281,24 +1429,15 @@ describe Book do
1281
1429
 
1282
1430
  end
1283
1431
 
1284
- it "should open the book in a new excel instance, if :if_unsaved is :new_excel" do
1285
- @new_book = Book.open(@simple_file1, :if_unsaved => :new_excel)
1286
- @book.should be_alive
1287
- @new_book.should be_alive
1288
- @new_book.filename.should == @book.filename
1289
- @new_book.excel.should_not == @book.excel
1290
- @new_book.close
1291
- end
1292
-
1293
1432
  it "should raise an error, if :if_unsaved is default" do
1294
1433
  expect {
1295
- @new_book = Book.open(@simple_file1, :if_unsaved => :raise)
1434
+ new_book = Book.open(@simple_file1, :if_unsaved => :raise)
1296
1435
  }.to raise_error(WorkbookNotSaved, /workbook is already open but not saved: "workbook.xls"/)
1297
1436
  end
1298
1437
 
1299
1438
  it "should raise an error, if :if_unsaved is invalid option" do
1300
1439
  expect {
1301
- @new_book = Book.open(@simple_file1, :if_unsaved => :invalid_option)
1440
+ new_book = Book.open(@simple_file1, :if_unsaved => :invalid_option)
1302
1441
  }.to raise_error(OptionInvalid, ":if_unsaved: invalid option: :invalid_option")
1303
1442
  end
1304
1443
  end
@@ -1314,79 +1453,90 @@ describe Book do
1314
1453
  book_before = Book.open(@simple_file1)
1315
1454
  book_before.close
1316
1455
  end
1317
- @book = Book.open(@simple_file_other_path)
1456
+ @book = Book.open(@simple_file_other_path1)
1318
1457
  #@book.Windows(@book.Name).Visible = true
1319
- @sheet_count = @book.ole_workbook.Worksheets.Count
1320
- @sheet = @book.sheet(1)
1321
- @book.add_sheet(@sheet, :as => 'a_name')
1458
+ #@sheet_count = @book.ole_workbook.Worksheets.Count
1459
+ sheet = @book.sheet(1)
1460
+ #@book.add_sheet(@sheet, :as => 'a_name')
1461
+ @old_value = sheet[1,1].Value
1462
+ sheet[1,1] = (sheet[1,1].value == "foo" ? "bar" : "foo")
1463
+ @new_value = sheet[1,1].Value
1464
+ @book.Saved.should be false
1322
1465
  end
1323
1466
 
1324
1467
  after do
1325
1468
  @book.close(:if_unsaved => :forget)
1326
- @new_book.close rescue nil
1469
+ #@new_book.close rescue nil
1327
1470
  end
1328
1471
 
1329
1472
  it "should raise an error, if :if_obstructed is :raise" do
1330
1473
  expect {
1331
- @new_book = Book.open(@simple_file1, :if_obstructed => :raise)
1474
+ new_book = Book.open(@simple_file1, :if_obstructed => :raise)
1332
1475
  }.to raise_error(WorkbookBlocked, /blocked by a workbook with the same name in a different path/)
1333
1476
  end
1334
1477
 
1335
1478
  it "should close the other book and open the new book, if :if_obstructed is :forget" do
1336
- @new_book = Book.open(@simple_file1, :if_obstructed => :forget)
1479
+ new_book = Book.open(@simple_file1, :if_obstructed => :forget)
1337
1480
  @book.should_not be_alive
1338
- @new_book.should be_alive
1339
- @new_book.filename.downcase.should == @simple_file.downcase
1481
+ new_book.should be_alive
1482
+ new_book.filename.downcase.should == @simple_file.downcase
1483
+ old_book = Book.open(@simple_file_other_path1, :if_obstructed => :forget)
1484
+ old_book.sheet(1)[1,1].Value.should == @old_value
1340
1485
  end
1341
1486
 
1342
1487
  it "should save the old book, close it, and open the new book, if :if_obstructed is :save" do
1343
- @new_book = Book.open(@simple_file1, :if_obstructed => :save)
1488
+ new_book = Book.open(@simple_file1, :if_obstructed => :save)
1344
1489
  @book.should_not be_alive
1345
- @new_book.should be_alive
1346
- @new_book.filename.downcase.should == @simple_file1.downcase
1347
- old_book = Book.open(@simple_file_other_path, :if_obstructed => :forget)
1348
- old_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
1490
+ new_book.should be_alive
1491
+ new_book.filename.downcase.should == @simple_file1.downcase
1492
+ old_book = Book.open(@simple_file_other_path1, :if_obstructed => :forget)
1493
+ old_book.sheet(1)[1,1].Value.should == @new_value
1494
+ #old_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
1349
1495
  old_book.close
1350
1496
  end
1351
1497
 
1352
1498
  it "should raise an error, if the old book is unsaved, and close the old book and open the new book,
1353
1499
  if :if_obstructed is :close_if_saved" do
1354
1500
  expect{
1355
- @new_book = Book.open(@simple_file1, :if_obstructed => :close_if_saved)
1501
+ new_book = Book.open(@simple_file1, :if_obstructed => :close_if_saved)
1356
1502
  }.to raise_error(WorkbookBlocked, /workbook with the same name in a different path is unsaved/)
1357
1503
  @book.save
1358
- @new_book = Book.open(@simple_file1, :if_obstructed => :close_if_saved)
1504
+ new_book = Book.open(@simple_file1, :if_obstructed => :close_if_saved)
1359
1505
  @book.should_not be_alive
1360
- @new_book.should be_alive
1361
- @new_book.filename.downcase.should == @simple_file1.downcase
1362
- old_book = Book.open(@simple_file_other_path, :if_obstructed => :forget)
1363
- old_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
1506
+ new_book.should be_alive
1507
+ new_book.filename.downcase.should == @simple_file1.downcase
1508
+ old_book = Book.open(@simple_file_other_path1, :if_obstructed => :forget)
1509
+ old_book.sheet(1)[1,1].Value.should == @new_value
1510
+ #old_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
1364
1511
  old_book.close
1365
1512
  end
1366
1513
 
1367
1514
  it "should close the old book and open the new book, if :if_obstructed is :close_if_saved" do
1368
1515
  @book.close(:if_unsaved => :forget)
1369
1516
  book = Book.open(@simple_file_other_path)
1370
- Book.open(@simple_file1, :if_obstructed => :close_if_saved)
1517
+ book2 = Book.open(@simple_file1, :if_obstructed => :close_if_saved)
1371
1518
  end
1372
1519
 
1373
1520
  it "should open the book in a new excel instance, if :if_obstructed is :new_excel" do
1374
- @new_book = Book.open(@simple_file1, :if_obstructed => :new_excel)
1521
+ new_book = Book.open(@simple_file1, :if_obstructed => :new_excel)
1375
1522
  @book.should be_alive
1376
- @new_book.should be_alive
1377
- @new_book.filename.should_not == @book.filename
1378
- @new_book.excel.should_not == @book.excel
1523
+ @book.Saved.should be false
1524
+ @book.sheet(1)[1,1].Value.should == @new_value
1525
+ new_book.should be_alive
1526
+ new_book.filename.should_not == @book.filename
1527
+ new_book.excel.should_not == @book.excel
1528
+ new_book.sheet(1)[1,1].Value.should == @old_value
1379
1529
  end
1380
1530
 
1381
1531
  it "should raise an error, if :if_obstructed is default" do
1382
1532
  expect {
1383
- @new_book = Book.open(@simple_file1)
1533
+ new_book = Book.open(@simple_file1)
1384
1534
  }.to raise_error(WorkbookBlocked, /blocked by a workbook with the same name in a different path/)
1385
1535
  end
1386
1536
 
1387
1537
  it "should raise an error, if :if_obstructed is invalid option" do
1388
1538
  expect {
1389
- @new_book = Book.open(@simple_file1, :if_obstructed => :invalid_option)
1539
+ new_book = Book.open(@simple_file1, :if_obstructed => :invalid_option)
1390
1540
  }.to raise_error(OptionInvalid, ":if_obstructed: invalid option: :invalid_option")
1391
1541
  end
1392
1542
  end
@@ -1451,7 +1601,7 @@ describe Book do
1451
1601
  book = Book.open(@simple_save_file, :if_absent => :create)
1452
1602
  book.should be_a Book
1453
1603
  book.close
1454
- File.exist?(@simple_save_file).should be_true
1604
+ File.exist?(@simple_save_file).should be true
1455
1605
  end
1456
1606
 
1457
1607
  it "should raise an exception by default" do
@@ -1485,7 +1635,7 @@ describe Book do
1485
1635
  it "should set update_links to :alert" do
1486
1636
  book = Book.open(@simple_file, :update_links => :alert)
1487
1637
  book.UpdateLinks.should == XlUpdateLinksUserSetting
1488
- book.Saved.should be_true
1638
+ book.Saved.should be true
1489
1639
  end
1490
1640
 
1491
1641
  it "should set update_links to :never" do
@@ -1512,14 +1662,14 @@ describe Book do
1512
1662
 
1513
1663
  it "should reopen the book with writable (unsaved changes from readonly will not be saved)" do
1514
1664
  book = Book.open(@simple_file1, :read_only => true)
1515
- book.ReadOnly.should be_true
1665
+ book.ReadOnly.should be true
1516
1666
  book.should be_alive
1517
1667
  sheet = book.sheet(1)
1518
1668
  old_cell_value = sheet[1,1].value
1519
1669
  sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
1520
- book.Saved.should be_false
1670
+ book.Saved.should be false
1521
1671
  new_book = Book.open(@simple_file1, :read_only => false, :if_unsaved => :accept)
1522
- new_book.ReadOnly.should be_false
1672
+ new_book.ReadOnly.should be false
1523
1673
  new_book.should be_alive
1524
1674
  book.should be_alive
1525
1675
  new_book.should == book
@@ -1530,28 +1680,28 @@ describe Book do
1530
1680
 
1531
1681
  it "should not raise an error when trying to reopen the book as read_only while the writable book had unsaved changes" do
1532
1682
  book = Book.open(@simple_file1, :read_only => false)
1533
- book.ReadOnly.should be_false
1683
+ book.ReadOnly.should be false
1534
1684
  book.should be_alive
1535
1685
  sheet = book.sheet(1)
1536
1686
  old_cell_value = sheet[1,1].value
1537
1687
  sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
1538
- book.Saved.should be_false
1688
+ book.Saved.should be false
1539
1689
  new_book = Book.open(@simple_file1, :read_only => true, :if_unsaved => :accept)
1540
- new_book.ReadOnly.should be_true
1541
- new_book.Saved.should be_true
1690
+ new_book.ReadOnly.should be true
1691
+ new_book.Saved.should be true
1542
1692
  new_book.should == book
1543
1693
  end
1544
1694
 
1545
1695
  it "should reopen the book with writable in the same Excel instance (unsaved changes from readonly will not be saved)" do
1546
1696
  book = Book.open(@simple_file1, :read_only => true)
1547
- book.ReadOnly.should be_true
1697
+ book.ReadOnly.should be true
1548
1698
  book.should be_alive
1549
1699
  sheet = book.sheet(1)
1550
1700
  old_cell_value = sheet[1,1].value
1551
1701
  sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
1552
- book.Saved.should be_false
1702
+ book.Saved.should be false
1553
1703
  new_book = Book.open(@simple_file1, :if_unsaved => :accept, :force => {:excel => book.excel}, :read_only => false)
1554
- new_book.ReadOnly.should be_false
1704
+ new_book.ReadOnly.should be false
1555
1705
  new_book.should be_alive
1556
1706
  book.should be_alive
1557
1707
  new_book.should == book
@@ -1562,23 +1712,26 @@ describe Book do
1562
1712
 
1563
1713
  it "should reopen the book with readonly (unsaved changes of the writable should be saved)" do
1564
1714
  book = Book.open(@simple_file1, :force => {:excel => :new}, :read_only => false)
1565
- book.ReadOnly.should be_false
1715
+ book.ReadOnly.should be false
1566
1716
  book.should be_alive
1567
1717
  sheet = book.sheet(1)
1568
1718
  old_cell_value = sheet[1,1].value
1569
1719
  sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
1570
- book.Saved.should be_false
1720
+ book.Saved.should be false
1571
1721
  new_book = Book.open(@simple_file1, :force => {:excel => book.excel}, :read_only => true, :if_unsaved => :accept)
1572
- new_book.ReadOnly.should be_true
1573
- new_book.Saved.should be_true
1722
+ new_book.ReadOnly.should be true
1723
+ new_book.Saved.should be true
1574
1724
  new_book.should == book
1725
+ new_sheet = new_book.sheet(1)
1726
+ new_cell_value = new_sheet[1,1].value
1727
+ new_cell_value.should_not == old_cell_value
1575
1728
  end
1576
1729
 
1577
1730
  it "should open the second book in another Excel as writable" do
1578
1731
  book = Book.open(@simple_file1, :read_only => true)
1579
- book.ReadOnly.should be_true
1732
+ book.ReadOnly.should be true
1580
1733
  new_book = Book.open(@simple_file1, :force => {:excel => :new}, :read_only => false)
1581
- new_book.ReadOnly.should be_false
1734
+ new_book.ReadOnly.should be false
1582
1735
  new_book.close
1583
1736
  book.close
1584
1737
  end
@@ -1618,10 +1771,10 @@ describe Book do
1618
1771
  book.close
1619
1772
  end
1620
1773
 
1621
- it "should open xlsm file" do
1622
- book = Book.open(@simple_file_xlsm, :visible => true)
1623
- book.close
1624
- end
1774
+ #it "should open xlsm file" do
1775
+ # book = Book.open(@simple_file_xlsm, :visible => true)
1776
+ # book.close
1777
+ #end
1625
1778
 
1626
1779
  it "should open xlsx file" do
1627
1780
  book = Book.open(@simple_file_xlsx, :visible => true)