robust_excel_ole 1.10 → 1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +8 -0
- data/README.rdoc +6 -4
- data/docs/README_open.rdoc +18 -13
- data/lib/robust_excel_ole/bookstore.rb +95 -9
- data/lib/robust_excel_ole/excel.rb +12 -7
- data/lib/robust_excel_ole/general.rb +20 -7
- data/lib/robust_excel_ole/range.rb +6 -0
- data/lib/robust_excel_ole/reo_common.rb +8 -0
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +201 -165
- data/lib/robust_excel_ole/worksheet.rb +6 -0
- data/spec/bookstore_spec.rb +92 -2
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/excel_spec.rb +86 -3
- data/spec/range_spec.rb +12 -0
- data/spec/workbook_spec.rb +56 -3
- data/spec/workbook_specs/workbook_open_spec.rb +332 -195
- data/spec/workbook_specs/workbook_unobtr_spec.rb +41 -1
- data/spec/worksheet_spec.rb +14 -0
- metadata +2 -2
@@ -180,6 +180,12 @@ module RobustExcelOle
|
|
180
180
|
RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(integer_range.min, col), @ole_worksheet.Cells(integer_range.max, col)))
|
181
181
|
end
|
182
182
|
|
183
|
+
def == other_worksheet
|
184
|
+
other_worksheet.is_a?(Worksheet) &&
|
185
|
+
self.workbook == other_worksheet.workbook &&
|
186
|
+
self.Name == other_worksheet.Name
|
187
|
+
end
|
188
|
+
|
183
189
|
# @private
|
184
190
|
def self.workbook_class
|
185
191
|
@workbook_class ||= begin
|
data/spec/bookstore_spec.rb
CHANGED
@@ -54,6 +54,11 @@ describe Bookstore do
|
|
54
54
|
@simple_file_other_path = @dir + '/more_data/workbook.xls'
|
55
55
|
@simple_file1 = @simple_file
|
56
56
|
@different_file1 = @different_file
|
57
|
+
|
58
|
+
@file_path = "spec/data/workbook.xls"
|
59
|
+
@absolute_file_path = "C:/gim/ats/aSrc/gems/robust_excel_ole/spec/data/workbook.xls"
|
60
|
+
@network_path = "N:/data/workbook.xls"
|
61
|
+
@hostname_share_path = "DESKTOP-A3C5CJ6/spec/workbook.xls"
|
57
62
|
end
|
58
63
|
|
59
64
|
after do
|
@@ -125,11 +130,96 @@ describe Bookstore do
|
|
125
130
|
end
|
126
131
|
end
|
127
132
|
|
128
|
-
|
129
133
|
end
|
130
134
|
|
131
|
-
|
132
135
|
describe "fetch" do
|
136
|
+
|
137
|
+
before do
|
138
|
+
@file_path = "spec/data/workbook.xls"
|
139
|
+
@absolute_file_path = "C:/gim/ats/aSrc/gems/robust_excel_ole/spec/data/workbook.xls"
|
140
|
+
@network_path = "N:/data/workbook.xls"
|
141
|
+
@hostname_share_path = "//DESKTOP-A3C5CJ6/spec/data/workbook.xls"
|
142
|
+
@network_path_not_existing = "M:/data/workbook.xls"
|
143
|
+
@hostname_not_existing_share_path = "//DESKTOP_not_existing/spec/data/workbook.xls"
|
144
|
+
@hostname_share_not_existing_path = "//DESKTOP-A3C5CJ6/spec_not_existing/data/workbook.xls"
|
145
|
+
end
|
146
|
+
|
147
|
+
context "with stored network and hostname share path" do
|
148
|
+
|
149
|
+
it "should fetch to a given network path file the stored hostname_share_path file" do
|
150
|
+
@book1 = Workbook.open(@hostname_share_path)
|
151
|
+
@bookstore.store(@book1)
|
152
|
+
new_book = @bookstore.fetch(@network_path)
|
153
|
+
new_book.should be_a Workbook
|
154
|
+
new_book.should be_alive
|
155
|
+
new_book.should == @book1
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should not fetch anything to a not existing network path file" do
|
159
|
+
@book1 = Workbook.open(@hostname_share_path)
|
160
|
+
@bookstore.store(@book1)
|
161
|
+
@bookstore.fetch(@network_path_not_existing).should == nil
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should fetch to a given network path file the stored absolute path file" do
|
165
|
+
@book1 = Workbook.open(@absolute_file_path)
|
166
|
+
@bookstore.store(@book1)
|
167
|
+
new_book = @bookstore.fetch(@network_path)
|
168
|
+
new_book.should be_a Workbook
|
169
|
+
new_book.should be_alive
|
170
|
+
new_book.should == @book1
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should not fetch anything to a not existing network path file the stored absolute path file" do
|
174
|
+
@book1 = Workbook.open(@absolute_file_path)
|
175
|
+
@bookstore.store(@book1)
|
176
|
+
@bookstore.fetch(@network_path_not_existing).should == nil
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should fetch to a given hostname share path file the stored network path file" do
|
180
|
+
@book1 = Workbook.open(@network_path)
|
181
|
+
@bookstore.store(@book1)
|
182
|
+
new_book = @bookstore.fetch(@hostname_share_path)
|
183
|
+
new_book.should be_a Workbook
|
184
|
+
new_book.should be_alive
|
185
|
+
new_book.should == @book1
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should fetch to a given hostname_share_path the stored absolute path file" do
|
189
|
+
@book1 = Workbook.open(@absolute_file_path)
|
190
|
+
@bookstore.store(@book1)
|
191
|
+
new_book = @bookstore.fetch(@hostname_share_path)
|
192
|
+
new_book.should be_a Workbook
|
193
|
+
new_book.should be_alive
|
194
|
+
new_book.should == @book1
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should not fetch anything to a given hostname share path file" do
|
198
|
+
@book1 = Workbook.open(@absolute_file_path)
|
199
|
+
@bookstore.store(@book1)
|
200
|
+
@bookstore.fetch(@hostname_not_existing_share_path).should == nil
|
201
|
+
@bookstore.fetch(@hostname_share_not_existing_path).should == nil
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should fetch to a given absolute path file the stored network path file" do
|
205
|
+
@book1 = Workbook.open(@network_path)
|
206
|
+
@bookstore.store(@book1)
|
207
|
+
new_book = @bookstore.fetch(@absolute_file_path)
|
208
|
+
new_book.should be_a Workbook
|
209
|
+
new_book.should be_alive
|
210
|
+
new_book.should == @book1
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should fetch to a given absolute path file the stored hostname share file" do
|
214
|
+
@book1 = Workbook.open(@hostname_share_path)
|
215
|
+
@bookstore.store(@book1)
|
216
|
+
new_book = @bookstore.fetch(@absolute_file_path)
|
217
|
+
new_book.should be_a Workbook
|
218
|
+
new_book.should be_alive
|
219
|
+
new_book.should == @book1
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
133
223
|
|
134
224
|
context "with one open book" do
|
135
225
|
|
Binary file
|
data/spec/excel_spec.rb
CHANGED
@@ -30,6 +30,80 @@ module RobustExcelOle
|
|
30
30
|
rm_tmp(@dir)
|
31
31
|
end
|
32
32
|
|
33
|
+
context "with connect and preserving options" do
|
34
|
+
|
35
|
+
before do
|
36
|
+
@ole_excel = WIN32OLE.new('Excel.Application')
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should preserve visible false" do
|
40
|
+
@ole_excel.Visible.should be false
|
41
|
+
excel = Excel.current
|
42
|
+
excel.Hwnd.should == @ole_excel.Hwnd
|
43
|
+
excel.Visible.should be false
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should preserve visible true" do
|
47
|
+
@ole_excel.Visible = true
|
48
|
+
@ole_excel.Visible.should be true
|
49
|
+
excel = Excel.current
|
50
|
+
excel.Hwnd.should == @ole_excel.Hwnd
|
51
|
+
excel.Visible.should be true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should set visible true" do
|
55
|
+
@ole_excel.Visible.should be false
|
56
|
+
excel = Excel.current(:visible => true)
|
57
|
+
excel.Visible.should be true
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should set visible false" do
|
61
|
+
excel = Excel.current(:visible => false)
|
62
|
+
excel.Visible.should be false
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should set visible false, even if it was true before" do
|
66
|
+
@ole_excel.Visible = true
|
67
|
+
@ole_excel.Visible.should be true
|
68
|
+
excel = Excel.current(:visible => false)
|
69
|
+
excel.Visible.should be false
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should preserve displayalerts true" do
|
73
|
+
@ole_excel.DisplayAlerts.should be true
|
74
|
+
excel = Excel.current
|
75
|
+
excel.Hwnd.should == @ole_excel.Hwnd
|
76
|
+
excel.DisplayAlerts.should be true
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should preserve displayalerts false" do
|
80
|
+
@ole_excel.DisplayAlerts = false
|
81
|
+
@ole_excel.DisplayAlerts.should be false
|
82
|
+
excel = Excel.current
|
83
|
+
excel.DisplayAlerts.should be false
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should set displayalerts true" do
|
87
|
+
@ole_excel.DisplayAlerts.should be true
|
88
|
+
excel = Excel.current(:displayalerts => true)
|
89
|
+
excel.DisplayAlerts.should be true
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should set displayalerts true, even if false before" do
|
93
|
+
@ole_excel.DisplayAlerts = false
|
94
|
+
@ole_excel.DisplayAlerts.should be false
|
95
|
+
excel = Excel.current(:displayalerts => true)
|
96
|
+
excel.DisplayAlerts.should be true
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should set displayalerts false" do
|
100
|
+
@ole_excel.DisplayAlerts.should be true
|
101
|
+
excel = Excel.current(:displayalerts => false)
|
102
|
+
excel.DisplayAlerts.should be false
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
33
107
|
context "with already open Excel instances and an open unsaved workbook" do
|
34
108
|
|
35
109
|
before do
|
@@ -196,6 +270,13 @@ module RobustExcelOle
|
|
196
270
|
@excel = @book.excel
|
197
271
|
end
|
198
272
|
|
273
|
+
it "lifts an Excel instance given as WIN32OLE object and has same Hwnd" do
|
274
|
+
app = WIN32OLE.new('Excel.Application')
|
275
|
+
ole_excel = WIN32OLE.connect("Excel.Application")
|
276
|
+
reo_excel = Excel.new(ole_excel)
|
277
|
+
ole_excel.Hwnd.should == reo_excel.Hwnd
|
278
|
+
end
|
279
|
+
|
199
280
|
it "lifts an Excel instance given as WIN32Ole object" do
|
200
281
|
win32ole_excel = WIN32OLE.connect(@book.ole_workbook.Fullname).Application
|
201
282
|
excel = Excel.new(win32ole_excel)
|
@@ -1726,6 +1807,8 @@ module RobustExcelOle
|
|
1726
1807
|
@excel.Visible.should be true
|
1727
1808
|
@excel.ScreenUpdating.should be true
|
1728
1809
|
book = Workbook.open(@simple_file)
|
1810
|
+
book.excel.calculation = :manual
|
1811
|
+
book.save
|
1729
1812
|
@excel.Calculation.should == XlCalculationManual
|
1730
1813
|
book.close
|
1731
1814
|
end
|
@@ -2043,10 +2126,10 @@ module RobustExcelOle
|
|
2043
2126
|
it "should raise an error if name cannot be evaluated" do
|
2044
2127
|
expect{
|
2045
2128
|
@excel1.set_namevalue_glob("foo", 1)
|
2046
|
-
}.to raise_error(
|
2129
|
+
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo"/)
|
2047
2130
|
expect{
|
2048
2131
|
@excel1["foo"] = 1
|
2049
|
-
}.to raise_error(
|
2132
|
+
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo"/)
|
2050
2133
|
end
|
2051
2134
|
|
2052
2135
|
it "should color the cell" do
|
@@ -2110,7 +2193,7 @@ module RobustExcelOle
|
|
2110
2193
|
it "should raise an error if name cannot be evaluated" do
|
2111
2194
|
expect{
|
2112
2195
|
@excel1.set_namevalue_glob("foo", 1)
|
2113
|
-
}.to raise_error(
|
2196
|
+
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo" in/)
|
2114
2197
|
end
|
2115
2198
|
|
2116
2199
|
it "should color the cell" do
|
data/spec/range_spec.rb
CHANGED
@@ -313,6 +313,18 @@ describe RobustExcelOle::Range do
|
|
313
313
|
|
314
314
|
end
|
315
315
|
|
316
|
+
describe "==" do
|
317
|
+
|
318
|
+
it "should return true for identical ranges" do
|
319
|
+
@sheet.range([1..2,3..4]).should == @sheet.range([1..2,3..4])
|
320
|
+
end
|
321
|
+
|
322
|
+
it "should return false for non-identical ranges" do
|
323
|
+
@sheet.range([3..4,1..2]).should_not == @sheet.range([1..2,3..4])
|
324
|
+
end
|
325
|
+
|
326
|
+
end
|
327
|
+
|
316
328
|
describe "#method_missing" do
|
317
329
|
it "can access COM method" do
|
318
330
|
@range.Range(@range.Cells.Item(1), @range.Cells.Item(3)).v.should eq [@range.values(0..2)]
|
data/spec/workbook_spec.rb
CHANGED
@@ -71,6 +71,7 @@ describe Workbook do
|
|
71
71
|
|
72
72
|
it "should save a file, if it is open" do
|
73
73
|
@book = Workbook.open(@simple_file)
|
74
|
+
@sheet = @book.sheet(1)
|
74
75
|
@book.add_sheet(@sheet, :as => 'a_name')
|
75
76
|
@new_sheet_count = @book.ole_workbook.Worksheets.Count
|
76
77
|
expect {
|
@@ -82,6 +83,7 @@ describe Workbook do
|
|
82
83
|
|
83
84
|
it "should not save a file, if it is not open" do
|
84
85
|
@book = Workbook.open(@simple_file)
|
86
|
+
@sheet = @book.sheet(1)
|
85
87
|
@book.add_sheet(@sheet, :as => 'a_name')
|
86
88
|
@new_sheet_count = @book.ole_workbook.Worksheets.Count
|
87
89
|
@book.close(:if_unsaved => :forget)
|
@@ -446,6 +448,56 @@ describe Workbook do
|
|
446
448
|
end
|
447
449
|
end
|
448
450
|
|
451
|
+
context "with :if_blocked" do
|
452
|
+
|
453
|
+
for i in 1..2 do
|
454
|
+
|
455
|
+
context "with and without reopen" do
|
456
|
+
|
457
|
+
before do
|
458
|
+
if i == 1 then
|
459
|
+
book_before = Workbook.open(@simple_file)
|
460
|
+
book_before.close
|
461
|
+
end
|
462
|
+
@book = Workbook.open(@simple_file_other_path1)
|
463
|
+
@sheet_count = @book.ole_workbook.Worksheets.Count
|
464
|
+
@sheet = @book.sheet(1)
|
465
|
+
@book.add_sheet(@sheet, :as => 'a_name')
|
466
|
+
end
|
467
|
+
|
468
|
+
after do
|
469
|
+
@book.close(:if_unsaved => :forget)
|
470
|
+
@new_book.close rescue nil
|
471
|
+
end
|
472
|
+
|
473
|
+
it "should save the old book, close it, and open the new book, if :if_blocked is :save" do
|
474
|
+
@new_book = Workbook.open(@simple_file1, :if_blocked => :save)
|
475
|
+
@book.should_not be_alive
|
476
|
+
@new_book.should be_alive
|
477
|
+
@new_book.filename.downcase.should == @simple_file1.downcase
|
478
|
+
old_book = Workbook.open(@simple_file_other_path1, :if_blocked => :forget)
|
479
|
+
old_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
|
480
|
+
old_book.close
|
481
|
+
end
|
482
|
+
|
483
|
+
it "should raise an error, if the old book is unsaved, and close the old book and open the new book,
|
484
|
+
if :if_blocked is :close_if_saved" do
|
485
|
+
expect{
|
486
|
+
@new_book = Workbook.open(@simple_file1, :if_blocked => :close_if_saved)
|
487
|
+
}.to raise_error(WorkbookBlocked, /workbook with the same name in a different path is unsaved/)
|
488
|
+
@book.save
|
489
|
+
@new_book = Workbook.open(@simple_file1, :if_blocked => :close_if_saved)
|
490
|
+
@book.should_not be_alive
|
491
|
+
@new_book.should be_alive
|
492
|
+
@new_book.filename.downcase.should == @simple_file1.downcase
|
493
|
+
old_book = Workbook.open(@simple_file_other_path1, :if_blocked => :forget)
|
494
|
+
old_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
|
495
|
+
old_book.close
|
496
|
+
end
|
497
|
+
end
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
449
501
|
context "with :if_obstructed" do
|
450
502
|
|
451
503
|
for i in 1..2 do
|
@@ -520,8 +572,8 @@ describe Workbook do
|
|
520
572
|
File.delete @simple_save_file rescue nil
|
521
573
|
expect {
|
522
574
|
Workbook.open(@simple_save_file)
|
523
|
-
}.to raise_error(FileNotFound,
|
524
|
-
|
575
|
+
}.to raise_error(FileNotFound, /not found/ )
|
576
|
+
# "\nHint: If you want to create a new file, use option :if_absent => :create or Workbook::create")
|
525
577
|
end
|
526
578
|
end
|
527
579
|
|
@@ -618,7 +670,8 @@ describe Workbook do
|
|
618
670
|
|
619
671
|
it "should preserve :visible if they are not set" do
|
620
672
|
excel1 = Excel.create(:visible => true)
|
621
|
-
book1 = Workbook.open(@
|
673
|
+
book1 = Workbook.open(@simple_file, :default => {:excel => :new})
|
674
|
+
book1.excel.should_not == excel1
|
622
675
|
book1.excel.Visible.should be false
|
623
676
|
end
|
624
677
|
|
@@ -25,12 +25,15 @@ describe Workbook do
|
|
25
25
|
@simple_file_other_path = @dir + '/more_data/workbook.xls'
|
26
26
|
@another_simple_file = @dir + '/another_workbook.xls'
|
27
27
|
@linked_file = @dir + '/workbook_linked.xlsm'
|
28
|
-
@simple_file_xlsm = @dir + '/workbook.
|
28
|
+
@simple_file_xlsm = @dir + '/workbook.xlsm'
|
29
29
|
@simple_file_xlsx = @dir + '/workbook.xlsx'
|
30
30
|
@simple_file1 = @simple_file
|
31
31
|
@different_file1 = @different_file
|
32
32
|
@simple_file_other_path1 = @simple_file_other_path
|
33
33
|
@another_simple_file1 = @another_simple_file
|
34
|
+
@simple_file_direct = File.join(File.dirname(__FILE__), 'data') + '/workbook.xls'
|
35
|
+
@simple_file_via_network = File.join('N:/', 'data') + '/workbook.xls'
|
36
|
+
|
34
37
|
end
|
35
38
|
|
36
39
|
after do
|
@@ -38,13 +41,176 @@ describe Workbook do
|
|
38
41
|
rm_tmp(@dir)
|
39
42
|
end
|
40
43
|
|
44
|
+
describe "connecting to unknown workbooks" do
|
45
|
+
|
46
|
+
context "with none workbook" do
|
47
|
+
|
48
|
+
it "should open one new Excel with the worbook" do
|
49
|
+
book1 = Workbook.open(@simple_file1)
|
50
|
+
book1.should be_alive
|
51
|
+
book1.should be_a Workbook
|
52
|
+
Excel.excels_number.should == 1
|
53
|
+
book1.ReadOnly.should be false
|
54
|
+
book1.excel.Visible.should be false
|
55
|
+
book1.CheckCompatibility.should be false
|
56
|
+
book1.Saved.should be true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should set the options" do
|
60
|
+
book1 = Workbook.open(@simple_file1, :force => {:visible => true}, :check_compatibility => true)
|
61
|
+
book1.visible.should be true
|
62
|
+
book1.CheckCompatibility.should be true
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should open in the given known Excel" do
|
66
|
+
excel1 = Excel.create
|
67
|
+
book1 = Workbook.open(@simple_file1)
|
68
|
+
book1.should be_alive
|
69
|
+
book1.should be_a Workbook
|
70
|
+
book1.excel.should == excel1
|
71
|
+
Excel.excels_number.should == 1
|
72
|
+
book1.excel.Visible.should be false
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should open in the given known visible Excel" do
|
76
|
+
excel1 = Excel.create(:visible => true)
|
77
|
+
book1 = Workbook.open(@simple_file1)
|
78
|
+
book1.should be_alive
|
79
|
+
book1.should be_a Workbook
|
80
|
+
book1.excel.should == excel1
|
81
|
+
Excel.excels_number.should == 1
|
82
|
+
book1.excel.Visible.should be true
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should open in the given known Excel" do
|
86
|
+
excel1 = Excel.create
|
87
|
+
book1 = Workbook.open(@simple_file1, :force => {:excel => :new})
|
88
|
+
book1.should be_alive
|
89
|
+
book1.should be_a Workbook
|
90
|
+
book1.excel.should_not == excel1
|
91
|
+
Excel.excels_number.should == 2
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should set the options in a given known Excel" do
|
95
|
+
excel1 = Excel.create
|
96
|
+
book1 = Workbook.open(@simple_file1, :force => {:visible => true}, :check_compatibility => true)
|
97
|
+
book1.visible.should be true
|
98
|
+
book1.CheckCompatibility.should be true
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should open the workbook in the given Excel if there are only unknown Excels" do
|
102
|
+
ole_excel1 = WIN32OLE.new('Excel.Application')
|
103
|
+
book1 = Workbook.open(@simple_file1)
|
104
|
+
book1.should be_alive
|
105
|
+
book1.should be_a Workbook
|
106
|
+
Excel.excels_number.should == 1
|
107
|
+
book1.excel.ole_excel.Hwnd.should == ole_excel1.Hwnd
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
context "with one unknown workbook" do
|
113
|
+
|
114
|
+
before do
|
115
|
+
ole_e1 = WIN32OLE.new('Excel.Application')
|
116
|
+
ws = ole_e1.Workbooks
|
117
|
+
abs_filename = General.absolute_path(@simple_file1).tr('/','\\')
|
118
|
+
@ole_wb = ws.Open(abs_filename)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should connect to an unknown workbook" do
|
122
|
+
Workbook.open(@simple_file1) do |book|
|
123
|
+
book.filename.should == @simple_file1
|
124
|
+
book.should be_alive
|
125
|
+
book.should be_a Workbook
|
126
|
+
book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should raise error when connecting to a blocking workbook with :if_blocked => :raise" do
|
131
|
+
expect{
|
132
|
+
Workbook.open(@simple_file_other_path1)
|
133
|
+
}.to raise_error(WorkbookBlocked, /blocked by/)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should close the blocking workbook and open the new workbook with :if_blocked => :forget" do
|
137
|
+
new_book = Workbook.open(@simple_file_other_path1, :if_blocked => :forget)
|
138
|
+
expect{
|
139
|
+
@ole_wb.Name
|
140
|
+
}.to raise_error
|
141
|
+
new_book.should be_alive
|
142
|
+
new_book.should be_a Workbook
|
143
|
+
new_book.Fullname.should == General.absolute_path(@simple_file_other_path1)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should let the workbook open, if :if_unsaved is :raise" do
|
147
|
+
@ole_wb.Worksheets.Add
|
148
|
+
expect{
|
149
|
+
new_book = Workbook.open(@simple_file1, :if_unsaved => :raise)
|
150
|
+
}.to raise_error(WorkbookNotSaved, /workbook is already open but not saved: "workbook.xls"/)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should let the workbook open, if :if_unsaved is :accept" do
|
154
|
+
@ole_wb.Worksheets.Add
|
155
|
+
sheet_num = @ole_wb.Worksheets.Count
|
156
|
+
new_book = Workbook.open(@simple_file1, :if_unsaved => :accept)
|
157
|
+
new_book.should be_alive
|
158
|
+
new_book.should be_a Workbook
|
159
|
+
new_book.Worksheets.Count.should == sheet_num
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should close the workbook, if :if_unsaved is :forget" do
|
163
|
+
@ole_wb.Worksheets.Add
|
164
|
+
sheet_num = @ole_wb.Worksheets.Count
|
165
|
+
new_book = Workbook.open(@simple_file1, :if_unsaved => :forget)
|
166
|
+
new_book.should be_alive
|
167
|
+
new_book.should be_a Workbook
|
168
|
+
new_book.Worksheets.Count.should == sheet_num - 1
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
context "with several unknown workbooks" do
|
174
|
+
|
175
|
+
before do
|
176
|
+
ole_e1 = WIN32OLE.new('Excel.Application')
|
177
|
+
ws1 = ole_e1.Workbooks
|
178
|
+
abs_filename1 = General.absolute_path(@simple_file1).tr('/','\\')
|
179
|
+
@ole_wb1 = ws1.Open(abs_filename1)
|
180
|
+
ole_e2 = WIN32OLE.new('Excel.Application')
|
181
|
+
ws2 = ole_e2.Workbooks
|
182
|
+
abs_filename2 = General.absolute_path(@different_file1).tr('/','\\')
|
183
|
+
@ole_wb2 = ws2.Open(abs_filename2)
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should connect to the 1st unknown workbook in the 1st Excel instance" do
|
187
|
+
Workbook.open(@simple_file1) do |book|
|
188
|
+
book.filename.should == @simple_file1
|
189
|
+
book.excel.ole_excel.Hwnd.should == @ole_wb1.Application.Hwnd
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should connect to the 2nd unknown workbook in the 2nd Excel instance" do
|
194
|
+
Workbook.open(@different_file1) do |book|
|
195
|
+
book.filename.should == @different_file1
|
196
|
+
book.excel.ole_excel.Hwnd.should == @ole_wb2.Application.Hwnd
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
end
|
205
|
+
|
41
206
|
describe "with already open Excel instances and an open unsaved workbook" do
|
42
207
|
|
43
208
|
before do
|
44
209
|
@ole_excel1 = WIN32OLE.new('Excel.Application')
|
45
210
|
@ole_excel2 = WIN32OLE.new('Excel.Application')
|
46
211
|
#@ole_workbook1 = @ole_excel1.Workbooks.Open(@simple_file1, { 'ReadOnly' => false })
|
47
|
-
|
212
|
+
abs_filename = General.absolute_path(@simple_file1).tr('/','\\')
|
213
|
+
@ole_workbook1 = @ole_excel1.Workbooks.Open(abs_filename, nil, false)
|
48
214
|
@ole_workbook1.Worksheets.Add
|
49
215
|
end
|
50
216
|
|
@@ -65,7 +231,7 @@ describe Workbook do
|
|
65
231
|
end
|
66
232
|
|
67
233
|
it "should fetch the workbook" do
|
68
|
-
new_book = Workbook.new(@ole_workbook1)
|
234
|
+
new_book = Workbook.new(@ole_workbook1, :if_unsaved => :forget)
|
69
235
|
new_book.should be_a Workbook
|
70
236
|
new_book.should be_alive
|
71
237
|
new_book.ole_workbook.should == @ole_workbook1
|
@@ -146,16 +312,16 @@ describe Workbook do
|
|
146
312
|
end
|
147
313
|
end
|
148
314
|
|
149
|
-
context "with :
|
315
|
+
context "with :if_blocked" do
|
150
316
|
|
151
|
-
it "should raise an error, if :
|
317
|
+
it "should raise an error, if :if_blocked is :raise" do
|
152
318
|
expect {
|
153
319
|
new_book = Workbook.open(@simple_file_other_path1)
|
154
|
-
}.to raise_error(WorkbookBlocked, /blocked by
|
320
|
+
}.to raise_error(WorkbookBlocked, /blocked by/)
|
155
321
|
end
|
156
322
|
|
157
|
-
it "should close the other book and open the new book, if :
|
158
|
-
new_book = Workbook.open(@simple_file_other_path1, :
|
323
|
+
it "should close the other book and open the new book, if :if_blocked is :forget" do
|
324
|
+
new_book = Workbook.open(@simple_file_other_path1, :if_blocked => :forget)
|
159
325
|
expect{
|
160
326
|
@ole_workbook1.Name
|
161
327
|
}.to raise_error
|
@@ -186,20 +352,81 @@ describe Workbook do
|
|
186
352
|
|
187
353
|
end
|
188
354
|
|
355
|
+
describe "network paths" do
|
356
|
+
|
357
|
+
it "should open the workbokk via network path" do
|
358
|
+
book1 = Workbook.open(@simple_file)
|
359
|
+
expect{
|
360
|
+
book2 = Workbook.open(@simple_file_via_network)
|
361
|
+
}.to_not raise_error
|
362
|
+
book1.should === book2
|
363
|
+
book1.Fullname.should == book2.Fullname
|
364
|
+
end
|
365
|
+
|
366
|
+
end
|
367
|
+
|
189
368
|
describe "new" do
|
190
369
|
|
191
|
-
|
370
|
+
context "with transparency identity" do
|
371
|
+
|
372
|
+
before do
|
373
|
+
@book = Workbook.open(@simple_file1)
|
374
|
+
abs_filename = General.absolute_path(@simple_file1).tr('/','\\')
|
375
|
+
@ole_book = WIN32OLE.connect(abs_filename)
|
376
|
+
end
|
377
|
+
|
378
|
+
after do
|
379
|
+
@book.close
|
380
|
+
end
|
381
|
+
|
382
|
+
it "should yield identical Workbook objects for identical Excel books after uplifting" do
|
383
|
+
book2 = Workbook.new(@ole_book)
|
384
|
+
book2.should === @book
|
385
|
+
book2.close
|
386
|
+
end
|
387
|
+
|
388
|
+
it "should yield different Workbook objects for different Excel books" do
|
389
|
+
book3 = Workbook.open(@different_file1)
|
390
|
+
abs_filename2 = General.absolute_path(@different_file1).tr('/','\\')
|
391
|
+
ole_book2 = WIN32OLE.connect(abs_filename2)
|
392
|
+
book2 = Workbook.new(ole_book2)
|
393
|
+
book2.should_not === @book
|
394
|
+
book2.close
|
395
|
+
book3.close
|
396
|
+
end
|
397
|
+
|
398
|
+
end
|
399
|
+
|
400
|
+
it "should simply create a new workbook given a file" do
|
192
401
|
book = Workbook.new(@simple_file)
|
193
402
|
book.should be_alive
|
194
403
|
book.should be_a Workbook
|
195
404
|
end
|
196
405
|
|
197
|
-
it "should set
|
198
|
-
book = Workbook.new(@simple_file, :visible => true
|
406
|
+
it "should create a new workbook given a file and set it visible" do
|
407
|
+
book = Workbook.new(@simple_file, :visible => true)
|
199
408
|
book.should be_alive
|
200
409
|
book.should be_a Workbook
|
201
410
|
book.excel.Visible.should be true
|
202
411
|
book.Windows(book.Name).Visible.should be true
|
412
|
+
end
|
413
|
+
|
414
|
+
it "should create a new workbook given a file and set it visible and readonly" do
|
415
|
+
book = Workbook.new(@simple_file, :visible => true, :read_only => true)
|
416
|
+
book.should be_alive
|
417
|
+
book.should be_a Workbook
|
418
|
+
book.excel.Visible.should be true
|
419
|
+
book.Windows(book.Name).Visible.should be true
|
420
|
+
book.ReadOnly.should be true
|
421
|
+
end
|
422
|
+
|
423
|
+
it "should create a new workbook given a file and set options" do
|
424
|
+
book = Workbook.new(@simple_file, :visible => true, :read_only => true, :force => {:excel => :new})
|
425
|
+
book.should be_alive
|
426
|
+
book.should be_a Workbook
|
427
|
+
book.excel.Visible.should be true
|
428
|
+
book.Windows(book.Name).
|
429
|
+
Visible.should be true
|
203
430
|
book.ReadOnly.should be true
|
204
431
|
book2 = Workbook.new(@different_file, :force => {:excel => :new}, :v => true)
|
205
432
|
book2.should be_alive
|
@@ -210,6 +437,83 @@ describe Workbook do
|
|
210
437
|
book2.excel.should_not == book.excel
|
211
438
|
end
|
212
439
|
|
440
|
+
it "should uplift an open known workbook" do
|
441
|
+
book = Workbook.open(@simple_file)
|
442
|
+
ole_workbook = book.ole_workbook
|
443
|
+
new_book = Workbook.new(ole_workbook)
|
444
|
+
new_book.should == book
|
445
|
+
new_book.Fullname.should == book.Fullname
|
446
|
+
new_book.excel.should == book.excel
|
447
|
+
end
|
448
|
+
|
449
|
+
it "should uplift an open known workbook and let it be visible" do
|
450
|
+
book = Workbook.open(@simple_file, :visible => true)
|
451
|
+
ole_workbook = book.ole_workbook
|
452
|
+
new_book = Workbook.new(ole_workbook)
|
453
|
+
new_book.should == book
|
454
|
+
new_book.Fullname.should == book.Fullname
|
455
|
+
new_book.excel.should == book.excel
|
456
|
+
new_book.excel.Visible.should == true
|
457
|
+
new_book.Windows(new_book.ole_workbook.Name).Visible.should == true
|
458
|
+
end
|
459
|
+
|
460
|
+
it "should uplift an open known workbook and let it be visible and readonly" do
|
461
|
+
book = Workbook.open(@simple_file, :visible => true, :read_only => true)
|
462
|
+
ole_workbook = book.ole_workbook
|
463
|
+
new_book = Workbook.new(ole_workbook)
|
464
|
+
new_book.should == book
|
465
|
+
new_book.Fullname.should == book.Fullname
|
466
|
+
new_book.excel.should == book.excel
|
467
|
+
new_book.excel.Visible.should == true
|
468
|
+
new_book.Windows(new_book.ole_workbook.Name).Visible.should == true
|
469
|
+
new_book.ReadOnly.should == true
|
470
|
+
end
|
471
|
+
|
472
|
+
it "should uplift an open known workbook and make it visible" do
|
473
|
+
book = Workbook.open(@simple_file)
|
474
|
+
ole_workbook = book.ole_workbook
|
475
|
+
new_book = Workbook.new(ole_workbook, :visible => true)
|
476
|
+
new_book.should == book
|
477
|
+
new_book.Fullname.should == book.Fullname
|
478
|
+
new_book.excel.should == book.excel
|
479
|
+
new_book.excel.Visible.should == true
|
480
|
+
new_book.Windows(new_book.ole_workbook.Name).Visible.should == true
|
481
|
+
end
|
482
|
+
|
483
|
+
it "should uplift an open unknown workbook" do
|
484
|
+
ole_excel = WIN32OLE.new('Excel.Application')
|
485
|
+
ws = ole_excel.Workbooks
|
486
|
+
abs_filename = General.absolute_path(@simple_file1).tr('/','\\')
|
487
|
+
ole_workbook = ws.Open(abs_filename)
|
488
|
+
new_book = Workbook.new(ole_workbook)
|
489
|
+
new_book.Fullname.should == ole_workbook.Fullname
|
490
|
+
new_book.excel.Hwnd.should == ole_excel.Hwnd
|
491
|
+
end
|
492
|
+
|
493
|
+
it "should uplift an open unknown workbook and make it visible" do
|
494
|
+
ole_excel = WIN32OLE.new('Excel.Application')
|
495
|
+
ws = ole_excel.Workbooks
|
496
|
+
abs_filename = General.absolute_path(@simple_file1).tr('/','\\')
|
497
|
+
ole_workbook = ws.Open(abs_filename)
|
498
|
+
new_book = Workbook.new(ole_workbook, :visible => true)
|
499
|
+
new_book.Fullname.should == ole_workbook.Fullname
|
500
|
+
new_book.excel.Hwnd.should == ole_excel.Hwnd
|
501
|
+
new_book.excel.Visible.should == true
|
502
|
+
new_book.Windows(new_book.ole_workbook.Name).Visible.should == true
|
503
|
+
end
|
504
|
+
|
505
|
+
it "should uplift an open unknown workbook and make it visible and readonly" do
|
506
|
+
ole_excel = WIN32OLE.new('Excel.Application')
|
507
|
+
ws = ole_excel.Workbooks
|
508
|
+
abs_filename = General.absolute_path(@simple_file1).tr('/','\\')
|
509
|
+
ole_workbook = ws.Open(abs_filename)
|
510
|
+
new_book = Workbook.new(ole_workbook, :visible => true)
|
511
|
+
new_book.Fullname.should == ole_workbook.Fullname
|
512
|
+
new_book.excel.Hwnd.should == ole_excel.Hwnd
|
513
|
+
new_book.excel.Visible.should == true
|
514
|
+
new_book.Windows(new_book.ole_workbook.Name).Visible.should == true
|
515
|
+
end
|
516
|
+
|
213
517
|
end
|
214
518
|
|
215
519
|
describe "open" do
|
@@ -545,48 +849,6 @@ describe Workbook do
|
|
545
849
|
@book.close rescue nil
|
546
850
|
end
|
547
851
|
|
548
|
-
it "should open not in the reserved Excel instance" do
|
549
|
-
Excel.kill_all
|
550
|
-
sleep 1
|
551
|
-
book2 = Workbook.open(@simple_file1, :force => {:excel => :reserved_new})
|
552
|
-
Excel.current.should_not == book2.excel
|
553
|
-
book3 = Workbook.open(@different_file1, :default => {:excel => :current})
|
554
|
-
book3.excel.should_not == book2.excel
|
555
|
-
book4 = Workbook.open(@another_simple_file1, :default => {:excel => :new})
|
556
|
-
book4.excel.should_not == book2.excel
|
557
|
-
book4.close
|
558
|
-
sleep 1
|
559
|
-
book5 = Workbook.open(@another_simple_file1, :default => {:excel => :reserved_new})
|
560
|
-
book5.excel.should_not == book2.excel
|
561
|
-
end
|
562
|
-
|
563
|
-
it "should open in the reserved Excel instance" do
|
564
|
-
excel1 = @book.excel
|
565
|
-
@book.close
|
566
|
-
book2 = Workbook.open(@simple_file1, :force => {:excel => :reserved_new})
|
567
|
-
book2.excel.should_not == excel1
|
568
|
-
end
|
569
|
-
|
570
|
-
it "should open in the reserved Excel instance" do
|
571
|
-
book2 = Workbook.open(@simple_file1, :force => {:excel => :reserved_new})
|
572
|
-
book3 = Workbook.open(@different_file1, :force => {:excel => :reserved_new})
|
573
|
-
book4 = Workbook.open(@another_simple_file1, :force => {:excel => :new})
|
574
|
-
book5 = Workbook.open(@another_simple_file1, :force => {:excel => :current})
|
575
|
-
book2.excel.should_not == @book.excel
|
576
|
-
book3.excel.should_not == book2.excel
|
577
|
-
book4.excel.should_not == @book.excel
|
578
|
-
book4.excel.should_not == book2.excel
|
579
|
-
book5.excel.should == @book.excel
|
580
|
-
end
|
581
|
-
|
582
|
-
it "should open in the reserved Excel instance" do
|
583
|
-
book2 = Workbook.open(@another_simple_file1, :force => {:excel => :new})
|
584
|
-
book3 = Workbook.open(@different_file1, :force => {:excel => :reserved_new})
|
585
|
-
book2.excel.should_not == @book.excel
|
586
|
-
book3.excel.should_not == @book.excel
|
587
|
-
book3.excel.should_not == book2.excel
|
588
|
-
end
|
589
|
-
|
590
852
|
it "should open in a given Excel provided as Excel, Workbook, or WIN32OLE representing an Excel or Workbook" do
|
591
853
|
book2 = Workbook.open(@another_simple_file)
|
592
854
|
book3 = Workbook.open(@different_file)
|
@@ -1057,112 +1319,6 @@ describe Workbook do
|
|
1057
1319
|
@book.close rescue nil
|
1058
1320
|
end
|
1059
1321
|
|
1060
|
-
context "with :default => {:excel => :reserved_new}" do
|
1061
|
-
|
1062
|
-
it "should open in the reserved Excel instance" do
|
1063
|
-
book3 = Workbook.open(@different_file1, :default => {:excel => :reserved_new})
|
1064
|
-
book3.excel.should_not == @book.excel
|
1065
|
-
end
|
1066
|
-
|
1067
|
-
it "should open in separate Excel instances" do
|
1068
|
-
Excel.kill_all
|
1069
|
-
sleep 1
|
1070
|
-
book2 = Workbook.open(@simple_file1, :default => {:excel => :reserved_new})
|
1071
|
-
book3 = Workbook.open(@different_file1, :default => {:excel => :reserved_new})
|
1072
|
-
book2.excel.should_not == book3.excel
|
1073
|
-
book4 = Workbook.open(@another_simple_file1, :default => {:excel => :current})
|
1074
|
-
book4.excel.should_not == book2.excel
|
1075
|
-
book4.excel.should_not == book3.excel
|
1076
|
-
end
|
1077
|
-
|
1078
|
-
it "should use the open book" do
|
1079
|
-
book2 = Workbook.open(@simple_file1, :default => {:excel => :reserved_new})
|
1080
|
-
book2.excel.should == @book.excel
|
1081
|
-
book2.should be_alive
|
1082
|
-
book2.should be_a Workbook
|
1083
|
-
book2.should == @book
|
1084
|
-
book2.close
|
1085
|
-
end
|
1086
|
-
|
1087
|
-
it "should open in the old Excel instance" do
|
1088
|
-
@book.close
|
1089
|
-
book2 = Workbook.open(@simple_file1, :default => {:excel => :reserved_new})
|
1090
|
-
book2.should be_alive
|
1091
|
-
book2.should be_a Workbook
|
1092
|
-
book2.should == @book
|
1093
|
-
book2.excel.should == @book.excel
|
1094
|
-
end
|
1095
|
-
|
1096
|
-
it "should open one book in the reserved Excel instance" do
|
1097
|
-
book3 = Workbook.open(@different_file1, :default => {:excel => :reserved_new})
|
1098
|
-
@book.close
|
1099
|
-
book2 = Workbook.open(@simple_file1, :default => {:excel => :reserved_new})
|
1100
|
-
book2.excel.should_not == book3.excel
|
1101
|
-
end
|
1102
|
-
|
1103
|
-
it "should not use the reserved Excel instance" do
|
1104
|
-
book3 = Workbook.open(@different_file1, :default => {:excel => :reserved_new})
|
1105
|
-
@book.close
|
1106
|
-
book2 = Workbook.open(@simple_file1, :default => {:excel => :new})
|
1107
|
-
book2.excel.should_not == book3.excel
|
1108
|
-
end
|
1109
|
-
|
1110
|
-
it "should not reopen in the reserved Excel instance" do
|
1111
|
-
book3 = Workbook.open(@different_file1, :default => {:excel => :reserved_new})
|
1112
|
-
@book.close
|
1113
|
-
@book.reopen
|
1114
|
-
@book.excel.should_not == book3.excel
|
1115
|
-
end
|
1116
|
-
|
1117
|
-
it "should reopen in the reserved Excel instance" do
|
1118
|
-
book3 = Workbook.open(@different_file1, :default => {:excel => :reserved_new})
|
1119
|
-
@book.close
|
1120
|
-
book3.close
|
1121
|
-
@book.reopen
|
1122
|
-
book3.reopen
|
1123
|
-
@book.excel.should_not == book3.excel
|
1124
|
-
end
|
1125
|
-
|
1126
|
-
it "should not reopen in the reserved Excel instance when opened the reserved Excel instance first" do
|
1127
|
-
Excel.kill_all
|
1128
|
-
sleep 1
|
1129
|
-
book1 = Workbook.open(@simple_file1, :default => {:excel => :reserved_new})
|
1130
|
-
book2 = Workbook.open(@different_file1, :default => {:excel => :new})
|
1131
|
-
book2.excel.should_not == book1.excel
|
1132
|
-
book3 = Workbook.open(@another_simple_file1, :default => {:excel => :current})
|
1133
|
-
book3.excel.should_not == book1.excel
|
1134
|
-
book2.close
|
1135
|
-
book2.reopen
|
1136
|
-
book2.excel.should_not == book1.excel
|
1137
|
-
book3.close
|
1138
|
-
book3.reopen
|
1139
|
-
book3.excel.should_not == book1.excel
|
1140
|
-
book1.close
|
1141
|
-
book1.reopen
|
1142
|
-
book1.excel.should_not == book2.excel
|
1143
|
-
book1.excel.should_not == book3.excel
|
1144
|
-
end
|
1145
|
-
|
1146
|
-
it "should open several workbooks in the reserved Excel instance" do
|
1147
|
-
book2 = Workbook.open(@different_file1, :default => {:excel => :reserved_new})
|
1148
|
-
book3 = Workbook.open(@another_simple_file1, :default => {:excel => :reserved_new})
|
1149
|
-
book2.excel.should_not == @book.excel
|
1150
|
-
book3.excel.should_not == @book.excel
|
1151
|
-
book2.excel.should_not == book3.excel
|
1152
|
-
end
|
1153
|
-
|
1154
|
-
it "should open several workbooks in the reserved Excel instance" do
|
1155
|
-
Excel.kill_all
|
1156
|
-
book1 = Workbook.open(@simple_file1, :default => {:excel => :reserved_new})
|
1157
|
-
book2 = Workbook.open(@different_file1, :default => {:excel => :current})
|
1158
|
-
book3 = Workbook.open(@another_simple_file1, :default => {:excel => :current})
|
1159
|
-
book2.excel.should_not == book1.excel
|
1160
|
-
book3.excel.should_not == book1.excel
|
1161
|
-
book2.excel.should == book3.excel
|
1162
|
-
end
|
1163
|
-
|
1164
|
-
end
|
1165
|
-
|
1166
1322
|
context "with :default => {:excel => :current}" do
|
1167
1323
|
|
1168
1324
|
it "should use the open book" do
|
@@ -1753,7 +1909,7 @@ describe Workbook do
|
|
1753
1909
|
|
1754
1910
|
it "should new_excel" do
|
1755
1911
|
book = Workbook.open(@simple_file1)
|
1756
|
-
book.sheet(1)[1,1].Value = "
|
1912
|
+
book.sheet(1)[1,1].Value = "foo"
|
1757
1913
|
book.Saved.should be false
|
1758
1914
|
book2 = Workbook.open(@simple_file1, :if_unsaved => :new_excel)
|
1759
1915
|
end
|
@@ -1872,7 +2028,7 @@ describe Workbook do
|
|
1872
2028
|
it "should raise an error, if :if_obstructed is :raise" do
|
1873
2029
|
expect {
|
1874
2030
|
new_book = Workbook.open(@simple_file1, :if_obstructed => :raise)
|
1875
|
-
}.to raise_error(WorkbookBlocked, /blocked by
|
2031
|
+
}.to raise_error(WorkbookBlocked, /blocked by/)
|
1876
2032
|
end
|
1877
2033
|
|
1878
2034
|
it "should close the other book and open the new book, if :if_obstructed is :forget" do
|
@@ -1925,22 +2081,23 @@ describe Workbook do
|
|
1925
2081
|
new_book.should be_alive
|
1926
2082
|
new_book.filename.should_not == @book.filename
|
1927
2083
|
new_book.excel.should_not == @book.excel
|
1928
|
-
new_book.sheet(1)[1,1].Value.should == @
|
2084
|
+
new_book.sheet(1)[1,1].Value.should == @book.sheet(1)[1,1].Value
|
1929
2085
|
end
|
1930
2086
|
|
1931
2087
|
it "should raise an error, if :if_obstructed is default" do
|
1932
2088
|
expect {
|
1933
2089
|
new_book = Workbook.open(@simple_file1)
|
1934
|
-
}.to raise_error(WorkbookBlocked, /blocked by
|
2090
|
+
}.to raise_error(WorkbookBlocked, /blocked by/)
|
1935
2091
|
end
|
1936
2092
|
|
1937
2093
|
it "should raise an error, if :if_obstructed is invalid option" do
|
1938
2094
|
expect {
|
1939
2095
|
new_book = Workbook.open(@simple_file1, :if_obstructed => :invalid_option)
|
1940
|
-
}.to raise_error(OptionInvalid
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
2096
|
+
}.to raise_error(OptionInvalid)
|
2097
|
+
#}.to raise_error(OptionInvalid, ":if_obstructed: invalid option: :invalid_option" +
|
2098
|
+
# "\nHint: Use the option :if_obstructed with values :forget or :save,
|
2099
|
+
# to close the old workbook, without or with saving before, respectively,
|
2100
|
+
# and to open the new workbook")
|
1944
2101
|
end
|
1945
2102
|
end
|
1946
2103
|
end
|
@@ -2012,7 +2169,8 @@ describe Workbook do
|
|
2012
2169
|
File.delete @simple_save_file rescue nil
|
2013
2170
|
expect {
|
2014
2171
|
Workbook.open(@simple_save_file)
|
2015
|
-
}.to raise_error(FileNotFound, "file #{General::absolute_path(@simple_save_file).gsub("/","\\").inspect} not found"
|
2172
|
+
}.to raise_error(FileNotFound, "file #{General::absolute_path(@simple_save_file).gsub("/","\\").inspect} not found" +
|
2173
|
+
"\nHint: If you want to create a new file, use option :if_absent => :create or Workbook::create")
|
2016
2174
|
end
|
2017
2175
|
|
2018
2176
|
end
|
@@ -2175,15 +2333,16 @@ describe Workbook do
|
|
2175
2333
|
book.close
|
2176
2334
|
end
|
2177
2335
|
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2336
|
+
it "should open xlsm file" do
|
2337
|
+
book = Workbook.open(@simple_file_xlsm, :visible => true)
|
2338
|
+
book.close
|
2339
|
+
end
|
2182
2340
|
|
2183
2341
|
it "should open xlsx file" do
|
2184
2342
|
book = Workbook.open(@simple_file_xlsx, :visible => true)
|
2185
2343
|
book.close
|
2186
2344
|
end
|
2345
|
+
|
2187
2346
|
end
|
2188
2347
|
|
2189
2348
|
|
@@ -2230,27 +2389,5 @@ describe Workbook do
|
|
2230
2389
|
@book.should === book1
|
2231
2390
|
end
|
2232
2391
|
end
|
2233
|
-
end
|
2234
|
-
|
2235
|
-
describe "uplifting" do
|
2236
|
-
|
2237
|
-
context "with standard" do
|
2238
|
-
|
2239
|
-
before do
|
2240
|
-
@book = Workbook.open(@simple_file)
|
2241
|
-
end
|
2242
|
-
|
2243
|
-
after do
|
2244
|
-
@book.close
|
2245
|
-
end
|
2246
|
-
|
2247
|
-
it "should uplift a workbook to a book with an open book" do
|
2248
|
-
workbook = @book.ole_workbook
|
2249
|
-
book1 = Workbook.new(workbook)
|
2250
|
-
book1.should be_a Workbook
|
2251
|
-
book1.should be_alive
|
2252
|
-
book1.should == @book
|
2253
|
-
end
|
2254
|
-
end
|
2255
|
-
end
|
2392
|
+
end
|
2256
2393
|
end
|