robust_excel_ole 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +1 -0
  2. data/Changelog +15 -0
  3. data/README.rdoc +128 -63
  4. data/README_detail.rdoc +130 -60
  5. data/examples/edit_sheets/example_access_sheets_and_cells.rb +1 -1
  6. data/examples/edit_sheets/example_adding_sheets.rb +2 -2
  7. data/examples/edit_sheets/example_copying.rb +1 -1
  8. data/examples/edit_sheets/example_expanding.rb +1 -1
  9. data/examples/edit_sheets/example_ranges.rb +1 -1
  10. data/examples/edit_sheets/example_saving.rb +2 -2
  11. data/examples/open_save_close/example_control_to_excel.rb +1 -1
  12. data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +2 -2
  13. data/examples/open_save_close/example_if_obstructed_save.rb +2 -2
  14. data/examples/open_save_close/example_if_unsaved_accept.rb +1 -1
  15. data/examples/open_save_close/example_if_unsaved_forget.rb +2 -2
  16. data/examples/open_save_close/example_if_unsaved_forget_more.rb +3 -3
  17. data/examples/open_save_close/example_read_only.rb +1 -1
  18. data/examples/open_save_close/example_rename_cells.rb +1 -1
  19. data/examples/open_save_close/example_simple.rb +1 -1
  20. data/examples/open_save_close/example_unobtrusively.rb +3 -3
  21. data/lib/robust_excel_ole.rb +1 -0
  22. data/lib/robust_excel_ole/book.rb +249 -193
  23. data/lib/robust_excel_ole/bookstore.rb +1 -1
  24. data/lib/robust_excel_ole/cell.rb +1 -1
  25. data/lib/robust_excel_ole/excel.rb +125 -4
  26. data/lib/robust_excel_ole/general.rb +1 -92
  27. data/lib/robust_excel_ole/range.rb +1 -1
  28. data/lib/robust_excel_ole/reo_common.rb +37 -0
  29. data/lib/robust_excel_ole/sheet.rb +77 -24
  30. data/lib/robust_excel_ole/version.rb +1 -1
  31. data/spec/book_spec.rb +112 -82
  32. data/spec/book_specs/book_close_spec.rb +44 -1
  33. data/spec/book_specs/book_misc_spec.rb +97 -92
  34. data/spec/book_specs/book_open_spec.rb +40 -8
  35. data/spec/book_specs/book_save_spec.rb +77 -7
  36. data/spec/book_specs/book_sheet_spec.rb +290 -66
  37. data/spec/book_specs/book_unobtr_spec.rb +99 -73
  38. data/spec/bookstore_spec.rb +1 -1
  39. data/spec/cell_spec.rb +2 -2
  40. data/spec/data/another_workbook.xls +0 -0
  41. data/spec/data/workbook.xls +0 -0
  42. data/spec/excel_spec.rb +174 -23
  43. data/spec/general_spec.rb +3 -18
  44. data/spec/range_spec.rb +3 -3
  45. data/spec/reo_common_spec.rb +104 -0
  46. data/spec/sheet_spec.rb +101 -60
  47. metadata +6 -4
@@ -34,92 +34,151 @@ describe Book do
34
34
  rm_tmp(@dir)
35
35
  end
36
36
 
37
- describe "#add_sheet" do
37
+ describe 'access sheet' do
38
38
  before do
39
39
  @book = Book.open(@simple_file)
40
- @sheet = @book[0]
41
40
  end
42
41
 
43
42
  after do
44
- @book.close(:if_unsaved => :forget)
43
+ @book.close
45
44
  end
46
45
 
47
- context "only first argument" do
48
- it "should add worksheet" do
49
- @book.ole_workbook.Worksheets.Count == 3
50
- @book.add_sheet @sheet
51
- @book.ole_workbook.Worksheets.Count == 4
52
- end
46
+ it 'with sheet name' do
47
+ @book.sheet("Sheet1").should be_kind_of Sheet
48
+ @book.sheet("Sheet1").name.should == "Sheet1"
49
+ end
53
50
 
54
- it "should return copyed sheet" do
55
- sheet = @book.add_sheet @sheet
56
- copyed_sheet = @book.ole_workbook.Worksheets.Item(@book.ole_workbook.Worksheets.Count)
57
- sheet.name.should eq copyed_sheet.name
58
- end
51
+ it 'with integer' do
52
+ @book.sheet(1).should be_kind_of Sheet
53
+ @book.sheet(1).name.should == "Sheet1"
59
54
  end
60
55
 
61
- context "with first argument" do
62
- context "with second argument is {:as => 'copyed_name'}" do
63
- it "copyed sheet name should be 'copyed_name'" do
64
- @book.add_sheet(@sheet, :as => 'copyed_name').name.should eq 'copyed_name'
65
- end
56
+ it 'with block' do
57
+ @book.each do |sheet|
58
+ sheet.should be_kind_of Sheet
66
59
  end
60
+ end
67
61
 
68
- context "with second argument is {:before => @sheet}" do
69
- it "should add the first sheet" do
70
- @book.add_sheet(@sheet, :before => @sheet).name.should eq @book[0].name
62
+ context 'open with block' do
63
+ it {
64
+ Book.open(@simple_file) do |book|
65
+ @book.sheet("Sheet1").should be_a Sheet
66
+ @book.sheet("Sheet1").name.should == "Sheet1"
71
67
  end
68
+ }
69
+ end
70
+ end
71
+
72
+ describe 'access first and last sheet' do
73
+ before do
74
+ @book = Book.open(@simple_file)
75
+ end
76
+
77
+ it "should access the first sheet" do
78
+ first_sheet = @book.first_sheet
79
+ first_sheet.name.should == Sheet.new(@book.Worksheets.Item(1)).Name
80
+ first_sheet.name.should == @book.sheet(1).Name
81
+ end
82
+
83
+ it "should access the last sheet" do
84
+ last_sheet = @book.last_sheet
85
+ last_sheet.name.should == Sheet.new(@book.Worksheets.Item(3)).Name
86
+ last_sheet.name.should == @book.sheet(3).Name
87
+ end
88
+ end
89
+
90
+ describe "add_sheet" do
91
+
92
+ context "with no given sheet" do
93
+
94
+ before do
95
+ @book = Book.open(@simple_file)
96
+ @sheet = @book.sheet(1)
72
97
  end
