robust_excel_ole 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog +6 -0
  3. data/README.rdoc +2 -2
  4. data/docs/README_excel.rdoc +2 -3
  5. data/docs/README_open.rdoc +8 -12
  6. data/docs/README_ranges.rdoc +21 -9
  7. data/docs/README_sheet.rdoc +1 -1
  8. data/lib/robust_excel_ole/book.rb +3 -23
  9. data/lib/robust_excel_ole/excel.rb +2 -15
  10. data/lib/robust_excel_ole/reo_common.rb +11 -7
  11. data/lib/robust_excel_ole/sheet.rb +36 -15
  12. data/lib/robust_excel_ole/version.rb +1 -1
  13. data/robust_excel_ole.gemspec +1 -1
  14. data/spec/book_spec.rb +1 -1
  15. data/spec/book_specs/book_close_spec.rb +3 -3
  16. data/spec/book_specs/book_misc_spec.rb +25 -1
  17. data/spec/book_specs/book_open_spec.rb +299 -5
  18. data/spec/book_specs/book_sheet_spec.rb +1 -1
  19. data/spec/book_specs/book_unobtr_spec.rb +275 -35
  20. data/spec/data/another_workbook.xls +0 -0
  21. data/spec/data/different_workbook.xls +0 -0
  22. data/spec/data/workbook.xls +0 -0
  23. data/spec/excel_spec.rb +118 -5
  24. data/spec/helpers/key_sender.rb +2 -2
  25. data/spec/reo_common_spec.rb +0 -4
  26. data/spec/sheet_spec.rb +32 -0
  27. data/spec/spec_helper.rb +3 -0
  28. metadata +3 -21
  29. data/spec/ruby1.8.6_rspec2.14/book_spec.rb +0 -1421
  30. data/spec/ruby1.8.6_rspec2.14/book_specs/book_all_spec.rb +0 -22
  31. data/spec/ruby1.8.6_rspec2.14/book_specs/book_close_spec.rb +0 -252
  32. data/spec/ruby1.8.6_rspec2.14/book_specs/book_misc_spec.rb +0 -1070
  33. data/spec/ruby1.8.6_rspec2.14/book_specs/book_open_spec.rb +0 -1855
  34. data/spec/ruby1.8.6_rspec2.14/book_specs/book_save_spec.rb +0 -514
  35. data/spec/ruby1.8.6_rspec2.14/book_specs/book_sheet_spec.rb +0 -395
  36. data/spec/ruby1.8.6_rspec2.14/book_specs/book_subclass_spec.rb +0 -51
  37. data/spec/ruby1.8.6_rspec2.14/book_specs/book_unobtr_spec.rb +0 -1737
  38. data/spec/ruby1.8.6_rspec2.14/bookstore_spec.rb +0 -495
  39. data/spec/ruby1.8.6_rspec2.14/cell_spec.rb +0 -76
  40. data/spec/ruby1.8.6_rspec2.14/cygwin_spec.rb +0 -42
  41. data/spec/ruby1.8.6_rspec2.14/excel_spec.rb +0 -1820
  42. data/spec/ruby1.8.6_rspec2.14/general_spec.rb +0 -212
  43. data/spec/ruby1.8.6_rspec2.14/range_spec.rb +0 -131
  44. data/spec/ruby1.8.6_rspec2.14/reo_common_spec.rb +0 -130
  45. data/spec/ruby1.8.6_rspec2.14/sheet_spec.rb +0 -663
  46. data/spec/ruby1.8.6_rspec2.14/spec_helper.rb +0 -35
