robust_excel_ole 1.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +14 -0
- data/README.rdoc +94 -351
- data/README_detail.rdoc +791 -0
- data/examples/edit_sheets/example_saving.rb +1 -1
- data/examples/open_save_close/example_default_excel.rb +5 -5
- data/examples/open_save_close/example_force_excel.rb +2 -2
- data/lib/robust_excel_ole/book.rb +237 -161
- data/lib/robust_excel_ole/excel.rb +96 -68
- data/lib/robust_excel_ole/reo_common.rb +19 -1
- data/lib/robust_excel_ole/sheet.rb +2 -3
- data/lib/robust_excel_ole/version.rb +1 -1
- data/robust_excel_ole.gemspec +2 -2
- data/spec/book_spec.rb +71 -16
- data/spec/book_specs/book_misc_spec.rb +244 -7
- data/spec/book_specs/book_open_spec.rb +472 -33
- data/spec/book_specs/book_save_spec.rb +19 -0
- data/spec/book_specs/book_unobtr_spec.rb +46 -4
- data/spec/data/another_workbook.xls +0 -0
- data/spec/data/book_with_blank.xls +0 -0
- data/spec/data/different_workbook.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +134 -31
- metadata +7 -6
- data/spec/data/refed_wb.xls +0 -0
@@ -12,8 +12,13 @@ module RobustExcelOle
|
|
12
12
|
class Excel < REOCommon
|
13
13
|
|
14
14
|
attr_accessor :ole_excel
|
15
|
-
attr_accessor :
|
16
|
-
|
15
|
+
attr_accessor :created
|
16
|
+
|
17
|
+
# setter methods are implemented below
|
18
|
+
attr_reader :visible
|
19
|
+
attr_reader :displayalerts
|
20
|
+
attr_reader :calculation
|
21
|
+
attr_reader :screenupdating
|
17
22
|
|
18
23
|
alias ole_object ole_excel
|
19
24
|
|
@@ -22,16 +27,20 @@ module RobustExcelOle
|
|
22
27
|
# creates a new Excel instance
|
23
28
|
# @param [Hash] options the options
|
24
29
|
# @option options [Variant] :displayalerts
|
25
|
-
# @option options [Boolean] :visible
|
30
|
+
# @option options [Boolean] :visible
|
31
|
+
# @option options [Symbol] :calculation
|
32
|
+
# @option options [Boolean] :screenupdating
|
26
33
|
# @return [Excel] a new Excel instance
|
27
34
|
def self.create(options = {})
|
28
35
|
new(options.merge({:reuse => false}))
|
29
36
|
end
|
30
37
|
|
31
|
-
#
|
38
|
+
# connects to the current (first opened) Excel instance, if such a running Excel instance exists
|
32
39
|
# returns a new Excel instance, otherwise
|
33
40
|
# @option options [Variant] :displayalerts
|
34
41
|
# @option options [Boolean] :visible
|
42
|
+
# @option options [Symbol] :calculation
|
43
|
+
# @option options [Boolean] :screenupdating
|
35
44
|
# @return [Excel] an Excel instance
|
36
45
|
def self.current(options = {})
|
37
46
|
new(options.merge({:reuse => true}))
|
@@ -42,33 +51,31 @@ module RobustExcelOle
|
|
42
51
|
# @param [Hash] options the options
|
43
52
|
# @option options [Boolean] :reuse
|
44
53
|
# @option options [Boolean] :visible
|
45
|
-
# @option options [Variant] :displayalerts
|
54
|
+
# @option options [Variant] :displayalerts
|
55
|
+
# @option options [Boolean] :screenupdating
|
56
|
+
# @option options [Symbol] :calculation
|
46
57
|
# options:
|
47
|
-
# :reuse
|
48
|
-
#
|
49
|
-
# :visible
|
50
|
-
# :displayalerts
|
58
|
+
# :reuse connects to an already running Excel instance (true) or
|
59
|
+
# creates a new Excel instance (false) (default: true)
|
60
|
+
# :visible makes the Excel visible (default: false)
|
61
|
+
# :displayalerts enables or disables DisplayAlerts (true, false, :if_visible (default))
|
62
|
+
# :calculation calculation mode is being forced to be manual (:manual) or automatic (:automtic)
|
63
|
+
# or is not being forced (default: nil)
|
64
|
+
# :screenupdating turns on or off screen updating (default: true)
|
51
65
|
# @return [Excel] an Excel instance
|
52
66
|
def self.new(options = {})
|
53
67
|
if options.is_a? WIN32OLE
|
54
68
|
ole_xl = options
|
55
69
|
else
|
56
70
|
options = {:reuse => true}.merge(options)
|
57
|
-
if options[:reuse] == true
|
58
|
-
ole_xl = current_excel
|
59
|
-
end
|
71
|
+
ole_xl = current_excel if options[:reuse] == true
|
60
72
|
end
|
61
|
-
ole_xl
|
62
|
-
|
73
|
+
ole_xl ||= WIN32OLE.new('Excel.Application')
|
63
74
|
hwnd = ole_xl.HWnd
|
64
75
|
stored = hwnd2excel(hwnd)
|
65
76
|
if stored and stored.alive?
|
66
77
|
result = stored
|
67
78
|
else
|
68
|
-
unless options.is_a? WIN32OLE
|
69
|
-
options[:visible] = options[:visible].nil? ? ole_xl.Visible : options[:visible]
|
70
|
-
options[:displayalerts] = options[:displayalerts].nil? ? :if_visible : options[:displayalerts]
|
71
|
-
end
|
72
79
|
result = super(options)
|
73
80
|
result.instance_variable_set(:@ole_excel, ole_xl)
|
74
81
|
WIN32OLE.const_load(ole_xl, RobustExcelOle) unless RobustExcelOle.const_defined?(:CONSTANTS)
|
@@ -77,15 +84,15 @@ module RobustExcelOle
|
|
77
84
|
|
78
85
|
unless options.is_a? WIN32OLE
|
79
86
|
begin
|
80
|
-
reused = options[:reuse] &&
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
result.
|
88
|
-
result.
|
87
|
+
reused = options[:reuse] && stored && stored.alive?
|
88
|
+
unless reused
|
89
|
+
options = {:displayalerts => :if_visible, :visible => false, :screenupdating => true}.merge(options)
|
90
|
+
end
|
91
|
+
result.visible = options[:visible] unless options[:visible].nil?
|
92
|
+
result.displayalerts = options[:displayalerts] unless options[:displayalerts].nil?
|
93
|
+
result.calculation = options[:calculation] unless options[:calculation].nil?
|
94
|
+
result.screenupdating = options[:screenupdating] unless options[:screenupdating].nil?
|
95
|
+
result.created = !reused
|
89
96
|
rescue WIN32OLERuntimeError
|
90
97
|
raise ExcelError, "cannot access Excel"
|
91
98
|
end
|
@@ -94,7 +101,10 @@ module RobustExcelOle
|
|
94
101
|
end
|
95
102
|
|
96
103
|
def initialize(options= {}) # :nodoc: #
|
97
|
-
|
104
|
+
end
|
105
|
+
|
106
|
+
def excel
|
107
|
+
self
|
98
108
|
end
|
99
109
|
|
100
110
|
# reopens a closed Excel instance
|
@@ -102,8 +112,9 @@ module RobustExcelOle
|
|
102
112
|
# @option opts [Boolean] :reopen_workbooks
|
103
113
|
# @option opts [Boolean] :displayalerts
|
104
114
|
# @option opts [Boolean] :visible
|
115
|
+
# @option opts [Boolean] :calculation
|
105
116
|
# options: reopen_workbooks (default: false): reopen the workbooks in the Excel instances
|
106
|
-
#
|
117
|
+
# :visible (default: false), :displayalerts (default: :if_visible), :calculation (default: false)
|
107
118
|
# @return [Excel] an Excel instance
|
108
119
|
def recreate(opts = {})
|
109
120
|
unless self.alive?
|
@@ -114,6 +125,7 @@ module RobustExcelOle
|
|
114
125
|
@ole_excel = WIN32OLE.new('Excel.Application')
|
115
126
|
self.visible = opts[:visible]
|
116
127
|
self.displayalerts = opts[:displayalerts]
|
128
|
+
self.calculation = opts[:calculation]
|
117
129
|
if opts[:reopen_workbooks]
|
118
130
|
books = book_class.books
|
119
131
|
books.each do |book|
|
@@ -176,15 +188,15 @@ module RobustExcelOle
|
|
176
188
|
weak_wkbks = @ole_excel.Workbooks
|
177
189
|
if not unsaved_workbooks.empty? then
|
178
190
|
case options[:if_unsaved]
|
179
|
-
when Proc
|
191
|
+
when Proc
|
180
192
|
options[:if_unsaved].call(self, unsaved_workbooks)
|
181
|
-
when :raise
|
193
|
+
when :raise
|
182
194
|
raise UnsavedWorkbooks, "Excel contains unsaved workbooks"
|
183
|
-
when :alert
|
195
|
+
when :alert
|
184
196
|
#nothing
|
185
|
-
when :forget
|
197
|
+
when :forget
|
186
198
|
unsaved_workbooks.each {|m| m.Saved = true}
|
187
|
-
when :save
|
199
|
+
when :save
|
188
200
|
unsaved_workbooks.each {|m| m.Save}
|
189
201
|
else
|
190
202
|
raise OptionInvalid, ":if_unsaved: invalid option: #{options[:if_unsaved].inspect}"
|
@@ -193,11 +205,10 @@ module RobustExcelOle
|
|
193
205
|
begin
|
194
206
|
@ole_excel.Workbooks.Close
|
195
207
|
rescue WIN32OLERuntimeError => msg
|
196
|
-
# trace "WIN32OLERuntimeError: #{msg.message}"
|
197
208
|
if msg.message =~ /800A03EC/
|
198
209
|
raise ExcelError, "user canceled or runtime error"
|
199
210
|
else
|
200
|
-
raise UnexpectedError, "unknown WIN32OLERuntimeError"
|
211
|
+
raise UnexpectedError, "unknown WIN32OLERuntimeError: #{msg.message}"
|
201
212
|
end
|
202
213
|
end
|
203
214
|
weak_wkbks = nil
|
@@ -403,6 +414,7 @@ module RobustExcelOle
|
|
403
414
|
trace "dead reference to an Excel"
|
404
415
|
begin
|
405
416
|
@@hwnd2excel.delete(hwnd)
|
417
|
+
nil
|
406
418
|
rescue
|
407
419
|
trace "Warning: deleting dead reference failed! (hwnd: #{hwnd.inspect})"
|
408
420
|
end
|
@@ -483,17 +495,57 @@ module RobustExcelOle
|
|
483
495
|
end
|
484
496
|
end
|
485
497
|
|
498
|
+
# makes the current Excel instance visible or invisible
|
499
|
+
def visible= visible_value
|
500
|
+
@ole_excel.Visible = @visible = visible_value
|
501
|
+
@ole_excel.DisplayAlerts = @visible if @displayalerts == :if_visible
|
502
|
+
end
|
503
|
+
|
486
504
|
# enables DisplayAlerts in the current Excel instance
|
487
505
|
def displayalerts= displayalerts_value
|
488
506
|
@displayalerts = displayalerts_value
|
489
507
|
@ole_excel.DisplayAlerts = (@displayalerts == :if_visible) ? @ole_excel.Visible : displayalerts_value
|
490
508
|
end
|
491
509
|
|
492
|
-
#
|
493
|
-
def
|
494
|
-
@ole_excel.
|
495
|
-
|
496
|
-
|
510
|
+
# sets ScreenUpdating
|
511
|
+
def screenupdating= screenupdating_value
|
512
|
+
@ole_excel.ScreenUpdating = @screenupdating = screenupdating_value
|
513
|
+
end
|
514
|
+
|
515
|
+
# sets calculation mode
|
516
|
+
def calculation= calculation_mode
|
517
|
+
return if calculation_mode.nil?
|
518
|
+
@calculation = calculation_mode
|
519
|
+
calc_mode_changable = @ole_excel.Workbooks.Count > 0 && @ole_excel.Calculation.is_a?(Fixnum)
|
520
|
+
if calc_mode_changable
|
521
|
+
@ole_excel.CalculateBeforeSave = false
|
522
|
+
@ole_excel.Calculation =
|
523
|
+
(calculation_mode == :automatic) ? XlCalculationAutomatic : XlCalculationManual
|
524
|
+
end
|
525
|
+
end
|
526
|
+
|
527
|
+
# VBA method overwritten
|
528
|
+
def Calculation= calculation_vba_mode
|
529
|
+
case calculation_vba_mode
|
530
|
+
when XlCalculationManual
|
531
|
+
@calculation = :manual
|
532
|
+
when XlCalculationAutomatic
|
533
|
+
@calculation = :automatic
|
534
|
+
end
|
535
|
+
@ole_excel.Calculation = calculation_vba_mode
|
536
|
+
end
|
537
|
+
|
538
|
+
# sets calculation mode in a block
|
539
|
+
def with_calculation(calculation_mode)
|
540
|
+
return unless calculation_mode
|
541
|
+
old_calculation_mode = @ole_excel.Calculation
|
542
|
+
begin
|
543
|
+
self.calculation = calculation_mode
|
544
|
+
yield self
|
545
|
+
ensure
|
546
|
+
@ole_excel.Calculation = old_calculation_mode if @ole_excel.Calculation.is_a?(Fixnum)
|
547
|
+
end
|
548
|
+
end
|
497
549
|
|
498
550
|
# make all workbooks visible or invisible
|
499
551
|
def workbooks_visible= visible_value
|
@@ -517,30 +569,6 @@ module RobustExcelOle
|
|
517
569
|
#end
|
518
570
|
end
|
519
571
|
|
520
|
-
# sets calculation mode in a block
|
521
|
-
def with_calculation(calculation_mode = :automatic)
|
522
|
-
if @ole_excel.Workbooks.Count > 0
|
523
|
-
old_calculation_mode = @ole_excel.Calculation
|
524
|
-
old_calculation_before_save_mode = @ole_excel.CalculateBeforeSave
|
525
|
-
@ole_excel.Calculation = calculation_mode == :automatic ? XlCalculationAutomatic : XlCalculationManual
|
526
|
-
@ole_excel.CalculateBeforeSave = (calculation_mode == :automatic)
|
527
|
-
begin
|
528
|
-
yield self
|
529
|
-
ensure
|
530
|
-
@ole_excel.Calculation = old_calculation_mode if alive?
|
531
|
-
@ole_excel.CalculateBeforeSave = old_calculation_before_save_mode if alive?
|
532
|
-
end
|
533
|
-
end
|
534
|
-
end
|
535
|
-
|
536
|
-
# sets calculation mode
|
537
|
-
def set_calculation(calculation_mode = :automatic)
|
538
|
-
if @ole_excel.Workbooks.Count > 0
|
539
|
-
@ole_excel.Calculation = calculation_mode == :automatic ? XlCalculationAutomatic : XlCalculationManual
|
540
|
-
@ole_excel.CalculateBeforeSave = (calculation_mode == :automatic)
|
541
|
-
end
|
542
|
-
end
|
543
|
-
|
544
572
|
# returns the value of a range
|
545
573
|
# @param [String] name the name of a range
|
546
574
|
# @returns [Variant] the value of the range
|
@@ -560,7 +588,7 @@ module RobustExcelOle
|
|
560
588
|
# if no contents could be returned, then return default value, if provided, raise error otherwise
|
561
589
|
# @param [String] name the range name
|
562
590
|
# @param [Hash] opts the options
|
563
|
-
# @option opts [Variant] :default
|
591
|
+
# @option opts [Variant] :default value (default: nil)
|
564
592
|
def nameval(name, opts = {:default => nil})
|
565
593
|
begin
|
566
594
|
name_obj = self.Names.Item(name)
|
@@ -578,7 +606,7 @@ module RobustExcelOle
|
|
578
606
|
raise RangeNotEvaluatable, "cannot evaluate range named #{name.inspect}"
|
579
607
|
end
|
580
608
|
end
|
581
|
-
if value
|
609
|
+
if value.is_a?(Bignum)
|
582
610
|
return opts[:default] if opts[:default]
|
583
611
|
raise RangeNotEvaluatable, "cannot evaluate range named #{name.inspect}"
|
584
612
|
end
|
@@ -623,7 +651,7 @@ module RobustExcelOle
|
|
623
651
|
raise RangeNotEvaluatable, "cannot determine value of range named #{name.inspect}"
|
624
652
|
end
|
625
653
|
return opts[:default] if (value.nil? && opts[:default])
|
626
|
-
raise RangeNotEvaluatable, "cannot evaluate range named #{name.inspect}" if value
|
654
|
+
raise RangeNotEvaluatable, "cannot evaluate range named #{name.inspect}" if value.is_a?(Bignum)
|
627
655
|
value
|
628
656
|
end
|
629
657
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
LOG_TO_STDOUT =
|
1
|
+
LOG_TO_STDOUT = true unless Object.const_defined?(:LOG_TO_STDOUT)
|
2
2
|
REO_LOG_DIR = "" unless Object.const_defined?(:REO_LOG_DIR)
|
3
3
|
REO_LOG_FILE = "reo.log" unless Object.const_defined?(:REO_LOG_FILE)
|
4
4
|
|
@@ -38,6 +38,24 @@ class REOCommon
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
def puts_hash(hash)
|
43
|
+
self.class.puts_hash(hash)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.puts_hash(hash)
|
47
|
+
hash.each do |e|
|
48
|
+
if e[1].is_a?(Hash)
|
49
|
+
puts "#{e[0]} =>"
|
50
|
+
e[1].each do |f|
|
51
|
+
puts " #{f[0]} => #{f[1]}"
|
52
|
+
end
|
53
|
+
else
|
54
|
+
puts "#{e[0]} => #{e[1]}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
41
59
|
end
|
42
60
|
|
43
61
|
module RobustExcelOle
|
@@ -36,8 +36,7 @@ module RobustExcelOle
|
|
36
36
|
if msg.message =~ /800A03EC/
|
37
37
|
raise NameAlreadyExists, "sheet name #{new_name.inspect} already exists"
|
38
38
|
else
|
39
|
-
|
40
|
-
raise UnexpectedError
|
39
|
+
raise UnexpectedError, "unexpected WIN32OLERuntimeError: #{msg.message}"
|
41
40
|
end
|
42
41
|
end
|
43
42
|
end
|
@@ -153,7 +152,7 @@ module RobustExcelOle
|
|
153
152
|
raise RangeNotEvaluatable, "cannot evaluate range named #{name.inspect} in #{self.Name}"
|
154
153
|
end
|
155
154
|
end
|
156
|
-
if value
|
155
|
+
if value.is_a?(Bignum) # RobustExcelOle::XlErrName
|
157
156
|
return opts[:default] if opts[:default]
|
158
157
|
raise RangeNotEvaluatable, "cannot evaluate range named #{name.inspect} in #{self.Name}"
|
159
158
|
end
|
data/robust_excel_ole.gemspec
CHANGED
@@ -10,10 +10,10 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "https://github.com/Thomas008/robust_excel_ole"
|
11
11
|
|
12
12
|
s.summary = "RobustExcelOle automates processing Excel files in Windows by using the win32ole library."
|
13
|
-
s.description = "RobustExcelOle automates modifying, reading and writing Excel files.
|
13
|
+
s.description = "RobustExcelOle automates modifying, reading and writing Excel files in Windows by using the win32ole library.
|
14
14
|
It supports simultaneously running Excel instances and user interactions.
|
15
15
|
RobustExcelOle deals with various cases of Excel (and user) behaviour,
|
16
|
-
supplies workarounds for some Excel bugs, and supports referenced libraries"
|
16
|
+
supplies workarounds for some Excel bugs, and supports referenced libraries."
|
17
17
|
|
18
18
|
s. licenses = ['MIT']
|
19
19
|
s.rubyforge_project = "robust_excel_ole"
|
data/spec/book_spec.rb
CHANGED
@@ -70,7 +70,7 @@ describe Book do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should open in a new Excel" do
|
73
|
-
book2 = Workbook.open(@simple_file, :
|
73
|
+
book2 = Workbook.open(@simple_file, :force => {:excel => :new})
|
74
74
|
book2.should be_alive
|
75
75
|
book2.should be_a Book
|
76
76
|
book2.excel.should_not == @book.excel
|
@@ -148,7 +148,7 @@ describe Book do
|
|
148
148
|
old_excel = @book.excel
|
149
149
|
@book.close
|
150
150
|
@book.should_not be_alive
|
151
|
-
book2 = Book.open(@simple_file, :
|
151
|
+
book2 = Book.open(@simple_file, :force => {:excel => :new})
|
152
152
|
book2.should_not === @book
|
153
153
|
book2.should be_alive
|
154
154
|
book2.excel.should_not == old_excel
|
@@ -167,7 +167,7 @@ describe Book do
|
|
167
167
|
end
|
168
168
|
|
169
169
|
it "should open in a new Excel" do
|
170
|
-
book2 = Book.open(@simple_file, :
|
170
|
+
book2 = Book.open(@simple_file, :force => {:excel => :new})
|
171
171
|
book2.should be_alive
|
172
172
|
book2.should be_a Book
|
173
173
|
book2.excel.should_not == @book.excel
|
@@ -178,22 +178,22 @@ describe Book do
|
|
178
178
|
end
|
179
179
|
|
180
180
|
it "should open in a given Excel, provide identity transparency, because book can be readonly, such that the old and the new book are readonly" do
|
181
|
-
book2 = Book.open(@simple_file1, :
|
181
|
+
book2 = Book.open(@simple_file1, :force => {:excel => :new})
|
182
182
|
book2.excel.should_not == @book.excel
|
183
|
-
book3 = Book.open(@simple_file1, :
|
183
|
+
book3 = Book.open(@simple_file1, :force => {:excel => :new})
|
184
184
|
book3.excel.should_not == book2.excel
|
185
185
|
book3.excel.should_not == @book.excel
|
186
186
|
book2.close
|
187
187
|
book3.close
|
188
188
|
@book.close
|
189
|
-
book4 = Book.open(@simple_file1, :
|
189
|
+
book4 = Book.open(@simple_file1, :force => {:excel => book2.excel}, :read_only => true)
|
190
190
|
book4.should be_alive
|
191
191
|
book4.should be_a Book
|
192
192
|
book4.excel.should == book2.excel
|
193
193
|
book4.ReadOnly.should be_true
|
194
194
|
book4.should == book2
|
195
195
|
book4.close
|
196
|
-
book5 = Book.open(@simple_file1, :
|
196
|
+
book5 = Book.open(@simple_file1, :force => {:excel => book2}, :read_only => true)
|
197
197
|
book5.should be_alive
|
198
198
|
book5.should be_a Book
|
199
199
|
book5.excel.should == book2.excel
|
@@ -232,7 +232,7 @@ describe Book do
|
|
232
232
|
it "should open a new excel, if the book cannot be reopened" do
|
233
233
|
@book.close
|
234
234
|
new_excel = Excel.new(:reuse => false)
|
235
|
-
book2 = Book.open(@different_file, :
|
235
|
+
book2 = Book.open(@different_file, :default => {:excel => :new})
|
236
236
|
book2.should be_alive
|
237
237
|
book2.should be_a Book
|
238
238
|
book2.excel.should_not == new_excel
|
@@ -243,17 +243,17 @@ describe Book do
|
|
243
243
|
it "should open in a given Excel provided as Excel, Book, or WIN32OLE representing an Excel or Workbook" do
|
244
244
|
book2 = Book.open(@another_simple_file)
|
245
245
|
different_file1 = @different_file
|
246
|
-
book3 = Book.open(different_file1, :
|
246
|
+
book3 = Book.open(different_file1, :default => {:excel => book2.excel})
|
247
247
|
book3.excel.should === book2.excel
|
248
248
|
book3.close
|
249
|
-
book4 = Book.open(different_file1, :
|
249
|
+
book4 = Book.open(different_file1, :default => {:excel => book2})
|
250
250
|
book4.excel.should === book2.excel
|
251
251
|
book4.close
|
252
252
|
book5 = Book.open(different_file1, :default_excel => book2.ole_workbook)
|
253
253
|
book5.excel.should === book2.excel
|
254
254
|
book5.close
|
255
255
|
win32ole_excel1 = WIN32OLE.connect(book2.ole_workbook.Fullname).Application
|
256
|
-
book6 = Book.open(different_file1, :
|
256
|
+
book6 = Book.open(different_file1, :default => {:excel => win32ole_excel1})
|
257
257
|
book6.excel.should === book2.excel
|
258
258
|
book6.close
|
259
259
|
end
|
@@ -506,14 +506,14 @@ describe Book do
|
|
506
506
|
|
507
507
|
it "should preserve :visible if they are not set" do
|
508
508
|
excel1 = Excel.create(:visible => true)
|
509
|
-
book1 = Book.open(@different_file, :
|
509
|
+
book1 = Book.open(@different_file, :default => {:excel => :new})
|
510
510
|
book1.excel.Visible.should be_false
|
511
511
|
end
|
512
512
|
|
513
513
|
it "should preserve :visible if they are not set" do
|
514
514
|
excel1 = Excel.create(:visible => true)
|
515
515
|
excel2 = Excel.create(:visible => true)
|
516
|
-
book1 = Book.open(@different_file, :
|
516
|
+
book1 = Book.open(@different_file, :force => {:excel => excel2})
|
517
517
|
book1.excel.Visible.should be_true
|
518
518
|
book1.close
|
519
519
|
end
|
@@ -605,7 +605,7 @@ describe Book do
|
|
605
605
|
end
|
606
606
|
|
607
607
|
it "should let an open Book open if two books have been opened and one has been closed and opened again" do
|
608
|
-
book2 = Book.open(@different_file, :
|
608
|
+
book2 = Book.open(@different_file, :force => {:excel => :new})
|
609
609
|
@book.close
|
610
610
|
book2.close
|
611
611
|
@book.reopen
|
@@ -726,7 +726,7 @@ describe Book do
|
|
726
726
|
end
|
727
727
|
|
728
728
|
it "should open unobtrusively the book in a new Excel such that the book is writable" do
|
729
|
-
book2 = Book.open(@simple_file1, :
|
729
|
+
book2 = Book.open(@simple_file1, :force => {:excel => :new}, :read_only => true)
|
730
730
|
@book.ReadOnly.should be_true
|
731
731
|
book2.Readonly.should be_true
|
732
732
|
sheet = @book.sheet(1)
|
@@ -796,7 +796,7 @@ describe Book do
|
|
796
796
|
|
797
797
|
before do
|
798
798
|
@book1 = Book.open(@simple_file1)
|
799
|
-
@book2 = Book.open(@simple_file1, :
|
799
|
+
@book2 = Book.open(@simple_file1, :force => {:excel => :new})
|
800
800
|
@book1.Readonly.should == false
|
801
801
|
@book2.Readonly.should == true
|
802
802
|
old_sheet = @book1.sheet(1)
|
@@ -1260,6 +1260,61 @@ describe Book do
|
|
1260
1260
|
end
|
1261
1261
|
end
|
1262
1262
|
|
1263
|
+
describe "with retain_saved" do
|
1264
|
+
|
1265
|
+
before do
|
1266
|
+
@book = Book.open(@simple_file)
|
1267
|
+
end
|
1268
|
+
|
1269
|
+
after do
|
1270
|
+
@book.close(:if_unsaved => :forget)
|
1271
|
+
end
|
1272
|
+
|
1273
|
+
it "should keep the save state 'unsaved'" do
|
1274
|
+
sheet = @book.sheet(1)
|
1275
|
+
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
1276
|
+
@book.Saved.should be_false
|
1277
|
+
@book.retain_saved do
|
1278
|
+
sheet = @book.sheet(1)
|
1279
|
+
a = sheet[1,1]
|
1280
|
+
b = @book.visible
|
1281
|
+
end
|
1282
|
+
@book.Saved.should be_false
|
1283
|
+
end
|
1284
|
+
|
1285
|
+
it "should keep the save state 'unsaved' even when the workbook was saved before" do
|
1286
|
+
sheet = @book.sheet(1)
|
1287
|
+
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
1288
|
+
@book.Saved.should be_false
|
1289
|
+
@book.retain_saved do
|
1290
|
+
@book.save
|
1291
|
+
@book.Saved.should be_true
|
1292
|
+
end
|
1293
|
+
@book.Saved.should be_false
|
1294
|
+
end
|
1295
|
+
end
|
1296
|
+
|
1297
|
+
=begin
|
1298
|
+
context "with test what happens with save-status when setting calculation status" do
|
1299
|
+
|
1300
|
+
it "should keep the save status" do
|
1301
|
+
book1 = Book.open(@simple_file, :visible => true)
|
1302
|
+
book1.Saved.should be_true
|
1303
|
+
book2 = Book.open(@another_simple_file, :visible => true)
|
1304
|
+
book1.Saved.should be_true
|
1305
|
+
book2.Saved.should be_true
|
1306
|
+
sheet2 = book2.sheet(1)
|
1307
|
+
sheet2[1,1] = sheet2[1,1].value == "foo" ? "bar" : "foo"
|
1308
|
+
book1.Saved.should be_true
|
1309
|
+
book2.Saved.should be_false
|
1310
|
+
book3 = Book.open(@different_file, :visible => true)
|
1311
|
+
book1.Saved.should be_true
|
1312
|
+
book2.Saved.should be_false
|
1313
|
+
book3.Saved.should be_true
|
1314
|
+
end
|
1315
|
+
end
|
1316
|
+
=end
|
1317
|
+
|
1263
1318
|
context 'open with block' do
|
1264
1319
|
it {
|
1265
1320
|
Book.open(@simple_file) do |book|
|