73
98
 
74
- context "with second argument is {:after => @sheet}" do
75
- it "should add the first sheet" do
76
- @book.add_sheet(@sheet, :after => @sheet).name.should eq @book[1].name
77
- end
99
+ after do
100
+ @book.close(:if_unsaved => :forget)
78
101
  end
79
102
 
80
- context "with second argument is {:before => @book[2], :after => @sheet}" do
81
- it "should arguments in the first is given priority" do
82
- @book.add_sheet(@sheet, :before => @book[2], :after => @sheet).name.should eq @book[2].name
83
- end
103
+ it "should add empty sheet" do
104
+ @book.ole_workbook.Worksheets.Count.should == 3
105
+ @book.add_sheet
106
+ @book.ole_workbook.Worksheets.Count.should == 4
84
107
  end
85
108
 
86
- end
109
+ it "should add an empty sheet and return this added sheet" do
110
+ sheet = @book.add_sheet
111
+ copyed_sheet = @book.ole_workbook.Worksheets.Item(@book.ole_workbook.Worksheets.Count)
112
+ sheet.name.should eq copyed_sheet.name
113
+ end
87
114
 
88
- context "without first argument" do
89
- context "second argument is {:as => 'new sheet'}" do
90
- it "should return new sheet" do
91
- @book.add_sheet(:as => 'new sheet').name.should eq 'new sheet'
92
- end
115
+ it "should return new sheet" do
116
+ @book.add_sheet(:as => 'new sheet').name.should eq 'new sheet'
93
117
  end
94
118
 
95
- context "second argument is {:before => @sheet}" do
96
- it "should add the first sheet" do
97
- @book.add_sheet(:before => @sheet).name.should eq @book[0].name
98
- end
119
+ it "should add the first sheet" do
120
+ @book.add_sheet(:before => @sheet).name.should eq @book.sheet(1).name
99
121
  end
100
122
 
101
- context "second argument is {:after => @sheet}" do
102
- it "should add the second sheet" do
103
- @book.add_sheet(:after => @sheet).name.should eq @book[1].name
104
- end
123
+ it "should add the second sheet" do
124
+ @book.add_sheet(:after => @sheet).name.should eq @book.sheet(2).name
105
125
  end
126
+
106
127
  end
107
128
 
108
- context "without argument" do
109
- it "should add empty sheet" do
129
+ context "with copying a given sheet" do
130
+
131
+ before do
132
+ @book = Book.open(@simple_file)
133
+ @sheet = @book.sheet(1)
134
+ @another_book = Book.open(@another_simple_file)
135
+ end
136
+
137
+ after do
138
+ @book.close(:if_unsaved => :forget)
139
+ @another_book.close(:if_unsaved => :forget)
140
+ end
141
+
142
+ it "should copy and append a given sheet" do
110
143
  @book.ole_workbook.Worksheets.Count.should == 3
111
- @book.add_sheet
144
+ @book.add_sheet @sheet
112
145
  @book.ole_workbook.Worksheets.Count.should == 4
146
+ @book.ole_workbook.Worksheets(4).Name.should == @sheet.Name + " (2)"
147
+ end
148
+
149
+ it "should copy sheet from another book " do
150
+ @book.ole_workbook.Worksheets.Count.should == 3
151
+ @another_book.add_sheet @sheet
152
+ @another_book.ole_workbook.Worksheets.Count.should == 4
153
+ @another_book.ole_workbook.Worksheets(4).Name.should == @sheet.Name + " (2)"
113
154
  end
114
155
 
115
156
  it "should return copyed sheet" do
116
- sheet = @book.add_sheet
157
+ sheet = @book.add_sheet @sheet
117
158
  copyed_sheet = @book.ole_workbook.Worksheets.Item(@book.ole_workbook.Worksheets.Count)
118
159
  sheet.name.should eq copyed_sheet.name
119
160
  end
120
- end
121
161
 
122
- context "should raise error if the sheet name already exists" do
162
+ it "should copy a given sheet and name the copyed sheet to 'copyed_name'" do
163
+ @book.add_sheet(@sheet, :as => 'copyed_name').name.should eq 'copyed_name'
164
+ end
165
+
166
+ it "should copy the first sheet and insert it before the first sheet" do
167
+ @book.add_sheet(@sheet, :before => @sheet).name.should eq @book.sheet(1).name
168
+ end
169
+
170
+ it "should copy the first sheet and insert it after the first sheet" do
171
+ @book.add_sheet(@sheet, :after => @sheet).name.should eq @book.sheet(2).name
172
+ end
173
+
174
+ it "should copy the first sheet before the third sheet and give 'before' the highest priority" do
175
+ @book.add_sheet(@sheet, :after => @sheet, :before => @book.sheet(3)).name.should eq @book.sheet(3).name
176
+ end
177
+
178
+ it "should copy the first sheet before the third sheet and give 'before' the highest priority" do
179
+ @book.add_sheet(@sheet, :before => @book.sheet(3), :after => @sheet).name.should eq @book.sheet(3).name
180
+ end
181
+
123
182
  it "should raise error with giving a name that already exists" do
124
183
  @book.add_sheet(@sheet, :as => 'new_sheet')