@@ -1,22 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require File.join(File.dirname(__FILE__), './../spec_helper')
4
-
5
-
6
- $VERBOSE = nil
7
-
8
- include General
9
-
10
- unless Object.method_defined?(:require_relative)
11
- def require_relative path
12
- require File.expand_path(path, File.dirname(__FILE__))
13
- end
14
- end
15
-
16
- require_relative "book_open_spec"
17
- require_relative "book_close_spec"
18
- require_relative "book_save_spec"
19
- require_relative "book_misc_spec"
20
- require_relative "book_sheet_spec"
21
- require_relative "book_unobtr_spec"
22
- require_relative "book_subclass_spec"
@@ -1,252 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require File.join(File.dirname(__FILE__), './../spec_helper')
4
-
5
-
6
- $VERBOSE = nil
7
-
8
- include RobustExcelOle
9
- include General
10
-
11
- describe Book do
12
-
13
- before(:all) do
14
- excel = Excel.new(:reuse => true)
15
- open_books = excel == nil ? 0 : excel.Workbooks.Count
16
- puts "*** open books *** : #{open_books}" if open_books > 0
17
- Excel.kill_all
18
- end
19
-
20
- before do
21
- @dir = create_tmpdir
22
- @simple_file = @dir + '/workbook.xls'
23
- @simple_save_file = @dir + '/workbook_save.xls'
24
- @different_file = @dir + '/different_workbook.xls'
25
- @simple_file_other_path = @dir + '/more_data/workbook.xls'
26
- @another_simple_file = @dir + '/another_workbook.xls'
27
- @linked_file = @dir + '/workbook_linked.xlsm'
28
- @simple_file_xlsm = @dir + '/workbook.xls'
29
- @simple_file_xlsx = @dir + '/workbook.xlsx'
30
- @simple_file1 = @simple_file
31
- end
32
-
33
- after do
34
- Excel.kill_all
35
- rm_tmp(@dir)
36
- end
37
-
38
- describe "close" do
39
-
40
- context "with saved book" do
41
- before do
42
- @book = Book.open(@simple_file)
43
- end
44
-
45
- it "should close book" do
46
- expect{
47
- @book.close
48
- }.to_not raise_error
49
- @book.should_not be_alive
50
- end
51
- end
52
-
53
- context "with unsaved read_only book" do
54
- before do
55
- @book = Book.open(@simple_file1, :read_only => true)
56
- @sheet_count = @book.ole_workbook.Worksheets.Count
57
- @book.add_sheet(@sheet, :as => 'a_name')
58
- end
59
-
60
- it "should close the unsaved book without error and without saving" do
61
- expect{
62
- @book.close
63
- }.to_not raise_error
64
- new_book = Book.open(@simple_file1)
65
- new_book.ole_workbook.Worksheets.Count.should == @sheet_count
66
- new_book.close
67
- end
68
- end
69
-
70
- context "with unsaved book" do
71
- before do
72
- @book = Book.open(@simple_file1)
73
- @sheet_count = @book.ole_workbook.Worksheets.Count
74
- @book.add_sheet(@sheet, :as => 'a_name')
75
- @sheet = @book.sheet(1)
76
- end
77
-
78
- after do
79
- @book.close(:if_unsaved => :forget) rescue nil
80
- end
81
-
82
- it "should raise error with option :raise" do
83
- expect{
84
- @book.close(:if_unsaved => :raise)
85
- }.to raise_error(WorkbookNotSaved, /workbook is unsaved: "workbook.xls"/)
86
- end
87
-
88
- it "should raise error by default" do
89
- expect{
90
- @book.close(:if_unsaved => :raise)
91
- }.to raise_error(WorkbookNotSaved, /workbook is unsaved: "workbook.xls"/)
92
- end
93
-
94
- it "should keep the book open" do
95
- ole_workbook = @book.ole_workbook
96
- excel = @book.excel
97
- excel.Workbooks.Count.should == 1
98
- @book.close(:if_unsaved => :keep_open)
99
- excel.Workbooks.Count.should == 1
100
- @book.should be_alive
101
- end
102
-
103
- it "should close the book and leave its file untouched with option :forget" do
104
- ole_workbook = @book.ole_workbook
105
- excel = @book.excel
106
- excel.Workbooks.Count.should == 1
107
- @book.close(:if_unsaved => :forget)
108
- excel.Workbooks.Count.should == 0
109
- @book.ole_workbook.should == nil
110
- @book.should_not be_alive
111
- expect{
112
- ole_workbook.Name}.to raise_error(WIN32OLERuntimeError)
113
- new_book = Book.open(@simple_file1)
114
- begin
115
- new_book.ole_workbook.Worksheets.Count.should == @sheet_count
116
- ensure
117
- new_book.close
118
- end
119
- end
120
-
121
- it "should close the book and leave its file untouched with option :forget even with displayalerts true" do
122
- ole_workbook = @book.ole_workbook
123
- excel = @book.excel
124
- excel.displayalerts = true
125
- excel.Workbooks.Count.should == 1
126
- @book.close(:if_unsaved => :forget)
127
- excel.Workbooks.Count.should == 0
128
- @book.ole_workbook.should == nil
129
- @book.should_not be_alive
130
- expect{
131
- ole_workbook.Name}.to raise_error(WIN32OLERuntimeError)
132
- new_book = Book.open(@simple_file1)
133
- begin
134
- new_book.ole_workbook.Worksheets.Count.should == @sheet_count
135
- ensure
136
- new_book.close
137
- end
138
- end
139
-
140
- it "should raise an error for invalid option" do
141
- expect {
142
- @book.close(:if_unsaved => :invalid_option)
143
- }.to raise_error(OptionInvalid, ":if_unsaved: invalid option: :invalid_option")
144
- end
145
-
146
-
147
- it "should save the book before close with option :save" do
148
- ole_workbook = @book.ole_workbook
149
- excel = @book.excel
150
- excel.Workbooks.Count.should == 1
151
- @book.close(:if_unsaved => :save)
152
- excel.Workbooks.Count.should == 0
153
- @book.ole_workbook.should == nil
154
- @book.should_not be_alive
155
- expect{
156
- ole_workbook.Name}.to raise_error(WIN32OLERuntimeError)
157
- new_book = Book.open(@simple_file1)
158
- begin
159
- new_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
160
- ensure
161
- new_book.close
162
- end
163
- end
164
-
165
- context "with :if_unsaved => :alert" do
166
- before do
167
- @key_sender = IO.popen 'ruby "' + File.join(File.dirname(__FILE__), '../helpers/key_sender.rb') + '" "Microsoft Excel" ' , "w"
168
- end
169
-
170
- after do
171
- @key_sender.close
172
- end
173
-
174
- possible_answers = [:yes, :no, :cancel]
175
- possible_answers.each_with_index do |answer, position|
176
- it "should" + (answer == :yes ? "" : " not") + " the unsaved book and" + (answer == :cancel ? " not" : "") + " close it" + "if user answers '#{answer}'" do
177
- # "Yes" is the default. "No" is right of "Yes", "Cancel" is right of "No" --> language independent
178
- @key_sender.puts "{right}" * position + "{enter}"
179
- ole_workbook = @book.ole_workbook
180
- excel = @book.excel
181
- displayalert_value = @book.excel.DisplayAlerts
182
- if answer == :cancel then
183
- expect {
184
- @book.close(:if_unsaved => :alert)
185
- }.to_not raise_error
186
- @book.ole_workbook.Saved.should be_false
187
- @book.ole_workbook.should_not == nil
188
- @book.should be_alive
189
- else
190
- @book.excel.Workbooks.Count.should == 1
191
- @book.close(:if_unsaved => :alert)
192
- @book.excel.Workbooks.Count.should == 0
193
- @book.ole_workbook.should == nil
194
- @book.should_not be_alive
195
- expect{ole_workbook.Name}.to raise_error(WIN32OLERuntimeError)
196
- end
197
- new_book = Book.open(@simple_file1, :if_unsaved => :forget)
198
- begin
199
- new_book.ole_workbook.Worksheets.Count.should == @sheet_count + (answer==:yes ? 1 : 0)
200
- new_book.excel.DisplayAlerts.should == displayalert_value
201
- ensure
202
- new_book.close
203
- end
204
- end
205
- end
206
- end
207
-
208
- context "with :if_unsaved => :excel" do
209
- before do
210
- @key_sender = IO.popen 'ruby "' + File.join(File.dirname(__FILE__), '../helpers/key_sender.rb') + '" "Microsoft Excel" ' , "w"
211
- end
212
-
213
- after do
214
- @key_sender.close
215
- end
216
-
217
- possible_answers = [:yes, :no, :cancel]
218
- possible_answers.each_with_index do |answer, position|
219
- it "should" + (answer == :yes ? "" : " not") + " the unsaved book and" + (answer == :cancel ? " not" : "") + " close it" + "if user answers '#{answer}'" do
220
- # "Yes" is the default. "No" is right of "Yes", "Cancel" is right of "No" --> language independent
221
- @key_sender.puts "{right}" * position + "{enter}"
222
- ole_workbook = @book.ole_workbook
223
- excel = @book.excel
224
- displayalert_value = @book.excel.DisplayAlerts
225
- if answer == :cancel then
226
- expect {
227
- @book.close(:if_unsaved => :excel)
228
- }.to_not raise_error
229
- @book.ole_workbook.Saved.should be_false
230
- @book.ole_workbook.should_not == nil
231
- @book.should be_alive
232
- else
233
- @book.excel.Workbooks.Count.should == 1
234
- @book.close(:if_unsaved => :excel)
235
- @book.excel.Workbooks.Count.should == 0
236
- @book.ole_workbook.should == nil
237
- @book.should_not be_alive
238
- expect{ole_workbook.Name}.to raise_error(WIN32OLERuntimeError)
239
- end
240
- new_book = Book.open(@simple_file1, :if_unsaved => :forget)
241
- begin
242
- new_book.ole_workbook.Worksheets.Count.should == @sheet_count + (answer==:yes ? 1 : 0)
243
- new_book.excel.DisplayAlerts.should == displayalert_value
244
- ensure
245
- new_book.close
246
- end
247
- end
248
- end
249
- end
250
- end
251
- end
252
- end
@@ -1,1070 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require File.join(File.dirname(__FILE__), './../spec_helper')
4
-
5
-
6
- $VERBOSE = nil
7
-
8
- include RobustExcelOle
9
- include General
10
-
11
- describe Book do
12
-
13
- before(:all) do
14
- excel = Excel.new(:reuse => true)
15
- open_books = excel == nil ? 0 : excel.Workbooks.Count
16
- puts "*** open books *** : #{open_books}" if open_books > 0
17
- Excel.kill_all
18
- end
19
-
20
- before do
21
- @dir = create_tmpdir
22
- @simple_file = @dir + '/workbook.xls'
23
- @simple_save_file = @dir + '/workbook_save.xls'
24
- @different_file = @dir + '/different_workbook.xls'
25
- @simple_file_other_path = @dir + '/more_data/workbook.xls'
26
- @another_simple_file = @dir + '/another_workbook.xls'
27
- @linked_file = @dir + '/workbook_linked.xlsm'
28
- @simple_file_xlsm = @dir + '/workbook.xls'
29
- @simple_file_xlsx = @dir + '/workbook.xlsx'
30
- @simple_file1 = @simple_file
31
- end
32
-
33
- after do
34
- Excel.kill_all
35
- #rm_tmp(@dir)
36
- end
37
-
38
- describe "create file" do
39
- context "with standard" do
40
- it "open an existing file" do
41
- expect {
42
- @book = Book.new(@simple_file)
43
- }.to_not raise_error
44
- @book.should be_a Book
45
- @book.close
46
- end
47
- end
48
- end
49
-
50
- describe "for_this_workbook" do
51
-
52
- before do
53
- @book = Book.open(@simple_file)
54
- end
55
-
56
- it "should set options" do
57
- @book.for_this_workbook(:visible => true)
58
- @book.excel.Visible.should be_true
59
- @book.Windows(@book.Name).Visible.should be_true
60
- @book.visible.should be_true
61
- @book.ReadOnly.should be_false
62
- @book.CheckCompatibility.should be_false
63
- @book.for_this_workbook(:visible => false)
64
- @book.excel.Visible.should be_true
65
- @book.Windows(@book.Name).Visible.should be_false
66
- @book.visible.should be_false
67
- @book.ReadOnly.should be_false
68
- @book.CheckCompatibility.should be_false
69
- @book.for_this_workbook(:read_only => true)
70
- @book.excel.Visible.should be_true
71
- @book.Windows(@book.Name).Visible.should be_false
72
- @book.visible.should be_false
73
- @book.ReadOnly.should be_true
74
- @book.CheckCompatibility.should be_false
75
- @book.for_this_workbook(:visible => true)
76
- @book.excel.Visible.should be_true
77
- @book.Windows(@book.Name).Visible.should be_true
78
- @book.visible.should be_true
79
- @book.ReadOnly.should be_true
80
- @book.CheckCompatibility.should be_false
81
- @book.for_this_workbook(:check_compatibility => true)
82
- @book.excel.Visible.should be_true
83
- @book.Windows(@book.Name).Visible.should be_true
84
- @book.visible.should be_true
85
- @book.ReadOnly.should be_true
86
- @book.CheckCompatibility.should be_true
87
- @book.for_this_workbook(:visible => false, :check_compatibility => false)
88
- @book.excel.Visible.should be_true
89
- @book.Windows(@book.Name).Visible.should be_false
90
- @book.visible.should be_false
91
- @book.ReadOnly.should be_true
92
- @book.CheckCompatibility.should be_false
93
- @book.for_this_workbook(:calculation => true)
94
- @book.excel.Visible.should be_true
95
- @book.Windows(@book.Name).Visible.should be_false
96
- @book.visible.should be_false
97
- @book.ReadOnly.should be_true
98
- @book.CheckCompatibility.should be_false
99
- @book.excel.calculation.should be_true
100
- end
101
-
102
- it "should set options" do
103
- @book.for_this_workbook(:read_only => true, :check_compatibility => true)
104
- @book.CheckCompatibility.should be_true
105
- end
106
-
107
- end
108
-
109
- describe "excel_of" do
110
-
111
- before do
112
- @book = Book.open(@simple_file)
113
- end
114
-
115
- after do
116
- @book.close
117
- end
118
-
119
- it "should access the excel" do
120
- workbook = @book.ole_workbook
121
- excel = Book.excel_of(workbook)
122
- excel.should be_a Excel
123
- excel.should == @book.excel
124
- end
125
-
126
- it "should access the Excel of the ole_excel" do
127
- excel = Book.excel_of(@book.excel.ole_excel)
128
- excel.should be_a Excel
129
- excel.should == @book.excel
130
- end
131
-
132
- it "should access the Excel of a Book" do
133
- excel = Book.excel_of(@book)
134
- excel.should be_a Excel
135
- excel.should == @book.excel
136
- end
137
-
138
- end
139
-
140
- describe "with retain_saved" do
141
-
142
- before do
143
- @book = Book.open(@simple_file)
144
- end
145
-
146
- after do
147
- @book.close(:if_unsaved => :forget)
148
- end
149
-
150
- it "should keep the save state 'saved' with empty assignments" do
151
- @book.Saved.should be_true
152
- @book.retain_saved do
153
- end
154
- @book.Saved.should be_true
155
- end
156
-
157
- it "should keep the save state 'saved' with non-affecting assignments" do
158
- @book.Saved.should be_true
159
- @book.retain_saved do
160
- sheet = @book.sheet(1)
161
- a = sheet[1,1]
162
- b = @book.visible
163
- end
164
- @book.Saved.should be_true
165
- end
166
-
167
- it "should keep the save state 'unsaved'" do
168
- sheet = @book.sheet(1)
169
- sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
170
- @book.Saved.should be_false
171
- @book.retain_saved do
172
- sheet = @book.sheet(1)
173
- a = sheet[1,1]
174
- b = @book.visible
175
- end
176
- @book.Saved.should be_false
177
- end
178
-
179
- it "should keep the save state 'saved'" do
180
- @book.Saved.should be_true
181
- @book.retain_saved do
182
- sheet = @book.sheet(1)
183
- sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
184
- @book.Saved.should be_false
185
- end
186
- @book.Saved.should be_true
187
- end
188
-
189
- it "should keep the save state 'unsaved' even when the workbook was saved before" do
190
- sheet = @book.sheet(1)
191
- sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
192
- @book.Saved.should be_false
193
- @book.retain_saved do
194
- @book.save
195
- @book.Saved.should be_true
196
- end
197
- @book.Saved.should be_false
198
- end
199
- end
200
-
201
- describe "default-visible" do
202
-
203
- it "should keep the visibility of the open workbook" do
204
- book1 = Book.open(@simple_file1)
205
- book1.excel.Visible.should be_false
206
- book1.Windows(book1.Name).Visible.should be_true
207
- book1.visible.should be_false
208
- book2 = Book.open(@simple_file1, :default => {:visible => true})
209
- book2.visible.should be_false
210
- book2.excel.Visible.should be_false
211
- book2.Windows(book2.Name).Visible.should be_true
212
- book1.visible.should be_false
213
- book2 = Book.open(@simple_file1, :default => {:visible => false})
214
- book2.visible.should be_false
215
- book2.excel.Visible.should be_false
216
- book2.Windows(book2.Name).Visible.should be_true
217
- book1.visible.should be_false
218
- end
219
-
220
- it "should keep the visibility of the open workbook per default" do
221
- book1 = Book.open(@simple_file1)
222
- book1.excel.Visible.should be_false
223
- book1.Windows(book1.Name).Visible.should be_true
224
- book1.visible.should be_false
225
- book2 = Book.open(@simple_file1)
226
- book2.visible.should be_false
227
- book2.excel.Visible.should be_false
228
- book2.Windows(book2.Name).Visible.should be_true
229
- book1.visible.should be_false
230
- end
231
-
232
- it "should keep the found Excel instance invisible" do
233
- book1 = Book.open(@simple_file1)
234
- excel1 = book1.excel
235
- excel1.Visible.should be_false
236
- book1.close
237
- book2 = Book.open(@simple_file1, :default => {:visible => true})
238
- excel2 = book2.excel
239
- excel2.should == excel1
240
- excel2.Visible.should be_false
241
- book2.Windows(book2.Name).Visible.should be_true
242
- end
243
-
244
- it "should keep the found Excel instance invisible with default invisible" do
245
- book1 = Book.open(@simple_file1)
246
- excel1 = book1.excel
247
- excel1.Visible.should be_false
248
- book1.close
249
- book2 = Book.open(@simple_file1, :default => {:visible => false})
250
- excel2 = book1.excel
251
- excel2.should == excel1
252
- excel2.Visible.should be_false
253
- book2.Windows(book2.Name).Visible.should be_false
254
- end
255
-
256
- it "should keep the found Excel instance visible" do
257
- book1 = Book.open(@simple_file1, :visible => true)
258
- excel1 = book1.excel
259
- book1.Windows(book1.Name).Visible.should be_true
260
- excel1.Visible.should be_true
261
- book1.close
262
- book2 = Book.open(@simple_file1, :default => {:visible => false})
263
- excel2 = book1.excel
264
- excel2.should == excel1
265
- excel2.Visible.should be_true
266
- book2.Windows(book2.Name).Visible.should be_false
267
- end
268
-
269
- it "should keep the found Excel instance visible with default visible true" do
270
- book1 = Book.open(@simple_file1, :visible => true)
271
- excel1 = book1.excel
272
- book1.Windows(book1.Name).Visible.should be_true
273
- excel1.Visible.should be_true
274
- book1.close
275
- book2 = Book.open(@simple_file1, :default => {:visible => true})
276
- excel2 = book1.excel
277
- excel2.should == excel1
278
- excel2.Visible.should be_true
279
- book2.Windows(book2.Name).Visible.should be_true
280
- end
281
-
282
- it "should keep the found Excel instance invisible per default" do
283
- book1 = Book.open(@simple_file1)
284
- excel1 = book1.excel
285
- excel1.Visible.should be_false
286
- book1.close
287
- book2 = Book.open(@simple_file1)
288
- excel2 = book1.excel
289
- excel2.should == excel1
290
- excel2.Visible.should be_false
291
- book2.Windows(book2.Name).Visible.should be_true
292
- end
293
-
294
- it "should open the workbook visible if the workbook is new" do
295
- book1 = Book.open(@simple_file1, :default => {:visible => true})
296
- book1.visible.should be_true
297
- book1.excel.Visible.should be_true
298
- book1.Windows(book1.Name).Visible.should be_true
299
- end
300
-
301
- it "should open the workbook invisible if the workbook is new" do
302
- book1 = Book.open(@simple_file1, :default => {:visible => false})
303
- book1.visible.should be_false
304
- book1.excel.Visible.should be_false
305
- book1.Windows(book1.Name).Visible.should be_false
306
- end
307
-
308
- it "should open the workbook invisible per default if the workbook is new" do
309
- book1 = Book.open(@simple_file1)
310
- book1.visible.should be_false
311
- book1.excel.Visible.should be_false
312
- book1.Windows(book1.Name).Visible.should be_true
313
- end
314
-
315
- it "should open the workbook visible if the old Excel is closed" do
316
- book1 = Book.open(@simple_file1)
317
- book1.visible.should be_false
318
- excel1 = book1.excel
319
- excel1.Visible.should be_false
320
- book1.Windows(book1.Name).Visible.should be_true
321
- book1.close
322
- excel1.close
323
- book2 = Book.open(@simple_file1, :default => {:visible => true})
324
- excel2 = book2.excel
325
- book2.visible.should be_true
326
- excel2.Visible.should be_true
327
- book1.Windows(book1.Name).Visible.should be_true
328
- end
329
-
330
- it "should open the workbook invisible if the old Excel is closed" do
331
- book1 = Book.open(@simple_file1, :default => {:visible => true})
332
- book1.visible.should be_true
333
- excel1 = book1.excel
334
- excel1.Visible.should be_true
335
- book1.Windows(book1.Name).Visible.should be_true
336
- book1.close
337
- excel1.close
338
- book2 = Book.open(@simple_file1, :default => {:visible => false})
339
- excel2 = book2.excel
340
- book2.visible.should be_false
341
- excel2.Visible.should be_false
342
- book1.Windows(book1.Name).Visible.should be_false
343
- end
344
-
345
- end
346
-
347
- describe "force-visible" do
348
-
349
- it "should change the visibility of the workbooks" do
350
- book1 = Book.open(@simple_file)
351
- book1.excel.Visible.should be_false
352
- book1.Windows(book1.Name).Visible.should be_true
353
- book1.visible.should be_false
354
- book2 = Book.open(@simple_file, :visible => true)
355
- book2.visible.should be_true
356
- book2.excel.Visible.should be_true
357
- book2.Windows(book2.Name).Visible.should be_true
358
- book1.visible.should be_true
359
- book2 = Book.open(@simple_file, :visible => false)
360
- book2.visible.should be_false
361
- book2.excel.Visible.should be_true
362
- book2.Windows(book2.Name).Visible.should be_false
363
- book1.visible.should be_false
364
- book1.Windows(book2.Name).Visible.should be_false
365
- end
366
- end
367
-
368
- describe "with visible" do
369
-
370
- it "should adapt its default value at the visible value of the Excel" do
371
- excel1 = Excel.create
372
- excel1.visible = true
373
- book1 = Book.open(@simple_file)
374
- excel1.Visible.should be_true
375
- excel1.visible.should be_true
376
- book1.visible.should be_true
377
- end
378
-
379
- it "should preserve :visible if it is not set" do
380
- book1 = Book.open(@simple_file)
381
- book1.excel.Visible.should be_false
382
- book1.Windows(book1.Name).Visible.should be_true
383
- book1.visible.should be_false
384
- end
385
-
386
- it "should set :visible to false" do
387
- book1 = Book.open(@simple_file, :visible => false)
388
- book1.excel.Visible.should be_false
389
- book1.Windows(book1.Name).Visible.should be_false
390
- book1.visible.should be_false
391
- end
392
-
393
- it "should set :visible to true" do
394
- book1 = Book.open(@simple_file, :visible => true)
395
- book1.excel.Visible.should be_true
396
- book1.Windows(book1.Name).Visible.should be_true
397
- book1.visible.should be_true
398
- end
399
-
400
- it "should preserve :visible if they are set to visible" do
401
- excel1 = Excel.create(:visible => true)
402
- book1 = Book.open(@simple_file)
403
- book1.excel.Visible.should be_true
404
- book1.Windows(book1.Name).Visible.should be_true
405
- book1.visible.should be_true
406
- end
407
-
408
- it "should preserve :visible" do
409
- excel1 = Excel.create
410
- book1 = Book.open(@simple_file)
411
- book1.excel.Visible.should be_false
412
- book1.Windows(book1.Name).Visible.should be_true
413
- book1.visible.should be_false
414
- end
415
-
416
-
417
- it "should preserve :visible if it is set to false" do
418
- excel1 = Excel.create
419
- book1 = Book.open(@simple_file, :visible => false)
420
- book1.excel.Visible.should be_false
421
- book1.Windows(book1.Name).Visible.should be_false
422
- book1.visible.should be_false
423
- end
424
-
425
- it "should preserve :visible if it is not set" do
426
- excel1 = Excel.create
427
- book1 = Book.open(@simple_file)
428
- book1.excel.Visible.should be_false
429
- book1.Windows(book1.Name).Visible.should be_true
430
- book1.visible.should be_false
431
- end
432
-
433
- it "should overwrite :visible to false" do
434
- excel1 = Excel.create(:visible => true)
435
- book1 = Book.open(@simple_file, :visible => false)
436
- book1.excel.Visible.should be_true
437
- book1.Windows(book1.Name).Visible.should be_false
438
- book1.visible.should be_false
439
- end
440
-
441
- it "should overwrite :visible to true" do
442
- excel1 = Excel.create(:visible => false)
443
- book1 = Book.open(@simple_file, :visible => true)
444
- book1.excel.Visible.should be_true
445
- book1.Windows(book1.Name).Visible.should be_true
446
- book1.visible.should be_true
447
- end
448
-
449
- it "should preserve :visible if it is not set with default_excel" do
450
- excel1 = Excel.create(:visible => true)
451
- book1 = Book.open(@simple_file)
452
- book2 = Book.open(@different_file, :default_excel => :new)
453
- book2.excel.Visible.should be_false
454
- book2.Windows(book2.Name).Visible.should be_true
455
- book2.visible.should be_false
456
- end
457
-
458
- it "should set :visible to true with default_excel" do
459
- excel1 = Excel.create(:visible => true)
460
- book1 = Book.open(@simple_file)
461
- book2 = Book.open(@different_file, :default_excel => :new, :visible => true)
462
- book2.excel.Visible.should be_true
463
- book2.Windows(book2.Name).Visible.should be_true
464
- book2.visible.should be_true
465
- end
466
-
467
- it "should set :visible to false with default_excel" do
468
- excel1 = Excel.create(:visible => true)
469
- book1 = Book.open(@simple_file)
470
- book2 = Book.open(@different_file, :default_excel => :new, :visible => false)
471
- book2.excel.Visible.should be_false
472
- book2.Windows(book2.Name).Visible.should be_false
473
- book2.visible.should be_false
474
- end
475
-
476
- it "should preserve :visible if it is set to true with default_excel" do
477
- excel1 = Excel.create(:visible => true)
478
- excel2 = Excel.create(:visible => true)
479
- book1 = Book.open(@different_file, :default_excel => excel2)
480
- book1.excel.Visible.should be_true
481
- book1.Windows(book1.Name).Visible.should be_true
482
- book1.visible.should be_true
483
- end
484
-
485
- it "should overwrite :visible to false with default_excel" do
486
- excel1 = Excel.create(:visible => true)
487
- excel2 = Excel.create(:visible => true)
488
- book1 = Book.open(@different_file, :default_excel => excel2, :visible => false)
489
- book1.excel.Visible.should be_true
490
- book1.Windows(book1.Name).Visible.should be_false
491
- book1.visible.should be_false
492
- end
493
-
494
- it "should preserve :visible if it is not set with force_excel => new" do
495
- excel1 = Excel.create(:visible => true)
496
- book1 = Book.open(@different_file, :force_excel => :new)
497
- book1.excel.Visible.should be_false
498
- book1.Windows(book1.Name).Visible.should be_true
499
- book1.visible.should be_false
500
- end
501
-
502
- it "should set :visible to true with force_excel" do
503
- excel1 = Excel.create(:visible => true)
504
- book1 = Book.open(@different_file, :force_excel => :new, :visible => true)
505
- book1.excel.Visible.should be_true
506
- book1.Windows(book1.Name).Visible.should be_true
507
- book1.visible.should be_true
508
- end
509
-
510
- it "should preserve :visible if it is not set with force_excel => excel" do
511
- excel1 = Excel.create(:visible => true)
512
- excel2 = Excel.create(:visible => true)
513
- book1 = Book.open(@different_file, :force_excel => excel2)
514
- book1.excel.Visible.should be_true
515
- book1.Windows(book1.Name).Visible.should be_true
516
- book1.visible.should be_true
517
- end
518
-
519
- it "should set visible to false with force_excel => excel" do
520
- excel1 = Excel.create(:visible => true)
521
- excel2 = Excel.create(:visible => true)
522
- book1 = Book.open(@different_file, :force_excel => excel2, :visible => false)
523
- book1.excel.Visible.should be_true
524
- book1.Windows(book1.Name).Visible.should be_false
525
- book1.visible.should be_false
526
- end
527
-
528
- it "should set visible to true with force_excel => excel" do
529
- excel1 = Excel.create(:visible => true)
530
- excel2 = Excel.create(:visible => true)
531
- book1 = Book.open(@different_file, :force_excel => excel2, :visible => true)
532
- book1.excel.Visible.should be_true
533
- book1.Windows(book1.Name).Visible.should be_true
534
- book1.visible.should be_true
535
- end
536
-
537
- it "should preserve :visible if it is set to true with force_excel => current" do
538
- excel1 = Excel.create(:visible => true)
539
- book1 = Book.open(@different_file, :force_excel => :current)
540
- book1.excel.Visible.should be_true
541
- book1.Windows(book1.Name).Visible.should be_true
542
- book1.visible.should be_true
543
- end
544
-
545
- it "should set :visible to false with force_excel => current" do
546
- excel1 = Excel.create(:visible => true)
547
- book1 = Book.open(@different_file, :force_excel => :current, :visible => false)
548
- book1.excel.Visible.should be_true
549
- book1.Windows(book1.Name).Visible.should be_false
550
- book1.visible.should be_false
551
- end
552
-
553
- it "should preserve :visible if it is set to false with force_excel => current" do
554
- excel1 = Excel.create(:visible => false)
555
- book1 = Book.open(@simple_file, :force_excel => :current)
556
- book1.excel.Visible.should be_false
557
- book1.Windows(book1.Name).Visible.should be_true
558
- book1.visible.should be_false
559
- end
560
-
561
- it "should set :visible to false with force_excel => current" do
562
- excel1 = Excel.create(:visible => false)
563
- book1 = Book.open(@simple_file, :force_excel => :current, :visible => true)
564
- book1.excel.Visible.should be_true
565
- book1.Windows(book1.Name).Visible.should be_true
566
- book1.visible.should be_true
567
- end
568
-
569
- it "should let an open Book open" do
570
- @book = Book.open(@simple_file1, :visible => true)
571
- Book.unobtrusively(@simple_file1) do |book|
572
- book.should be_a Book
573
- book.should be_alive
574
- book.excel.should == @book.excel
575
- book.excel.Visible.should be_true
576
- end
577
- @book.should be_alive
578
- @book.should be_a Book
579
- @book.excel.Visible.should be_true
580
- @book.close(:if_unsaved => :forget)
581
- @book2.close(:if_unsaved => :forget) rescue nil
582
- end
583
-
584
- it "should set visible and displayalerts if displayalerts => :if_visible" do
585
- book1 = Book.open(@simple_file)
586
- book1.excel.Visible.should be_false
587
- book1.excel.displayalerts.should == :if_visible
588
- book1.Windows(book1.Name).Visible.should be_true
589
- book1.visible.should be_false
590
- book2 = Book.open(@different_file)
591
- book2.excel.Visible.should be_false
592
- book2.Windows(book2.Name).Visible.should be_true
593
- book2.visible.should be_false
594
- book2.excel.visible.should be_false
595
- book2.excel.displayalerts.should == :if_visible
596
- book2.excel.DisplayAlerts.should be_false
597
- end
598
-
599
- it "should set visible and displayalerts if displayalerts => :if_visible" do
600
- book1 = Book.open(@simple_file)
601
- book1.excel.Visible.should be_false
602
- book1.excel.displayalerts.should == :if_visible
603
- book1.Windows(book1.Name).Visible.should be_true
604
- book1.visible.should be_false
605
- book2 = Book.open(@different_file, :visible => true)
606
- book2.excel.Visible.should be_true
607
- book2.Windows(book2.Name).Visible.should be_true
608
- book2.visible.should be_true
609
- book2.excel.visible.should be_true
610
- book2.excel.displayalerts.should == :if_visible
611
- book2.excel.DisplayAlerts.should be_true
612
- end
613
- end
614
-
615
- describe "send methods to workbook" do
616
-
617
- context "with standard" do
618
- before do
619
- @book = Book.open(@simple_file)
620
- end
621
-
622
- after do
623
- @book.close
624
- end
625
-
626
- it "should send Saved to workbook" do
627
- @book.Saved.should be_true
628
- end
629
-
630
- it "should send Fullname to workbook" do
631
- @book.Fullname.tr('\\','/').should == @simple_file
632
- end
633
-
634
- it "should raise an error for unknown methods or properties" do
635
- expect{
636
- @book.Foo
637
- }.to raise_error(VBAMethodMissingError, /unknown VBA property or method :Foo/)
638
- end
639
-
640
- it "should report that workbook is not alive" do
641
- @book.close
642
- expect{ @book.Nonexisting_method }.to raise_error(ObjectNotAlive, "method missing: workbook not alive")
643
- end
644
- end
645
-
646
- end
647
-
648
- describe "hidden_excel" do
649
-
650
- context "with some open book" do
651
-
652
- before do
653
- @book = Book.open(@simple_file1)
654
- end
655
-
656
- after do
657
- @book.close
658
- end
659
-
660
- it "should create and use a hidden Excel instance" do
661
- book2 = Book.open(@simple_file1, :force_excel => @book.bookstore.hidden_excel)
662
- book2.excel.should_not == @book.excel
663
- book2.excel.visible.should be_false
664
- book2.excel.displayalerts.should == :if_visible
665
- book2.close
666
- end
667
- end
668
- end
669
-
670
- describe "nameval, set_nameval, [], []=" do
671
-
672
- before do
673
- @book1 = Book.open(@another_simple_file)
674
- end
675
-
676
- after do
677
- @book1.close(:if_unsaved => :forget)
678
- end
679
-
680
- it "should return value of a range" do
681
- @book1.nameval("new").should == "foo"
682
- @book1.nameval("one").should == 1
683
- @book1.nameval("firstrow").should == [[1,2]]
684
- @book1.nameval("four").should == [[1,2],[3,4]]
685
- @book1.nameval("firstrow").should_not == "12"
686
- @book1.nameval("firstcell").should == "foo"
687
- end
688
-
689
- it "should return value of a range via []" do
690
- @book1["new"].should == "foo"
691
- @book1["one"].should == 1
692
- @book1["firstrow"] == [[1,2]]
693
- @book1["four"].should == [[1,2],[3,4]]
694
- @book1["firstrow"].should_not == "12"
695
- @book1["firstcell"].should == "foo"
696
- end
697
-
698
- it "should set value of a range" do
699
- @book1.set_nameval("new", "bar")
700
- @book1.nameval("new").should == "bar"
701
- end
702
-
703
- it "should set value of a range via []=" do
704
- @book1["new"] = "bar"
705
- @book1.nameval("new").should == "bar"
706
- end
707
-
708
- #it "should evaluate a formula" do
709
- # @book1.nameval("named_formula").should == 4
710
- #end
711
-
712
- #it "should evaluate a formula via []" do
713
- # @book1["named_formula"].should == 4
714
- #end
715
-
716
- it "should raise an error if name not defined and default value is not provided" do
717
- expect {
718
- @book1.nameval("foo", :default => nil)
719
- }.to_not raise_error
720
- expect {
721
- @book1.nameval("foo", :default => :__not_provided)
722
- }.to raise_error(NameNotFound, /name "foo" not in #<Book: another_workbook/)
723
- expect {
724
- @book1.nameval("foo")
725
- }.to raise_error(NameNotFound, /name "foo" not in #<Book: another_workbook/)
726
- @book1.nameval("foo", :default => nil).should be_nil
727
- @book1.nameval("foo", :default => 1).should == 1
728
- expect {
729
- @book1.set_nameval("foo","bar")
730
- }.to raise_error(NameNotFound, /name "foo" not in #<Book: another_workbook/)
731
- expect {
732
- @book1["foo"] = "bar"
733
- }.to raise_error(NameNotFound, /name "foo" not in #<Book: another_workbook/)
734
- @book1.nameval("empty", :default => 1).should be_nil
735
- end
736
-
737
- it "should raise an error if name was defined but contents is calcuated" do
738
- expect {
739
- @book1.set_nameval("named_formula","bar")
740
- }.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "named_formula" in #<Book: another_workbook/)
741
- expect {
742
- @book1["named_formula"] = "bar"
743
- }.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "named_formula" in #<Book: another_workbook/)
744
- end
745
-
746
- # Excel Bug: for local names without uqifier: takes the first sheet as default even if another sheet is activated
747
- it "should take the first sheet as default even if the second sheet is activated" do
748
- @book1.nameval("Sheet1!localname").should == "bar"
749
- @book1.nameval("Sheet2!localname").should == "simple"
750
- @book1.nameval("localname").should == "bar"
751
- @book1.Worksheets.Item(2).Activate
752
- @book1.nameval("localname").should == "bar"
753
- @book1.Worksheets.Item(1).Delete
754
- @book1.nameval("localname").should == "simple"
755
- end
756
- end
757
-
758
- describe "rename_range" do
759
-
760
- before do
761
- @book1 = Book.open(@another_simple_file)
762
- end
763
-
764
- after do
765
- @book1.close(:if_unsaved => :forget)
766
- end
767
-
768
- it "should rename a range" do
769
- @book1.rename_range("four","five")
770
- @book1.nameval("five").should == [[1,2],[3,4]]
771
- expect {
772
- @book1.rename_range("four","five")
773
- }.to raise_error(NameNotFound, /name "four" not in "another_workbook.xls"/)
774
- end
775
- end
776
-
777
- describe "alive?, filename, ==, visible, focus, saved, check_compatibility" do
778
-
779
- context "with alive?" do
780
-
781
- before do
782
- @book = Book.open(@simple_file)
783
- end
784
-
785
- after do
786
- @book.close
787
- end
788
-
789
- it "should return true, if book is alive" do
790
- @book.should be_alive
791
- end
792
-
793
- it "should return false, if book is dead" do
794
- @book.close
795
- @book.should_not be_alive
796
- end
797
-
798
- end
799
-
800
- context "with filename" do
801
-
802
- before do
803
- @book = Book.open(@simple_file)
804
- end
805
-
806
- after do
807
- @book.close
808
- end
809
-
810
- it "should return full file name" do
811
- @book.filename.should == @simple_file
812
- end
813
-
814
- it "should return nil for dead book" do
815
- @book.close
816
- @book.filename.should == nil
817
- end
818
-
819
- end
820
-
821
- context "with ==" do
822
-
823
- before do
824
- @book = Book.open(@simple_file1)
825
- end
826
-
827
- after do
828
- @book.close
829
- @new_book.close rescue nil
830
- end
831
-
832
- it "should be true with two identical books" do
833
- @new_book = Book.open(@simple_file1)
834
- @new_book.should == @book
835
- end
836
-
837
- it "should be false with two different books" do
838
- @new_book = Book.new(@different_file)
839
- @new_book.should_not == @book
840
- end
841
-
842
- it "should be false with same book names but different paths" do
843
- @new_book = Book.new(@simple_file_other_path, :force_excel => :new)
844
- @new_book.should_not == @book
845
- end
846
-
847
- it "should be false with same book names but different excel instances" do
848
- @new_book = Book.new(@simple_file, :force_excel => :new)
849
- @new_book.should_not == @book
850
- end
851
-
852
- it "should be false with non-Books" do
853
- @book.should_not == "hallo"
854
- @book.should_not == 7
855
- @book.should_not == nil
856
- end
857
- end
858
-
859
- context "with saved" do
860
-
861
- before do
862
- @book = Book.open(@simple_file)
863
- end
864
-
865
- after do
866
- @book.close(:if_unsaved => :forget)
867
- end
868
-
869
- it "should yield true for a saved book" do
870
- @book.saved.should be_true
871
- end
872
-
873
- it "should yield false for an unsaved book" do
874
- sheet = @book.sheet(1)
875
- sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
876
- @book.saved.should be_false
877
- end
878
- end
879
-
880
-
881
- context "with :visible => " do
882
-
883
- it "should leave the excel invisible when opening with default option" do
884
- excel1 = Excel.new(:reuse => false, :visible => false)
885
- book1 = Book.open(@simple_file)
886
- excel1.Visible.should be_false
887
- book1.Windows(book1.Name).Visible.should be_true
888
- book1.visible.should be_false
889
- end
890
-
891
- it "should leave the excel invisible when opening with :visible => false" do
892
- excel1 = Excel.new(:reuse => false, :visible => false)
893
- book1 = Book.open(@simple_file, :visible => false)
894
- excel1.Visible.should be_false
895
- book1.Windows(book1.Name).Visible.should be_false
896
- book1.visible.should be_false
897
- end
898
-
899
- it "should leave the excel visible" do
900
- excel1 = Excel.new(:reuse => false, :visible => false)
901
- book1 = Book.open(@simple_file, :visible => true)
902
- excel1.Visible.should be_true
903
- book1.Windows(book1.Name).Visible.should be_true
904
- book1.visible.should be_true
905
- book2 = Book.open(@another_simple_file)
906
- excel1.Visible.should be_true
907
- book2.Windows(book2.Name).Visible.should be_true
908
- book2.visible.should be_true
909
- book3 = Book.open(@different_file, :visible => false)
910
- excel1.Visible.should be_true
911
- book3.Windows(book3.Name).Visible.should be_false
912
- book3.visible.should be_false
913
- end
914
-
915
- it "should leave the excel visible when opening with default option" do
916
- excel1 = Excel.new(:reuse => false, :visible => true)
917
- book1 = Book.open(@simple_file)
918
- excel1.Visible.should be_true
919
- book1.Windows(book1.Name).Visible.should be_true
920
- book1.visible.should be_true
921
- end
922
-
923
- it "should leave the excel visible when opening with :visible => false" do
924
- excel1 = Excel.new(:reuse => false, :visible => true)
925
- book1 = Book.open(@simple_file, :visible => false)
926
- excel1.Visible.should be_true
927
- book1.Windows(book1.Name).Visible.should be_false
928
- book1.visible.should be_false
929
- book2 = Book.open(@another_simple_file)
930
- excel1.Visible.should be_true
931
- book2.Windows(book2.Name).Visible.should be_true
932
- book2.visible.should be_true
933
- end
934
-
935
- it "should leave the excel visible" do
936
- excel1 = Excel.new(:reuse => false, :visible => true)
937
- book1 = Book.open(@simple_file, :visible => true)
938
- excel1.Visible.should be_true
939
- book1.Windows(book1.Name).Visible.should be_true
940
- book1.visible.should be_true
941
- book2 = Book.open(@different_file, :visible => false)
942
- excel1.Visible.should be_true
943
- book2.Windows(book2.Name).Visible.should be_false
944
- book2.visible.should be_false
945
- end
946
-
947
- it "should leave the visibility of Excel" do
948
- excel1 = Excel.new(:reuse => false, :visible => false)
949
- book1 = Book.open(@simple_file, :visible => true)
950
- excel1.Visible.should be_true
951
- book1.Windows(book1.Name).Visible.should be_true
952
- book1.visible.should be_true
953
- excel1.visible = false
954
- book2 = Book.open(@different_file)
955
- excel1.Visible.should be_false
956
- book2.Windows(book2.Name).Visible.should be_true
957
- book2.visible.should be_false
958
- end
959
-
960
- it "should leave the visibility of Excel" do
961
- excel1 = Excel.new(:reuse => false, :visible => false)
962
- book1 = Book.open(@simple_file, :visible => false)
963
- excel1.Visible.should be_false
964
- book1.Windows(book1.Name).Visible.should be_false
965
- book1.visible.should be_false
966
- excel1.visible = true
967
- book2 = Book.open(@different_file)
968
- excel1.Visible.should be_true
969
- book2.Windows(book2.Name).Visible.should be_true
970
- book2.visible.should be_true
971
- end
972
- end
973
-
974
- context "with visible, visible=" do
975
-
976
- before do
977
- @book1 = Book.open(@simple_file)
978
- @book2 = Book.open(@different_file, :force_excel => :new, :visible => true)
979
- end
980
-
981
- after do
982
- @book1.close
983
- @book2.close
984
- end
985
-
986
- it "should make the invisible workbook visible and invisible" do
987
- @book1.excel.Visible.should be_false
988
- @book1.Windows(@book1.Name).Visible.should be_true
989
- @book1.visible.should be_false
990
- @book1.visible = true
991
- @book1.Saved.should be_true
992
- @book1.excel.Visible.should be_true
993
- @book1.Windows(@book1.Name).Visible.should be_true
994
- @book1.visible.should be_true
995
- @book1.visible = false
996
- @book1.Saved.should be_true
997
- @book1.excel.should be_true
998
- @book1.Windows(@book1.Name).Visible.should be_false
999
- @book1.visible.should be_false
1000
- @book2.excel.Visible.should be_true
1001
- end
1002
-
1003
- it "should make the visible workbook and the invisible workbook invisible" do
1004
- @book2.Windows(@book2.Name).Visible.should be_true
1005
- @book2.visible.should be_true
1006
- @book2.visible = true
1007
- @book2.Saved.should be_true
1008
- @book2.excel.Visible.should be_true
1009
- @book2.Windows(@book2.Name).Visible.should be_true
1010
- @book2.excel.visible = false
1011
- @book2.visible = false
1012
- @book2.Saved.should be_true
1013
- @book2.excel.Visible.should be_false
1014
- @book2.Windows(@book2.Name).Visible.should be_false
1015
- @book2.visible.should be_false
1016
- end
1017
-
1018
- end
1019
-
1020
- context "with focus" do
1021
-
1022
- before do
1023
- @key_sender = IO.popen 'ruby "' + File.join(File.dirname(__FILE__), '../helpers/key_sender.rb') + '" "Microsoft Office Excel" ' , "w"
1024
- @book = Book.open(@simple_file, :visible => true)
1025
- @book.excel.displayalerts = false
1026
- @book2 = Book.open(@another_simple_file, :visible => true)
1027
- @book2.excel.displayalerts = false
1028
- end
1029
-
1030
- after do
1031
- @book.close(:if_unsaved => :forget)
1032
- @book2.close(:if_unsaved => :forget)
1033
- @key_sender.close
1034
- end
1035
-
1036
- it "should bring a book to focus" do
1037
- sheet = @book.sheet(2)
1038
- sheet.Activate
1039
- sheet[2,3].Activate
1040
- sheet2 = @book2.sheet(2)
1041
- sheet2.Activate
1042
- sheet2[3,2].Activate
1043
- Excel.current.should == @book.excel
1044
- @book2.focus
1045
- @key_sender.puts "{a}{enter}"
1046
- sleep 1
1047
- sheet2[3,2].Value.should == "a"
1048
- #Excel.current.should == @book2.excel
1049
- @book.focus
1050
- @key_sender.puts "{a}{enter}"
1051
- sleep 1
1052
- sheet[2,3].Value.should == "a"
1053
- Excel.current.should == @book.excel
1054
- end
1055
- end
1056
-
1057
- context "with compatibility" do
1058
-
1059
- it "should open with checking compatibility" do
1060
- book = Book.open(@simple_file, :visible => true, :check_compatibility => true)
1061
- book.CheckCompatibility.should be_true
1062
- end
1063
-
1064
- it "should open without checking compatibility" do
1065
- book = Book.open(@simple_file, :visible => true, :check_compatibility => false)
1066
- book.CheckCompatibility.should be_false
1067
- end
1068
- end
1069
- end
1070
- end