robust_excel_ole 0.5.1 → 0.6
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.
- data/Changelog +13 -0
- data/README.rdoc +70 -21
- data/README_detail.rdoc +60 -27
- data/examples/edit_sheets/example_access_sheets_and_cells.rb +2 -2
- data/examples/edit_sheets/example_adding_sheets.rb +2 -2
- data/examples/edit_sheets/example_concating.rb +2 -3
- data/examples/edit_sheets/example_copying.rb +2 -3
- data/examples/edit_sheets/example_expanding.rb +2 -3
- data/examples/edit_sheets/example_naming.rb +2 -3
- data/examples/edit_sheets/example_ranges.rb +2 -2
- data/examples/edit_sheets/example_saving.rb +2 -3
- data/examples/open_save_close/example_control_to_excel.rb +3 -3
- data/examples/open_save_close/example_default_excel.rb +4 -4
- data/examples/open_save_close/example_force_excel.rb +2 -2
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +2 -2
- data/examples/open_save_close/example_if_obstructed_forget.rb +2 -2
- data/examples/open_save_close/example_if_obstructed_save.rb +2 -2
- data/examples/open_save_close/example_if_unsaved_accept.rb +2 -2
- data/examples/open_save_close/example_if_unsaved_forget.rb +2 -2
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +4 -5
- data/examples/open_save_close/example_read_only.rb +2 -2
- data/examples/open_save_close/example_rename_cells.rb +3 -3
- data/examples/open_save_close/example_reuse.rb +2 -2
- data/examples/open_save_close/example_simple.rb +3 -4
- data/examples/open_save_close/example_unobtrusively.rb +2 -2
- data/lib/robust_excel_ole/book.rb +84 -78
- data/lib/robust_excel_ole/bookstore.rb +5 -1
- data/lib/robust_excel_ole/excel.rb +165 -188
- data/lib/robust_excel_ole/reo_common.rb +4 -0
- data/lib/robust_excel_ole/sheet.rb +15 -6
- data/lib/robust_excel_ole/version.rb +1 -1
- data/spec/book_spec.rb +104 -77
- data/spec/book_specs/book_close_spec.rb +9 -8
- data/spec/book_specs/book_misc_spec.rb +367 -26
- data/spec/book_specs/book_open_spec.rb +375 -94
- data/spec/book_specs/book_save_spec.rb +137 -112
- data/spec/book_specs/book_sheet_spec.rb +1 -1
- data/spec/book_specs/book_subclass_spec.rb +2 -1
- data/spec/book_specs/book_unobtr_spec.rb +87 -96
- data/spec/bookstore_spec.rb +8 -5
- data/spec/cell_spec.rb +1 -1
- data/spec/data/another_workbook.xls +0 -0
- data/spec/data/book_with_blank.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +484 -72
- data/spec/range_spec.rb +1 -1
- data/spec/sheet_spec.rb +47 -1
- metadata +4 -5
@@ -14,7 +14,7 @@ describe Book do
|
|
14
14
|
excel = Excel.new(:reuse => true)
|
15
15
|
open_books = excel == nil ? 0 : excel.Workbooks.Count
|
16
16
|
puts "*** open books *** : #{open_books}" if open_books > 0
|
17
|
-
Excel.
|
17
|
+
Excel.kill_all
|
18
18
|
end
|
19
19
|
|
20
20
|
before do
|
@@ -27,15 +27,30 @@ describe Book do
|
|
27
27
|
@linked_file = @dir + '/workbook_linked.xlsm'
|
28
28
|
@simple_file_xlsm = @dir + '/workbook.xls'
|
29
29
|
@simple_file_xlsx = @dir + '/workbook.xlsx'
|
30
|
+
@simple_file1 = @simple_file
|
31
|
+
@different_file1 = @different_file
|
30
32
|
end
|
31
33
|
|
32
34
|
after do
|
33
35
|
Excel.kill_all
|
34
|
-
rm_tmp(@dir)
|
36
|
+
#rm_tmp(@dir)
|
35
37
|
end
|
36
38
|
|
37
39
|
describe "open" do
|
38
40
|
|
41
|
+
context "with causing warning dead excel without window handle" do
|
42
|
+
|
43
|
+
it "combined" do
|
44
|
+
Excel.kill_all
|
45
|
+
book1 = Book.open(@simple_file, :visible => true)
|
46
|
+
book2 = Book.open(@different_file)
|
47
|
+
Excel.kill_all
|
48
|
+
#sleep 1
|
49
|
+
book3 = Book.open(@another_simple_file)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
39
54
|
context "with class identifier 'Workbook'" do
|
40
55
|
|
41
56
|
before do
|
@@ -91,22 +106,23 @@ describe Book do
|
|
91
106
|
new_book.filename.should == @book.filename
|
92
107
|
new_book.excel.should == @book.excel
|
93
108
|
new_book.excel.Visible.should be_true
|
94
|
-
new_book.excel.DisplayAlerts.should
|
109
|
+
new_book.excel.DisplayAlerts.should be_true
|
95
110
|
new_book.should === @book
|
96
111
|
new_book.close
|
97
112
|
end
|
98
113
|
|
99
|
-
it "should yield an identical Book and set visible
|
114
|
+
it "should yield an identical Book and set visible value" do
|
100
115
|
workbook = @book.ole_workbook
|
101
|
-
new_book = Book.new(workbook, :visible => true
|
116
|
+
new_book = Book.new(workbook, :visible => true)
|
117
|
+
new_book.excel.displayalerts = true
|
102
118
|
new_book.should be_a Book
|
103
119
|
new_book.should be_alive
|
104
120
|
new_book.should == @book
|
105
121
|
new_book.filename.should == @book.filename
|
106
122
|
new_book.excel.should == @book.excel
|
107
123
|
new_book.should === @book
|
108
|
-
new_book.excel.
|
109
|
-
new_book.excel.
|
124
|
+
new_book.excel.Visible.should be_true
|
125
|
+
new_book.excel.DisplayAlerts.should be_true
|
110
126
|
new_book.close
|
111
127
|
end
|
112
128
|
|
@@ -129,7 +145,7 @@ describe Book do
|
|
129
145
|
context "with identity transperence" do
|
130
146
|
|
131
147
|
before do
|
132
|
-
@book = Book.open(@
|
148
|
+
@book = Book.open(@simple_file1)
|
133
149
|
end
|
134
150
|
|
135
151
|
after do
|
@@ -137,7 +153,7 @@ describe Book do
|
|
137
153
|
end
|
138
154
|
|
139
155
|
it "should yield identical Book objects for identical Excel books" do
|
140
|
-
book2 = Book.open(@
|
156
|
+
book2 = Book.open(@simple_file1)
|
141
157
|
book2.should === @book
|
142
158
|
book2.close
|
143
159
|
end
|
@@ -158,7 +174,7 @@ describe Book do
|
|
158
174
|
@book.should be_alive
|
159
175
|
@book.close
|
160
176
|
@book.should_not be_alive
|
161
|
-
book2 = Book.open(@
|
177
|
+
book2 = Book.open(@simple_file1)
|
162
178
|
book2.should === @book
|
163
179
|
book2.should be_alive
|
164
180
|
book2.close
|
@@ -168,7 +184,7 @@ describe Book do
|
|
168
184
|
@book.should be_alive
|
169
185
|
@book.close
|
170
186
|
Excel.close_all
|
171
|
-
book2 = Book.open(@
|
187
|
+
book2 = Book.open(@simple_file1)
|
172
188
|
book2.should be_alive
|
173
189
|
book2.should === @book
|
174
190
|
book2.close
|
@@ -179,7 +195,7 @@ describe Book do
|
|
179
195
|
old_excel = @book.excel
|
180
196
|
@book.close
|
181
197
|
@book.should_not be_alive
|
182
|
-
book2 = Book.open(@
|
198
|
+
book2 = Book.open(@simple_file1, :force_excel => :new)
|
183
199
|
book2.should_not === @book
|
184
200
|
book2.should be_alive
|
185
201
|
book2.excel.should_not == old_excel
|
@@ -191,7 +207,7 @@ describe Book do
|
|
191
207
|
new_excel = Excel.new(:reuse => false)
|
192
208
|
@book.close
|
193
209
|
@book.should_not be_alive
|
194
|
-
book2 = Book.open(@
|
210
|
+
book2 = Book.open(@simple_file1, :force_excel => new_excel)
|
195
211
|
book2.should_not === @book
|
196
212
|
book2.should be_alive
|
197
213
|
book2.excel.should == new_excel
|
@@ -204,7 +220,7 @@ describe Book do
|
|
204
220
|
new_excel = Excel.new(:reuse => false)
|
205
221
|
@book.close
|
206
222
|
@book.should_not be_alive
|
207
|
-
book2 = Book.open(@
|
223
|
+
book2 = Book.open(@simple_file1, :force_excel => old_excel)
|
208
224
|
book2.should === @book
|
209
225
|
book2.should be_alive
|
210
226
|
book2.excel.should == old_excel
|
@@ -217,7 +233,7 @@ describe Book do
|
|
217
233
|
context "with :force_excel" do
|
218
234
|
|
219
235
|
before do
|
220
|
-
@book = Book.open(@
|
236
|
+
@book = Book.open(@simple_file1)
|
221
237
|
end
|
222
238
|
|
223
239
|
after do
|
@@ -227,22 +243,22 @@ describe Book do
|
|
227
243
|
it "should open in a given Excel provided as Excel, Book, or WIN32OLE representing an Excel or Workbook" do
|
228
244
|
book2 = Book.open(@another_simple_file)
|
229
245
|
book3 = Book.open(@different_file)
|
230
|
-
book3 = Book.open(@
|
246
|
+
book3 = Book.open(@simple_file1, :force_excel => book2.excel)
|
231
247
|
book3.excel.should === book2.excel
|
232
|
-
book4 = Book.open(@
|
248
|
+
book4 = Book.open(@simple_file1, :force_excel => @book)
|
233
249
|
book4.excel.should === @book.excel
|
234
250
|
book3.close
|
235
251
|
book4.close
|
236
|
-
book5 = Book.open(@
|
252
|
+
book5 = Book.open(@simple_file1, :force_excel => book2.ole_workbook)
|
237
253
|
book5.excel.should === book2.excel
|
238
254
|
win32ole_excel1 = WIN32OLE.connect(@book.ole_workbook.Fullname).Application
|
239
|
-
book6 = Book.open(@
|
255
|
+
book6 = Book.open(@simple_file1, :force_excel => win32ole_excel1)
|
240
256
|
book6.excel.should === @book.excel
|
241
257
|
end
|
242
258
|
|
243
259
|
|
244
260
|
it "should open in a new Excel" do
|
245
|
-
book2 = Book.open(@
|
261
|
+
book2 = Book.open(@simple_file1, :force_excel => :new)
|
246
262
|
book2.should be_alive
|
247
263
|
book2.should be_a Book
|
248
264
|
book2.excel.should_not == @book.excel
|
@@ -253,20 +269,20 @@ describe Book do
|
|
253
269
|
end
|
254
270
|
|
255
271
|
it "should open in a given Excel, not provide identity transparency, because old book readonly, new book writable" do
|
256
|
-
book2 = Book.open(@
|
272
|
+
book2 = Book.open(@simple_file1, :force_excel => :new)
|
257
273
|
book2.excel.should_not == @book.excel
|
258
|
-
book3 = Book.open(@
|
274
|
+
book3 = Book.open(@simple_file1, :force_excel => :new)
|
259
275
|
book3.excel.should_not == book2.excel
|
260
276
|
book3.excel.should_not == @book.excel
|
261
277
|
book2.close
|
262
|
-
book4 = Book.open(@
|
278
|
+
book4 = Book.open(@simple_file1, :force_excel => book2.excel)
|
263
279
|
book4.should be_alive
|
264
280
|
book4.should be_a Book
|
265
281
|
book4.excel.should == book2.excel
|
266
282
|
book4.Readonly.should == true
|
267
283
|
book4.should_not == book2
|
268
284
|
book4.close
|
269
|
-
book5 = Book.open(@
|
285
|
+
book5 = Book.open(@simple_file1, :force_excel => book2)
|
270
286
|
book5.should be_alive
|
271
287
|
book5.should be_a Book
|
272
288
|
book5.excel.should == book2.excel
|
@@ -277,22 +293,22 @@ describe Book do
|
|
277
293
|
end
|
278
294
|
|
279
295
|
it "should open in a given Excel, provide identity transparency, because book can be readonly, such that the old and the new book are readonly" do
|
280
|
-
book2 = Book.open(@
|
296
|
+
book2 = Book.open(@simple_file1, :force_excel => :new)
|
281
297
|
book2.excel.should_not == @book.excel
|
282
|
-
book3 = Book.open(@
|
298
|
+
book3 = Book.open(@simple_file1, :force_excel => :new)
|
283
299
|
book3.excel.should_not == book2.excel
|
284
300
|
book3.excel.should_not == @book.excel
|
285
301
|
book2.close
|
286
302
|
book3.close
|
287
303
|
@book.close
|
288
|
-
book4 = Book.open(@
|
304
|
+
book4 = Book.open(@simple_file1, :force_excel => book2.excel, :read_only => true)
|
289
305
|
book4.should be_alive
|
290
306
|
book4.should be_a Book
|
291
307
|
book4.excel.should == book2.excel
|
292
308
|
book4.ReadOnly.should be_true
|
293
309
|
book4.should == book2
|
294
310
|
book4.close
|
295
|
-
book5 = Book.open(@
|
311
|
+
book5 = Book.open(@simple_file1, :force_excel => book2, :read_only => true)
|
296
312
|
book5.should be_alive
|
297
313
|
book5.should be_a Book
|
298
314
|
book5.excel.should == book2.excel
|
@@ -303,11 +319,11 @@ describe Book do
|
|
303
319
|
end
|
304
320
|
|
305
321
|
it "should open in a given Excel, provide identity transparency, because book can be readonly, such that the old and the new book are readonly" do
|
306
|
-
book2 = Book.open(@
|
322
|
+
book2 = Book.open(@simple_file1, :force_excel => :new)
|
307
323
|
book2.excel.should_not == @book.excel
|
308
324
|
book2.close
|
309
325
|
@book.close
|
310
|
-
book4 = Book.open(@
|
326
|
+
book4 = Book.open(@simple_file1, :force_excel => book2, :read_only => true)
|
311
327
|
book4.should be_alive
|
312
328
|
book4.should be_a Book
|
313
329
|
book4.excel.should == book2.excel
|
@@ -318,12 +334,12 @@ describe Book do
|
|
318
334
|
|
319
335
|
it "should raise an error if no Excel or Book is given" do
|
320
336
|
expect{
|
321
|
-
Book.open(@
|
337
|
+
Book.open(@simple_file1, :force_excel => :b)
|
322
338
|
}.to raise_error(ExcelErrorOpen, "given object is neither an Excel, a Workbook, nor a Win32ole")
|
323
339
|
end
|
324
340
|
|
325
341
|
it "should do force_excel even if both force_ and default_excel is given" do
|
326
|
-
book2 = Book.open(@
|
342
|
+
book2 = Book.open(@simple_file1, :default_excel => @book.excel, :force_excel => :new)
|
327
343
|
book2.should be_alive
|
328
344
|
book2.should be_a Book
|
329
345
|
book2.excel.should_not == @book.excel
|
@@ -338,34 +354,32 @@ describe Book do
|
|
338
354
|
end
|
339
355
|
|
340
356
|
it "should force_excel with :reuse" do
|
341
|
-
book2 = Book.open(@different_file, :force_excel => :
|
357
|
+
book2 = Book.open(@different_file, :force_excel => :current)
|
342
358
|
book2.should be_alive
|
343
359
|
book2.should be_a Book
|
344
360
|
book2.excel.should == @book.excel
|
345
361
|
end
|
346
362
|
|
347
363
|
it "should force_excel with :reuse even if :default_excel says sth. else" do
|
348
|
-
book2 = Book.open(@different_file, :force_excel => :
|
364
|
+
book2 = Book.open(@different_file, :force_excel => :current, :default_excel => :new)
|
349
365
|
book2.should be_alive
|
350
366
|
book2.should be_a Book
|
351
367
|
book2.excel.should == @book.excel
|
352
368
|
end
|
353
369
|
|
354
|
-
it "should
|
370
|
+
it "should force_excel with :reuse when reopening and the Excel is not alive even if :default_excel says sth. else" do
|
355
371
|
excel2 = Excel.new(:reuse => false)
|
356
|
-
excel1_hwnd = @book.excel.hwnd
|
357
372
|
@book.excel.close
|
358
|
-
book2 = Book.open(@
|
373
|
+
book2 = Book.open(@simple_file1, :force_excel => :current, :default_excel => :new)
|
359
374
|
book2.should be_alive
|
360
375
|
book2.should be_a Book
|
361
|
-
book2.excel.
|
362
|
-
book2.excel.hwnd.should == excel1_hwnd
|
376
|
+
book2.excel.should === excel2
|
363
377
|
end
|
364
378
|
|
365
379
|
it "should force_excel with :reuse when reopening and the Excel is not alive even if :default_excel says sth. else" do
|
366
|
-
book2 = Book.open(@
|
380
|
+
book2 = Book.open(@different_file1, :force_excel => :new)
|
367
381
|
book2.excel.close
|
368
|
-
book3 = Book.open(@
|
382
|
+
book3 = Book.open(@different_file1, :force_excel => :current, :default_excel => :new)
|
369
383
|
book3.should be_alive
|
370
384
|
book3.should be_a Book
|
371
385
|
book3.excel.should == @book.excel
|
@@ -376,7 +390,7 @@ describe Book do
|
|
376
390
|
context "with :default_excel" do
|
377
391
|
|
378
392
|
before do
|
379
|
-
@book = Book.open(@
|
393
|
+
@book = Book.open(@simple_file1, :visible => true)
|
380
394
|
end
|
381
395
|
|
382
396
|
after do
|
@@ -384,7 +398,7 @@ describe Book do
|
|
384
398
|
end
|
385
399
|
|
386
400
|
it "should use the open book" do
|
387
|
-
book2 = Book.open(@
|
401
|
+
book2 = Book.open(@simple_file1, :default_excel => :current)
|
388
402
|
book2.excel.should == @book.excel
|
389
403
|
book2.should be_alive
|
390
404
|
book2.should be_a Book
|
@@ -395,7 +409,7 @@ describe Book do
|
|
395
409
|
it "should reopen the book in the excel instance where it was opened before" do
|
396
410
|
excel = Excel.new(:reuse => false)
|
397
411
|
@book.close
|
398
|
-
book2 = Book.open(@
|
412
|
+
book2 = Book.open(@simple_file1)
|
399
413
|
book2.should be_alive
|
400
414
|
book2.should be_a Book
|
401
415
|
book2.excel.should == @book.excel
|
@@ -412,7 +426,7 @@ describe Book do
|
|
412
426
|
fn = @book.filename
|
413
427
|
@book.close
|
414
428
|
Excel.close_all
|
415
|
-
book2 = Book.open(@
|
429
|
+
book2 = Book.open(@simple_file1, :default_excel => :current)
|
416
430
|
book2.should be_alive
|
417
431
|
book2.should be_a Book
|
418
432
|
book2.filename.should == fn
|
@@ -426,7 +440,7 @@ describe Book do
|
|
426
440
|
Excel.close_all
|
427
441
|
new_excel = Excel.new(:reuse => false)
|
428
442
|
new_excel2 = Excel.new(:reuse => false)
|
429
|
-
book2 = Book.open(@
|
443
|
+
book2 = Book.open(@simple_file1, :default_excel => :current)
|
430
444
|
book2.should be_alive
|
431
445
|
book2.should be_a Book
|
432
446
|
book2.excel.should_not == excel
|
@@ -442,7 +456,7 @@ describe Book do
|
|
442
456
|
Excel.close_all
|
443
457
|
excel1 = Excel.new(:reuse => false)
|
444
458
|
excel2 = Excel.new(:reuse => false)
|
445
|
-
book2 = Book.open(@different_file, :default_excel => :
|
459
|
+
book2 = Book.open(@different_file, :default_excel => :current)
|
446
460
|
book2.should be_alive
|
447
461
|
book2.should be_a Book
|
448
462
|
book2.excel.should == excel1
|
@@ -454,12 +468,12 @@ describe Book do
|
|
454
468
|
excel1 = @book.excel
|
455
469
|
excel2 = Excel.new(:reuse => false)
|
456
470
|
@book.close
|
457
|
-
book2 = Book.open(@
|
471
|
+
book2 = Book.open(@simple_file1, :default_excel => :current)
|
458
472
|
book2.excel.should == excel1
|
459
473
|
book2.close
|
460
|
-
book3 = Book.open(@
|
474
|
+
book3 = Book.open(@simple_file1, :force_excel => excel2)
|
461
475
|
book3.close
|
462
|
-
book3 = Book.open(@
|
476
|
+
book3 = Book.open(@simple_file1, :default_excel => :current)
|
463
477
|
book3.excel.should == excel2
|
464
478
|
book3.close
|
465
479
|
end
|
@@ -468,7 +482,7 @@ describe Book do
|
|
468
482
|
book2 = Book.open(@simple_file, :force_excel => :new)
|
469
483
|
@book.close
|
470
484
|
book2.close
|
471
|
-
book3 = Book.open(@
|
485
|
+
book3 = Book.open(@simple_file1)
|
472
486
|
book2.should be_alive
|
473
487
|
book2.should be_a Book
|
474
488
|
book3.excel.should == book2.excel
|
@@ -478,7 +492,7 @@ describe Book do
|
|
478
492
|
end
|
479
493
|
|
480
494
|
it "should open the book in a new excel if the book was not opened before" do
|
481
|
-
book2 = Book.open(@different_file, :default_excel => :
|
495
|
+
book2 = Book.open(@different_file, :default_excel => :current)
|
482
496
|
book2.excel.should == @book.excel
|
483
497
|
book3 = Book.open(@another_simple_file, :default_excel => :new)
|
484
498
|
book3.excel.should_not == @book.excel
|
@@ -488,13 +502,13 @@ describe Book do
|
|
488
502
|
excel = @book.excel
|
489
503
|
excel2 = Excel.new(:reuse => false)
|
490
504
|
excel.close
|
491
|
-
book2 = Book.open(@
|
505
|
+
book2 = Book.open(@simple_file1, :default_excel => :new)
|
492
506
|
book2.excel.should_not == excel2
|
493
507
|
book2.close
|
494
508
|
end
|
495
509
|
|
496
510
|
it "should open the book in a given excel if the book was not opened before" do
|
497
|
-
book2 = Book.open(@different_file, :default_excel => :
|
511
|
+
book2 = Book.open(@different_file, :default_excel => :current)
|
498
512
|
book2.excel.should == @book.excel
|
499
513
|
excel = Excel.new(:reuse => false)
|
500
514
|
book3 = Book.open(@another_simple_file, :default_excel => excel)
|
@@ -504,7 +518,7 @@ describe Book do
|
|
504
518
|
it "should open the book in a given excel if the book was opened before but the excel has been closed" do
|
505
519
|
excel2 = Excel.new(:reuse => false, :visible => true)
|
506
520
|
@book.excel.close
|
507
|
-
book2 = Book.open(@
|
521
|
+
book2 = Book.open(@simple_file1, :visible => true, :default_excel => excel2)
|
508
522
|
book2.excel.should == excel2
|
509
523
|
end
|
510
524
|
|
@@ -542,16 +556,245 @@ describe Book do
|
|
542
556
|
end
|
543
557
|
|
544
558
|
it "should reuse an open book by default" do
|
545
|
-
book2 = Book.open(@
|
559
|
+
book2 = Book.open(@simple_file1)
|
560
|
+
book2.excel.should == @book.excel
|
561
|
+
book2.should == @book
|
562
|
+
end
|
563
|
+
|
564
|
+
it "should raise an error if no Excel or Book is given" do
|
565
|
+
expect{
|
566
|
+
Book.open(@different_file, :default_excel => :a)
|
567
|
+
}.to raise_error(ExcelErrorOpen, "given object is neither an Excel, a Workbook, nor a Win32ole")
|
568
|
+
end
|
569
|
+
|
570
|
+
end
|
571
|
+
|
572
|
+
context "with :active instead of :current" do
|
573
|
+
|
574
|
+
before do
|
575
|
+
@book = Book.open(@simple_file1)
|
576
|
+
end
|
577
|
+
|
578
|
+
after do
|
579
|
+
@book.close rescue nil
|
580
|
+
end
|
581
|
+
|
582
|
+
it "should force_excel with :active" do
|
583
|
+
book2 = Book.open(@different_file, :force_excel => :active)
|
584
|
+
book2.should be_alive
|
585
|
+
book2.should be_a Book
|
586
|
+
book2.excel.should == @book.excel
|
587
|
+
end
|
588
|
+
|
589
|
+
it "should force_excel with :reuse even if :default_excel says sth. else" do
|
590
|
+
book2 = Book.open(@different_file, :force_excel => :active, :default_excel => :new)
|
591
|
+
book2.should be_alive
|
592
|
+
book2.should be_a Book
|
593
|
+
book2.excel.should == @book.excel
|
594
|
+
end
|
595
|
+
|
596
|
+
it "should open force_excel with :reuse when reopening and the Excel is not alive even if :default_excel says sth. else" do
|
597
|
+
excel2 = Excel.new(:reuse => false)
|
598
|
+
@book.excel.close
|
599
|
+
book2 = Book.open(@simple_file1, :force_excel => :active, :default_excel => :new)
|
600
|
+
book2.should be_alive
|
601
|
+
book2.should be_a Book
|
602
|
+
book2.excel.should === excel2
|
603
|
+
end
|
604
|
+
|
605
|
+
it "should force_excel with :reuse when reopening and the Excel is not alive even if :default_excel says sth. else" do
|
606
|
+
book2 = Book.open(@different_file1, :force_excel => :new)
|
607
|
+
book2.excel.close
|
608
|
+
book3 = Book.open(@different_file1, :force_excel => :active, :default_excel => :new)
|
609
|
+
book3.should be_alive
|
610
|
+
book3.should be_a Book
|
611
|
+
book3.excel.should == @book.excel
|
612
|
+
end
|
613
|
+
|
614
|
+
it "should use the open book" do
|
615
|
+
book2 = Book.open(@simple_file1, :default_excel => :active)
|
616
|
+
book2.excel.should == @book.excel
|
617
|
+
book2.should be_alive
|
618
|
+
book2.should be_a Book
|
619
|
+
book2.should == @book
|
620
|
+
book2.close
|
621
|
+
end
|
622
|
+
|
623
|
+
it "should reopen a book in a new Excel if all Excel instances are closed" do
|
624
|
+
excel = Excel.new(:reuse => false)
|
625
|
+
excel2 = @book.excel
|
626
|
+
fn = @book.filename
|
627
|
+
@book.close
|
628
|
+
Excel.close_all
|
629
|
+
book2 = Book.open(@simple_file1, :default_excel => :active)
|
630
|
+
book2.should be_alive
|
631
|
+
book2.should be_a Book
|
632
|
+
book2.filename.should == fn
|
633
|
+
@book.should be_alive
|
634
|
+
book2.should == @book
|
635
|
+
book2.close
|
636
|
+
end
|
637
|
+
|
638
|
+
it "should reopen a book in the first opened Excel if the old Excel is closed" do
|
639
|
+
excel = @book.excel
|
640
|
+
Excel.close_all
|
641
|
+
new_excel = Excel.new(:reuse => false)
|
642
|
+
new_excel2 = Excel.new(:reuse => false)
|
643
|
+
book2 = Book.open(@simple_file1, :default_excel => :active)
|
644
|
+
book2.should be_alive
|
645
|
+
book2.should be_a Book
|
646
|
+
book2.excel.should_not == excel
|
647
|
+
book2.excel.should_not == new_excel2
|
648
|
+
book2.excel.should == new_excel
|
649
|
+
@book.should be_alive
|
650
|
+
book2.should == @book
|
651
|
+
book2.close
|
652
|
+
end
|
653
|
+
|
654
|
+
it "should reopen a book in the first opened excel, if the book cannot be reopened" do
|
655
|
+
@book.close
|
656
|
+
Excel.close_all
|
657
|
+
excel1 = Excel.new(:reuse => false)
|
658
|
+
excel2 = Excel.new(:reuse => false)
|
659
|
+
book2 = Book.open(@different_file, :default_excel => :active)
|
660
|
+
book2.should be_alive
|
661
|
+
book2.should be_a Book
|
662
|
+
book2.excel.should == excel1
|
663
|
+
book2.excel.should_not == excel2
|
664
|
+
book2.close
|
665
|
+
end
|
666
|
+
|
667
|
+
it "should reopen the book in the Excel where it was opened most recently" do
|
668
|
+
excel1 = @book.excel
|
669
|
+
excel2 = Excel.new(:reuse => false)
|
670
|
+
@book.close
|
671
|
+
book2 = Book.open(@simple_file1, :default_excel => :active)
|
672
|
+
book2.excel.should == excel1
|
673
|
+
book2.close
|
674
|
+
book3 = Book.open(@simple_file1, :force_excel => excel2)
|
675
|
+
book3.close
|
676
|
+
book3 = Book.open(@simple_file1, :default_excel => :active)
|
677
|
+
book3.excel.should == excel2
|
678
|
+
book3.close
|
679
|
+
end
|
680
|
+
|
681
|
+
end
|
682
|
+
|
683
|
+
context "with :reuse instead of :current" do
|
684
|
+
|
685
|
+
before do
|
686
|
+
@book = Book.open(@simple_file1)
|
687
|
+
end
|
688
|
+
|
689
|
+
after do
|
690
|
+
@book.close rescue nil
|
691
|
+
end
|
692
|
+
|
693
|
+
it "should force_excel with :reuse" do
|
694
|
+
book2 = Book.open(@different_file, :force_excel => :reuse)
|
695
|
+
book2.should be_alive
|
696
|
+
book2.should be_a Book
|
697
|
+
book2.excel.should == @book.excel
|
698
|
+
end
|
699
|
+
|
700
|
+
it "should force_excel with :reuse even if :default_excel says sth. else" do
|
701
|
+
book2 = Book.open(@different_file, :force_excel => :reuse, :default_excel => :new)
|
702
|
+
book2.should be_alive
|
703
|
+
book2.should be_a Book
|
704
|
+
book2.excel.should == @book.excel
|
705
|
+
end
|
706
|
+
|
707
|
+
it "should open force_excel with :reuse when reopening and the Excel is not alive even if :default_excel says sth. else" do
|
708
|
+
excel2 = Excel.new(:reuse => false)
|
709
|
+
@book.excel.close
|
710
|
+
book2 = Book.open(@simple_file1, :force_excel => :reuse, :default_excel => :new)
|
711
|
+
book2.should be_alive
|
712
|
+
book2.should be_a Book
|
713
|
+
book2.excel.should === excel2
|
714
|
+
end
|
715
|
+
|
716
|
+
it "should force_excel with :reuse when reopening and the Excel is not alive even if :default_excel says sth. else" do
|
717
|
+
book2 = Book.open(@different_file1, :force_excel => :new)
|
718
|
+
book2.excel.close
|
719
|
+
book3 = Book.open(@different_file1, :force_excel => :reuse, :default_excel => :new)
|
720
|
+
book3.should be_alive
|
721
|
+
book3.should be_a Book
|
722
|
+
book3.excel.should == @book.excel
|
723
|
+
end
|
724
|
+
|
725
|
+
it "should use the open book" do
|
726
|
+
book2 = Book.open(@simple_file1, :default_excel => :reuse)
|
546
727
|
book2.excel.should == @book.excel
|
728
|
+
book2.should be_alive
|
729
|
+
book2.should be_a Book
|
730
|
+
book2.should == @book
|
731
|
+
book2.close
|
732
|
+
end
|
733
|
+
|
734
|
+
it "should reopen a book in a new Excel if all Excel instances are closed" do
|
735
|
+
excel = Excel.new(:reuse => false)
|
736
|
+
excel2 = @book.excel
|
737
|
+
fn = @book.filename
|
738
|
+
@book.close
|
739
|
+
Excel.close_all
|
740
|
+
book2 = Book.open(@simple_file1, :default_excel => :reuse)
|
741
|
+
book2.should be_alive
|
742
|
+
book2.should be_a Book
|
743
|
+
book2.filename.should == fn
|
744
|
+
@book.should be_alive
|
745
|
+
book2.should == @book
|
746
|
+
book2.close
|
747
|
+
end
|
748
|
+
|
749
|
+
it "should reopen a book in the first opened Excel if the old Excel is closed" do
|
750
|
+
excel = @book.excel
|
751
|
+
Excel.close_all
|
752
|
+
new_excel = Excel.new(:reuse => false)
|
753
|
+
new_excel2 = Excel.new(:reuse => false)
|
754
|
+
book2 = Book.open(@simple_file1, :default_excel => :reuse)
|
755
|
+
book2.should be_alive
|
756
|
+
book2.should be_a Book
|
757
|
+
book2.excel.should_not == excel
|
758
|
+
book2.excel.should_not == new_excel2
|
759
|
+
book2.excel.should == new_excel
|
760
|
+
@book.should be_alive
|
547
761
|
book2.should == @book
|
762
|
+
book2.close
|
763
|
+
end
|
764
|
+
|
765
|
+
it "should reopen a book in the first opened excel, if the book cannot be reopened" do
|
766
|
+
@book.close
|
767
|
+
Excel.close_all
|
768
|
+
excel1 = Excel.new(:reuse => false)
|
769
|
+
excel2 = Excel.new(:reuse => false)
|
770
|
+
book2 = Book.open(@different_file, :default_excel => :reuse)
|
771
|
+
book2.should be_alive
|
772
|
+
book2.should be_a Book
|
773
|
+
book2.excel.should == excel1
|
774
|
+
book2.excel.should_not == excel2
|
775
|
+
book2.close
|
776
|
+
end
|
777
|
+
|
778
|
+
it "should reopen the book in the Excel where it was opened most recently" do
|
779
|
+
excel1 = @book.excel
|
780
|
+
excel2 = Excel.new(:reuse => false)
|
781
|
+
@book.close
|
782
|
+
book2 = Book.open(@simple_file1, :default_excel => :reuse)
|
783
|
+
book2.excel.should == excel1
|
784
|
+
book2.close
|
785
|
+
book3 = Book.open(@simple_file1, :force_excel => excel2)
|
786
|
+
book3.close
|
787
|
+
book3 = Book.open(@simple_file1, :default_excel => :reuse)
|
788
|
+
book3.excel.should == excel2
|
789
|
+
book3.close
|
548
790
|
end
|
791
|
+
|
549
792
|
end
|
550
793
|
|
551
794
|
context "with :if_unsaved" do
|
552
795
|
|
553
796
|
before do
|
554
|
-
@book = Book.open(@
|
797
|
+
@book = Book.open(@simple_file1)
|
555
798
|
@sheet = @book.sheet(1)
|
556
799
|
@book.add_sheet(@sheet, :as => 'a_name')
|
557
800
|
end
|
@@ -563,13 +806,13 @@ describe Book do
|
|
563
806
|
|
564
807
|
it "should raise an error, if :if_unsaved is :raise" do
|
565
808
|
expect {
|
566
|
-
@new_book = Book.open(@
|
809
|
+
@new_book = Book.open(@simple_file1, :if_unsaved => :raise)
|
567
810
|
}.to raise_error(ExcelErrorOpen, /workbook is already open but not saved: "workbook.xls"/)
|
568
811
|
end
|
569
812
|
|
570
813
|
it "should let the book open, if :if_unsaved is :accept" do
|
571
814
|
expect {
|
572
|
-
@new_book = Book.open(@
|
815
|
+
@new_book = Book.open(@simple_file1, :if_unsaved => :accept)
|
573
816
|
}.to_not raise_error
|
574
817
|
@book.should be_alive
|
575
818
|
@new_book.should be_alive
|
@@ -577,7 +820,7 @@ describe Book do
|
|
577
820
|
end
|
578
821
|
|
579
822
|
it "should open book and close old book, if :if_unsaved is :forget" do
|
580
|
-
@new_book = Book.open(@
|
823
|
+
@new_book = Book.open(@simple_file1, :if_unsaved => :forget)
|
581
824
|
@book.should_not be_alive
|
582
825
|
@new_book.should be_alive
|
583
826
|
@new_book.filename.downcase.should == @simple_file.downcase
|
@@ -595,7 +838,7 @@ describe Book do
|
|
595
838
|
it "should open the new book and close the unsaved book, if user answers 'yes'" do
|
596
839
|
# "Yes" is the default. --> language independent
|
597
840
|
@key_sender.puts "{enter}"
|
598
|
-
@new_book = Book.open(@
|
841
|
+
@new_book = Book.open(@simple_file1, :if_unsaved => :alert)
|
599
842
|
@new_book.should be_alive
|
600
843
|
@new_book.filename.downcase.should == @simple_file.downcase
|
601
844
|
@book.should_not be_alive
|
@@ -609,7 +852,7 @@ describe Book do
|
|
609
852
|
@key_sender.puts "{right}{enter}"
|
610
853
|
@key_sender.puts "{right}{enter}"
|
611
854
|
expect{
|
612
|
-
Book.open(@
|
855
|
+
Book.open(@simple_file1, :if_unsaved => :alert)
|
613
856
|
}.to raise_error(ExcelErrorOpen, "open: user canceled or open error")
|
614
857
|
@book.should be_alive
|
615
858
|
end
|
@@ -627,9 +870,9 @@ describe Book do
|
|
627
870
|
it "should open the new book and close the unsaved book, if user answers 'yes'" do
|
628
871
|
# "Yes" is the default. --> language independent
|
629
872
|
@key_sender.puts "{enter}"
|
630
|
-
@new_book = Book.open(@
|
873
|
+
@new_book = Book.open(@simple_file1, :if_unsaved => :excel)
|
631
874
|
@new_book.should be_alive
|
632
|
-
@new_book.filename.downcase.should == @
|
875
|
+
@new_book.filename.downcase.should == @simple_file1.downcase
|
633
876
|
@book.should_not be_alive
|
634
877
|
end
|
635
878
|
|
@@ -641,14 +884,14 @@ describe Book do
|
|
641
884
|
@key_sender.puts "{right}{enter}"
|
642
885
|
@key_sender.puts "{right}{enter}"
|
643
886
|
expect{
|
644
|
-
Book.open(@
|
887
|
+
Book.open(@simple_file1, :if_unsaved => :excel)
|
645
888
|
}.to raise_error(ExcelErrorOpen, "open: user canceled or open error")
|
646
889
|
@book.should be_alive
|
647
890
|
end
|
648
891
|
end
|
649
892
|
|
650
893
|
it "should open the book in a new excel instance, if :if_unsaved is :new_excel" do
|
651
|
-
@new_book = Book.open(@
|
894
|
+
@new_book = Book.open(@simple_file1, :if_unsaved => :new_excel)
|
652
895
|
@book.should be_alive
|
653
896
|
@new_book.should be_alive
|
654
897
|
@new_book.filename.should == @book.filename
|
@@ -658,13 +901,13 @@ describe Book do
|
|
658
901
|
|
659
902
|
it "should raise an error, if :if_unsaved is default" do
|
660
903
|
expect {
|
661
|
-
@new_book = Book.open(@
|
904
|
+
@new_book = Book.open(@simple_file1, :if_unsaved => :raise)
|
662
905
|
}.to raise_error(ExcelErrorOpen, /workbook is already open but not saved: "workbook.xls"/)
|
663
906
|
end
|
664
907
|
|
665
908
|
it "should raise an error, if :if_unsaved is invalid option" do
|
666
909
|
expect {
|
667
|
-
@new_book = Book.open(@
|
910
|
+
@new_book = Book.open(@simple_file1, :if_unsaved => :invalid_option)
|
668
911
|
}.to raise_error(ExcelErrorOpen, ":if_unsaved: invalid option: :invalid_option")
|
669
912
|
end
|
670
913
|
end
|
@@ -677,7 +920,7 @@ describe Book do
|
|
677
920
|
|
678
921
|
before do
|
679
922
|
if i == 1 then
|
680
|
-
book_before = Book.open(@
|
923
|
+
book_before = Book.open(@simple_file1)
|
681
924
|
book_before.close
|
682
925
|
end
|
683
926
|
@book = Book.open(@simple_file_other_path)
|
@@ -693,22 +936,22 @@ describe Book do
|
|
693
936
|
|
694
937
|
it "should raise an error, if :if_obstructed is :raise" do
|
695
938
|
expect {
|
696
|
-
@new_book = Book.open(@
|
939
|
+
@new_book = Book.open(@simple_file1, :if_obstructed => :raise)
|
697
940
|
}.to raise_error(ExcelErrorOpen, /blocked by a book with the same name in a different path/)
|
698
941
|
end
|
699
942
|
|
700
943
|
it "should close the other book and open the new book, if :if_obstructed is :forget" do
|
701
|
-
@new_book = Book.open(@
|
944
|
+
@new_book = Book.open(@simple_file1, :if_obstructed => :forget)
|
702
945
|
@book.should_not be_alive
|
703
946
|
@new_book.should be_alive
|
704
947
|
@new_book.filename.downcase.should == @simple_file.downcase
|
705
948
|
end
|
706
949
|
|
707
950
|
it "should save the old book, close it, and open the new book, if :if_obstructed is :save" do
|
708
|
-
@new_book = Book.open(@
|
951
|
+
@new_book = Book.open(@simple_file1, :if_obstructed => :save)
|
709
952
|
@book.should_not be_alive
|
710
953
|
@new_book.should be_alive
|
711
|
-
@new_book.filename.downcase.should == @
|
954
|
+
@new_book.filename.downcase.should == @simple_file1.downcase
|
712
955
|
old_book = Book.open(@simple_file_other_path, :if_obstructed => :forget)
|
713
956
|
old_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
|
714
957
|
old_book.close
|
@@ -717,20 +960,20 @@ describe Book do
|
|
717
960
|
it "should raise an error, if the old book is unsaved, and close the old book and open the new book,
|
718
961
|
if :if_obstructed is :close_if_saved" do
|
719
962
|
expect{
|
720
|
-
@new_book = Book.open(@
|
963
|
+
@new_book = Book.open(@simple_file1, :if_obstructed => :close_if_saved)
|
721
964
|
}.to raise_error(ExcelErrorOpen, /workbook with the same name in a different path is unsaved/)
|
722
965
|
@book.save
|
723
|
-
@new_book = Book.open(@
|
966
|
+
@new_book = Book.open(@simple_file1, :if_obstructed => :close_if_saved)
|
724
967
|
@book.should_not be_alive
|
725
968
|
@new_book.should be_alive
|
726
|
-
@new_book.filename.downcase.should == @
|
969
|
+
@new_book.filename.downcase.should == @simple_file1.downcase
|
727
970
|
old_book = Book.open(@simple_file_other_path, :if_obstructed => :forget)
|
728
971
|
old_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
|
729
972
|
old_book.close
|
730
973
|
end
|
731
974
|
|
732
975
|
it "should open the book in a new excel instance, if :if_obstructed is :new_excel" do
|
733
|
-
@new_book = Book.open(@
|
976
|
+
@new_book = Book.open(@simple_file1, :if_obstructed => :new_excel)
|
734
977
|
@book.should be_alive
|
735
978
|
@new_book.should be_alive
|
736
979
|
@new_book.filename.should_not == @book.filename
|
@@ -739,13 +982,13 @@ describe Book do
|
|
739
982
|
|
740
983
|
it "should raise an error, if :if_obstructed is default" do
|
741
984
|
expect {
|
742
|
-
@new_book = Book.open(@
|
985
|
+
@new_book = Book.open(@simple_file1)
|
743
986
|
}.to raise_error(ExcelErrorOpen, /blocked by a book with the same name in a different path/)
|
744
987
|
end
|
745
988
|
|
746
989
|
it "should raise an error, if :if_obstructed is invalid option" do
|
747
990
|
expect {
|
748
|
-
@new_book = Book.open(@
|
991
|
+
@new_book = Book.open(@simple_file1, :if_obstructed => :invalid_option)
|
749
992
|
}.to raise_error(ExcelErrorOpen, ":if_obstructed: invalid option: :invalid_option")
|
750
993
|
end
|
751
994
|
end
|
@@ -765,8 +1008,8 @@ describe Book do
|
|
765
1008
|
possible_options.each do |options_value|
|
766
1009
|
context "with :if_unsaved => #{options_value} and in the same and different path" do
|
767
1010
|
before do
|
768
|
-
@new_book = Book.open(@
|
769
|
-
@different_book = Book.new(@different_file, :reuse=> true, :if_unsaved => options_value)
|
1011
|
+
@new_book = Book.open(@simple_file1, :reuse => true, :if_unsaved => options_value)
|
1012
|
+
@different_book = Book.new(@different_file, :reuse => true, :if_unsaved => options_value)
|
770
1013
|
end
|
771
1014
|
after do
|
772
1015
|
@new_book.close
|
@@ -786,7 +1029,13 @@ describe Book do
|
|
786
1029
|
|
787
1030
|
context "with non-existing file" do
|
788
1031
|
|
789
|
-
it "should raise
|
1032
|
+
it "should raise error if filename is nil" do
|
1033
|
+
expect{
|
1034
|
+
Book.open(@nonexisting)
|
1035
|
+
}.to raise_error(ExcelErrorOpen, "filename is nil")
|
1036
|
+
end
|
1037
|
+
|
1038
|
+
it "should raise error if file does not exist" do
|
790
1039
|
File.delete @simple_save_file rescue nil
|
791
1040
|
expect {
|
792
1041
|
Book.open(@simple_save_file, :if_absent => :raise)
|
@@ -825,17 +1074,49 @@ describe Book do
|
|
825
1074
|
end
|
826
1075
|
end
|
827
1076
|
|
1077
|
+
context "with :update_links" do
|
1078
|
+
|
1079
|
+
it "should set update_links to :alert" do
|
1080
|
+
book = Book.open(@simple_file, :update_links => :alert)
|
1081
|
+
book.UpdateLinks.should == XlUpdateLinksUserSetting
|
1082
|
+
#book.UpdateRemoteReferences.should be_true
|
1083
|
+
book.Saved.should be_true
|
1084
|
+
end
|
1085
|
+
|
1086
|
+
it "should set update_links to :never" do
|
1087
|
+
book = Book.open(@simple_file, :update_links => :never)
|
1088
|
+
book.UpdateLinks.should == XlUpdateLinksNever
|
1089
|
+
#book.UpdateRemoteReferences.should be_false
|
1090
|
+
book = Book.open(@simple_file, :update_links => :foo)
|
1091
|
+
book.UpdateLinks.should == XlUpdateLinksNever
|
1092
|
+
#book.UpdateRemoteReferences.should be_false
|
1093
|
+
end
|
1094
|
+
|
1095
|
+
it "should set update_links to :always" do
|
1096
|
+
book = Book.open(@simple_file, :update_links => :always)
|
1097
|
+
book.UpdateLinks.should == XlUpdateLinksAlways
|
1098
|
+
#book.UpdateRemoteReferences.should be_true
|
1099
|
+
end
|
1100
|
+
|
1101
|
+
it "should set update_links to :never per default" do
|
1102
|
+
book = Book.open(@simple_file)
|
1103
|
+
book.UpdateLinks.should == XlUpdateLinksNever
|
1104
|
+
#book.UpdateRemoteReferences.should be_false
|
1105
|
+
end
|
1106
|
+
|
1107
|
+
end
|
1108
|
+
|
828
1109
|
context "with :read_only" do
|
829
1110
|
|
830
1111
|
it "should reopen the book with writable (unsaved changes from readonly will not be saved)" do
|
831
|
-
book = Book.open(@
|
1112
|
+
book = Book.open(@simple_file1, :read_only => true)
|
832
1113
|
book.ReadOnly.should be_true
|
833
1114
|
book.should be_alive
|
834
1115
|
sheet = book.sheet(1)
|
835
1116
|
old_cell_value = sheet[1,1].value
|
836
1117
|
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
837
1118
|
book.Saved.should be_false
|
838
|
-
new_book = Book.open(@
|
1119
|
+
new_book = Book.open(@simple_file1, :read_only => false, :if_unsaved => :accept)
|
839
1120
|
new_book.ReadOnly.should be_false
|
840
1121
|
new_book.should be_alive
|
841
1122
|
book.should be_alive
|
@@ -846,28 +1127,28 @@ describe Book do
|
|
846
1127
|
end
|
847
1128
|
|
848
1129
|
it "should not raise an error when trying to reopen the book as read_only while the writable book had unsaved changes" do
|
849
|
-
book = Book.open(@
|
1130
|
+
book = Book.open(@simple_file1, :read_only => false)
|
850
1131
|
book.ReadOnly.should be_false
|
851
1132
|
book.should be_alive
|
852
1133
|
sheet = book.sheet(1)
|
853
1134
|
old_cell_value = sheet[1,1].value
|
854
1135
|
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
855
1136
|
book.Saved.should be_false
|
856
|
-
new_book = Book.open(@
|
1137
|
+
new_book = Book.open(@simple_file1, :read_only => true, :if_unsaved => :accept)
|
857
1138
|
new_book.ReadOnly.should be_false
|
858
1139
|
new_book.Saved.should be_false
|
859
1140
|
new_book.should == book
|
860
1141
|
end
|
861
1142
|
|
862
1143
|
it "should reopen the book with writable in the same Excel instance (unsaved changes from readonly will not be saved)" do
|
863
|
-
book = Book.open(@
|
1144
|
+
book = Book.open(@simple_file1, :read_only => true)
|
864
1145
|
book.ReadOnly.should be_true
|
865
1146
|
book.should be_alive
|
866
1147
|
sheet = book.sheet(1)
|
867
1148
|
old_cell_value = sheet[1,1].value
|
868
1149
|
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
869
1150
|
book.Saved.should be_false
|
870
|
-
new_book = Book.open(@
|
1151
|
+
new_book = Book.open(@simple_file1, :if_unsaved => :accept, :force_excel => book.excel, :read_only => false)
|
871
1152
|
new_book.ReadOnly.should be_false
|
872
1153
|
new_book.should be_alive
|
873
1154
|
book.should be_alive
|
@@ -878,30 +1159,30 @@ describe Book do
|
|
878
1159
|
end
|
879
1160
|
|
880
1161
|
it "should reopen the book with readonly (unsaved changes of the writable should be saved)" do
|
881
|
-
book = Book.open(@
|
1162
|
+
book = Book.open(@simple_file1, :force_excel => :new, :read_only => false)
|
882
1163
|
book.ReadOnly.should be_false
|
883
1164
|
book.should be_alive
|
884
1165
|
sheet = book.sheet(1)
|
885
1166
|
old_cell_value = sheet[1,1].value
|
886
1167
|
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
887
1168
|
book.Saved.should be_false
|
888
|
-
new_book = Book.open(@
|
1169
|
+
new_book = Book.open(@simple_file1, :force_excel => book.excel, :read_only => true, :if_unsaved => :accept)
|
889
1170
|
new_book.ReadOnly.should be_false
|
890
1171
|
new_book.Saved.should be_false
|
891
1172
|
new_book.should == book
|
892
1173
|
end
|
893
1174
|
|
894
1175
|
it "should open the second book in another Excel as writable" do
|
895
|
-
book = Book.open(@
|
1176
|
+
book = Book.open(@simple_file1, :read_only => true)
|
896
1177
|
book.ReadOnly.should be_true
|
897
|
-
new_book = Book.open(@
|
1178
|
+
new_book = Book.open(@simple_file1, :force_excel => :new, :read_only => false)
|
898
1179
|
new_book.ReadOnly.should be_false
|
899
1180
|
new_book.close
|
900
1181
|
book.close
|
901
1182
|
end
|
902
1183
|
|
903
1184
|
it "should be able to save, if :read_only => false" do
|
904
|
-
book = Book.open(@
|
1185
|
+
book = Book.open(@simple_file1, :read_only => false)
|
905
1186
|
book.should be_a Book
|
906
1187
|
expect {
|
907
1188
|
book.save_as(@simple_save_file, :if_exists => :overwrite)
|
@@ -910,7 +1191,7 @@ describe Book do
|
|
910
1191
|
end
|
911
1192
|
|
912
1193
|
it "should be able to save, if :read_only is default" do
|
913
|
-
book = Book.open(@
|
1194
|
+
book = Book.open(@simple_file1)
|
914
1195
|
book.should be_a Book
|
915
1196
|
expect {
|
916
1197
|
book.save_as(@simple_save_file, :if_exists => :overwrite)
|