125
184
  expect{
@@ -129,37 +188,202 @@ describe Book do
129
188
  end
130
189
  end
131
190
 
132
- describe 'access sheet' do
191
+ describe "add_empty_sheet" do
192
+
133
193
  before do
134
194
  @book = Book.open(@simple_file)
195
+ @sheet = @book.sheet(1)
135
196
  end
136
197
 
137
198
  after do
138
- @book.close
199
+ @book.close(:if_unsaved => :forget)
139
200
  end
140
201
 
141
- it 'with sheet name' do
142
- @book['Sheet1'].should be_kind_of Sheet
202
+ it "should add empty sheet" do
203
+ @book.ole_workbook.Worksheets.Count.should == 3
204
+ @book.add_empty_sheet
205
+ @book.ole_workbook.Worksheets.Count.should == 4
143
206
  end
144
207
 
145
- it 'with integer' do
146
- @book[0].should be_kind_of Sheet
208
+ it "should add an empty sheet and return this added sheet" do
209
+ sheet = @book.add_empty_sheet
210
+ copyed_sheet = @book.ole_workbook.Worksheets.Item(@book.ole_workbook.Worksheets.Count)
211
+ sheet.name.should eq copyed_sheet.name
147
212
  end
148
213
 
149
- it 'with block' do
150
- @book.each do |sheet|
151
- sheet.should be_kind_of Sheet
214
+ it "should return new sheet" do
215
+ @book.add_empty_sheet(:as => 'new sheet').name.should eq 'new sheet'
216
+ end
217
+
218
+ it "should add the first sheet" do
219
+ @book.add_empty_sheet(:before => @sheet).name.should eq @book.sheet(1).name
220
+ end
221
+
222
+ it "should add the second sheet" do
223
+ @book.add_empty_sheet(:after => @sheet).name.should eq @book.sheet(2).name
224
+ end
225
+ end
226
+
227
+ describe "copy_sheet" do
228
+
229
+ before do
230
+ @book = Book.open(@simple_file)
231
+ @sheet = @book.sheet(1)
232
+ @another_book = Book.open(@another_simple_file)
233
+ end
234
+
235
+ after do
236
+ @book.close(:if_unsaved => :forget)
237
+ @another_book.close(:if_unsaved => :forget)
238
+ end
239
+
240
+ it "should copy and append a given sheet" do
241
+ @book.ole_workbook.Worksheets.Count.should == 3
242
+ @book.copy_sheet @sheet
243
+ @book.ole_workbook.Worksheets.Count.should == 4
244
+ @book.ole_workbook.Worksheets(4).Name.should == @sheet.Name + " (2)"
245
+ end
246
+
247
+ it "should copy sheet from another book " do
248
+ @book.ole_workbook.Worksheets.Count.should == 3
249
+ @another_book.copy_sheet @sheet
250
+ @another_book.ole_workbook.Worksheets.Count.should == 4
251
+ @another_book.ole_workbook.Worksheets(4).Name.should == @sheet.Name + " (2)"
252
+ end
253
+
254
+ it "should return copyed sheet" do
255
+ sheet = @book.add_sheet @sheet
256
+ copyed_sheet = @book.ole_workbook.Worksheets.Item(@book.ole_workbook.Worksheets.Count)
257
+ sheet.name.should eq copyed_sheet.name
258
+ end
259
+
260
+ it "should copy a given sheet and name the copyed sheet to 'copyed_name'" do
261
+ @book.copy_sheet(@sheet, :as => 'copyed_name').name.should eq 'copyed_name'
262
+ end
263
+
264
+ it "should copy the first sheet and insert it before the first sheet" do
265
+ @book.copy_sheet(@sheet, :before => @sheet).name.should eq @book.sheet(1).name
266
+ end
267
+
268
+ it "should copy the first sheet and insert it after the first sheet" do
269
+ @book.copy_sheet(@sheet, :after => @sheet).name.should eq @book.sheet(2).name
270
+ end
271
+
272
+ it "should copy the first sheet before the third sheet and give 'before' the highest priority" do
273
+ @book.copy_sheet(@sheet, :after => @sheet, :before => @book.sheet(3)).name.should eq @book.sheet(3).name
274
+ end
275
+
276
+ it "should copy the first sheet before the third sheet and give 'before' the highest priority" do
277
+ @book.copy_sheet(@sheet, :before => @book.sheet(3), :after => @sheet).name.should eq @book.sheet(3).name
278
+ end
279
+
280
+ it "should raise error with giving a name that already exists" do
281
+ @book.copy_sheet(@sheet, :as => 'new_sheet')
282
+ expect{
283
+ @book.copy_sheet(@sheet, :as => 'new_sheet')
284
+ }.to raise_error(ExcelErrorSheet, /sheet name "new_sheet" already exists/)
285
+ end
286
+ end
287
+
288
+ describe "add_or_copy_sheet" do
289
+
290
+ context "with no given sheet" do
291
+
292
+ before do
293
+ @book = Book.open(@simple_file)
294
+ @sheet = @book.sheet(1)
295
+ end
296
+
297
+ after do
298
+ @book.close(:if_unsaved => :forget)
299
+ end
300
+
301
+ it "should add empty sheet" do
302
+ @book.ole_workbook.Worksheets.Count.should == 3
303
+ @book.add_or_copy_sheet
304
+ @book.ole_workbook.Worksheets.Count.should == 4
305
+ end
306
+
307
+ it "should add an empty sheet and return this added sheet" do
308
+ sheet = @book.add_or_copy_sheet
309
+ copyed_sheet = @book.ole_workbook.Worksheets.Item(@book.ole_workbook.Worksheets.Count)
310
+ sheet.name.should eq copyed_sheet.name
152
311
  end
312
+
313
+ it "should return new sheet" do
314
+ @book.add_or_copy_sheet(:as => 'new sheet').name.should eq 'new sheet'
315
+ end
316
+
317
+ it "should add the first sheet" do
318
+ @book.add_or_copy_sheet(:before => @sheet).name.should eq @book.sheet(1).name
319
+ end
320
+
321
+ it "should add the second sheet" do
322
+ @book.add_or_copy_sheet(:after => @sheet).name.should eq @book.sheet(2).name
323
+ end
324
+
153
325
  end
154
326
 
155
- context 'open with block' do
156
- it {
157
- Book.open(@simple_file) do |book|
158
- book['Sheet1'].should be_a Sheet
159
- end
160
- }
327
+ context "with copying a given sheet" do
328
+
329
+ before do
330
+ @book = Book.open(@simple_file)
331
+ @sheet = @book.sheet(1)
332
+ @another_book = Book.open(@another_simple_file)
333
+ end
334
+
335
+ after do
336
+ @book.close(:if_unsaved => :forget)
337
+ @another_book.close(:if_unsaved => :forget)
338
+ end
339
+
340
+ it "should copy and append a given sheet" do
341
+ @book.ole_workbook.Worksheets.Count.should == 3
342
+ @book.add_or_copy_sheet @sheet
343
+ @book.ole_workbook.Worksheets.Count.should == 4
344
+ @book.ole_workbook.Worksheets(4).Name.should == @sheet.Name + " (2)"
345
+ end
346
+
347
+ it "should copy sheet from another book " do
348
+ @book.ole_workbook.Worksheets.Count.should == 3
349
+ @another_book.add_or_copy_sheet @sheet
350
+ @another_book.ole_workbook.Worksheets.Count.should == 4
351
+ @another_book.ole_workbook.Worksheets(4).Name.should == @sheet.Name + " (2)"
352
+ end
353
+
354
+ it "should return copyed sheet" do
355
+ sheet = @book.add_or_copy_sheet @sheet
356
+ copyed_sheet = @book.ole_workbook.Worksheets.Item(@book.ole_workbook.Worksheets.Count)
357
+ sheet.name.should eq copyed_sheet.name
358
+ end
359
+
360
+ it "should copy a given sheet and name the copyed sheet to 'copyed_name'" do
361
+ @book.add_or_copy_sheet(@sheet, :as => 'copyed_name').name.should eq 'copyed_name'
362
+ end
363
+
364
+ it "should copy the first sheet and insert it before the first sheet" do
365
+ @book.add_or_copy_sheet(@sheet, :before => @sheet).name.should eq @book.sheet(1).name
366
+ end
367
+
368
+ it "should copy the first sheet and insert it after the first sheet" do
369
+ @book.add_or_copy_sheet(@sheet, :after => @sheet).name.should eq @book.sheet(2).name
370
+ end
371
+
372
+ it "should copy the first sheet before the third sheet and give 'before' the highest priority" do
373
+ @book.add_or_copy_sheet(@sheet, :after => @sheet, :before => @book.sheet(3)).name.should eq @book.sheet(3).name
374
+ end
375
+
376
+ it "should copy the first sheet before the third sheet and give 'before' the highest priority" do
377
+ @book.add_or_copy_sheet(@sheet, :before => @book.sheet(3), :after => @sheet).name.should eq @book.sheet(3).name
378
+ end
379
+
380
+ it "should raise error with giving a name that already exists" do
381
+ @book.add_or_copy_sheet(@sheet, :as => 'new_sheet')
382
+ expect{
383
+ @book.add_or_copy_sheet(@sheet, :as => 'new_sheet')
384
+ }.to raise_error(ExcelErrorSheet, /sheet name "new_sheet" already exists/)
385
+ end
161
386
  end
162
387
  end
163
388
 
164
389
  end
165
-
@@ -40,7 +40,7 @@ describe Book do
40
40
  def unobtrusively_ok? # :nodoc: #
41
41
  Book.unobtrusively(@simple_file) do |book|
42
42
  book.should be_a Book
43
- sheet = book[0]
43
+ sheet = book.sheet(1)
44
44
  sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
45
45
  book.should be_alive
46
46
  book.Saved.should be_false
@@ -121,7 +121,7 @@ describe Book do
121
121
  expect{
122
122
  Book.unobtrusively(@simple_file, :invalid_option) do |book|
123
123
  end
124
- }.to raise_error(ExcelError, "receiver instance is neither an Excel nor a Book")
124
+ }.to raise_error(ExcelErrorOpen, "given object is neither an Excel, a Book, nor a Win32ole")
125
125
  end
