robust_excel_ole 1.3 → 1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +6 -0
- data/README.rdoc +1 -1
- data/docs/README_open.rdoc +1 -1
- data/docs/README_ranges.rdoc +60 -57
- data/docs/README_sheet.rdoc +1 -1
- data/examples/introducing_examples/example_introducing.rb +42 -0
- data/examples/introducing_examples/example_open.rb +49 -0
- data/examples/introducing_examples/example_range.rb +67 -0
- data/examples/{edit_sheets → modifying_sheets}/example_access_sheets_and_cells.rb +0 -0
- data/examples/{edit_sheets → modifying_sheets}/example_adding_sheets.rb +0 -0
- data/examples/{edit_sheets → modifying_sheets}/example_concating.rb +1 -1
- data/examples/{edit_sheets → modifying_sheets}/example_copying.rb +1 -1
- data/examples/{edit_sheets → modifying_sheets}/example_expanding.rb +1 -1
- data/examples/{edit_sheets → modifying_sheets}/example_naming.rb +1 -1
- data/examples/{edit_sheets → modifying_sheets}/example_ranges.rb +1 -1
- data/examples/{edit_sheets → modifying_sheets}/example_saving.rb +1 -1
- data/examples/open_save_close/example_control_to_excel.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 +1 -1
- data/examples/open_save_close/example_if_unsaved_forget.rb +3 -3
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +4 -4
- data/examples/open_save_close/example_read_only.rb +1 -1
- data/examples/open_save_close/example_rename_cells.rb +1 -1
- data/examples/open_save_close/example_simple.rb +1 -1
- data/examples/open_save_close/example_unobtrusively.rb +3 -3
- data/lib/robust_excel_ole.rb +2 -2
- data/lib/robust_excel_ole/bookstore.rb +1 -1
- data/lib/robust_excel_ole/cell.rb +15 -2
- data/lib/robust_excel_ole/excel.rb +14 -12
- data/lib/robust_excel_ole/general.rb +12 -0
- data/lib/robust_excel_ole/range.rb +37 -20
- data/lib/robust_excel_ole/reo_common.rb +63 -37
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/{book.rb → workbook.rb} +35 -33
- data/lib/robust_excel_ole/{sheet.rb → worksheet.rb} +22 -22
- data/spec/bookstore_spec.rb +38 -38
- data/spec/cell_spec.rb +10 -10
- data/spec/data/another_workbook.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +113 -105
- data/spec/general_spec.rb +37 -5
- data/spec/range_spec.rb +34 -19
- data/spec/reo_common_spec.rb +58 -48
- data/spec/{book_spec.rb → workbook_spec.rb} +198 -198
- data/spec/workbook_specs/workbook_all_spec.rb +33 -0
- data/spec/{book_specs/book_close_spec.rb → workbook_specs/workbook_close_spec.rb} +10 -10
- data/spec/{book_specs/book_misc_spec.rb → workbook_specs/workbook_misc_spec.rb} +148 -128
- data/spec/{book_specs/book_open_spec.rb → workbook_specs/workbook_open_spec.rb} +427 -427
- data/spec/{book_specs/book_save_spec.rb → workbook_specs/workbook_save_spec.rb} +44 -44
- data/spec/{book_specs/book_sheet_spec.rb → workbook_specs/workbook_sheet_spec.rb} +19 -19
- data/spec/{book_specs/book_subclass_spec.rb → workbook_specs/workbook_subclass_spec.rb} +5 -6
- data/spec/{book_specs/book_unobtr_spec.rb → workbook_specs/workbook_unobtr_spec.rb} +339 -344
- data/spec/{sheet_spec.rb → worksheet_spec.rb} +85 -55
- metadata +25 -22
- data/spec/book_specs/book_all_spec.rb +0 -22
@@ -8,7 +8,7 @@ $VERBOSE = nil
|
|
8
8
|
include RobustExcelOle
|
9
9
|
include General
|
10
10
|
|
11
|
-
describe
|
11
|
+
describe Workbook do
|
12
12
|
|
13
13
|
before(:all) do
|
14
14
|
excel = Excel.new(:reuse => true)
|
@@ -44,7 +44,7 @@ describe Book do
|
|
44
44
|
context "with simple save" do
|
45
45
|
|
46
46
|
it "should save for a file opened without :read_only" do
|
47
|
-
@book =
|
47
|
+
@book = Workbook.open(@simple_file)
|
48
48
|
@book.add_sheet(@sheet, :as => 'a_name')
|
49
49
|
@new_sheet_count = @book.ole_workbook.Worksheets.Count
|
50
50
|
expect {
|
@@ -55,7 +55,7 @@ describe Book do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should raise error with read_only" do
|
58
|
-
@book =
|
58
|
+
@book = Workbook.open(@simple_file, :read_only => true)
|
59
59
|
expect {
|
60
60
|
@book.save
|
61
61
|
}.to raise_error(WorkbookReadOnly, "Not opened for writing (opened with :read_only option)")
|
@@ -63,7 +63,7 @@ describe Book do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should raise error if workbook is not alive" do
|
66
|
-
@book =
|
66
|
+
@book = Workbook.open(@simple_file)
|
67
67
|
@book.close
|
68
68
|
expect{
|
69
69
|
@book.save
|
@@ -74,7 +74,7 @@ describe Book do
|
|
74
74
|
|
75
75
|
context "with open with read only" do
|
76
76
|
before do
|
77
|
-
@book =
|
77
|
+
@book = Workbook.open(@simple_file, :read_only => true)
|
78
78
|
end
|
79
79
|
|
80
80
|
after do
|
@@ -92,21 +92,21 @@ describe Book do
|
|
92
92
|
context "with save_as" do
|
93
93
|
|
94
94
|
it "should save to 'simple_save_file.xls'" do
|
95
|
-
|
95
|
+
Workbook.open(@simple_file) do |book|
|
96
96
|
book.save_as(@simple_save_file1, :if_exists => :overwrite)
|
97
97
|
end
|
98
98
|
File.exist?(@simple_save_file1).should be true
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should raise error if filename is nil" do
|
102
|
-
book =
|
102
|
+
book = Workbook.open(@simple_file)
|
103
103
|
expect{
|
104
104
|
book.save_as(@wrong_name)
|
105
105
|
}.to raise_error(FileNameNotGiven, "filename is nil")
|
106
106
|
end
|
107
107
|
|
108
108
|
it "should raise error if workbook is not alive" do
|
109
|
-
book =
|
109
|
+
book = Workbook.open(@simple_file)
|
110
110
|
book.close
|
111
111
|
expect{
|
112
112
|
book.save_as(@simple_save_file)
|
@@ -116,7 +116,7 @@ describe Book do
|
|
116
116
|
|
117
117
|
context "with different extensions" do
|
118
118
|
before do
|
119
|
-
@book =
|
119
|
+
@book = Workbook.open(@simple_file)
|
120
120
|
end
|
121
121
|
|
122
122
|
after do
|
@@ -130,8 +130,8 @@ describe Book do
|
|
130
130
|
File.delete simple_save_file rescue nil
|
131
131
|
@book.save_as(simple_save_file, :if_exists => :overwrite)
|
132
132
|
File.exist?(simple_save_file).should be true
|
133
|
-
new_book =
|
134
|
-
new_book.should be_a
|
133
|
+
new_book = Workbook.open(simple_save_file)
|
134
|
+
new_book.should be_a Workbook
|
135
135
|
new_book.close
|
136
136
|
end
|
137
137
|
end
|
@@ -140,7 +140,7 @@ describe Book do
|
|
140
140
|
context "with saving with the same name in another directory" do
|
141
141
|
|
142
142
|
before do
|
143
|
-
@book =
|
143
|
+
@book = Workbook.open(@simple_file1)
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should save with the same name in another directory" do
|
@@ -157,8 +157,8 @@ describe Book do
|
|
157
157
|
context "with blocked by another file" do
|
158
158
|
|
159
159
|
before do
|
160
|
-
@book =
|
161
|
-
@book2 =
|
160
|
+
@book = Workbook.open(@simple_file1)
|
161
|
+
@book2 = Workbook.open(@another_simple_file)
|
162
162
|
end
|
163
163
|
|
164
164
|
after do
|
@@ -185,8 +185,8 @@ describe Book do
|
|
185
185
|
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :forget)
|
186
186
|
@book.should_not be_alive
|
187
187
|
File.exist?(@simple_file_other_path1).should be true
|
188
|
-
new_book =
|
189
|
-
new_book.should be_a
|
188
|
+
new_book = Workbook.open(@simple_file_other_path1)
|
189
|
+
new_book.should be_a Workbook
|
190
190
|
new_book.close
|
191
191
|
end
|
192
192
|
|
@@ -196,19 +196,19 @@ describe Book do
|
|
196
196
|
file.puts "garbage"
|
197
197
|
end
|
198
198
|
sheet = @book.sheet(1)
|
199
|
-
cell_value = sheet[1,1].
|
200
|
-
sheet[1,1] = sheet[1,1].
|
199
|
+
cell_value = sheet[1,1].Value
|
200
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
201
201
|
@book.Saved.should be false
|
202
202
|
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :forget)
|
203
203
|
@book.should_not be_alive
|
204
204
|
@book2.should be_alive
|
205
205
|
File.exist?(@simple_file_other_path1).should be true
|
206
|
-
new_book =
|
207
|
-
new_book.should be_a
|
206
|
+
new_book = Workbook.open(@simple_file_other_path1)
|
207
|
+
new_book.should be_a Workbook
|
208
208
|
new_book.close
|
209
|
-
old_book =
|
209
|
+
old_book = Workbook.open(@simple_file1)
|
210
210
|
old_sheet = old_book.sheet(1)
|
211
|
-
old_sheet[1,1].
|
211
|
+
old_sheet[1,1].Value.should == cell_value
|
212
212
|
old_book.close
|
213
213
|
end
|
214
214
|
|
@@ -218,19 +218,19 @@ describe Book do
|
|
218
218
|
file.puts "garbage"
|
219
219
|
end
|
220
220
|
sheet = @book.sheet(1)
|
221
|
-
cell_value = sheet[1,1].
|
222
|
-
sheet[1,1] = sheet[1,1].
|
221
|
+
cell_value = sheet[1,1].Value
|
222
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
223
223
|
@book.Saved.should be false
|
224
224
|
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :save)
|
225
225
|
@book.should_not be_alive
|
226
226
|
@book2.should be_alive
|
227
227
|
File.exist?(@simple_file_other_path1).should be true
|
228
|
-
new_book =
|
229
|
-
new_book.should be_a
|
228
|
+
new_book = Workbook.open(@simple_file_other_path1)
|
229
|
+
new_book.should be_a Workbook
|
230
230
|
new_book.close
|
231
|
-
old_book =
|
231
|
+
old_book = Workbook.open(@simple_file1)
|
232
232
|
old_sheet = old_book.sheet(1)
|
233
|
-
old_sheet[1,1].
|
233
|
+
old_sheet[1,1].Value.should_not == cell_value
|
234
234
|
old_book.close
|
235
235
|
end
|
236
236
|
|
@@ -244,15 +244,15 @@ describe Book do
|
|
244
244
|
@book.should_not be_alive
|
245
245
|
@book2.should be_alive
|
246
246
|
File.exist?(@simple_file_other_path1).should be true
|
247
|
-
new_book =
|
248
|
-
new_book.should be_a
|
247
|
+
new_book = Workbook.open(@simple_file_other_path1)
|
248
|
+
new_book.should be_a Workbook
|
249
249
|
new_book.close
|
250
250
|
end
|
251
251
|
|
252
252
|
it "should raise an error if the blocking workbook was unsaved with :if_obstructed => :close_if_saved" do
|
253
253
|
sheet = @book.sheet(1)
|
254
|
-
cell_value = sheet[1,1].
|
255
|
-
sheet[1,1] = sheet[1,1].
|
254
|
+
cell_value = sheet[1,1].Value
|
255
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
256
256
|
@book.Saved.should be false
|
257
257
|
expect{
|
258
258
|
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :close_if_saved)
|
@@ -308,7 +308,7 @@ describe Book do
|
|
308
308
|
possible_displayalerts.each do |displayalert_value|
|
309
309
|
context "with displayalerts=#{displayalert_value}" do
|
310
310
|
before do
|
311
|
-
@book =
|
311
|
+
@book = Workbook.open(@simple_file)
|
312
312
|
@book.excel.displayalerts = displayalert_value
|
313
313
|
end
|
314
314
|
|
@@ -319,7 +319,7 @@ describe Book do
|
|
319
319
|
it "should raise an error if the book is open" do
|
320
320
|
File.delete @simple_save_file1 rescue nil
|
321
321
|
FileUtils.copy @simple_file, @simple_save_file1
|
322
|
-
book_save =
|
322
|
+
book_save = Workbook.open(@simple_save_file1, :excel => :new)
|
323
323
|
expect{
|
324
324
|
@book.save_as(@simple_save_file1, :if_exists => :overwrite)
|
325
325
|
}.to raise_error(WorkbookBeingUsed, "workbook is open and used in Excel")
|
@@ -333,19 +333,19 @@ describe Book do
|
|
333
333
|
end
|
334
334
|
@book.save_as(@simple_save_file1, :if_exists => :overwrite)
|
335
335
|
File.exist?(@simple_save_file1).should be true
|
336
|
-
new_book =
|
337
|
-
new_book.should be_a
|
336
|
+
new_book = Workbook.open(@simple_save_file1)
|
337
|
+
new_book.should be_a Workbook
|
338
338
|
new_book.close
|
339
339
|
end
|
340
340
|
|
341
341
|
it "should simple save if file name is equal to the old one with :if_exists => :overwrite" do
|
342
342
|
sheet = @book.sheet(1)
|
343
|
-
sheet[1,1] = sheet[1,1].
|
344
|
-
new_value = sheet[1,1].
|
343
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
344
|
+
new_value = sheet[1,1].Value
|
345
345
|
@book.save_as(@simple_file1, :if_exists => :overwrite)
|
346
|
-
new_book =
|
346
|
+
new_book = Workbook.open(@simple_file1)
|
347
347
|
new_sheet = new_book.sheet(1)
|
348
|
-
new_sheet[1,1].
|
348
|
+
new_sheet[1,1].Value.should == new_value
|
349
349
|
new_book.close
|
350
350
|
end
|
351
351
|
|
@@ -387,8 +387,8 @@ describe Book do
|
|
387
387
|
File.exist?(@simple_save_file1).should be true
|
388
388
|
File.size?(@simple_save_file1).should > @garbage_length
|
389
389
|
@book.excel.DisplayAlerts.should == displayalert_value
|
390
|
-
new_book =
|
391
|
-
new_book.should be_a
|
390
|
+
new_book = Workbook.open(@simple_save_file1, :excel => :new)
|
391
|
+
new_book.should be_a Workbook
|
392
392
|
new_book.close
|
393
393
|
@book.excel.DisplayAlerts.should == displayalert_value
|
394
394
|
end
|
@@ -441,8 +441,8 @@ describe Book do
|
|
441
441
|
File.exist?(@simple_save_file1).should be true
|
442
442
|
File.size?(@simple_save_file1).should > @garbage_length
|
443
443
|
@book.excel.DisplayAlerts.should == displayalert_value
|
444
|
-
new_book =
|
445
|
-
new_book.should be_a
|
444
|
+
new_book = Workbook.open(@simple_save_file1, :excel => :new)
|
445
|
+
new_book.should be_a Workbook
|
446
446
|
new_book.close
|
447
447
|
|
448
448
|
@book.excel.DisplayAlerts.should == displayalert_value
|
@@ -8,7 +8,7 @@ $VERBOSE = nil
|
|
8
8
|
include RobustExcelOle
|
9
9
|
include General
|
10
10
|
|
11
|
-
describe
|
11
|
+
describe Workbook do
|
12
12
|
|
13
13
|
before(:all) do
|
14
14
|
excel = Excel.new(:reuse => true)
|
@@ -36,7 +36,7 @@ describe Book do
|
|
36
36
|
|
37
37
|
describe 'access sheet' do
|
38
38
|
before do
|
39
|
-
@book =
|
39
|
+
@book = Workbook.open(@simple_file)
|
40
40
|
end
|
41
41
|
|
42
42
|
after do
|
@@ -44,25 +44,25 @@ describe Book do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'with sheet name' do
|
47
|
-
@book.sheet("Sheet1").should be_kind_of
|
47
|
+
@book.sheet("Sheet1").should be_kind_of Worksheet
|
48
48
|
@book.sheet("Sheet1").name.should == "Sheet1"
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'with integer' do
|
52
|
-
@book.sheet(1).should be_kind_of
|
52
|
+
@book.sheet(1).should be_kind_of Worksheet
|
53
53
|
@book.sheet(1).name.should == "Sheet1"
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'with block' do
|
57
57
|
@book.each do |sheet|
|
58
|
-
sheet.should be_kind_of
|
58
|
+
sheet.should be_kind_of Worksheet
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
context 'open with block' do
|
63
63
|
it {
|
64
|
-
|
65
|
-
@book.sheet("Sheet1").should be_a
|
64
|
+
Workbook.open(@simple_file) do |book|
|
65
|
+
@book.sheet("Sheet1").should be_a Worksheet
|
66
66
|
@book.sheet("Sheet1").name.should == "Sheet1"
|
67
67
|
end
|
68
68
|
}
|
@@ -71,18 +71,18 @@ describe Book do
|
|
71
71
|
|
72
72
|
describe 'access first and last sheet' do
|
73
73
|
before do
|
74
|
-
@book =
|
74
|
+
@book = Workbook.open(@simple_file)
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should access the first sheet" do
|
78
78
|
first_sheet = @book.first_sheet
|
79
|
-
first_sheet.name.should ==
|
79
|
+
first_sheet.name.should == Worksheet.new(@book.Worksheets.Item(1)).Name
|
80
80
|
first_sheet.name.should == @book.sheet(1).Name
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should access the last sheet" do
|
84
84
|
last_sheet = @book.last_sheet
|
85
|
-
last_sheet.name.should ==
|
85
|
+
last_sheet.name.should == Worksheet.new(@book.Worksheets.Item(3)).Name
|
86
86
|
last_sheet.name.should == @book.sheet(3).Name
|
87
87
|
end
|
88
88
|
end
|
@@ -92,7 +92,7 @@ describe Book do
|
|
92
92
|
context "with no given sheet" do
|
93
93
|
|
94
94
|
before do
|
95
|
-
@book =
|
95
|
+
@book = Workbook.open(@simple_file)
|
96
96
|
@sheet = @book.sheet(1)
|
97
97
|
end
|
98
98
|
|
@@ -129,9 +129,9 @@ describe Book do
|
|
129
129
|
context "with copying a given sheet" do
|
130
130
|
|
131
131
|
before do
|
132
|
-
@book =
|
132
|
+
@book = Workbook.open(@simple_file)
|
133
133
|
@sheet = @book.sheet(1)
|
134
|
-
@another_book =
|
134
|
+
@another_book = Workbook.open(@another_simple_file)
|
135
135
|
end
|
136
136
|
|
137
137
|
after do
|
@@ -193,7 +193,7 @@ describe Book do
|
|
193
193
|
describe "add_empty_sheet" do
|
194
194
|
|
195
195
|
before do
|
196
|
-
@book =
|
196
|
+
@book = Workbook.open(@simple_file)
|
197
197
|
@sheet = @book.sheet(1)
|
198
198
|
end
|
199
199
|
|
@@ -229,9 +229,9 @@ describe Book do
|
|
229
229
|
describe "copy_sheet" do
|
230
230
|
|
231
231
|
before do
|
232
|
-
@book =
|
232
|
+
@book = Workbook.open(@simple_file)
|
233
233
|
@sheet = @book.sheet(1)
|
234
|
-
@another_book =
|
234
|
+
@another_book = Workbook.open(@another_simple_file)
|
235
235
|
end
|
236
236
|
|
237
237
|
after do
|
@@ -294,7 +294,7 @@ describe Book do
|
|
294
294
|
context "with no given sheet" do
|
295
295
|
|
296
296
|
before do
|
297
|
-
@book =
|
297
|
+
@book = Workbook.open(@simple_file)
|
298
298
|
@sheet = @book.sheet(1)
|
299
299
|
end
|
300
300
|
|
@@ -331,9 +331,9 @@ describe Book do
|
|
331
331
|
context "with copying a given sheet" do
|
332
332
|
|
333
333
|
before do
|
334
|
-
@book =
|
334
|
+
@book = Workbook.open(@simple_file)
|
335
335
|
@sheet = @book.sheet(1)
|
336
|
-
@another_book =
|
336
|
+
@another_book = Workbook.open(@another_simple_file)
|
337
337
|
end
|
338
338
|
|
339
339
|
after do
|
@@ -7,12 +7,12 @@ module My # :nodoc: #
|
|
7
7
|
class Excel < RobustExcelOle::Excel # :nodoc: #
|
8
8
|
end
|
9
9
|
|
10
|
-
class
|
10
|
+
class Workbook < RobustExcelOle::Workbook # :nodoc: #
|
11
11
|
end
|
12
12
|
|
13
13
|
end
|
14
14
|
|
15
|
-
describe "subclassed
|
15
|
+
describe "subclassed Workbook" do
|
16
16
|
|
17
17
|
before(:all) do
|
18
18
|
excel = RobustExcelOle::Excel.new(:reuse => true)
|
@@ -35,10 +35,9 @@ describe "subclassed Book" do
|
|
35
35
|
describe "open" do
|
36
36
|
|
37
37
|
it "should use the subclassed Excel" do
|
38
|
-
|
39
|
-
|
40
|
-
book.should be_a
|
41
|
-
book.should be_a My::Book
|
38
|
+
My::Workbook.open(@simple_file) do |book|
|
39
|
+
book.should be_a RobustExcelOle::Workbook
|
40
|
+
book.should be_a My::Workbook
|
42
41
|
book.excel.should be_a RobustExcelOle::Excel
|
43
42
|
book.excel.class.should == My::Excel
|
44
43
|
book.excel.should be_a My::Excel
|
@@ -8,7 +8,7 @@ $VERBOSE = nil
|
|
8
8
|
include RobustExcelOle
|
9
9
|
include General
|
10
10
|
|
11
|
-
describe
|
11
|
+
describe Workbook do
|
12
12
|
|
13
13
|
before(:all) do
|
14
14
|
excel = Excel.new(:reuse => true)
|
@@ -39,10 +39,10 @@ describe Book do
|
|
39
39
|
describe "unobtrusively" do
|
40
40
|
|
41
41
|
def unobtrusively_ok? # :nodoc: #
|
42
|
-
|
43
|
-
book.should be_a
|
42
|
+
Workbook.unobtrusively(@simple_file) do |book|
|
43
|
+
book.should be_a Workbook
|
44
44
|
sheet = book.sheet(1)
|
45
|
-
sheet[1,1] = sheet[1,1].
|
45
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
46
46
|
book.should be_alive
|
47
47
|
book.Saved.should be false
|
48
48
|
end
|
@@ -63,7 +63,7 @@ describe Book do
|
|
63
63
|
context "with open unsaved workbook" do
|
64
64
|
|
65
65
|
before do
|
66
|
-
@book1 =
|
66
|
+
@book1 = Workbook.open(@simple_file1)
|
67
67
|
@book1.sheet(1)[1,1] = "foo"
|
68
68
|
#@ole_workbook1 = @ole_excel1.Workbooks.Open(@simple_file1, { 'ReadOnly' => false })
|
69
69
|
#@old_value = @ole_workbook1.Worksheets.Item(1).Cells.Item(1, 1).Value
|
@@ -74,7 +74,7 @@ describe Book do
|
|
74
74
|
context "with writability" do
|
75
75
|
|
76
76
|
it "should open as read-write by default" do
|
77
|
-
|
77
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
78
78
|
book.Readonly.should be false
|
79
79
|
#book.filename.should == @ole_workbook1.Fullname.tr('\\','/')
|
80
80
|
#book.excel.ole_excel.Hwnd.should == @ole_excel1.Hwnd
|
@@ -83,12 +83,12 @@ describe Book do
|
|
83
83
|
#@ole_workbook1.Saved.should be false
|
84
84
|
Excel.kill_all
|
85
85
|
sleep 1
|
86
|
-
book2 =
|
86
|
+
book2 = Workbook.open(@simple_file1)
|
87
87
|
#book2.sheet(1)[1,1].Value.should == @old_value
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should open not writable" do
|
91
|
-
|
91
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
92
92
|
book.ReadOnly.should be false
|
93
93
|
book.filename.should == @ole_workbook1.Fullname.tr('\\','/')
|
94
94
|
book.excel.ole_excel.Hwnd.should == @ole_excel1.Hwnd
|
@@ -98,7 +98,7 @@ describe Book do
|
|
98
98
|
@book.sheet(1)[1,1].Value.should_not == @old_value
|
99
99
|
Excel.kill_all
|
100
100
|
sleep 1
|
101
|
-
book2 =
|
101
|
+
book2 = Workbook.open(@simple_file1)
|
102
102
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
103
103
|
end
|
104
104
|
end
|
@@ -106,13 +106,13 @@ describe Book do
|
|
106
106
|
context "further tests" do
|
107
107
|
|
108
108
|
it "should write in the outer and not in the inner block" do
|
109
|
-
|
109
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
110
110
|
@old_value = book.sheet(1)[1,1].Value
|
111
111
|
book.ReadOnly.should be false
|
112
112
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
113
113
|
book.Saved.should be false
|
114
114
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
115
|
-
|
115
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book2|
|
116
116
|
book2.should == book
|
117
117
|
book2.ReadOnly.should be false
|
118
118
|
book2.Saved.should be false
|
@@ -124,62 +124,62 @@ describe Book do
|
|
124
124
|
book.Saved.should be false
|
125
125
|
book.sheet(1)[1,1].Value.should == @old_value
|
126
126
|
end
|
127
|
-
book =
|
127
|
+
book = Workbook.open(@simple_file1)
|
128
128
|
book.sheet(1)[1,1].Value.should == @old_value
|
129
129
|
end
|
130
130
|
|
131
131
|
it "should use the excel of the book and keep open the book" do
|
132
|
-
@book =
|
132
|
+
@book = Workbook.open(@simple_file1)
|
133
133
|
excel = Excel.new(:reuse => false)
|
134
134
|
sheet = @book.sheet(1)
|
135
|
-
old_cell_value = sheet[1,1].
|
135
|
+
old_cell_value = sheet[1,1].Value
|
136
136
|
@book.close
|
137
137
|
@book.should_not be_alive
|
138
|
-
|
139
|
-
book.should be_a
|
138
|
+
Workbook.unobtrusively(@simple_file, :keep_open => true) do |book|
|
139
|
+
book.should be_a Workbook
|
140
140
|
book.excel.should == @book.excel
|
141
141
|
book.excel.should_not == excel
|
142
142
|
sheet = book.sheet(1)
|
143
143
|
cell = sheet[1,1]
|
144
|
-
sheet[1,1] = cell.
|
144
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
145
145
|
book.Saved.should be false
|
146
146
|
end
|
147
147
|
@book.should be_alive
|
148
148
|
@book.close
|
149
|
-
new_book =
|
149
|
+
new_book = Workbook.open(@simple_file1)
|
150
150
|
sheet = new_book.sheet(1)
|
151
|
-
sheet[1,1].
|
151
|
+
sheet[1,1].Value.should_not == old_cell_value
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should use the excel of the book and keep open the book" do
|
155
|
-
@book =
|
155
|
+
@book = Workbook.open(@simple_file1)
|
156
156
|
excel = Excel.new(:reuse => false)
|
157
157
|
sheet = @book.sheet(1)
|
158
|
-
old_cell_value = sheet[1,1].
|
158
|
+
old_cell_value = sheet[1,1].Value
|
159
159
|
@book.close
|
160
160
|
@book.should_not be_alive
|
161
|
-
|
162
|
-
book.should be_a
|
161
|
+
Workbook.unobtrusively(@simple_file, :if_closed => :new) do |book|
|
162
|
+
book.should be_a Workbook
|
163
163
|
book.should be_alive
|
164
164
|
book.excel.should_not == @book.excel
|
165
165
|
book.excel.should_not == excel
|
166
166
|
sheet = book.sheet(1)
|
167
167
|
cell = sheet[1,1]
|
168
|
-
sheet[1,1] = cell.
|
168
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
169
169
|
book.Saved.should be false
|
170
170
|
end
|
171
171
|
@book.should_not be_alive
|
172
|
-
new_book =
|
172
|
+
new_book = Workbook.open(@simple_file1)
|
173
173
|
sheet = new_book.sheet(1)
|
174
|
-
sheet[1,1].
|
174
|
+
sheet[1,1].Value.should_not == old_cell_value
|
175
175
|
end
|
176
176
|
|
177
177
|
it "should use a given Excel" do
|
178
|
-
@book =
|
178
|
+
@book = Workbook.open(@simple_file1)
|
179
179
|
@book.close
|
180
180
|
new_excel = Excel.new(:reuse => false)
|
181
181
|
another_excel = Excel.new(:reuse => false)
|
182
|
-
|
182
|
+
Workbook.unobtrusively(@simple_file1, :if_closed => another_excel) do |book|
|
183
183
|
book.excel.should_not == @book.excel
|
184
184
|
book.excel.should_not == new_excel
|
185
185
|
book.excel.should == another_excel
|
@@ -188,34 +188,34 @@ describe Book do
|
|
188
188
|
|
189
189
|
it "should reuse Excel" do
|
190
190
|
new_excel = Excel.new(:reuse => false)
|
191
|
-
|
191
|
+
Workbook.unobtrusively(@simple_file1, :if_closed => :reuse) do |book|
|
192
192
|
book.excel.should == @book.excel
|
193
193
|
book.excel.should_not == new_excel
|
194
194
|
end
|
195
195
|
|
196
196
|
it "should open unobtrusively the closed book in the most recent Excel where it was open before" do
|
197
|
-
@book1 =
|
198
|
-
@book2 =
|
197
|
+
@book1 = Workbook.open(@simple_file1)
|
198
|
+
@book2 = Workbook.open(@simple_file1, :force_excel => :new)
|
199
199
|
@book1.Readonly.should == false
|
200
200
|
@book2.Readonly.should == true
|
201
201
|
old_sheet = @book1.sheet(1)
|
202
|
-
@old_cell_value = old_sheet[1,1].
|
202
|
+
@old_cell_value = old_sheet[1,1].Value
|
203
203
|
@book1.close
|
204
204
|
@book2.close
|
205
205
|
@book1.should_not be_alive
|
206
206
|
@book2.should_not be_alive
|
207
|
-
|
207
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
208
208
|
book.excel.should_not == @book2.excel
|
209
209
|
book.excel.should == @book1.excel
|
210
210
|
book.ReadOnly.should == false
|
211
211
|
sheet = book.sheet(1)
|
212
212
|
cell = sheet[1,1]
|
213
|
-
sheet[1,1] = cell.
|
213
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
214
214
|
book.Saved.should be false
|
215
215
|
end
|
216
|
-
new_book =
|
216
|
+
new_book = Workbook.open(@simple_file1)
|
217
217
|
sheet = new_book.sheet(1)
|
218
|
-
sheet[1,1].
|
218
|
+
sheet[1,1].Value.should_not == @old_cell_value
|
219
219
|
end
|
220
220
|
end
|
221
221
|
end
|
@@ -232,7 +232,7 @@ describe Book do
|
|
232
232
|
context "with writability" do
|
233
233
|
|
234
234
|
it "should open as read-only by default" do
|
235
|
-
|
235
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
236
236
|
book.Readonly.should be true
|
237
237
|
book.filename.should == @ole_workbook1.Fullname.tr('\\','/')
|
238
238
|
book.excel.ole_excel.Hwnd.should == @ole_excel1.Hwnd
|
@@ -243,12 +243,12 @@ describe Book do
|
|
243
243
|
@ole_workbook1.Worksheets.Item(1).Cells.Item(1, 1).Value.should_not == @old_value
|
244
244
|
Excel.kill_all
|
245
245
|
sleep 1
|
246
|
-
book2 =
|
246
|
+
book2 = Workbook.open(@simple_file1)
|
247
247
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
248
248
|
end
|
249
249
|
|
250
250
|
it "should open not writable" do
|
251
|
-
|
251
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
252
252
|
book.ReadOnly.should be true
|
253
253
|
book.filename.should == @ole_workbook1.Fullname.tr('\\','/')
|
254
254
|
book.excel.ole_excel.Hwnd.should == @ole_excel1.Hwnd
|
@@ -259,7 +259,7 @@ describe Book do
|
|
259
259
|
@ole_workbook1.Worksheets.Item(1).Cells.Item(1, 1).Value.should_not == @old_value
|
260
260
|
Excel.kill_all
|
261
261
|
sleep 1
|
262
|
-
book2 =
|
262
|
+
book2 = Workbook.open(@simple_file1)
|
263
263
|
book2.sheet(1)[1,1].Value.should == @old_value
|
264
264
|
end
|
265
265
|
end
|
@@ -271,14 +271,14 @@ describe Book do
|
|
271
271
|
describe "block transparency" do
|
272
272
|
|
273
273
|
it "should return correct value of the block" do
|
274
|
-
(
|
274
|
+
(Workbook.unobtrusively(@simple_file1) do |book|
|
275
275
|
22
|
276
276
|
end).should == 22
|
277
277
|
end
|
278
278
|
|
279
279
|
it "should return value of the last block" do
|
280
|
-
(
|
281
|
-
|
280
|
+
(Workbook.unobtrusively(@simple_file1) do |book|
|
281
|
+
Workbook.unobtrusively(@different_file) do |book2|
|
282
282
|
11
|
283
283
|
end
|
284
284
|
22
|
@@ -286,8 +286,8 @@ describe Book do
|
|
286
286
|
end
|
287
287
|
|
288
288
|
it "should return correct value in several blocks" do
|
289
|
-
(
|
290
|
-
|
289
|
+
(Workbook.unobtrusively(@simple_file1) do |book|
|
290
|
+
Workbook.unobtrusively(@different_file) do |book2|
|
291
291
|
22
|
292
292
|
end
|
293
293
|
end).should == 22
|
@@ -300,104 +300,104 @@ describe Book do
|
|
300
300
|
context "with no book" do
|
301
301
|
|
302
302
|
it "should open read-write" do
|
303
|
-
|
303
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
304
304
|
book.ReadOnly.should be false
|
305
305
|
@old_value = book.sheet(1)[1,1].Value
|
306
306
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
307
307
|
book.Saved.should be false
|
308
308
|
end
|
309
309
|
Excel.current.Workbooks.Count.should == 0
|
310
|
-
b1 =
|
310
|
+
b1 = Workbook.open(@simple_file1)
|
311
311
|
b1.sheet(1)[1,1].Value.should_not == @old_value
|
312
312
|
end
|
313
313
|
|
314
314
|
it "should open as read-write" do
|
315
|
-
|
315
|
+
Workbook.unobtrusively(@simple_file, :read_only => false) do |book|
|
316
316
|
book.ReadOnly.should be false
|
317
317
|
@old_value = book.sheet(1)[1,1].Value
|
318
318
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
319
319
|
book.Saved.should be false
|
320
320
|
end
|
321
321
|
Excel.current.Workbooks.Count.should == 0
|
322
|
-
b1 =
|
322
|
+
b1 = Workbook.open(@simple_file1)
|
323
323
|
b1.sheet(1)[1,1].Value.should_not == @old_value
|
324
324
|
end
|
325
325
|
|
326
326
|
it "should open as read-write" do
|
327
|
-
|
327
|
+
Workbook.unobtrusively(@simple_file, :read_only => false, :writable => false) do |book|
|
328
328
|
book.ReadOnly.should be false
|
329
329
|
@old_value = book.sheet(1)[1,1].Value
|
330
330
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
331
331
|
book.Saved.should be false
|
332
332
|
end
|
333
333
|
Excel.current.Workbooks.Count.should == 0
|
334
|
-
b1 =
|
334
|
+
b1 = Workbook.open(@simple_file1)
|
335
335
|
b1.sheet(1)[1,1].Value.should_not == @old_value
|
336
336
|
end
|
337
337
|
|
338
338
|
it "should open as read-write" do
|
339
|
-
|
339
|
+
Workbook.unobtrusively(@simple_file, :writable => true) do |book|
|
340
340
|
book.ReadOnly.should be false
|
341
341
|
@old_value = book.sheet(1)[1,1].Value
|
342
342
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
343
343
|
book.Saved.should be false
|
344
344
|
end
|
345
345
|
Excel.current.Workbooks.Count.should == 0
|
346
|
-
b1 =
|
346
|
+
b1 = Workbook.open(@simple_file1)
|
347
347
|
b1.sheet(1)[1,1].Value.should_not == @old_value
|
348
348
|
end
|
349
349
|
|
350
350
|
it "should open as read-write" do
|
351
|
-
|
351
|
+
Workbook.unobtrusively(@simple_file, :writable => true, :read_only => false) do |book|
|
352
352
|
book.ReadOnly.should be false
|
353
353
|
@old_value = book.sheet(1)[1,1].Value
|
354
354
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
355
355
|
book.Saved.should be false
|
356
356
|
end
|
357
357
|
Excel.current.Workbooks.Count.should == 0
|
358
|
-
b1 =
|
358
|
+
b1 = Workbook.open(@simple_file1)
|
359
359
|
b1.sheet(1)[1,1].Value.should_not == @old_value
|
360
360
|
end
|
361
361
|
|
362
362
|
it "should open read-only" do
|
363
|
-
|
363
|
+
Workbook.unobtrusively(@simple_file, :read_only => true) do |book|
|
364
364
|
book.ReadOnly.should be true
|
365
365
|
@old_value = book.sheet(1)[1,1].Value
|
366
366
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
367
367
|
book.Saved.should be false
|
368
368
|
end
|
369
369
|
Excel.current.Workbooks.Count.should == 0
|
370
|
-
b1 =
|
370
|
+
b1 = Workbook.open(@simple_file1)
|
371
371
|
b1.sheet(1)[1,1].Value.should == @old_value
|
372
372
|
end
|
373
373
|
|
374
374
|
it "should open read-only" do
|
375
|
-
|
375
|
+
Workbook.unobtrusively(@simple_file, :read_only => true, :writable => false) do |book|
|
376
376
|
book.ReadOnly.should be true
|
377
377
|
@old_value = book.sheet(1)[1,1].Value
|
378
378
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
379
379
|
book.Saved.should be false
|
380
380
|
end
|
381
381
|
Excel.current.Workbooks.Count.should == 0
|
382
|
-
b1 =
|
382
|
+
b1 = Workbook.open(@simple_file1)
|
383
383
|
b1.sheet(1)[1,1].Value.should == @old_value
|
384
384
|
end
|
385
385
|
|
386
386
|
it "should open not writable" do
|
387
|
-
|
387
|
+
Workbook.unobtrusively(@simple_file, :writable => false) do |book|
|
388
388
|
book.ReadOnly.should be true
|
389
389
|
@old_value = book.sheet(1)[1,1].Value
|
390
390
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
391
391
|
book.Saved.should be false
|
392
392
|
end
|
393
393
|
Excel.current.Workbooks.Count.should == 0
|
394
|
-
b1 =
|
394
|
+
b1 = Workbook.open(@simple_file1)
|
395
395
|
b1.sheet(1)[1,1].Value.should == @old_value
|
396
396
|
end
|
397
397
|
|
398
398
|
it "should raise error if both options are true" do
|
399
399
|
expect{
|
400
|
-
|
400
|
+
Workbook.unobtrusively(@simple_file, :writable => true, :read_only => true) {|book|}
|
401
401
|
}.to raise_error(OptionInvalid, "contradicting options")
|
402
402
|
end
|
403
403
|
end
|
@@ -405,12 +405,12 @@ describe Book do
|
|
405
405
|
context "with open writable book" do
|
406
406
|
|
407
407
|
before do
|
408
|
-
@book =
|
408
|
+
@book = Workbook.open(@simple_file1)
|
409
409
|
@old_value = @book.sheet(1)[1,1].Value
|
410
410
|
end
|
411
411
|
|
412
412
|
it "should open as read-write by default" do
|
413
|
-
|
413
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
414
414
|
book.Readonly.should be false
|
415
415
|
book.should == @book
|
416
416
|
book.filename.should == @book.filename
|
@@ -418,12 +418,12 @@ describe Book do
|
|
418
418
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
419
419
|
end
|
420
420
|
@book.close
|
421
|
-
book2 =
|
421
|
+
book2 = Workbook.open(@simple_file1)
|
422
422
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
423
423
|
end
|
424
424
|
|
425
425
|
it "should open as read-write" do
|
426
|
-
|
426
|
+
Workbook.unobtrusively(@simple_file1, :read_only => false) do |book|
|
427
427
|
book.Readonly.should be false
|
428
428
|
book.should == @book
|
429
429
|
book.filename.should == @book.filename
|
@@ -431,12 +431,12 @@ describe Book do
|
|
431
431
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
432
432
|
end
|
433
433
|
@book.close
|
434
|
-
book2 =
|
434
|
+
book2 = Workbook.open(@simple_file1)
|
435
435
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
436
436
|
end
|
437
437
|
|
438
438
|
it "should open as read-write" do
|
439
|
-
|
439
|
+
Workbook.unobtrusively(@simple_file1, :read_only => false, :writable => false) do |book|
|
440
440
|
book.Readonly.should be false
|
441
441
|
book.should == @book
|
442
442
|
book.filename.should == @book.filename
|
@@ -444,12 +444,12 @@ describe Book do
|
|
444
444
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
445
445
|
end
|
446
446
|
@book.close
|
447
|
-
book2 =
|
447
|
+
book2 = Workbook.open(@simple_file1)
|
448
448
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
449
449
|
end
|
450
450
|
|
451
451
|
it "should open as read-write" do
|
452
|
-
|
452
|
+
Workbook.unobtrusively(@simple_file1, :writable => true) do |book|
|
453
453
|
book.Readonly.should be false
|
454
454
|
book.should == @book
|
455
455
|
book.filename.should == @book.filename
|
@@ -457,12 +457,12 @@ describe Book do
|
|
457
457
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
458
458
|
end
|
459
459
|
@book.close
|
460
|
-
book2 =
|
460
|
+
book2 = Workbook.open(@simple_file1)
|
461
461
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
462
462
|
end
|
463
463
|
|
464
464
|
it "should open as read-write" do
|
465
|
-
|
465
|
+
Workbook.unobtrusively(@simple_file1, :writable => true, :read_only => false) do |book|
|
466
466
|
book.Readonly.should be false
|
467
467
|
book.should == @book
|
468
468
|
book.filename.should == @book.filename
|
@@ -470,12 +470,12 @@ describe Book do
|
|
470
470
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
471
471
|
end
|
472
472
|
@book.close
|
473
|
-
book2 =
|
473
|
+
book2 = Workbook.open(@simple_file1)
|
474
474
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
475
475
|
end
|
476
476
|
|
477
477
|
it "should force to read-only" do
|
478
|
-
|
478
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book|
|
479
479
|
book.ReadOnly.should be true
|
480
480
|
book.should == @book
|
481
481
|
book.filename.should == @book.filename
|
@@ -483,12 +483,12 @@ describe Book do
|
|
483
483
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
484
484
|
end
|
485
485
|
@book.close
|
486
|
-
book2 =
|
486
|
+
book2 = Workbook.open(@simple_file1)
|
487
487
|
book2.sheet(1)[1,1].Value.should == @old_value
|
488
488
|
end
|
489
489
|
|
490
490
|
it "should force to read-only" do
|
491
|
-
|
491
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true, :writable => false) do |book|
|
492
492
|
book.ReadOnly.should be true
|
493
493
|
book.should == @book
|
494
494
|
book.filename.should == @book.filename
|
@@ -496,12 +496,12 @@ describe Book do
|
|
496
496
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
497
497
|
end
|
498
498
|
@book.close
|
499
|
-
book2 =
|
499
|
+
book2 = Workbook.open(@simple_file1)
|
500
500
|
book2.sheet(1)[1,1].Value.should == @old_value
|
501
501
|
end
|
502
502
|
|
503
503
|
it "should open not writable" do
|
504
|
-
|
504
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
505
505
|
book.ReadOnly.should be false
|
506
506
|
book.should == @book
|
507
507
|
book.filename.should == @book.filename
|
@@ -509,7 +509,7 @@ describe Book do
|
|
509
509
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
510
510
|
end
|
511
511
|
@book.close
|
512
|
-
book2 =
|
512
|
+
book2 = Workbook.open(@simple_file1)
|
513
513
|
book2.sheet(1)[1,1].Value.should == @old_value
|
514
514
|
end
|
515
515
|
end
|
@@ -517,27 +517,27 @@ describe Book do
|
|
517
517
|
context "with open read-only book" do
|
518
518
|
|
519
519
|
before do
|
520
|
-
@book =
|
520
|
+
@book = Workbook.open(@simple_file1, :read_only => true)
|
521
521
|
@old_value = @book.sheet(1)[1,1].Value
|
522
522
|
end
|
523
523
|
|
524
524
|
it "should not write" do
|
525
|
-
|
525
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
526
526
|
book.Readonly.should be true
|
527
527
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
528
528
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
529
529
|
end
|
530
530
|
@book.close
|
531
|
-
|
531
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
532
532
|
book.sheet(1)[1,1].Value.should == @old_value
|
533
533
|
end
|
534
534
|
#@book.close
|
535
|
-
#book2 =
|
535
|
+
#book2 = Workbook.open(@simple_file1)
|
536
536
|
#book2.sheet(1)[1,1].Value.should == @old_value
|
537
537
|
end
|
538
538
|
|
539
539
|
it "should not change the read_only mode" do
|
540
|
-
|
540
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
541
541
|
book.Readonly.should be true
|
542
542
|
book.should == @book
|
543
543
|
book.filename.should == @book.filename
|
@@ -545,12 +545,12 @@ describe Book do
|
|
545
545
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
546
546
|
end
|
547
547
|
@book.close
|
548
|
-
book2 =
|
548
|
+
book2 = Workbook.open(@simple_file1)
|
549
549
|
book2.sheet(1)[1,1].Value.should == @old_value
|
550
550
|
end
|
551
551
|
|
552
552
|
it "should open as read-write" do
|
553
|
-
|
553
|
+
Workbook.unobtrusively(@simple_file1, :read_only => false) do |book|
|
554
554
|
book.Readonly.should be true
|
555
555
|
book.should == @book
|
556
556
|
book.filename.should == @book.filename
|
@@ -558,12 +558,12 @@ describe Book do
|
|
558
558
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
559
559
|
end
|
560
560
|
@book.close
|
561
|
-
book2 =
|
561
|
+
book2 = Workbook.open(@simple_file1)
|
562
562
|
book2.sheet(1)[1,1].Value.should == @old_value
|
563
563
|
end
|
564
564
|
|
565
565
|
it "should open as read-write" do
|
566
|
-
|
566
|
+
Workbook.unobtrusively(@simple_file1, :read_only => false, :writable => false) do |book|
|
567
567
|
book.Readonly.should be true
|
568
568
|
book.should == @book
|
569
569
|
book.filename.should == @book.filename
|
@@ -571,12 +571,12 @@ describe Book do
|
|
571
571
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
572
572
|
end
|
573
573
|
@book.close
|
574
|
-
book2 =
|
574
|
+
book2 = Workbook.open(@simple_file1)
|
575
575
|
book2.sheet(1)[1,1].Value.should == @old_value
|
576
576
|
end
|
577
577
|
|
578
578
|
it "should force to read-write" do
|
579
|
-
|
579
|
+
Workbook.unobtrusively(@simple_file1, :writable => true) do |book|
|
580
580
|
book.Readonly.should be false
|
581
581
|
book.should == @book
|
582
582
|
book.filename.should == @book.filename
|
@@ -584,12 +584,12 @@ describe Book do
|
|
584
584
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
585
585
|
end
|
586
586
|
@book.close
|
587
|
-
book2 =
|
587
|
+
book2 = Workbook.open(@simple_file1)
|
588
588
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
589
589
|
end
|
590
590
|
|
591
591
|
it "should force to read-write" do
|
592
|
-
|
592
|
+
Workbook.unobtrusively(@simple_file1, :writable => true, :read_only => false) do |book|
|
593
593
|
book.Readonly.should be false
|
594
594
|
book.should == @book
|
595
595
|
book.filename.should == @book.filename
|
@@ -597,25 +597,25 @@ describe Book do
|
|
597
597
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
598
598
|
end
|
599
599
|
@book.close
|
600
|
-
book2 =
|
600
|
+
book2 = Workbook.open(@simple_file1)
|
601
601
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
602
602
|
end
|
603
603
|
|
604
604
|
it "should force to read-write" do
|
605
605
|
e1 = Excel.create
|
606
|
-
|
606
|
+
Workbook.unobtrusively(@simple_file1, :writable => true, :rw_change_excel => e1) do |book|
|
607
607
|
book.Readonly.should be false
|
608
608
|
book.filename.should == @book.filename
|
609
609
|
book.excel.should == e1
|
610
610
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
611
611
|
end
|
612
612
|
@book.close
|
613
|
-
book2 =
|
613
|
+
book2 = Workbook.open(@simple_file1)
|
614
614
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
615
615
|
end
|
616
616
|
|
617
617
|
it "should force to read-write" do
|
618
|
-
|
618
|
+
Workbook.unobtrusively(@simple_file1, :writable => true, :rw_change_excel => :current) do |book|
|
619
619
|
book.Readonly.should be false
|
620
620
|
book.should == @book
|
621
621
|
book.filename.should == @book.filename
|
@@ -623,24 +623,24 @@ describe Book do
|
|
623
623
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
624
624
|
end
|
625
625
|
@book.close
|
626
|
-
book2 =
|
626
|
+
book2 = Workbook.open(@simple_file1)
|
627
627
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
628
628
|
end
|
629
629
|
|
630
630
|
it "should force to read-write" do
|
631
|
-
|
631
|
+
Workbook.unobtrusively(@simple_file1, :writable => true, :rw_change_excel => :new) do |book|
|
632
632
|
book.Readonly.should be false
|
633
633
|
book.filename.should == @book.filename
|
634
634
|
book.excel.should_not == @book.excel
|
635
635
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
636
636
|
end
|
637
637
|
@book.close
|
638
|
-
book2 =
|
638
|
+
book2 = Workbook.open(@simple_file1)
|
639
639
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
640
640
|
end
|
641
641
|
|
642
642
|
it "should force to read-write" do
|
643
|
-
|
643
|
+
Workbook.unobtrusively(@simple_file1, :writable => true, :read_only => false) do |book|
|
644
644
|
book.Readonly.should be false
|
645
645
|
book.should == @book
|
646
646
|
book.filename.should == @book.filename
|
@@ -648,12 +648,12 @@ describe Book do
|
|
648
648
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
649
649
|
end
|
650
650
|
@book.close
|
651
|
-
book2 =
|
651
|
+
book2 = Workbook.open(@simple_file1)
|
652
652
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
653
653
|
end
|
654
654
|
|
655
655
|
it "should force to read-only" do
|
656
|
-
|
656
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book|
|
657
657
|
book.ReadOnly.should be true
|
658
658
|
book.should == @book
|
659
659
|
book.filename.should == @book.filename
|
@@ -661,12 +661,12 @@ describe Book do
|
|
661
661
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
662
662
|
end
|
663
663
|
@book.close
|
664
|
-
book2 =
|
664
|
+
book2 = Workbook.open(@simple_file1)
|
665
665
|
book2.sheet(1)[1,1].Value.should == @old_value
|
666
666
|
end
|
667
667
|
|
668
668
|
it "should force to read-only" do
|
669
|
-
|
669
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true, :writable => false) do |book|
|
670
670
|
book.ReadOnly.should be true
|
671
671
|
book.should == @book
|
672
672
|
book.filename.should == @book.filename
|
@@ -674,12 +674,12 @@ describe Book do
|
|
674
674
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
675
675
|
end
|
676
676
|
@book.close
|
677
|
-
book2 =
|
677
|
+
book2 = Workbook.open(@simple_file1)
|
678
678
|
book2.sheet(1)[1,1].Value.should == @old_value
|
679
679
|
end
|
680
680
|
|
681
681
|
it "should open not writable" do
|
682
|
-
|
682
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
683
683
|
book.ReadOnly.should be true
|
684
684
|
book.should == @book
|
685
685
|
book.filename.should == @book.filename
|
@@ -687,7 +687,7 @@ describe Book do
|
|
687
687
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
688
688
|
end
|
689
689
|
@book.close
|
690
|
-
book2 =
|
690
|
+
book2 = Workbook.open(@simple_file1)
|
691
691
|
book2.sheet(1)[1,1].Value.should == @old_value
|
692
692
|
end
|
693
693
|
end
|
@@ -695,13 +695,13 @@ describe Book do
|
|
695
695
|
context "with open unsaved writable book" do
|
696
696
|
|
697
697
|
before do
|
698
|
-
@book =
|
698
|
+
@book = Workbook.open(@simple_file1)
|
699
699
|
@book.sheet(1)[1,1] = @book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
700
700
|
@old_value = @book.sheet(1)[1,1].Value
|
701
701
|
end
|
702
702
|
|
703
703
|
it "should open as read-write by default" do
|
704
|
-
|
704
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
705
705
|
book.Readonly.should be false
|
706
706
|
book.should == @book
|
707
707
|
book.filename.should == @book.filename
|
@@ -713,7 +713,7 @@ describe Book do
|
|
713
713
|
end
|
714
714
|
|
715
715
|
it "should open as read-write" do
|
716
|
-
|
716
|
+
Workbook.unobtrusively(@simple_file1, :read_only => false) do |book|
|
717
717
|
book.Readonly.should be false
|
718
718
|
book.should == @book
|
719
719
|
book.filename.should == @book.filename
|
@@ -725,7 +725,7 @@ describe Book do
|
|
725
725
|
end
|
726
726
|
|
727
727
|
it "should open as read-write" do
|
728
|
-
|
728
|
+
Workbook.unobtrusively(@simple_file1, :read_only => false, :writable => false) do |book|
|
729
729
|
book.Readonly.should be false
|
730
730
|
book.should == @book
|
731
731
|
book.filename.should == @book.filename
|
@@ -737,7 +737,7 @@ describe Book do
|
|
737
737
|
end
|
738
738
|
|
739
739
|
it "should force to read-write" do
|
740
|
-
|
740
|
+
Workbook.unobtrusively(@simple_file1, :writable => true) do |book|
|
741
741
|
book.Readonly.should be false
|
742
742
|
book.should == @book
|
743
743
|
book.filename.should == @book.filename
|
@@ -749,7 +749,7 @@ describe Book do
|
|
749
749
|
end
|
750
750
|
|
751
751
|
it "should force to read-write" do
|
752
|
-
|
752
|
+
Workbook.unobtrusively(@simple_file1, :writable => true, :read_only => false) do |book|
|
753
753
|
book.Readonly.should be false
|
754
754
|
book.should == @book
|
755
755
|
book.filename.should == @book.filename
|
@@ -762,18 +762,18 @@ describe Book do
|
|
762
762
|
|
763
763
|
it "should force to read-only (not implemented)" do
|
764
764
|
expect{
|
765
|
-
|
765
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true)
|
766
766
|
}.to raise_error(NotImplementedREOError)
|
767
767
|
end
|
768
768
|
|
769
769
|
it "should force to read-only (not implemented)" do
|
770
770
|
expect{
|
771
|
-
|
771
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true, :writable => false)
|
772
772
|
}.to raise_error(NotImplementedREOError)
|
773
773
|
end
|
774
774
|
|
775
775
|
it "should open not writable" do
|
776
|
-
|
776
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
777
777
|
book.ReadOnly.should be false
|
778
778
|
book.should == @book
|
779
779
|
book.filename.should == @book.filename
|
@@ -783,7 +783,7 @@ describe Book do
|
|
783
783
|
@book.Saved.should be false
|
784
784
|
@book.sheet(1)[1,1].Value.should_not == @old_value
|
785
785
|
@book.close(:if_unsaved => :forget)
|
786
|
-
book2 =
|
786
|
+
book2 = Workbook.open(@simple_file1)
|
787
787
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
788
788
|
end
|
789
789
|
end
|
@@ -791,13 +791,13 @@ describe Book do
|
|
791
791
|
context "with open unsaved read-only book" do
|
792
792
|
|
793
793
|
before do
|
794
|
-
@book =
|
794
|
+
@book = Workbook.open(@simple_file1, :read_only => true)
|
795
795
|
@book.sheet(1)[1,1] = @book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
796
796
|
@old_value = @book.sheet(1)[1,1].Value
|
797
797
|
end
|
798
798
|
|
799
799
|
it "should open as read-only by default" do
|
800
|
-
|
800
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
801
801
|
book.Readonly.should be true
|
802
802
|
book.should == @book
|
803
803
|
book.filename.should == @book.filename
|
@@ -808,12 +808,12 @@ describe Book do
|
|
808
808
|
@book.ReadOnly.should be true
|
809
809
|
@book.sheet(1)[1,1].Value.should_not == @old_value
|
810
810
|
@book.close
|
811
|
-
book2 =
|
811
|
+
book2 = Workbook.open(@simple_file1)
|
812
812
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
813
813
|
end
|
814
814
|
|
815
815
|
it "should open as read-only" do
|
816
|
-
|
816
|
+
Workbook.unobtrusively(@simple_file1, :read_only => false) do |book|
|
817
817
|
book.Readonly.should be true
|
818
818
|
book.should == @book
|
819
819
|
book.filename.should == @book.filename
|
@@ -824,12 +824,12 @@ describe Book do
|
|
824
824
|
@book.ReadOnly.should be true
|
825
825
|
@book.sheet(1)[1,1].Value.should_not == @old_value
|
826
826
|
@book.close
|
827
|
-
book2 =
|
827
|
+
book2 = Workbook.open(@simple_file1)
|
828
828
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
829
829
|
end
|
830
830
|
|
831
831
|
it "should open as read-only" do
|
832
|
-
|
832
|
+
Workbook.unobtrusively(@simple_file1, :read_only => false, :writable => false) do |book|
|
833
833
|
book.Readonly.should be true
|
834
834
|
book.should == @book
|
835
835
|
book.filename.should == @book.filename
|
@@ -840,24 +840,24 @@ describe Book do
|
|
840
840
|
@book.ReadOnly.should be true
|
841
841
|
@book.sheet(1)[1,1].Value.should_not == @old_value
|
842
842
|
@book.close
|
843
|
-
book2 =
|
843
|
+
book2 = Workbook.open(@simple_file1)
|
844
844
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
845
845
|
end
|
846
846
|
|
847
847
|
it "should raise an error" do
|
848
848
|
expect{
|
849
|
-
|
849
|
+
Workbook.unobtrusively(@simple_file1, :writable => true)
|
850
850
|
}.to raise_error(NotImplementedREOError, "unsaved read-only workbook shall be written")
|
851
851
|
end
|
852
852
|
|
853
853
|
it "should raise an error" do
|
854
854
|
expect{
|
855
|
-
|
855
|
+
Workbook.unobtrusively(@simple_file1, :writable => true)
|
856
856
|
}.to raise_error(NotImplementedREOError, "unsaved read-only workbook shall be written")
|
857
857
|
end
|
858
858
|
|
859
859
|
it "should force to read-only" do
|
860
|
-
|
860
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book|
|
861
861
|
book.ReadOnly.should be true
|
862
862
|
book.should == @book
|
863
863
|
book.filename.should == @book.filename
|
@@ -868,12 +868,12 @@ describe Book do
|
|
868
868
|
@book.ReadOnly.should be true
|
869
869
|
@book.sheet(1)[1,1].Value.should_not == @old_value
|
870
870
|
@book.close
|
871
|
-
book2 =
|
871
|
+
book2 = Workbook.open(@simple_file1)
|
872
872
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
873
873
|
end
|
874
874
|
|
875
875
|
it "should force to read-only" do
|
876
|
-
|
876
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true, :writable => false) do |book|
|
877
877
|
book.ReadOnly.should be true
|
878
878
|
book.should == @book
|
879
879
|
book.filename.should == @book.filename
|
@@ -884,12 +884,12 @@ describe Book do
|
|
884
884
|
@book.ReadOnly.should be true
|
885
885
|
@book.sheet(1)[1,1].Value.should_not == @old_value
|
886
886
|
@book.close
|
887
|
-
book2 =
|
887
|
+
book2 = Workbook.open(@simple_file1)
|
888
888
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
889
889
|
end
|
890
890
|
|
891
891
|
it "should open not writable" do
|
892
|
-
|
892
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
893
893
|
book.ReadOnly.should be true
|
894
894
|
book.should == @book
|
895
895
|
book.filename.should == @book.filename
|
@@ -900,7 +900,7 @@ describe Book do
|
|
900
900
|
@book.ReadOnly.should be true
|
901
901
|
@book.sheet(1)[1,1].Value.should_not == @old_value
|
902
902
|
@book.close
|
903
|
-
book2 =
|
903
|
+
book2 = Workbook.open(@simple_file1)
|
904
904
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
905
905
|
end
|
906
906
|
end
|
@@ -912,12 +912,12 @@ describe Book do
|
|
912
912
|
context "with no book" do
|
913
913
|
|
914
914
|
it "should not close the book in the outer block" do
|
915
|
-
|
916
|
-
|
915
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
916
|
+
Workbook.unobtrusively(@simple_file1) do |book2|
|
917
917
|
book2.should == book
|
918
918
|
end
|
919
919
|
book.should be_alive
|
920
|
-
|
920
|
+
Workbook.unobtrusively(@simple_file1) do |book3|
|
921
921
|
book3.should == book
|
922
922
|
end
|
923
923
|
book.should be_alive
|
@@ -925,26 +925,22 @@ describe Book do
|
|
925
925
|
end
|
926
926
|
|
927
927
|
it "should not close the book in the outer block with writable false" do
|
928
|
-
|
929
|
-
|
928
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
929
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book2|
|
930
930
|
book2.should == book
|
931
931
|
end
|
932
932
|
book.should be_alive
|
933
|
-
#Book.unobtrusively(@simple_file1, :writable => false) do |book3|
|
934
|
-
# book3.should == book
|
935
|
-
#end
|
936
|
-
#book.should be_alive
|
937
933
|
end
|
938
934
|
end
|
939
935
|
|
940
936
|
it "should write in the outer and inner block" do
|
941
|
-
|
937
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
942
938
|
@old_value = book.sheet(1)[1,1].Value
|
943
939
|
book.ReadOnly.should be false
|
944
940
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
945
941
|
book.Saved.should be false
|
946
942
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
947
|
-
|
943
|
+
Workbook.unobtrusively(@simple_file1) do |book2|
|
948
944
|
book2.should == book
|
949
945
|
book2.ReadOnly.should be false
|
950
946
|
book2.Saved.should be false
|
@@ -956,19 +952,19 @@ describe Book do
|
|
956
952
|
book.Saved.should be false
|
957
953
|
book.sheet(1)[1,1].Value.should == @old_value
|
958
954
|
end
|
959
|
-
book =
|
955
|
+
book = Workbook.open(@simple_file1)
|
960
956
|
book.sheet(1)[1,1].Value.should == @old_value
|
961
957
|
end
|
962
958
|
|
963
959
|
it "should write in the outer and not in the inner block" do
|
964
960
|
expect{
|
965
|
-
|
961
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
966
962
|
@old_value = book.sheet(1)[1,1].Value
|
967
963
|
book.ReadOnly.should be false
|
968
964
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
969
965
|
book.Saved.should be false
|
970
966
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
971
|
-
|
967
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book2|
|
972
968
|
book2.should == book
|
973
969
|
book2.ReadOnly.should be true
|
974
970
|
#book2.Saved.should be false
|
@@ -980,19 +976,19 @@ describe Book do
|
|
980
976
|
book.Saved.should be false
|
981
977
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
982
978
|
end
|
983
|
-
book =
|
979
|
+
book = Workbook.open(@simple_file1)
|
984
980
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
985
981
|
}.to raise_error(NotImplementedREOError)
|
986
982
|
end
|
987
983
|
|
988
984
|
it "should write in the outer and not in the inner block" do
|
989
|
-
|
985
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
990
986
|
@old_value = book.sheet(1)[1,1].Value
|
991
987
|
book.ReadOnly.should be false
|
992
988
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
993
989
|
book.Saved.should be false
|
994
990
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
995
|
-
|
991
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book2|
|
996
992
|
book2.should == book
|
997
993
|
book2.ReadOnly.should be false
|
998
994
|
book2.Saved.should be false
|
@@ -1004,18 +1000,18 @@ describe Book do
|
|
1004
1000
|
book.Saved.should be false
|
1005
1001
|
book.sheet(1)[1,1].Value.should == @old_value
|
1006
1002
|
end
|
1007
|
-
book =
|
1003
|
+
book = Workbook.open(@simple_file1)
|
1008
1004
|
book.sheet(1)[1,1].Value.should == @old_value
|
1009
1005
|
end
|
1010
1006
|
|
1011
1007
|
it "should be read-only in the outer and write in the inner block" do
|
1012
|
-
|
1008
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book|
|
1013
1009
|
@old_value = book.sheet(1)[1,1].Value
|
1014
1010
|
book.ReadOnly.should be true
|
1015
1011
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
1016
1012
|
book.Saved.should be false
|
1017
1013
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
1018
|
-
|
1014
|
+
Workbook.unobtrusively(@simple_file1) do |book2|
|
1019
1015
|
book2.should == book
|
1020
1016
|
book2.ReadOnly.should be true
|
1021
1017
|
book2.Saved.should be false
|
@@ -1028,7 +1024,7 @@ describe Book do
|
|
1028
1024
|
book.ReadOnly.should be true
|
1029
1025
|
book.sheet(1)[1,1].Value.should == @old_value
|
1030
1026
|
end
|
1031
|
-
book =
|
1027
|
+
book = Workbook.open(@simple_file1)
|
1032
1028
|
book.sheet(1)[1,1].Value.should == @old_value
|
1033
1029
|
end
|
1034
1030
|
|
@@ -1041,15 +1037,15 @@ describe Book do
|
|
1041
1037
|
context "with openess" do
|
1042
1038
|
|
1043
1039
|
it "should remain closed" do
|
1044
|
-
|
1040
|
+
Workbook.unobtrusively(@simple_file) do |book|
|
1045
1041
|
end
|
1046
1042
|
Excel.current.Workbooks.Count.should == 0
|
1047
1043
|
end
|
1048
1044
|
|
1049
1045
|
it "should remain open" do
|
1050
|
-
book1 =
|
1051
|
-
|
1052
|
-
book.should be_a
|
1046
|
+
book1 = Workbook.open(@simple_file1)
|
1047
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1048
|
+
book.should be_a Workbook
|
1053
1049
|
book.should be_alive
|
1054
1050
|
end
|
1055
1051
|
book1.should be_alive
|
@@ -1060,45 +1056,45 @@ describe Book do
|
|
1060
1056
|
context "with writability" do
|
1061
1057
|
|
1062
1058
|
it "should remain read_only" do
|
1063
|
-
book1 =
|
1064
|
-
|
1059
|
+
book1 = Workbook.open(@simple_file1, :read_only => true)
|
1060
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1065
1061
|
end
|
1066
1062
|
book1.ReadOnly.should be true
|
1067
1063
|
end
|
1068
1064
|
|
1069
1065
|
it "should remain writable" do
|
1070
|
-
book1 =
|
1071
|
-
|
1066
|
+
book1 = Workbook.open(@simple_file1, :read_only => false)
|
1067
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1072
1068
|
end
|
1073
1069
|
book1.ReadOnly.should be false
|
1074
1070
|
end
|
1075
1071
|
|
1076
1072
|
it "should write and remain read_only and open the workbook in another Excel" do
|
1077
|
-
book1 =
|
1073
|
+
book1 = Workbook.open(@simple_file1, :read_only => true)
|
1078
1074
|
old_value = book1.sheet(1)[1,1].Value
|
1079
|
-
|
1075
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1080
1076
|
sheet = book.sheet(1)
|
1081
|
-
sheet[1,1] = sheet[1,1].
|
1077
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
1082
1078
|
book.excel.should == book1.excel
|
1083
1079
|
end
|
1084
1080
|
book1.ReadOnly.should be true
|
1085
1081
|
book1.close
|
1086
|
-
book2 =
|
1082
|
+
book2 = Workbook.open(@simple_file1)
|
1087
1083
|
book2.sheet(1)[1,1].Value.should == old_value
|
1088
1084
|
end
|
1089
1085
|
|
1090
1086
|
it "should write and remain read_only and open the workbook in the same Excel" do
|
1091
|
-
book1 =
|
1087
|
+
book1 = Workbook.open(@simple_file1, :read_only => true)
|
1092
1088
|
old_value = book1.sheet(1)[1,1].Value
|
1093
|
-
|
1089
|
+
Workbook.unobtrusively(@simple_file1, :writable => true) do |book|
|
1094
1090
|
book.ReadOnly.should be false
|
1095
1091
|
sheet = book.sheet(1)
|
1096
|
-
sheet[1,1] = sheet[1,1].
|
1092
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
1097
1093
|
book.excel.should == book1.excel
|
1098
1094
|
end
|
1099
1095
|
book1.ReadOnly.should be true
|
1100
1096
|
book1.close
|
1101
|
-
book2 =
|
1097
|
+
book2 = Workbook.open(@simple_file1)
|
1102
1098
|
book2.sheet(1)[1,1].Value.should_not == old_value
|
1103
1099
|
end
|
1104
1100
|
|
@@ -1107,15 +1103,15 @@ describe Book do
|
|
1107
1103
|
context "with visibility" do
|
1108
1104
|
|
1109
1105
|
it "should remain invisible" do
|
1110
|
-
book1 =
|
1111
|
-
|
1106
|
+
book1 = Workbook.open(@simple_file1, :visible => false)
|
1107
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1112
1108
|
end
|
1113
1109
|
book1.excel.Visible.should be false
|
1114
1110
|
end
|
1115
1111
|
|
1116
1112
|
it "should remain visible" do
|
1117
|
-
book1 =
|
1118
|
-
|
1113
|
+
book1 = Workbook.open(@simple_file1, :visible => true)
|
1114
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1119
1115
|
end
|
1120
1116
|
book1.excel.Visible.should be true
|
1121
1117
|
book1.Windows(book1.Name).Visible.should be true
|
@@ -1126,15 +1122,15 @@ describe Book do
|
|
1126
1122
|
context "with check-compatibility" do
|
1127
1123
|
|
1128
1124
|
it "should remain check-compatibility false" do
|
1129
|
-
book1 =
|
1130
|
-
|
1125
|
+
book1 = Workbook.open(@simple_file1, :check_compatibility => false)
|
1126
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1131
1127
|
end
|
1132
1128
|
book1.CheckCompatibility.should be false
|
1133
1129
|
end
|
1134
1130
|
|
1135
1131
|
it "should remain check-compatibility true" do
|
1136
|
-
book1 =
|
1137
|
-
|
1132
|
+
book1 = Workbook.open(@simple_file1, :check_compatibility => true)
|
1133
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1138
1134
|
end
|
1139
1135
|
book1.CheckCompatibility.should be true
|
1140
1136
|
end
|
@@ -1144,23 +1140,23 @@ describe Book do
|
|
1144
1140
|
context "with calculation" do
|
1145
1141
|
|
1146
1142
|
it "should remain the calculation mode" do
|
1147
|
-
book1 =
|
1143
|
+
book1 = Workbook.open(@simple_file1)
|
1148
1144
|
old_calculation = book1.excel.calculation
|
1149
|
-
|
1145
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1150
1146
|
end
|
1151
1147
|
book1.excel.calculation.should == old_calculation
|
1152
1148
|
end
|
1153
1149
|
|
1154
1150
|
it "should remain calculation manual" do
|
1155
|
-
book1 =
|
1156
|
-
|
1151
|
+
book1 = Workbook.open(@simple_file1, :calculation => :manual)
|
1152
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1157
1153
|
end
|
1158
1154
|
book1.excel.Calculation.should == XlCalculationManual
|
1159
1155
|
end
|
1160
1156
|
|
1161
1157
|
it "should remain calculation automatic" do
|
1162
|
-
book1 =
|
1163
|
-
|
1158
|
+
book1 = Workbook.open(@simple_file1, :calculation => :automatic)
|
1159
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1164
1160
|
end
|
1165
1161
|
book1.excel.Calculation.should == XlCalculationAutomatic
|
1166
1162
|
end
|
@@ -1172,8 +1168,8 @@ describe Book do
|
|
1172
1168
|
|
1173
1169
|
it "should open unobtrusively if no Excel is open" do
|
1174
1170
|
Excel.close_all
|
1175
|
-
|
1176
|
-
book.should be_a
|
1171
|
+
Workbook.unobtrusively(@simple_file) do |book|
|
1172
|
+
book.should be_a Workbook
|
1177
1173
|
book.excel.Visible.should be false
|
1178
1174
|
book.CheckCompatibility.should be false
|
1179
1175
|
book.ReadOnly.should be false
|
@@ -1201,15 +1197,15 @@ describe Book do
|
|
1201
1197
|
end
|
1202
1198
|
|
1203
1199
|
it "should open unobtrusively in the first opened Excel" do
|
1204
|
-
|
1200
|
+
Workbook.unobtrusively(@simple_file) do |book|
|
1205
1201
|
book.excel.should == @excel1
|
1206
1202
|
book.excel.should_not == @excel2
|
1207
1203
|
end
|
1208
1204
|
end
|
1209
1205
|
|
1210
1206
|
it "should open unobtrusively in a new Excel" do
|
1211
|
-
|
1212
|
-
book.should be_a
|
1207
|
+
Workbook.unobtrusively(@simple_file, :if_closed => :new) do |book|
|
1208
|
+
book.should be_a Workbook
|
1213
1209
|
book.should be_alive
|
1214
1210
|
book.excel.should_not == @excel1
|
1215
1211
|
book.excel.should_not == @excel2
|
@@ -1217,8 +1213,8 @@ describe Book do
|
|
1217
1213
|
end
|
1218
1214
|
|
1219
1215
|
it "should open unobtrusively in a given Excel" do
|
1220
|
-
|
1221
|
-
book.should be_a
|
1216
|
+
Workbook.unobtrusively(@simple_file, :if_closed => @excel2) do |book|
|
1217
|
+
book.should be_a Workbook
|
1222
1218
|
book.should be_alive
|
1223
1219
|
book.excel.should_not == @excel1
|
1224
1220
|
book.excel.should == @excel2
|
@@ -1229,7 +1225,7 @@ describe Book do
|
|
1229
1225
|
Excel.kill_all
|
1230
1226
|
sleep 2
|
1231
1227
|
expect{
|
1232
|
-
|
1228
|
+
Workbook.unobtrusively(@simple_file, :if_closed => @excel2) do |book|
|
1233
1229
|
book.should be_alive
|
1234
1230
|
end
|
1235
1231
|
}.to_not raise_error
|
@@ -1237,7 +1233,7 @@ describe Book do
|
|
1237
1233
|
|
1238
1234
|
it "should raise an error if the option is invalid" do
|
1239
1235
|
expect{
|
1240
|
-
|
1236
|
+
Workbook.unobtrusively(@simple_file, :if_closed => :invalid_option) do |book|
|
1241
1237
|
end
|
1242
1238
|
}.to raise_error(TypeREOError, "given object is neither an Excel, a Workbook, nor a Win32ole")
|
1243
1239
|
end
|
@@ -1247,7 +1243,7 @@ describe Book do
|
|
1247
1243
|
context "with an open book" do
|
1248
1244
|
|
1249
1245
|
before do
|
1250
|
-
@book =
|
1246
|
+
@book = Workbook.open(@simple_file1)
|
1251
1247
|
end
|
1252
1248
|
|
1253
1249
|
after do
|
@@ -1255,37 +1251,36 @@ describe Book do
|
|
1255
1251
|
@book2.close(:if_unsaved => :forget) rescue nil
|
1256
1252
|
end
|
1257
1253
|
|
1258
|
-
it "should let an open
|
1254
|
+
it "should let an open Workbook open if it has been closed and opened again" do
|
1259
1255
|
@book.close
|
1260
1256
|
@book.reopen
|
1261
|
-
|
1262
|
-
book.should be_a
|
1257
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1258
|
+
book.should be_a Workbook
|
1263
1259
|
book.should be_alive
|
1264
1260
|
book.excel.should == @book.excel
|
1265
1261
|
end
|
1266
1262
|
@book.should be_alive
|
1267
|
-
@book.should be_a
|
1263
|
+
@book.should be_a Workbook
|
1268
1264
|
end
|
1269
1265
|
|
1270
|
-
it "should let an open
|
1271
|
-
book2 =
|
1266
|
+
it "should let an open Workbook open if two books have been opened and one has been closed and opened again" do
|
1267
|
+
book2 = Workbook.open(@different_file, :force_excel => :new)
|
1272
1268
|
@book.close
|
1273
1269
|
book2.close
|
1274
1270
|
@book.reopen
|
1275
|
-
|
1276
|
-
book.should be_a
|
1271
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1272
|
+
book.should be_a Workbook
|
1277
1273
|
book.should be_alive
|
1278
1274
|
book.excel.should == @book.excel
|
1279
1275
|
end
|
1280
1276
|
@book.should be_alive
|
1281
|
-
@book.should be_a
|
1277
|
+
@book.should be_a Workbook
|
1282
1278
|
end
|
1283
1279
|
|
1284
|
-
it "should open in the Excel of the given
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
book.should be_a Book
|
1280
|
+
it "should open in the Excel of the given Workbook" do
|
1281
|
+
@book2 = Workbook.open(@another_simple_file, :force_excel => :new)
|
1282
|
+
Workbook.unobtrusively(@different_file, :if_closed => @book2) do |book|
|
1283
|
+
book.should be_a Workbook
|
1289
1284
|
book.should be_alive
|
1290
1285
|
book.excel.should_not == @book.excel
|
1291
1286
|
book.excel.should == @book2.excel
|
@@ -1296,43 +1291,43 @@ describe Book do
|
|
1296
1291
|
@book.Saved.should be true
|
1297
1292
|
@book.should be_alive
|
1298
1293
|
sheet = @book.sheet(1)
|
1299
|
-
old_cell_value = sheet[1,1].
|
1294
|
+
old_cell_value = sheet[1,1].Value
|
1300
1295
|
unobtrusively_ok?
|
1301
1296
|
@book.Saved.should be true
|
1302
1297
|
@book.should be_alive
|
1303
1298
|
sheet = @book.sheet(1)
|
1304
|
-
sheet[1,1].
|
1299
|
+
sheet[1,1].Value.should_not == old_cell_value
|
1305
1300
|
end
|
1306
1301
|
|
1307
1302
|
it "should let the unsaved book unsaved" do
|
1308
1303
|
sheet = @book.sheet(1)
|
1309
|
-
sheet[1,1] = sheet[1,1].
|
1310
|
-
old_cell_value = sheet[1,1].
|
1304
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
1305
|
+
old_cell_value = sheet[1,1].Value
|
1311
1306
|
@book.Saved.should be false
|
1312
1307
|
unobtrusively_ok?
|
1313
1308
|
@book.should be_alive
|
1314
1309
|
@book.Saved.should be false
|
1315
1310
|
@book.close(:if_unsaved => :forget)
|
1316
|
-
@book2 =
|
1311
|
+
@book2 = Workbook.open(@simple_file1)
|
1317
1312
|
sheet2 = @book2.sheet(1)
|
1318
|
-
sheet2[1,1].
|
1313
|
+
sheet2[1,1].Value.should_not == old_cell_value
|
1319
1314
|
end
|
1320
1315
|
|
1321
1316
|
it "should modify unobtrusively the second, writable book" do
|
1322
|
-
@book2 =
|
1317
|
+
@book2 = Workbook.open(@simple_file1, :force_excel => :new)
|
1323
1318
|
@book.ReadOnly.should be false
|
1324
1319
|
@book2.ReadOnly.should be true
|
1325
1320
|
sheet = @book2.sheet(1)
|
1326
|
-
old_cell_value = sheet[1,1].
|
1327
|
-
sheet[1,1] = sheet[1,1].
|
1321
|
+
old_cell_value = sheet[1,1].Value
|
1322
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
1328
1323
|
unobtrusively_ok?
|
1329
1324
|
@book2.should be_alive
|
1330
1325
|
@book2.Saved.should be false
|
1331
1326
|
@book2.close(:if_unsaved => :forget)
|
1332
1327
|
@book.close
|
1333
|
-
new_book =
|
1328
|
+
new_book = Workbook.open(@simple_file1)
|
1334
1329
|
sheet2 = new_book.sheet(1)
|
1335
|
-
sheet2[1,1].
|
1330
|
+
sheet2[1,1].Value.should_not == old_cell_value
|
1336
1331
|
end
|
1337
1332
|
end
|
1338
1333
|
|
@@ -1340,7 +1335,7 @@ describe Book do
|
|
1340
1335
|
context "with a closed book" do
|
1341
1336
|
|
1342
1337
|
before do
|
1343
|
-
@book =
|
1338
|
+
@book = Workbook.open(@simple_file)
|
1344
1339
|
end
|
1345
1340
|
|
1346
1341
|
after do
|
@@ -1349,12 +1344,12 @@ describe Book do
|
|
1349
1344
|
|
1350
1345
|
it "should let the closed book closed by default" do
|
1351
1346
|
sheet = @book.sheet(1)
|
1352
|
-
old_cell_value = sheet[1,1].
|
1347
|
+
old_cell_value = sheet[1,1].Value
|
1353
1348
|
@book.close
|
1354
1349
|
@book.should_not be_alive
|
1355
1350
|
unobtrusively_ok?
|
1356
1351
|
@book.should_not be_alive
|
1357
|
-
new_book =
|
1352
|
+
new_book = Workbook.open(@simple_file1)
|
1358
1353
|
sheet = new_book.sheet(1)
|
1359
1354
|
sheet[1,1].Value.should_not == old_cell_value
|
1360
1355
|
end
|
@@ -1363,105 +1358,105 @@ describe Book do
|
|
1363
1358
|
it "should use the excel of the book and keep open the book" do
|
1364
1359
|
excel = Excel.new(:reuse => false)
|
1365
1360
|
sheet = @book.sheet(1)
|
1366
|
-
old_cell_value = sheet[1,1].
|
1361
|
+
old_cell_value = sheet[1,1].Value
|
1367
1362
|
@book.close
|
1368
1363
|
@book.should_not be_alive
|
1369
|
-
|
1370
|
-
book.should be_a
|
1364
|
+
Workbook.unobtrusively(@simple_file, :keep_open => true) do |book|
|
1365
|
+
book.should be_a Workbook
|
1371
1366
|
book.excel.should == @book.excel
|
1372
1367
|
book.excel.should_not == excel
|
1373
1368
|
sheet = book.sheet(1)
|
1374
1369
|
cell = sheet[1,1]
|
1375
|
-
sheet[1,1] = cell.
|
1370
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1376
1371
|
book.Saved.should be false
|
1377
1372
|
end
|
1378
1373
|
@book.should be_alive
|
1379
1374
|
@book.close
|
1380
|
-
new_book =
|
1375
|
+
new_book = Workbook.open(@simple_file1)
|
1381
1376
|
sheet = new_book.sheet(1)
|
1382
|
-
sheet[1,1].
|
1377
|
+
sheet[1,1].Value.should_not == old_cell_value
|
1383
1378
|
end
|
1384
1379
|
|
1385
1380
|
# book shall be reanimated
|
1386
1381
|
it "should use the excel of the book and keep open the book" do
|
1387
1382
|
excel = Excel.new(:reuse => false)
|
1388
1383
|
sheet = @book.sheet(1)
|
1389
|
-
old_cell_value = sheet[1,1].
|
1384
|
+
old_cell_value = sheet[1,1].Value
|
1390
1385
|
@book.close
|
1391
1386
|
@book.should_not be_alive
|
1392
|
-
|
1393
|
-
book.should be_a
|
1387
|
+
Workbook.unobtrusively(@simple_file, :if_closed => :new) do |book|
|
1388
|
+
book.should be_a Workbook
|
1394
1389
|
book.should be_alive
|
1395
1390
|
book.excel.should_not == @book.excel
|
1396
1391
|
book.excel.should_not == excel
|
1397
1392
|
sheet = book.sheet(1)
|
1398
1393
|
cell = sheet[1,1]
|
1399
|
-
sheet[1,1] = cell.
|
1394
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1400
1395
|
book.Saved.should be false
|
1401
1396
|
end
|
1402
1397
|
@book.should_not be_alive
|
1403
|
-
new_book =
|
1398
|
+
new_book = Workbook.open(@simple_file1)
|
1404
1399
|
sheet = new_book.sheet(1)
|
1405
|
-
sheet[1,1].
|
1400
|
+
sheet[1,1].Value.should_not == old_cell_value
|
1406
1401
|
end
|
1407
1402
|
|
1408
1403
|
it "should use another excel if the Excels are closed" do
|
1409
1404
|
sheet = @book.sheet(1)
|
1410
|
-
old_cell_value = sheet[1,1].
|
1405
|
+
old_cell_value = sheet[1,1].Value
|
1411
1406
|
@book.close
|
1412
1407
|
@book.should_not be_alive
|
1413
|
-
|
1414
|
-
book.should be_a
|
1408
|
+
Workbook.unobtrusively(@simple_file, :keep_open => true) do |book|
|
1409
|
+
book.should be_a Workbook
|
1415
1410
|
sheet = book.sheet(1)
|
1416
1411
|
cell = sheet[1,1]
|
1417
|
-
sheet[1,1] = cell.
|
1412
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1418
1413
|
book.Saved.should be false
|
1419
1414
|
end
|
1420
1415
|
@book.should be_alive
|
1421
1416
|
@book.close
|
1422
|
-
new_book =
|
1417
|
+
new_book = Workbook.open(@simple_file1)
|
1423
1418
|
sheet = new_book.sheet(1)
|
1424
|
-
sheet[1,1].
|
1419
|
+
sheet[1,1].Value.should_not == old_cell_value
|
1425
1420
|
end
|
1426
1421
|
|
1427
1422
|
it "should use another excel if the Excels are closed" do
|
1428
1423
|
excel = Excel.new(:reuse => false)
|
1429
1424
|
sheet = @book.sheet(1)
|
1430
|
-
old_cell_value = sheet[1,1].
|
1425
|
+
old_cell_value = sheet[1,1].Value
|
1431
1426
|
@book.close
|
1432
1427
|
@book.should_not be_alive
|
1433
1428
|
Excel.kill_all
|
1434
|
-
|
1435
|
-
book.should be_a
|
1429
|
+
Workbook.unobtrusively(@simple_file, :if_closed => :new, :keep_open => true) do |book|
|
1430
|
+
book.should be_a Workbook
|
1436
1431
|
book.excel.should_not == @book.excel
|
1437
1432
|
book.excel.should_not == excel
|
1438
1433
|
sheet = book.sheet(1)
|
1439
1434
|
cell = sheet[1,1]
|
1440
|
-
sheet[1,1] = cell.
|
1435
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1441
1436
|
book.Saved.should be false
|
1442
1437
|
end
|
1443
1438
|
@book.should_not be_alive
|
1444
|
-
new_book =
|
1439
|
+
new_book = Workbook.open(@simple_file1)
|
1445
1440
|
sheet = new_book.sheet(1)
|
1446
|
-
sheet[1,1].
|
1441
|
+
sheet[1,1].Value.should_not == old_cell_value
|
1447
1442
|
end
|
1448
1443
|
|
1449
1444
|
it "should modify unobtrusively the copied file" do
|
1450
1445
|
sheet = @book.sheet(1)
|
1451
|
-
old_cell_value = sheet[1,1].
|
1446
|
+
old_cell_value = sheet[1,1].Value
|
1452
1447
|
File.delete simple_save_file rescue nil
|
1453
1448
|
@book.save_as(@simple_save_file)
|
1454
1449
|
@book.close
|
1455
|
-
|
1450
|
+
Workbook.unobtrusively(@simple_save_file) do |book|
|
1456
1451
|
sheet = book.sheet(1)
|
1457
1452
|
cell = sheet[1,1]
|
1458
1453
|
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1459
1454
|
end
|
1460
|
-
old_book =
|
1455
|
+
old_book = Workbook.open(@simple_file1)
|
1461
1456
|
old_sheet = old_book.sheet(1)
|
1462
1457
|
old_sheet[1,1].Value.should == old_cell_value
|
1463
1458
|
old_book.close
|
1464
|
-
new_book =
|
1459
|
+
new_book = Workbook.open(@simple_save_file)
|
1465
1460
|
new_sheet = new_book.sheet(1)
|
1466
1461
|
new_sheet[1,1].Value.should_not == old_cell_value
|
1467
1462
|
new_book.close
|
@@ -1471,7 +1466,7 @@ describe Book do
|
|
1471
1466
|
context "with a visible book" do
|
1472
1467
|
|
1473
1468
|
before do
|
1474
|
-
@book =
|
1469
|
+
@book = Workbook.open(@simple_file1, :visible => true)
|
1475
1470
|
end
|
1476
1471
|
|
1477
1472
|
after do
|
@@ -1479,15 +1474,15 @@ describe Book do
|
|
1479
1474
|
@book2.close(:if_unsaved => :forget) rescue nil
|
1480
1475
|
end
|
1481
1476
|
|
1482
|
-
it "should let an open
|
1483
|
-
|
1484
|
-
book.should be_a
|
1477
|
+
it "should let an open Workbook open" do
|
1478
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1479
|
+
book.should be_a Workbook
|
1485
1480
|
book.should be_alive
|
1486
1481
|
book.excel.should == @book.excel
|
1487
1482
|
book.excel.Visible.should be true
|
1488
1483
|
end
|
1489
1484
|
@book.should be_alive
|
1490
|
-
@book.should be_a
|
1485
|
+
@book.should be_a Workbook
|
1491
1486
|
@book.excel.Visible.should be true
|
1492
1487
|
end
|
1493
1488
|
|
@@ -1496,14 +1491,14 @@ describe Book do
|
|
1496
1491
|
context "with various options for an Excel instance in which to open a closed book" do
|
1497
1492
|
|
1498
1493
|
before do
|
1499
|
-
@book =
|
1494
|
+
@book = Workbook.open(@simple_file1)
|
1500
1495
|
@book.close
|
1501
1496
|
end
|
1502
1497
|
|
1503
1498
|
it "should use a given Excel" do
|
1504
1499
|
new_excel = Excel.new(:reuse => false)
|
1505
1500
|
another_excel = Excel.new(:reuse => false)
|
1506
|
-
|
1501
|
+
Workbook.unobtrusively(@simple_file1, :if_closed => another_excel) do |book|
|
1507
1502
|
book.excel.should_not == @book.excel
|
1508
1503
|
book.excel.should_not == new_excel
|
1509
1504
|
book.excel.should == another_excel
|
@@ -1512,14 +1507,14 @@ describe Book do
|
|
1512
1507
|
|
1513
1508
|
it "should use another Excel" do
|
1514
1509
|
new_excel = Excel.new(:reuse => false)
|
1515
|
-
|
1510
|
+
Workbook.unobtrusively(@simple_file1, :if_closed => :new) do |book|
|
1516
1511
|
book.excel.should_not == @book.excel
|
1517
1512
|
book.excel.should_not == new_excel
|
1518
1513
|
book.excel.visible.should be false
|
1519
1514
|
book.excel.displayalerts.should == :if_visible
|
1520
1515
|
@another_excel = book.excel
|
1521
1516
|
end
|
1522
|
-
|
1517
|
+
Workbook.unobtrusively(@simple_file1, :if_closed => :reuse) do |book|
|
1523
1518
|
book.excel.should == @book.excel
|
1524
1519
|
book.excel.should_not == new_excel
|
1525
1520
|
book.excel.visible.should be false
|
@@ -1530,7 +1525,7 @@ describe Book do
|
|
1530
1525
|
|
1531
1526
|
it "should reuse Excel" do
|
1532
1527
|
new_excel = Excel.new(:reuse => false)
|
1533
|
-
|
1528
|
+
Workbook.unobtrusively(@simple_file1, :if_closed => :reuse) do |book|
|
1534
1529
|
book.excel.should == @book.excel
|
1535
1530
|
book.excel.should_not == new_excel
|
1536
1531
|
end
|
@@ -1538,7 +1533,7 @@ describe Book do
|
|
1538
1533
|
|
1539
1534
|
it "should reuse Excel by default" do
|
1540
1535
|
new_excel = Excel.new(:reuse => false)
|
1541
|
-
|
1536
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1542
1537
|
book.excel.should == @book.excel
|
1543
1538
|
book.excel.should_not == new_excel
|
1544
1539
|
end
|
@@ -1549,7 +1544,7 @@ describe Book do
|
|
1549
1544
|
context "with a read_only book" do
|
1550
1545
|
|
1551
1546
|
before do
|
1552
|
-
@book =
|
1547
|
+
@book = Workbook.open(@simple_file1, :read_only => true)
|
1553
1548
|
end
|
1554
1549
|
|
1555
1550
|
after do
|
@@ -1560,27 +1555,27 @@ describe Book do
|
|
1560
1555
|
@book.ReadOnly.should be true
|
1561
1556
|
@book.Saved.should be true
|
1562
1557
|
sheet = @book.sheet(1)
|
1563
|
-
old_cell_value = sheet[1,1].
|
1558
|
+
old_cell_value = sheet[1,1].Value
|
1564
1559
|
unobtrusively_ok?
|
1565
1560
|
@book.should be_alive
|
1566
1561
|
@book.Saved.should be true
|
1567
1562
|
@book.ReadOnly.should be true
|
1568
1563
|
@book.close
|
1569
|
-
book2 =
|
1564
|
+
book2 = Workbook.open(@simple_file1)
|
1570
1565
|
sheet2 = book2.sheet(1)
|
1571
|
-
sheet2[1,1].
|
1566
|
+
sheet2[1,1].Value.should == old_cell_value
|
1572
1567
|
end
|
1573
1568
|
|
1574
1569
|
it "should let the unsaved book unsaved" do
|
1575
1570
|
@book.ReadOnly.should be true
|
1576
1571
|
sheet = @book.sheet(1)
|
1577
|
-
sheet[1,1] = sheet[1,1].
|
1572
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
1578
1573
|
@book.Saved.should be false
|
1579
1574
|
@book.should be_alive
|
1580
|
-
|
1581
|
-
book.should be_a
|
1575
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1576
|
+
book.should be_a Workbook
|
1582
1577
|
sheet = book.sheet(1)
|
1583
|
-
sheet[1,1] = sheet[1,1].
|
1578
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
1584
1579
|
@cell_value = sheet[1,1].Value
|
1585
1580
|
book.should be_alive
|
1586
1581
|
book.Saved.should be false
|
@@ -1589,24 +1584,24 @@ describe Book do
|
|
1589
1584
|
@book.Saved.should be false
|
1590
1585
|
@book.ReadOnly.should be true
|
1591
1586
|
@book.close
|
1592
|
-
book2 =
|
1587
|
+
book2 = Workbook.open(@simple_file1)
|
1593
1588
|
sheet2 = book2.sheet(1)
|
1594
1589
|
# modifies unobtrusively the saved version, not the unsaved version
|
1595
|
-
sheet2[1,1].
|
1590
|
+
sheet2[1,1].Value.should == @cell_value
|
1596
1591
|
end
|
1597
1592
|
|
1598
1593
|
it "should open unobtrusively by default the writable book" do
|
1599
|
-
book2 =
|
1594
|
+
book2 = Workbook.open(@simple_file1, :force_excel => :new, :read_only => false)
|
1600
1595
|
@book.ReadOnly.should be true
|
1601
1596
|
book2.Readonly.should be false
|
1602
1597
|
sheet = @book.sheet(1)
|
1603
|
-
cell_value = sheet[1,1].
|
1604
|
-
|
1605
|
-
book.should be_a
|
1598
|
+
cell_value = sheet[1,1].Value
|
1599
|
+
Workbook.unobtrusively(@simple_file1, :if_closed => :new) do |book|
|
1600
|
+
book.should be_a Workbook
|
1606
1601
|
book.excel.should == book2.excel
|
1607
1602
|
book.excel.should_not == @book.excel
|
1608
1603
|
sheet = book.sheet(1)
|
1609
|
-
sheet[1,1] = sheet[1,1].
|
1604
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
1610
1605
|
book.should be_alive
|
1611
1606
|
book.Saved.should be false
|
1612
1607
|
end
|
@@ -1614,29 +1609,29 @@ describe Book do
|
|
1614
1609
|
@book.ReadOnly.should be true
|
1615
1610
|
@book.close
|
1616
1611
|
book2.close
|
1617
|
-
book3 =
|
1612
|
+
book3 = Workbook.open(@simple_file1)
|
1618
1613
|
new_sheet = book3.sheet(1)
|
1619
|
-
new_sheet[1,1].
|
1614
|
+
new_sheet[1,1].Value.should_not == cell_value
|
1620
1615
|
book3.close
|
1621
1616
|
end
|
1622
1617
|
|
1623
1618
|
it "should open unobtrusively the book in a new Excel to open the book writable" do
|
1624
1619
|
excel1 = Excel.new(:reuse => false)
|
1625
1620
|
excel2 = Excel.new(:reuse => false)
|
1626
|
-
book2 =
|
1621
|
+
book2 = Workbook.open(@simple_file1, :force_excel => :new, :read_only => true)
|
1627
1622
|
@book.ReadOnly.should be true
|
1628
1623
|
book2.Readonly.should be true
|
1629
1624
|
sheet = @book.sheet(1)
|
1630
|
-
cell_value = sheet[1,1].
|
1631
|
-
|
1632
|
-
book.should be_a
|
1625
|
+
cell_value = sheet[1,1].Value
|
1626
|
+
Workbook.unobtrusively(@simple_file1, :writable => true, :if_closed => :new, :rw_change_excel => :new) do |book|
|
1627
|
+
book.should be_a Workbook
|
1633
1628
|
book.ReadOnly.should be false
|
1634
1629
|
book.excel.should_not == book2.excel
|
1635
1630
|
book.excel.should_not == @book.excel
|
1636
1631
|
book.excel.should_not == excel1
|
1637
1632
|
book.excel.should_not == excel2
|
1638
1633
|
sheet = book.sheet(1)
|
1639
|
-
sheet[1,1] = sheet[1,1].
|
1634
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
1640
1635
|
book.should be_alive
|
1641
1636
|
book.Saved.should be false
|
1642
1637
|
end
|
@@ -1644,26 +1639,26 @@ describe Book do
|
|
1644
1639
|
@book.ReadOnly.should be true
|
1645
1640
|
@book.close
|
1646
1641
|
book2.close
|
1647
|
-
book3 =
|
1642
|
+
book3 = Workbook.open(@simple_file1)
|
1648
1643
|
new_sheet = book3.sheet(1)
|
1649
|
-
new_sheet[1,1].
|
1644
|
+
new_sheet[1,1].Value.should_not == cell_value
|
1650
1645
|
book3.close
|
1651
1646
|
end
|
1652
1647
|
|
1653
1648
|
it "should open unobtrusively the book in the same Excel to open the book writable" do
|
1654
1649
|
excel1 = Excel.new(:reuse => false)
|
1655
1650
|
excel2 = Excel.new(:reuse => false)
|
1656
|
-
book2 =
|
1651
|
+
book2 = Workbook.open(@simple_file1, :force_excel => :new, :read_only => true)
|
1657
1652
|
@book.ReadOnly.should be true
|
1658
1653
|
book2.Readonly.should be true
|
1659
1654
|
sheet = @book.sheet(1)
|
1660
|
-
cell_value = sheet[1,1].
|
1661
|
-
|
1662
|
-
book.should be_a
|
1655
|
+
cell_value = sheet[1,1].Value
|
1656
|
+
Workbook.unobtrusively(@simple_file1, :writable => true, :if_closed => :new, :rw_change_excel => :current) do |book|
|
1657
|
+
book.should be_a Workbook
|
1663
1658
|
book.excel.should == book2.excel
|
1664
1659
|
book.ReadOnly.should be false
|
1665
1660
|
sheet = book.sheet(1)
|
1666
|
-
sheet[1,1] = sheet[1,1].
|
1661
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
1667
1662
|
book.should be_alive
|
1668
1663
|
book.Saved.should be false
|
1669
1664
|
end
|
@@ -1671,20 +1666,20 @@ describe Book do
|
|
1671
1666
|
book2.ReadOnly.should be true
|
1672
1667
|
@book.close
|
1673
1668
|
book2.close
|
1674
|
-
book3 =
|
1669
|
+
book3 = Workbook.open(@simple_file1)
|
1675
1670
|
new_sheet = book3.sheet(1)
|
1676
|
-
new_sheet[1,1].
|
1671
|
+
new_sheet[1,1].Value.should_not == cell_value
|
1677
1672
|
book3.close
|
1678
1673
|
end
|
1679
1674
|
|
1680
1675
|
it "should open unobtrusively the book in the Excel where it was opened most recently" do
|
1681
|
-
book2 =
|
1676
|
+
book2 = Workbook.open(@simple_file1, :force_excel => :new, :read_only => true)
|
1682
1677
|
@book.ReadOnly.should be true
|
1683
1678
|
book2.Readonly.should be true
|
1684
1679
|
sheet = @book.sheet(1)
|
1685
|
-
cell_value = sheet[1,1].
|
1686
|
-
|
1687
|
-
book.should be_a
|
1680
|
+
cell_value = sheet[1,1].Value
|
1681
|
+
Workbook.unobtrusively(@simple_file1, :if_closed => :new, :read_only => true) do |book|
|
1682
|
+
book.should be_a Workbook
|
1688
1683
|
book.excel.should == book2.excel
|
1689
1684
|
book.excel.should_not == @book.excel
|
1690
1685
|
book.should be_alive
|
@@ -1698,9 +1693,9 @@ describe Book do
|
|
1698
1693
|
|
1699
1694
|
end
|
1700
1695
|
|
1701
|
-
context "with a virgin
|
1696
|
+
context "with a virgin Workbook class" do
|
1702
1697
|
before do
|
1703
|
-
class
|
1698
|
+
class Workbook
|
1704
1699
|
@@bookstore = nil
|
1705
1700
|
end
|
1706
1701
|
end
|
@@ -1711,10 +1706,10 @@ describe Book do
|
|
1711
1706
|
|
1712
1707
|
context "with a book never opened before" do
|
1713
1708
|
before do
|
1714
|
-
class
|
1709
|
+
class Workbook
|
1715
1710
|
@@bookstore = nil
|
1716
1711
|
end
|
1717
|
-
other_book =
|
1712
|
+
other_book = Workbook.open(@different_file)
|
1718
1713
|
end
|
1719
1714
|
it "should open the book" do
|
1720
1715
|
expect{ unobtrusively_ok? }.to_not raise_error
|
@@ -1724,7 +1719,7 @@ describe Book do
|
|
1724
1719
|
context "with a saved book" do
|
1725
1720
|
|
1726
1721
|
before do
|
1727
|
-
@book1 =
|
1722
|
+
@book1 = Workbook.open(@simple_file1)
|
1728
1723
|
end
|
1729
1724
|
|
1730
1725
|
after do
|
@@ -1733,12 +1728,12 @@ describe Book do
|
|
1733
1728
|
|
1734
1729
|
it "should save if the book was modified during unobtrusively" do
|
1735
1730
|
m_time = File.mtime(@book1.stored_filename)
|
1736
|
-
|
1731
|
+
Workbook.unobtrusively(@simple_file1, :if_closed => :new) do |book|
|
1737
1732
|
@book1.Saved.should be true
|
1738
1733
|
book.Saved.should be true
|
1739
1734
|
sheet = book.sheet(1)
|
1740
1735
|
cell = sheet[1,1]
|
1741
|
-
sheet[1,1] = cell.
|
1736
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1742
1737
|
@book1.Saved.should be false
|
1743
1738
|
book.Saved.should be false
|
1744
1739
|
sleep 1
|
@@ -1750,7 +1745,7 @@ describe Book do
|
|
1750
1745
|
|
1751
1746
|
it "should not save the book if it was not modified during unobtrusively" do
|
1752
1747
|
m_time = File.mtime(@book1.stored_filename)
|
1753
|
-
|
1748
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1754
1749
|
@book1.Saved.should be true
|
1755
1750
|
book.Saved.should be true
|
1756
1751
|
sleep 1
|
@@ -1762,7 +1757,7 @@ describe Book do
|
|
1762
1757
|
|
1763
1758
|
context "with block result" do
|
1764
1759
|
before do
|
1765
|
-
@book1 =
|
1760
|
+
@book1 = Workbook.open(@simple_file1)
|
1766
1761
|
end
|
1767
1762
|
|
1768
1763
|
after do
|
@@ -1771,7 +1766,7 @@ describe Book do
|
|
1771
1766
|
|
1772
1767
|
it "should yield the block result true" do
|
1773
1768
|
result =
|
1774
|
-
|
1769
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1775
1770
|
@book1.Saved.should be true
|
1776
1771
|
end
|
1777
1772
|
result.should == true
|
@@ -1779,18 +1774,18 @@ describe Book do
|
|
1779
1774
|
|
1780
1775
|
it "should yield the block result nil" do
|
1781
1776
|
result =
|
1782
|
-
|
1777
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1783
1778
|
end
|
1784
1779
|
result.should == nil
|
1785
1780
|
end
|
1786
1781
|
|
1787
1782
|
it "should yield the block result with an unmodified book" do
|
1788
1783
|
sheet1 = @book1.sheet(1)
|
1789
|
-
cell1 = sheet1[1,1].
|
1784
|
+
cell1 = sheet1[1,1].Value
|
1790
1785
|
result =
|
1791
|
-
|
1786
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1792
1787
|
sheet = book.sheet(1)
|
1793
|
-
cell = sheet[1,1].
|
1788
|
+
cell = sheet[1,1].Value
|
1794
1789
|
end
|
1795
1790
|
result.should == cell1
|
1796
1791
|
end
|
@@ -1799,7 +1794,7 @@ describe Book do
|
|
1799
1794
|
sheet1 = @book1.sheet(1)
|
1800
1795
|
@book1.save
|
1801
1796
|
result =
|
1802
|
-
|
1797
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1803
1798
|
sheet = book.sheet(1)
|
1804
1799
|
sheet[1,1] = 22
|
1805
1800
|
@book1.Saved.should be false
|
@@ -1813,12 +1808,12 @@ describe Book do
|
|
1813
1808
|
context "with several Excel instances" do
|
1814
1809
|
|
1815
1810
|
before do
|
1816
|
-
@book1 =
|
1817
|
-
@book2 =
|
1811
|
+
@book1 = Workbook.open(@simple_file1)
|
1812
|
+
@book2 = Workbook.open(@simple_file1, :force_excel => :new)
|
1818
1813
|
@book1.Readonly.should == false
|
1819
1814
|
@book2.Readonly.should == true
|
1820
1815
|
old_sheet = @book1.sheet(1)
|
1821
|
-
@old_cell_value = old_sheet[1,1].
|
1816
|
+
@old_cell_value = old_sheet[1,1].Value
|
1822
1817
|
@book1.close
|
1823
1818
|
@book2.close
|
1824
1819
|
@book1.should_not be_alive
|
@@ -1826,47 +1821,47 @@ describe Book do
|
|
1826
1821
|
end
|
1827
1822
|
|
1828
1823
|
it "should open unobtrusively the closed book in the most recent Excel where it was open before" do
|
1829
|
-
|
1824
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
1830
1825
|
book.excel.should_not == @book2.excel
|
1831
1826
|
book.excel.should == @book1.excel
|
1832
1827
|
book.ReadOnly.should == false
|
1833
1828
|
sheet = book.sheet(1)
|
1834
1829
|
cell = sheet[1,1]
|
1835
|
-
sheet[1,1] = cell.
|
1830
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1836
1831
|
book.Saved.should be false
|
1837
1832
|
end
|
1838
|
-
new_book =
|
1833
|
+
new_book = Workbook.open(@simple_file1)
|
1839
1834
|
sheet = new_book.sheet(1)
|
1840
|
-
sheet[1,1].
|
1835
|
+
sheet[1,1].Value.should_not == @old_cell_value
|
1841
1836
|
end
|
1842
1837
|
|
1843
1838
|
it "should open unobtrusively the closed book in the new Excel" do
|
1844
|
-
|
1839
|
+
Workbook.unobtrusively(@simple_file1, :if_closed => :new) do |book|
|
1845
1840
|
book.excel.should_not == @book2.excel
|
1846
1841
|
book.excel.should_not == @book1.excel
|
1847
1842
|
book.ReadOnly.should == false
|
1848
1843
|
sheet = book.sheet(1)
|
1849
1844
|
cell = sheet[1,1]
|
1850
|
-
sheet[1,1] = cell.
|
1845
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1851
1846
|
book.Saved.should be false
|
1852
1847
|
end
|
1853
|
-
new_book =
|
1848
|
+
new_book = Workbook.open(@simple_file1)
|
1854
1849
|
sheet = new_book.sheet(1)
|
1855
1850
|
sheet[1,1].Value.should_not == @old_cell_value
|
1856
1851
|
end
|
1857
1852
|
|
1858
1853
|
it "should open unobtrusively the closed book in a new Excel if the Excel is not alive anymore" do
|
1859
1854
|
Excel.kill_all
|
1860
|
-
|
1855
|
+
Workbook.unobtrusively(@simple_file1, :if_closed => :new) do |book|
|
1861
1856
|
book.ReadOnly.should == false
|
1862
1857
|
book.excel.should_not == @book1.excel
|
1863
1858
|
book.excel.should_not == @book2.excel
|
1864
1859
|
sheet = book.sheet(1)
|
1865
1860
|
cell = sheet[1,1]
|
1866
|
-
sheet[1,1] = cell.
|
1861
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1867
1862
|
book.Saved.should be false
|
1868
1863
|
end
|
1869
|
-
new_book =
|
1864
|
+
new_book = Workbook.open(@simple_file1)
|
1870
1865
|
sheet = new_book.sheet(1)
|
1871
1866
|
sheet[1,1].Value.should_not == @old_cell_value
|
1872
1867
|
end
|
@@ -1878,24 +1873,24 @@ describe Book do
|
|
1878
1873
|
context "open unobtrusively for reading and modifying" do
|
1879
1874
|
|
1880
1875
|
before do
|
1881
|
-
@book =
|
1876
|
+
@book = Workbook.open(@simple_file1)
|
1882
1877
|
sheet = @book.sheet(1)
|
1883
|
-
@old_cell_value = sheet[1,1].
|
1878
|
+
@old_cell_value = sheet[1,1].Value
|
1884
1879
|
@book.close
|
1885
1880
|
end
|
1886
1881
|
|
1887
1882
|
it "should not change the value" do
|
1888
|
-
|
1889
|
-
book.should be_a
|
1883
|
+
Workbook.for_reading(@simple_file1) do |book|
|
1884
|
+
book.should be_a Workbook
|
1890
1885
|
book.should be_alive
|
1891
1886
|
book.Saved.should be true
|
1892
1887
|
sheet = book.sheet(1)
|
1893
1888
|
cell = sheet[1,1]
|
1894
|
-
sheet[1,1] = cell.
|
1889
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1895
1890
|
book.Saved.should be false
|
1896
1891
|
book.excel.should == @book.excel
|
1897
1892
|
end
|
1898
|
-
new_book =
|
1893
|
+
new_book = Workbook.open(@simple_file1, :visible => true)
|
1899
1894
|
sheet = new_book.sheet(1)
|
1900
1895
|
sheet[1,1].Value.should == @old_cell_value
|
1901
1896
|
end
|
@@ -1903,41 +1898,41 @@ describe Book do
|
|
1903
1898
|
it "should not change the value and use a given Excel" do
|
1904
1899
|
new_excel = Excel.new(:reuse => false)
|
1905
1900
|
another_excel = Excel.new(:reuse => false)
|
1906
|
-
|
1901
|
+
Workbook.for_reading(@simple_file1, :if_closed => another_excel) do |book|
|
1907
1902
|
sheet = book.sheet(1)
|
1908
1903
|
cell = sheet[1,1]
|
1909
|
-
sheet[1,1] = cell.
|
1904
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1910
1905
|
book.excel.should == another_excel
|
1911
1906
|
end
|
1912
|
-
new_book =
|
1907
|
+
new_book = Workbook.open(@simple_file1, :visible => true)
|
1913
1908
|
sheet = new_book.sheet(1)
|
1914
1909
|
sheet[1,1].Value.should == @old_cell_value
|
1915
1910
|
end
|
1916
1911
|
|
1917
1912
|
it "should not change the value and use the new Excel instance" do
|
1918
1913
|
new_excel = Excel.new(:reuse => false)
|
1919
|
-
|
1914
|
+
Workbook.for_reading(@simple_file1, :if_closed => :new) do |book|
|
1920
1915
|
sheet = book.sheet(1)
|
1921
1916
|
cell = sheet[1,1]
|
1922
|
-
sheet[1,1] = cell.
|
1917
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1923
1918
|
book.excel.should_not == @book.excel
|
1924
1919
|
book.excel.should_not == new_excel
|
1925
1920
|
book.excel.visible.should be false
|
1926
1921
|
book.excel.displayalerts.should == :if_visible
|
1927
1922
|
end
|
1928
|
-
new_book =
|
1923
|
+
new_book = Workbook.open(@simple_file1, :visible => true)
|
1929
1924
|
sheet = new_book.sheet(1)
|
1930
1925
|
sheet[1,1].Value.should == @old_cell_value
|
1931
1926
|
end
|
1932
1927
|
|
1933
1928
|
it "should change the value" do
|
1934
|
-
|
1929
|
+
Workbook.for_modifying(@simple_file1) do |book|
|
1935
1930
|
sheet = book.sheet(1)
|
1936
1931
|
cell = sheet[1,1]
|
1937
|
-
sheet[1,1] = cell.
|
1932
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1938
1933
|
book.excel.should == @book.excel
|
1939
1934
|
end
|
1940
|
-
new_book =
|
1935
|
+
new_book = Workbook.open(@simple_file, :visible => true)
|
1941
1936
|
sheet = new_book.sheet(1)
|
1942
1937
|
sheet[1,1].Value.should_not == @old_cell_value
|
1943
1938
|
end
|
@@ -1945,29 +1940,29 @@ describe Book do
|
|
1945
1940
|
it "should change the value and use a given Excel" do
|
1946
1941
|
new_excel = Excel.new(:reuse => false)
|
1947
1942
|
another_excel = Excel.new(:reuse => false)
|
1948
|
-
|
1943
|
+
Workbook.for_modifying(@simple_file1, :if_closed => another_excel) do |book|
|
1949
1944
|
sheet = book.sheet(1)
|
1950
1945
|
cell = sheet[1,1]
|
1951
|
-
sheet[1,1] = cell.
|
1946
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1952
1947
|
book.excel.should == another_excel
|
1953
1948
|
end
|
1954
|
-
new_book =
|
1949
|
+
new_book = Workbook.open(@simple_file1, :visible => true)
|
1955
1950
|
sheet = new_book.sheet(1)
|
1956
1951
|
sheet[1,1].Value.should_not == @old_cell_value
|
1957
1952
|
end
|
1958
1953
|
|
1959
1954
|
it "should change the value and use the new Excel instance" do
|
1960
1955
|
new_excel = Excel.new(:reuse => false)
|
1961
|
-
|
1956
|
+
Workbook.for_modifying(@simple_file1, :if_closed => :new) do |book|
|
1962
1957
|
sheet = book.sheet(1)
|
1963
1958
|
cell = sheet[1,1]
|
1964
|
-
sheet[1,1] = cell.
|
1959
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1965
1960
|
book.excel.should_not == @book.excel
|
1966
1961
|
book.excel.should_not == new_excel
|
1967
1962
|
book.excel.visible.should be false
|
1968
1963
|
book.excel.displayalerts.should == :if_visible
|
1969
1964
|
end
|
1970
|
-
new_book =
|
1965
|
+
new_book = Workbook.open(@simple_file1, :visible => true)
|
1971
1966
|
sheet = new_book.sheet(1)
|
1972
1967
|
sheet[1,1].Value.should_not == @old_cell_value
|
1973
1968
|
end
|