126
126
 
127
127
  it "should be visible and displayalerts" do
@@ -206,17 +206,17 @@ describe Book do
206
206
  it "should let a saved book saved" do
207
207
  @book.Saved.should be_true
208
208
  @book.should be_alive
209
- sheet = @book[0]
209
+ sheet = @book.sheet(1)
210
210
  old_cell_value = sheet[1,1].value
211
211
  unobtrusively_ok?
212
212
  @book.Saved.should be_true
213
213
  @book.should be_alive
214
- sheet = @book[0]
214
+ sheet = @book.sheet(1)
215
215
  sheet[1,1].value.should_not == old_cell_value
216
216
  end
217
217
 
218
218
  it "should let the unsaved book unsaved" do
219
- sheet = @book[0]
219
+ sheet = @book.sheet(1)
220
220
  sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
221
221
  old_cell_value = sheet[1,1].value
222
222
  @book.Saved.should be_false
@@ -225,7 +225,7 @@ describe Book do
225
225
  @book.Saved.should be_false
226
226
  @book.close(:if_unsaved => :forget)
227
227
  @book2 = Book.open(@simple_file)
228
- sheet2 = @book2[0]
228
+ sheet2 = @book2.sheet(1)
229
229
  sheet2[1,1].value.should_not == old_cell_value
230
230
  end
231
231
 
@@ -233,7 +233,7 @@ describe Book do
233
233
  @book2 = Book.open(@simple_file, :force_excel => :new)
234
234
  @book.ReadOnly.should be_false
235
235
  @book2.ReadOnly.should be_true
236
- sheet = @book2[0]
236
+ sheet = @book2.sheet(1)
237
237
  old_cell_value = sheet[1,1].value
238
238
  sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
239
239
  unobtrusively_ok?
@@ -242,9 +242,34 @@ describe Book do
242
242
  @book2.close(:if_unsaved => :forget)
243
243
  @book.close
244
244
  @book = Book.open(@simple_file)
245
- sheet2 = @book[0]
245
+ sheet2 = @book.sheet(1)
246
246
  sheet2[1,1].value.should_not == old_cell_value
247
247
  end
248
+
249
+ it "should set checkcompatibilty to true" do
250
+ Book.unobtrusively(@simple_file, :check_compatibility => true) do |book|
251
+ book.should be_a Book
252
+ book.CheckCompatibility.should be_true
253
+ end
254
+ @book.CheckCompatibility.should be_true
255
+ end
256
+
257
+ it "should set the checkcompatibilty to false" do
258
+ Book.unobtrusively(@simple_file, :check_compatibility => false) do |book|
259
+ book.should be_a Book
260
+ book.CheckCompatibility.should be_false
261
+ end
262
+ @book.CheckCompatibility.should be_true
263
+ end
264
+
265
+ it "should set the checkcompatibilty to false" do
266
+ @book.CheckCompatibility = false
267
+ Book.unobtrusively(@simple_file, :check_compatibility => true) do |book|
268
+ book.should be_a Book
269
+ book.CheckCompatibility.should be_true
270
+ end
271
+ @book.CheckCompatibility.should be_false
272
+ end
248
273
  end
249
274
 
250
275
  context "with a closed book" do
@@ -258,21 +283,21 @@ describe Book do
258
283
  end
259
284
 
260
285
  it "should let the closed book closed by default" do
261
- sheet = @book[0]
286
+ sheet = @book.sheet(1)
262
287
  old_cell_value = sheet[1,1].value
263
288
  @book.close
264
289
  @book.should_not be_alive
265
290
  unobtrusively_ok?
266
291
  @book.should_not be_alive
267
292
  @book = Book.open(@simple_file)
268
- sheet = @book[0]
293
+ sheet = @book.sheet(1)
269
294
  sheet[1,1].Value.should_not == old_cell_value
270
295
  end
271
296
 
272
297
  # The bold reanimation of the @book
273
298
  it "should use the excel of the book and keep open the book" do
274
299
  excel = Excel.new(:reuse => false)
275
- sheet = @book[0]
300
+ sheet = @book.sheet(1)
276
301
  old_cell_value = sheet[1,1].value
277
302
  @book.close
278
303
  @book.should_not be_alive
@@ -280,7 +305,7 @@ describe Book do
280
305
  book.should be_a Book
281
306
  book.excel.should == @book.excel
282
307
  book.excel.should_not == excel
283
- sheet = book[0]
308
+ sheet = book.sheet(1)
284
309
  cell = sheet[1,1]
285
310
  sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
286
311
  book.Saved.should be_false
@@ -288,10 +313,10 @@ describe Book do
288
313
  @book.should be_alive
289
314
  @book.close
290
315
  new_book = Book.open(@simple_file)
291
- sheet = new_book[0]
316
+ sheet = new_book.sheet(1)
292
317
  sheet[1,1].value.should_not == old_cell_value
293
318
  end
294
-
319
+ =begin
295
320
  it "should set can_be_closed" do
296
321
  Excel.close_all
297
322
  Book.unobtrusively(@simple_file, :keep_open => true) do |book|
@@ -304,11 +329,12 @@ describe Book do
304
329
  book = Book.open(@simple_file)
305
330
  book.can_be_closed.should be_true
306
331
  end
332
+ =end
307
333
 
308
334
  # book shall be reanimated even with :hidden
309
335
  it "should use the excel of the book and keep open the book" do
310
336
  excel = Excel.new(:reuse => false)
311
- sheet = @book[0]
337
+ sheet = @book.sheet(1)
312
338
  old_cell_value = sheet[1,1].value
313
339
  @book.close
314
340
  @book.should_not be_alive
@@ -317,20 +343,20 @@ describe Book do
317
343
  book.should be_alive
318
344
  book.excel.should_not == @book.excel
319
345
  book.excel.should_not == excel
320
- sheet = book[0]
346
+ sheet = book.sheet(1)
321
347
  cell = sheet[1,1]
322
348
  sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
323
349
  book.Saved.should be_false
324
350
  end
325
351
  @book.should_not be_alive
326
352
  new_book = Book.open(@simple_file)
327
- sheet = new_book[0]
353
+ sheet = new_book.sheet(1)
328
354
  sheet[1,1].value.should_not == old_cell_value
329
355
  end
330
356
 
331
357
  it "should use another excel if the Excels are closed" do
332
358
  excel = Excel.new(:reuse => false)
333
- sheet = @book[0]
359
+ sheet = @book.sheet(1)
334
360
  old_cell_value = sheet[1,1].value
335
361
  @book.close
336
362
  @book.should_not be_alive
@@ -339,7 +365,7 @@ describe Book do
339
365
  book.should be_a Book
340
366
  book.excel.should == @book.excel
341
367
  book.excel.should_not == excel
342
- sheet = book[0]
368
+ sheet = book.sheet(1)
343
369
  cell = sheet[1,1]
344
370
  sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
345
371
  book.Saved.should be_false
@@ -347,13 +373,13 @@ describe Book do
347
373
  @book.should be_alive
348
374
  @book.close
349
375
  new_book = Book.open(@simple_file)
350
- sheet = new_book[0]
376
+ sheet = new_book.sheet(1)
351
377
  sheet[1,1].value.should_not == old_cell_value
352
378
  end
353
379
 
354
380
  it "should use another excel if the Excels are closed" do
355
381
  excel = Excel.new(:reuse => false)
356
- sheet = @book[0]
382
+ sheet = @book.sheet(1)
357
383
  old_cell_value = sheet[1,1].value
358
384
  @book.close
359
385
  @book.should_not be_alive
@@ -362,34 +388,34 @@ describe Book do
362
388
  book.should be_a Book
363
389
  book.excel.should_not == @book.excel
364
390
  book.excel.should_not == excel
365
- sheet = book[0]
391
+ sheet = book.sheet(1)
366
392
  cell = sheet[1,1]
367
393
  sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
368
394
  book.Saved.should be_false
369
395
  end
370
396
  @book.should_not be_alive
371
397
  new_book = Book.open(@simple_file)
372
- sheet = new_book[0]
398
+ sheet = new_book.sheet(1)
373
399
  sheet[1,1].value.should_not == old_cell_value
374
400
  end
375
401
 
376
402
  it "should modify unobtrusively the copied file" do
377
- sheet = @book[0]
403
+ sheet = @book.sheet(1)
378
404
  old_cell_value = sheet[1,1].value
379
405
  File.delete simple_save_file rescue nil
380
406
  @book.save_as(@simple_save_file)
381
407
  @book.close
382
408
  Book.unobtrusively(@simple_save_file) do |book|
383
- sheet = book[0]
409
+ sheet = book.sheet(1)
384
410
  cell = sheet[1,1]
385
411
  sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
386
412
  end
387
413
  old_book = Book.open(@simple_file)
388
- old_sheet = old_book[0]
414
+ old_sheet = old_book.sheet(1)
389
415
  old_sheet[1,1].Value.should == old_cell_value
390
416
  old_book.close
391
417
  new_book = Book.open(@simple_save_file)
392
- new_sheet = new_book[0]
418
+ new_sheet = new_book.sheet(1)
393
419
  new_sheet[1,1].Value.should_not == old_cell_value
394
420
  new_book.close
395
421
  end
@@ -486,7 +512,7 @@ describe Book do
486
512
  it "should let the saved book saved" do
487
513
  @book.ReadOnly.should be_true
488
514
  @book.Saved.should be_true
489
- sheet = @book[0]
515
+ sheet = @book.sheet(1)
490
516
  old_cell_value = sheet[1,1].value
491
517
  unobtrusively_ok?
492
518
  @book.should be_alive
@@ -494,19 +520,19 @@ describe Book do
494
520
  @book.ReadOnly.should be_true
495
521
  @book.close
496
522
  book2 = Book.open(@simple_file)
497
- sheet2 = book2[0]
523
+ sheet2 = book2.sheet(1)
498
524
  sheet2[1,1].value.should_not == old_cell_value
499
525
  end
500
526
 
501
527
  it "should let the unsaved book unsaved" do
502
528
  @book.ReadOnly.should be_true
503
- sheet = @book[0]
529
+ sheet = @book.sheet(1)
504
530
  sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
505
531
  @book.Saved.should be_false
506
532
  @book.should be_alive
507
533
  Book.unobtrusively(@simple_file) do |book|
508
534
  book.should be_a Book
509
- sheet = book[0]
535
+ sheet = book.sheet(1)
510
536
  sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
511
537
  @cell_value = sheet[1,1].Value
512
538
  book.should be_alive
@@ -517,7 +543,7 @@ describe Book do
517
543
  @book.ReadOnly.should be_true
518
544
  @book.close
519
545
  book2 = Book.open(@simple_file)
520
- sheet2 = book2[0]
546
+ sheet2 = book2.sheet(1)
521
547
  # modifies unobtrusively the saved version, not the unsaved version
522
548
  sheet2[1,1].value.should == @cell_value
523
549
  end
@@ -526,13 +552,13 @@ describe Book do
526
552
  book2 = Book.open(@simple_file, :force_excel => :new, :read_only => false)
527
553
  @book.ReadOnly.should be_true
528
554
  book2.Readonly.should be_false
529
- sheet = @book[0]
555
+ sheet = @book.sheet(1)
530
556
  cell_value = sheet[1,1].value
531
557
  Book.unobtrusively(@simple_file, :hidden) do |book|
532
558
  book.should be_a Book
533
559
  book.excel.should == book2.excel
534
560
  book.excel.should_not == @book.excel
535
- sheet = book[0]
561
+ sheet = book.sheet(1)
536
562
  sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
537
563
  book.should be_alive
538
564
  book.Saved.should be_false
@@ -542,7 +568,7 @@ describe Book do
542
568
  @book.close
543
569
  book2.close
544
570
  book3 = Book.open(@simple_file)
545
- new_sheet = book3[0]
571
+ new_sheet = book3.sheet(1)
546
572
  new_sheet[1,1].value.should_not == cell_value
547
573
  book3.close
548
574
  end
@@ -551,13 +577,13 @@ describe Book do
551
577
  book2 = Book.open(@simple_file, :force_excel => :new, :read_only => true)
552
578
  @book.ReadOnly.should be_true
553
579
  book2.Readonly.should be_true
554
- sheet = @book[0]
580
+ sheet = @book.sheet(1)
555
581
  cell_value = sheet[1,1].value
556
582
  Book.unobtrusively(@simple_file, :hidden) do |book|
557
583
  book.should be_a Book
558
584
  book.excel.should_not == book2.excel
559
585
  book.excel.should_not == @book.excel
560
- sheet = book[0]
586
+ sheet = book.sheet(1)
561
587
  sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
562
588
  book.should be_alive
563
589
  book.Saved.should be_false
@@ -567,7 +593,7 @@ describe Book do
567
593
  @book.close
568
594
  book2.close
569
595
  book3 = Book.open(@simple_file)
570
- new_sheet = book3[0]
596
+ new_sheet = book3.sheet(1)
571
597
  new_sheet[1,1].value.should_not == cell_value
572
598
  book3.close
573
599
  end
@@ -576,13 +602,13 @@ describe Book do
576
602
  book2 = Book.open(@simple_file, :force_excel => :new, :read_only => true)
577
603
  @book.ReadOnly.should be_true
578
604
  book2.Readonly.should be_true
579
- sheet = @book[0]
605
+ sheet = @book.sheet(1)
580
606
  cell_value = sheet[1,1].value
581
607
  Book.unobtrusively(@simple_file, :hidden) do |book|
582
608
  book.should be_a Book
583
609
  book.excel.should_not == book2.excel
584
610
  book.excel.should_not == @book.excel
585
- sheet = book[0]
611
+ sheet = book.sheet(1)
586
612
  sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
587
613
  book.should be_alive
588
614
  book.Saved.should be_false
@@ -592,7 +618,7 @@ describe Book do
592
618
  @book.close
593
619
  book2.close
594
620
  book3 = Book.open(@simple_file)
595
- new_sheet = book3[0]
621
+ new_sheet = book3.sheet(1)
596
622
  new_sheet[1,1].value.should_not == cell_value
597
623
  book3.close
598
624
  end
@@ -603,7 +629,7 @@ describe Book do
603
629
  book2 = Book.open(@simple_file, :force_excel => :new, :read_only => true)
604
630
  @book.ReadOnly.should be_true
605
631
  book2.Readonly.should be_true
606
- sheet = @book[0]
632
+ sheet = @book.sheet(1)
607
633
  cell_value = sheet[1,1].value
608
634
  Book.unobtrusively(@simple_file, :hidden, :readonly_excel => false) do |book|
609
635
  book.should be_a Book
@@ -612,7 +638,7 @@ describe Book do
612
638
  book.excel.should_not == @book.excel
613
639
  book.excel.should_not == excel1
614
640
  book.excel.should_not == excel2
615
- sheet = book[0]
641
+ sheet = book.sheet(1)
616
642
  sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
617
643
  book.should be_alive
618
644
  book.Saved.should be_false
@@ -622,7 +648,7 @@ describe Book do
622
648
  @book.close
623
649
  book2.close
624
650
  book3 = Book.open(@simple_file)
625
- new_sheet = book3[0]
651
+ new_sheet = book3.sheet(1)
626
652
  new_sheet[1,1].value.should_not == cell_value
627
653
  book3.close
628
654
  end
@@ -633,13 +659,13 @@ describe Book do
633
659
  book2 = Book.open(@simple_file, :force_excel => :new, :read_only => true)
634
660
  @book.ReadOnly.should be_true
635
661
  book2.Readonly.should be_true
636
- sheet = @book[0]
662
+ sheet = @book.sheet(1)
637
663
  cell_value = sheet[1,1].value
638
664
  Book.unobtrusively(@simple_file, :hidden, :readonly_excel => true) do |book|
639
665
  book.should be_a Book
640
666
  book.excel.should == book2.excel
641
667
  book.ReadOnly.should be_false
642
- sheet = book[0]
668
+ sheet = book.sheet(1)
643
669
  sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
644
670
  book.should be_alive
645
671
  book.Saved.should be_false
@@ -649,7 +675,7 @@ describe Book do
649
675
  @book.close
650
676
  book2.close
651
677
  book3 = Book.open(@simple_file)
652
- new_sheet = book3[0]
678
+ new_sheet = book3.sheet(1)
653
679
  new_sheet[1,1].value.should_not == cell_value
654
680
  book3.close
655
681
  end
@@ -658,7 +684,7 @@ describe Book do
658
684
  book2 = Book.open(@simple_file, :force_excel => :new, :read_only => true)
659
685
  @book.ReadOnly.should be_true
660
686
  book2.Readonly.should be_true
661
- sheet = @book[0]
687
+ sheet = @book.sheet(1)
662
688
  cell_value = sheet[1,1].value
663
689
  Book.unobtrusively(@simple_file, :hidden, :read_only => true) do |book|
664
690
  book.should be_a Book
@@ -713,7 +739,7 @@ describe Book do
713
739
  Book.unobtrusively(@simple_file, :hidden) do |book|
714
740
  @book1.Saved.should be_true
715
741
  book.Saved.should be_true
716
- sheet = book[0]
742
+ sheet = book.sheet(1)
717
743
  cell = sheet[1,1]
718
744
  sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
719
745
  @book1.Saved.should be_false
@@ -762,22 +788,22 @@ describe Book do
762
788
  end
763
789
 
764
790
  it "should yield the block result with an unmodified book" do
765
- sheet1 = @book1[0]
791
+ sheet1 = @book1.sheet(1)
766
792
  cell1 = sheet1[1,1].value
767
793
  result =
768
794
  Book.unobtrusively(@simple_file) do |book|
769
- sheet = book[0]
795
+ sheet = book.sheet(1)
770
796
  cell = sheet[1,1].value
771
797
  end
772
798
  result.should == cell1
773
799
  end
774
800
 
775
801
  it "should yield the block result even if the book gets saved" do
776
- sheet1 = @book1[0]
802
+ sheet1 = @book1.sheet(1)
777
803
  @book1.save
778
804
  result =
779
805
  Book.unobtrusively(@simple_file) do |book|
780
- sheet = book[0]
806
+ sheet = book.sheet(1)
781
807
  sheet[1,1] = 22
782
808
  @book1.Saved.should be_false
783
809
  42
@@ -794,7 +820,7 @@ describe Book do
794
820
  @book2 = Book.open(@simple_file, :force_excel => :new)
795
821
  @book1.Readonly.should == false
796
822
  @book2.Readonly.should == true
797
- old_sheet = @book1[0]
823
+ old_sheet = @book1.sheet(1)
798
824
  @old_cell_value = old_sheet[1,1].value
799
825
  @book1.close
800
826
  @book2.close
@@ -807,13 +833,13 @@ describe Book do
807
833
  book.excel.should == @book2.excel
808
834
  book.excel.should_not == @book1.excel
809
835
  book.ReadOnly.should == false
810
- sheet = book[0]
836
+ sheet = book.sheet(1)
811
837
  cell = sheet[1,1]
812
838
  sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
813
839
  book.Saved.should be_false
814
840
  end
815
841
  new_book = Book.open(@simple_file)
816
- sheet = new_book[0]
842
+ sheet = new_book.sheet(1)
817
843
  sheet[1,1].value.should_not == @old_cell_value
818
844
  end
819
845
 
@@ -822,13 +848,13 @@ describe Book do
822
848
  book.excel.should_not == @book2.excel
823
849
  book.excel.should_not == @book1.excel
824
850
  book.ReadOnly.should == false
825
- sheet = book[0]
851
+ sheet = book.sheet(1)
826
852
  cell = sheet[1,1]
827
853
  sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
828
854
  book.Saved.should be_false
829
855
  end
830
856
  new_book = Book.open(@simple_file)
831
- sheet = new_book[0]
857
+ sheet = new_book.sheet(1)
832
858
  sheet[1,1].Value.should_not == @old_cell_value
833
859
  end
834
860
 
@@ -838,13 +864,13 @@ describe Book do
838
864
  book.ReadOnly.should == false
839
865
  book.excel.should_not == @book1.excel
840
866
  book.excel.should_not == @book2.excel
841
- sheet = book[0]
867
+ sheet = book.sheet(1)
842
868
  cell = sheet[1,1]
843
869
  sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
844
870
  book.Saved.should be_false
845
871
  end
846
872
  new_book = Book.open(@simple_file)
847
- sheet = new_book[0]
873
+ sheet = new_book.sheet(1)
848
874
  sheet[1,1].Value.should_not == @old_cell_value
849
875
  end
850
876
  end
@@ -944,7 +970,7 @@ describe Book do
944
970
 
945
971
  before do
946
972
  @book = Book.open(@simple_file)
947
- sheet = @book[0]
973
+ sheet = @book.sheet(1)
948
974
  @old_cell_value = sheet[1,1].value
949
975
  @book.close
950
976
  end
@@ -954,14 +980,14 @@ describe Book do
954
980
  book.should be_a Book
955
981
  book.should be_alive
956
982
  book.Saved.should be_true
957
- sheet = book[0]
983
+ sheet = book.sheet(1)
958
984
  cell = sheet[1,1]
959
985
  sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
960
986
  book.Saved.should be_false
961
987
  book.excel.should == @book.excel
962
988
  end
963
989
  new_book = Book.open(@simple_file, :visible => true)
964
- sheet = new_book[0]
990
+ sheet = new_book.sheet(1)
965
991
  sheet[1,1].Value.should == @old_cell_value
966
992
  end
967
993
 
@@ -969,20 +995,20 @@ describe Book do
969
995
  new_excel = Excel.new(:reuse => false)
970
996
  another_excel = Excel.new(:reuse => false)
971
997
  Book.for_reading(@simple_file, another_excel) do |book|
972
- sheet = book[0]
998
+ sheet = book.sheet(1)
973
999
  cell = sheet[1,1]
974
1000
  sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
975
1001
  book.excel.should == another_excel
976
1002
  end
977
1003
  new_book = Book.open(@simple_file, :visible => true)
978
- sheet = new_book[0]
1004
+ sheet = new_book.sheet(1)
979
1005
  sheet[1,1].Value.should == @old_cell_value
980
1006
  end
981
1007
 
982
1008
  it "should not change the value and use the hidden Excel instance" do
983
1009
  new_excel = Excel.new(:reuse => false)
984
1010
  Book.for_reading(@simple_file, :hidden) do |book|
985
- sheet = book[0]
1011
+ sheet = book.sheet(1)
986
1012
  cell = sheet[1,1]
987
1013
  sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
988
1014
  book.excel.should_not == @book.excel
@@ -991,19 +1017,19 @@ describe Book do
991
1017
  book.excel.displayalerts.should be_false
992
1018
  end
993
1019
  new_book = Book.open(@simple_file, :visible => true)
994
- sheet = new_book[0]
1020
+ sheet = new_book.sheet(1)
995
1021
  sheet[1,1].Value.should == @old_cell_value
996
1022
  end
997
1023
 
998
1024
  it "should change the value" do
999
1025
  Book.for_modifying(@simple_file) do |book|
1000
- sheet = book[0]
1026
+ sheet = book.sheet(1)
1001
1027
  cell = sheet[1,1]
1002
1028
  sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
1003
1029
  book.excel.should == @book.excel
1004
1030
  end
1005
1031
  new_book = Book.open(@simple_file, :visible => true)
1006
- sheet = new_book[0]
1032
+ sheet = new_book.sheet(1)
1007
1033
  sheet[1,1].Value.should_not == @old_cell_value
1008
1034
  end
1009
1035
 
@@ -1011,20 +1037,20 @@ describe Book do
1011
1037
  new_excel = Excel.new(:reuse => false)
1012
1038
  another_excel = Excel.new(:reuse => false)
1013
1039
  Book.for_modifying(@simple_file, another_excel) do |book|
1014
- sheet = book[0]
1040
+ sheet = book.sheet(1)
1015
1041
  cell = sheet[1,1]
1016
1042
  sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
1017
1043
  book.excel.should == another_excel
1018
1044
  end
1019
1045
  new_book = Book.open(@simple_file, :visible => true)
1020
- sheet = new_book[0]
1046
+ sheet = new_book.sheet(1)
1021
1047
  sheet[1,1].Value.should_not == @old_cell_value
1022
1048
  end
1023
1049
 
1024
1050
  it "should change the value and use the hidden Excel instance" do
1025
1051
  new_excel = Excel.new(:reuse => false)
1026
1052
  Book.for_modifying(@simple_file, :hidden) do |book|
1027
- sheet = book[0]
1053
+ sheet = book.sheet(1)
1028
1054
  cell = sheet[1,1]
1029
1055
  sheet[1,1] = cell.value == "foo" ? "bar" : "foo"
1030
1056
  book.excel.should_not == @book.excel
@@ -1033,7 +1059,7 @@ describe Book do
1033
1059
  book.excel.displayalerts.should be_false
1034
1060
  end
1035
1061
  new_book = Book.open(@simple_file, :visible => true)
1036
- sheet = new_book[0]
1062
+ sheet = new_book.sheet(1)
1037
1063
  sheet[1,1].Value.should_not == @old_cell_value
1038
1064
  end
1039
1065
  end