robust_excel_ole 1.14 → 1.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +7 -1
- data/README.rdoc +2 -5
- data/docs/README_excel.rdoc +1 -1
- data/docs/README_open.rdoc +27 -18
- data/lib/robust_excel_ole/cell.rb +1 -1
- data/lib/robust_excel_ole/excel.rb +43 -32
- data/lib/robust_excel_ole/general.rb +6 -6
- data/lib/robust_excel_ole/range.rb +4 -4
- data/lib/robust_excel_ole/range_owners.rb +5 -5
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +90 -122
- data/lib/robust_excel_ole/worksheet.rb +15 -10
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/excel_spec.rb +96 -94
- data/spec/general_spec.rb +4 -4
- data/spec/reo_common_spec.rb +15 -11
- data/spec/workbook_spec.rb +4 -4
- data/spec/workbook_specs/workbook_misc_spec.rb +18 -19
- data/spec/workbook_specs/workbook_open_spec.rb +7 -7
- data/spec/workbook_specs/workbook_unobtr_spec.rb +416 -112
- metadata +2 -2
data/spec/general_spec.rb
CHANGED
@@ -41,25 +41,25 @@ module RobustExcelOle
|
|
41
41
|
@book1 = Workbook.open(@simple_file)
|
42
42
|
end
|
43
43
|
|
44
|
-
it "should
|
44
|
+
it "should type-lift an Excel" do
|
45
45
|
excel = @book1.excel.ole_excel.to_reo
|
46
46
|
excel.class.should == RobustExcelOle::Excel
|
47
47
|
excel.should be_alive
|
48
48
|
end
|
49
49
|
|
50
|
-
it "should
|
50
|
+
it "should type-lift a workbook" do
|
51
51
|
workbook = @book1.ole_workbook.to_reo
|
52
52
|
workbook.should be_a Workbook
|
53
53
|
workbook.should be_alive
|
54
54
|
end
|
55
55
|
|
56
|
-
it "should
|
56
|
+
it "should type-lift a worksheet" do
|
57
57
|
worksheet = @book1.sheet(1).ole_worksheet.to_reo
|
58
58
|
worksheet.should be_kind_of Worksheet
|
59
59
|
worksheet.name.should == "Sheet1"
|
60
60
|
end
|
61
61
|
|
62
|
-
it "should
|
62
|
+
it "should type-lift a range" do
|
63
63
|
range = @book1.sheet(1).range([1,1]).ole_range.to_reo
|
64
64
|
range.should be_kind_of Range
|
65
65
|
range.Value.should == "foo"
|
data/spec/reo_common_spec.rb
CHANGED
@@ -103,22 +103,26 @@ module RobustExcelOle
|
|
103
103
|
|
104
104
|
describe "misc" do
|
105
105
|
|
106
|
-
|
107
|
-
REOCommon::trace "foo"
|
106
|
+
it "should" do
|
108
107
|
|
109
|
-
|
110
|
-
|
108
|
+
LOG_TO_STDOUT = true
|
109
|
+
REOCommon::trace "foo"
|
111
110
|
|
112
|
-
|
113
|
-
|
111
|
+
LOG_TO_STDOUT = false
|
112
|
+
REOCommon::trace "foo"
|
114
113
|
|
115
|
-
|
116
|
-
|
114
|
+
REO_LOG_DIR = ""
|
115
|
+
REOCommon::trace "foo"
|
117
116
|
|
118
|
-
|
117
|
+
#REO_LOG_DIR = "C:"
|
118
|
+
#REOCommon::trace "foo"
|
119
119
|
|
120
|
-
|
121
|
-
|
120
|
+
REOCommon::tr1 "foo"
|
121
|
+
|
122
|
+
h = {:a => {:c => 4}, :b => 2}
|
123
|
+
REOCommon::puts_hash(h)
|
124
|
+
|
125
|
+
end
|
122
126
|
|
123
127
|
end
|
124
128
|
end
|
data/spec/workbook_spec.rb
CHANGED
@@ -669,7 +669,7 @@ describe Workbook do
|
|
669
669
|
end
|
670
670
|
end
|
671
671
|
|
672
|
-
describe "
|
672
|
+
describe "type-lifting" do
|
673
673
|
|
674
674
|
context "with standard" do
|
675
675
|
|
@@ -681,7 +681,7 @@ describe Workbook do
|
|
681
681
|
@book.close
|
682
682
|
end
|
683
683
|
|
684
|
-
it "should
|
684
|
+
it "should type-lift a win32ole workbook object to a workbook object with an open workbook" do
|
685
685
|
workbook = @book.ole_workbook
|
686
686
|
book1 = Workbook.new(workbook)
|
687
687
|
book1.should be_a Workbook
|
@@ -1109,8 +1109,8 @@ describe Workbook do
|
|
1109
1109
|
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1110
1110
|
book.excel.should_not == @book.excel
|
1111
1111
|
book.excel.should_not == new_excel
|
1112
|
-
book.excel.visible.should be false
|
1113
|
-
book.excel.displayalerts.should == :if_visible
|
1112
|
+
book.excel.properties[:visible].should be false
|
1113
|
+
book.excel.properties[:displayalerts].should == :if_visible
|
1114
1114
|
end
|
1115
1115
|
new_book = Workbook.open(@simple_file1, :visible => true)
|
1116
1116
|
sheet = new_book.sheet(1)
|
@@ -251,7 +251,7 @@ describe Workbook do
|
|
251
251
|
excel2 = book1.excel
|
252
252
|
excel2.should == excel1
|
253
253
|
excel2.Visible.should be false
|
254
|
-
book2.Windows(book2.Name).Visible.should be
|
254
|
+
book2.Windows(book2.Name).Visible.should be true
|
255
255
|
end
|
256
256
|
|
257
257
|
it "should keep the found Excel instance visible" do
|
@@ -264,7 +264,7 @@ describe Workbook do
|
|
264
264
|
excel2 = book1.excel
|
265
265
|
excel2.should == excel1
|
266
266
|
excel2.Visible.should be true
|
267
|
-
book2.Windows(book2.Name).Visible.should be
|
267
|
+
book2.Windows(book2.Name).Visible.should be true
|
268
268
|
end
|
269
269
|
|
270
270
|
it "should keep the found Excel instance visible with default visible true" do
|
@@ -292,17 +292,17 @@ describe Workbook do
|
|
292
292
|
book2.Windows(book2.Name).Visible.should be true
|
293
293
|
end
|
294
294
|
|
295
|
-
it "should open the workbook visible if the workbook is new" do
|
295
|
+
it "should open the workbook not visible if the workbook is new" do
|
296
296
|
book1 = Workbook.open(@simple_file1, :default => {:visible => true})
|
297
|
-
book1.excel.Visible.should be
|
297
|
+
book1.excel.Visible.should be false
|
298
298
|
book1.Windows(book1.Name).Visible.should be true
|
299
|
-
book1.visible.should be
|
299
|
+
book1.visible.should be false
|
300
300
|
end
|
301
301
|
|
302
302
|
it "should open the workbook invisible if the workbook is new" do
|
303
303
|
book1 = Workbook.open(@simple_file1, :default => {:visible => false})
|
304
304
|
book1.excel.Visible.should be false
|
305
|
-
book1.Windows(book1.Name).Visible.should be
|
305
|
+
book1.Windows(book1.Name).Visible.should be true
|
306
306
|
book1.visible.should be false
|
307
307
|
end
|
308
308
|
|
@@ -324,13 +324,13 @@ describe Workbook do
|
|
324
324
|
book2 = Workbook.open(@simple_file1, :default => {:visible => true})
|
325
325
|
excel2 = book2.excel
|
326
326
|
book1.Windows(book1.Name).Visible.should be true
|
327
|
-
excel2.Visible.should be
|
328
|
-
book2.visible.should be
|
327
|
+
excel2.Visible.should be false
|
328
|
+
book2.visible.should be false
|
329
329
|
end
|
330
330
|
|
331
331
|
it "should open the workbook invisible if the old Excel is closed" do
|
332
332
|
book1 = Workbook.open(@simple_file1, :default => {:visible => true})
|
333
|
-
book1.visible.should be
|
333
|
+
book1.visible.should be false
|
334
334
|
excel1 = book1.excel
|
335
335
|
excel1.Visible.should be true
|
336
336
|
book1.Windows(book1.Name).Visible.should be true
|
@@ -344,7 +344,6 @@ describe Workbook do
|
|
344
344
|
end
|
345
345
|
|
346
346
|
end
|
347
|
-
|
348
347
|
=end
|
349
348
|
|
350
349
|
describe "force-visible" do
|
@@ -375,7 +374,7 @@ describe Workbook do
|
|
375
374
|
excel1.visible = true
|
376
375
|
book1 = Workbook.open(@simple_file)
|
377
376
|
excel1.Visible.should be true
|
378
|
-
excel1.visible.should be true
|
377
|
+
excel1.properties[:visible].should be true
|
379
378
|
book1.visible.should be true
|
380
379
|
end
|
381
380
|
|
@@ -587,30 +586,30 @@ describe Workbook do
|
|
587
586
|
it "should set visible and displayalerts if displayalerts => :if_visible" do
|
588
587
|
book1 = Workbook.open(@simple_file)
|
589
588
|
book1.excel.Visible.should be false
|
590
|
-
book1.excel.displayalerts.should == :if_visible
|
589
|
+
book1.excel.properties[:displayalerts].should == :if_visible
|
591
590
|
book1.Windows(book1.Name).Visible.should be true
|
592
591
|
book1.visible.should be false
|
593
592
|
book2 = Workbook.open(@different_file)
|
594
593
|
book2.excel.Visible.should be false
|
595
594
|
book2.Windows(book2.Name).Visible.should be true
|
596
595
|
book2.visible.should be false
|
597
|
-
book2.excel.visible.should be false
|
598
|
-
book2.excel.displayalerts.should == :if_visible
|
596
|
+
book2.excel.properties[:visible].should be false
|
597
|
+
book2.excel.properties[:displayalerts].should == :if_visible
|
599
598
|
book2.excel.DisplayAlerts.should be false
|
600
599
|
end
|
601
600
|
|
602
601
|
it "should set visible and displayalerts if displayalerts => :if_visible" do
|
603
602
|
book1 = Workbook.open(@simple_file)
|
604
603
|
book1.excel.Visible.should be false
|
605
|
-
book1.excel.displayalerts.should == :if_visible
|
604
|
+
book1.excel.properties[:displayalerts].should == :if_visible
|
606
605
|
book1.Windows(book1.Name).Visible.should be true
|
607
606
|
book1.visible.should be false
|
608
607
|
book2 = Workbook.open(@different_file, :visible => true)
|
609
608
|
book2.excel.Visible.should be true
|
610
609
|
book2.Windows(book2.Name).Visible.should be true
|
611
610
|
book2.visible.should be true
|
612
|
-
book2.excel.visible.should be true
|
613
|
-
book2.excel.displayalerts.should == :if_visible
|
611
|
+
book2.excel.properties[:visible].should be true
|
612
|
+
book2.excel.properties[:displayalerts].should == :if_visible
|
614
613
|
book2.excel.DisplayAlerts.should be true
|
615
614
|
end
|
616
615
|
end
|
@@ -663,8 +662,8 @@ describe Workbook do
|
|
663
662
|
it "should create and use a hidden Excel instance" do
|
664
663
|
book2 = Workbook.open(@simple_file1, :force_excel => @book.bookstore.hidden_excel)
|
665
664
|
book2.excel.should_not == @book.excel
|
666
|
-
book2.excel.visible.should be false
|
667
|
-
book2.excel.displayalerts.should == :if_visible
|
665
|
+
book2.excel.properties[:visible].should be false
|
666
|
+
book2.excel.properties[:displayalerts].should == :if_visible
|
668
667
|
book2.close
|
669
668
|
end
|
670
669
|
end
|
@@ -510,7 +510,7 @@ describe Workbook do
|
|
510
510
|
book2.excel.should_not == book.excel
|
511
511
|
end
|
512
512
|
|
513
|
-
it "should
|
513
|
+
it "should type-lift an open known workbook" do
|
514
514
|
book = Workbook.open(@simple_file)
|
515
515
|
ole_workbook = book.ole_workbook
|
516
516
|
new_book = Workbook.new(ole_workbook)
|
@@ -520,7 +520,7 @@ describe Workbook do
|
|
520
520
|
new_book.excel.should == book.excel
|
521
521
|
end
|
522
522
|
|
523
|
-
it "should
|
523
|
+
it "should type-lift an open known workbook and let it be visible" do
|
524
524
|
book = Workbook.open(@simple_file, :visible => true)
|
525
525
|
ole_workbook = book.ole_workbook
|
526
526
|
new_book = Workbook.new(ole_workbook)
|
@@ -532,7 +532,7 @@ describe Workbook do
|
|
532
532
|
new_book.Windows(new_book.ole_workbook.Name).Visible.should == true
|
533
533
|
end
|
534
534
|
|
535
|
-
it "should
|
535
|
+
it "should type-lift an open known workbook and let it be visible and readonly" do
|
536
536
|
book = Workbook.open(@simple_file, :visible => true, :read_only => true)
|
537
537
|
ole_workbook = book.ole_workbook
|
538
538
|
new_book = Workbook.new(ole_workbook)
|
@@ -545,7 +545,7 @@ describe Workbook do
|
|
545
545
|
new_book.ReadOnly.should == true
|
546
546
|
end
|
547
547
|
|
548
|
-
it "should
|
548
|
+
it "should type-lift an open known workbook and make it visible" do
|
549
549
|
book = Workbook.open(@simple_file)
|
550
550
|
ole_workbook = book.ole_workbook
|
551
551
|
new_book = Workbook.new(ole_workbook, :visible => true)
|
@@ -557,7 +557,7 @@ describe Workbook do
|
|
557
557
|
new_book.Windows(new_book.ole_workbook.Name).Visible.should == true
|
558
558
|
end
|
559
559
|
|
560
|
-
it "should
|
560
|
+
it "should type-lift an open unknown workbook" do
|
561
561
|
ole_excel = WIN32OLE.new('Excel.Application')
|
562
562
|
ws = ole_excel.Workbooks
|
563
563
|
abs_filename = General.absolute_path(@simple_file1)
|
@@ -567,7 +567,7 @@ describe Workbook do
|
|
567
567
|
new_book.excel.Hwnd.should == ole_excel.Hwnd
|
568
568
|
end
|
569
569
|
|
570
|
-
it "should
|
570
|
+
it "should type-lift an open unknown workbook and make it visible" do
|
571
571
|
ole_excel = WIN32OLE.new('Excel.Application')
|
572
572
|
ws = ole_excel.Workbooks
|
573
573
|
abs_filename = General.absolute_path(@simple_file1)
|
@@ -579,7 +579,7 @@ describe Workbook do
|
|
579
579
|
new_book.Windows(new_book.ole_workbook.Name).Visible.should == true
|
580
580
|
end
|
581
581
|
|
582
|
-
it "should
|
582
|
+
it "should type-lift an open unknown workbook and make it visible and readonly" do
|
583
583
|
ole_excel = WIN32OLE.new('Excel.Application')
|
584
584
|
ws = ole_excel.Workbooks
|
585
585
|
abs_filename = General.absolute_path(@simple_file1)
|
@@ -35,8 +35,239 @@ describe Workbook do
|
|
35
35
|
rm_tmp(@dir)
|
36
36
|
end
|
37
37
|
|
38
|
+
describe "Workbook#for_reading, #for_modifying" do
|
39
|
+
|
40
|
+
context "with standard" do
|
41
|
+
|
42
|
+
before do
|
43
|
+
@book = Workbook.open(@simple_file1)
|
44
|
+
@old_value = @book.sheet(1)[1,1].Value
|
45
|
+
end
|
46
|
+
|
47
|
+
after do
|
48
|
+
@book.close(:if_unsaved => :forget) if @book && @book.alive?
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should not change the value" do
|
52
|
+
@book.for_reading do |book|
|
53
|
+
book.should be_a Workbook
|
54
|
+
book.should be_alive
|
55
|
+
book.Saved.should be true
|
56
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
57
|
+
book.Saved.should be false
|
58
|
+
end
|
59
|
+
@book.close(:if_unsaved => :forget)
|
60
|
+
new_book = Workbook.open(@simple_file1)
|
61
|
+
new_book.sheet(1)[1,1].Value.should == @old_value
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should change the value" do
|
65
|
+
@book.for_modifying do |book|
|
66
|
+
book.should be_a Workbook
|
67
|
+
book.should be_alive
|
68
|
+
book.Saved.should be true
|
69
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
70
|
+
book.Saved.should be false
|
71
|
+
end
|
72
|
+
@book.close(:if_unsaved => :forget)
|
73
|
+
new_book = Workbook.open(@simple_file1)
|
74
|
+
new_book.sheet(1)[1,1].Value.should_not == @old_value
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should not change the value and make visible" do
|
78
|
+
@book.for_reading(:visible => true) do |book|
|
79
|
+
book.should be_a Workbook
|
80
|
+
book.should be_alive
|
81
|
+
book.visible.should be true
|
82
|
+
book.Saved.should be true
|
83
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
84
|
+
book.Saved.should be false
|
85
|
+
end
|
86
|
+
@book.close(:if_unsaved => :forget)
|
87
|
+
new_book = Workbook.open(@simple_file1)
|
88
|
+
new_book.sheet(1)[1,1].Value.should == @old_value
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should change the value and make visible" do
|
92
|
+
@book.for_modifying(:visible => true) do |book|
|
93
|
+
book.should be_a Workbook
|
94
|
+
book.should be_alive
|
95
|
+
book.visible.should be true
|
96
|
+
book.Saved.should be true
|
97
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
98
|
+
book.Saved.should be false
|
99
|
+
end
|
100
|
+
@book.close(:if_unsaved => :forget)
|
101
|
+
new_book = Workbook.open(@simple_file1)
|
102
|
+
new_book.sheet(1)[1,1].Value.should_not == @old_value
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "Workbook#unobtrusively" do
|
110
|
+
|
111
|
+
context "with a writable saved workbook" do
|
112
|
+
|
113
|
+
before do
|
114
|
+
@book = Workbook.open(@simple_file1, :visible => true)
|
115
|
+
@old_value = @book.sheet(1)[1,1].Value
|
116
|
+
end
|
117
|
+
|
118
|
+
after do
|
119
|
+
@book.close(:if_unsaved => :forget) if @book && @book.alive?
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should unobtrusively open, modify, and retain the status" do
|
123
|
+
@book.unobtrusively do |book|
|
124
|
+
book.saved.should be true
|
125
|
+
book.visible.should be true
|
126
|
+
book.writable.should be true
|
127
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
128
|
+
end
|
129
|
+
@book.saved.should be true
|
130
|
+
@book.visible.should be true
|
131
|
+
@book.writable.should be true
|
132
|
+
@book.sheet(1)[1,1].Value.should_not == @old_value
|
133
|
+
@book.close
|
134
|
+
new_book = Workbook.open(@simple_file1)
|
135
|
+
new_book.sheet(1)[1,1].Value.should_not == @old_value
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should unobtrusively open, modify, and not save the changes" do
|
139
|
+
@book.unobtrusively(:writable => false) do |book|
|
140
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
141
|
+
end
|
142
|
+
@book.saved.should be true
|
143
|
+
@book.visible.should be true
|
144
|
+
@book.writable.should be true
|
145
|
+
@book.sheet(1)[1,1].Value.should_not == @old_value
|
146
|
+
@book.close
|
147
|
+
new_book = Workbook.open(@simple_file1)
|
148
|
+
new_book.sheet(1)[1,1].Value.should == @old_value
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should unobtrusively open, modify, and save the changes" do
|
152
|
+
@book.unobtrusively(:writable => true) do |book|
|
153
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
154
|
+
end
|
155
|
+
@book.saved.should be true
|
156
|
+
@book.visible.should be true
|
157
|
+
@book.writable.should be true
|
158
|
+
@book.sheet(1)[1,1].Value.should_not == @old_value
|
159
|
+
@book.close
|
160
|
+
new_book = Workbook.open(@simple_file1)
|
161
|
+
new_book.sheet(1)[1,1].Value.should_not == @old_value
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
context "with an writable unsaved workbook" do
|
167
|
+
|
168
|
+
before do
|
169
|
+
@book = Workbook.open(@simple_file1, :visible => true)
|
170
|
+
@old_value = @book.sheet(1)[1,1].Value
|
171
|
+
sheet = @book.sheet(1)
|
172
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
173
|
+
end
|
174
|
+
|
175
|
+
after do
|
176
|
+
@book.close(:if_unsaved => :forget) if @book && @book.alive?
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should unobtrusively open, modify, and retain the status" do
|
180
|
+
@book.unobtrusively do |book|
|
181
|
+
book.saved.should be false
|
182
|
+
book.visible.should be true
|
183
|
+
book.writable.should be true
|
184
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
185
|
+
end
|
186
|
+
@book.saved.should be false
|
187
|
+
@book.visible.should be true
|
188
|
+
@book.writable.should be true
|
189
|
+
@book.sheet(1)[1,1].Value.should == @old_value
|
190
|
+
@book.close(:if_unsaved => :forget)
|
191
|
+
@book = Workbook.open(@simple_file1)
|
192
|
+
@book.sheet(1)[1,1].Value.should == @old_value
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should unobtrusively open, modify, and not save the changes" do
|
196
|
+
@book.unobtrusively(:writable => false) do |book|
|
197
|
+
book.sheet(1)[1,1] = "bla"
|
198
|
+
end
|
199
|
+
@book.saved.should be false
|
200
|
+
@book.visible.should be true
|
201
|
+
@book.writable.should be true
|
202
|
+
@book.sheet(1)[1,1].Value.should == "bla"
|
203
|
+
@book.close(:if_unsaved => :forget)
|
204
|
+
new_book = Workbook.open(@simple_file1)
|
205
|
+
new_book.sheet(1)[1,1].Value.should == @old_value
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should unobtrusively open, modify, and save the changes" do
|
209
|
+
@book.unobtrusively(:writable => true) do |book|
|
210
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
211
|
+
end
|
212
|
+
@book.saved.should be false
|
213
|
+
@book.visible.should be true
|
214
|
+
@book.writable.should be true
|
215
|
+
@book.sheet(1)[1,1].Value.should == @old_value
|
216
|
+
@book.close(:if_unsaved => :forget)
|
217
|
+
new_book = Workbook.open(@simple_file1)
|
218
|
+
new_book.sheet(1)[1,1].Value.should == @old_value
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
context "with a closed workbook" do
|
224
|
+
|
225
|
+
before do
|
226
|
+
@book = Workbook.open(@simple_file1, :visible => true)
|
227
|
+
@old_value = @book.sheet(1)[1,1].Value
|
228
|
+
@book.close
|
229
|
+
end
|
230
|
+
|
231
|
+
after do
|
232
|
+
@book.close(:if_unsaved => :forget) if @book && @book.alive?
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should unobtrusively open and close the workbook" do
|
236
|
+
@book.unobtrusively do |book|
|
237
|
+
book.should be_alive
|
238
|
+
book.saved.should be true
|
239
|
+
book.visible.should be true
|
240
|
+
book.writable.should be true
|
241
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
242
|
+
end
|
243
|
+
@book.should_not be_alive
|
244
|
+
new_book = Workbook.open(@simple_file1)
|
245
|
+
new_book.sheet(1)[1,1].Value.should_not == @old_value
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should unobtrusively open and and not close the workbook" do
|
249
|
+
@book.unobtrusively(:visible => true, :keep_open => true) do |book|
|
250
|
+
book.should be_alive
|
251
|
+
book.saved.should be true
|
252
|
+
book.visible.should be true
|
253
|
+
book.writable.should be true
|
254
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
255
|
+
end
|
256
|
+
@book.should be_alive
|
257
|
+
@book.saved.should be true
|
258
|
+
@book.visible.should be true
|
259
|
+
@book.writable.should be true
|
260
|
+
@book.sheet(1)[1,1].Value.should_not == @old_value
|
261
|
+
@book.close
|
262
|
+
new_book = Workbook.open(@simple_file1)
|
263
|
+
new_book.sheet(1)[1,1].Value.should_not == @old_value
|
264
|
+
end
|
265
|
+
|
266
|
+
end
|
267
|
+
|
268
|
+
end
|
38
269
|
|
39
|
-
describe "unobtrusively" do
|
270
|
+
describe "Workbook.unobtrusively" do
|
40
271
|
|
41
272
|
# @private
|
42
273
|
def unobtrusively_ok?
|
@@ -88,13 +319,13 @@ describe Workbook do
|
|
88
319
|
@ole_e1 = WIN32OLE.new('Excel.Application')
|
89
320
|
ws = @ole_e1.Workbooks
|
90
321
|
@abs_filename = General.absolute_path(@simple_file1)
|
91
|
-
@ole_wb = ws.Open(abs_filename)
|
322
|
+
@ole_wb = ws.Open(@abs_filename)
|
92
323
|
@old_value = @ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value
|
93
324
|
end
|
94
325
|
|
95
326
|
it "should connect" do
|
96
|
-
|
97
|
-
book.excel.
|
327
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
328
|
+
book.excel.Workbooks.Count.should == 1
|
98
329
|
Excel.excels_number.should == 1
|
99
330
|
book.FullName.should == General.absolute_path(@simple_file1)
|
100
331
|
book.saved.should be true
|
@@ -108,22 +339,24 @@ describe Workbook do
|
|
108
339
|
end
|
109
340
|
|
110
341
|
it "should set visible => true and remain invisiblity" do
|
111
|
-
|
342
|
+
Workbook.unobtrusively(@simple_file1, :visible => true) do |book|
|
112
343
|
book.saved.should be true
|
113
344
|
book.visible.should be true
|
114
345
|
book.writable.should be true
|
115
346
|
end
|
116
347
|
ole_wb = WIN32OLE.connect(@abs_filename)
|
117
348
|
ole_wb.Saved.should be true
|
118
|
-
@ole_e1.Visible.should be
|
349
|
+
@ole_e1.Visible.should be true
|
350
|
+
ole_wb.Windows(ole_wb.Name).Visible.should be false
|
119
351
|
ole_wb.ReadOnly.should be false
|
120
352
|
end
|
121
353
|
|
122
354
|
it "should set read_only => true and remain writability" do
|
123
|
-
|
355
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book|
|
124
356
|
book.saved.should be true
|
125
357
|
book.visible.should be false
|
126
|
-
book.
|
358
|
+
book.ReadOnly.should be true
|
359
|
+
book.writable.should be false
|
127
360
|
end
|
128
361
|
ole_wb = WIN32OLE.connect(@abs_filename)
|
129
362
|
ole_wb.Saved.should be true
|
@@ -132,19 +365,21 @@ describe Workbook do
|
|
132
365
|
end
|
133
366
|
|
134
367
|
it "should set visible => true, read_only => true" do
|
135
|
-
|
368
|
+
Workbook.unobtrusively(@simple_file1, :visible => true, :read_only => true) do |book|
|
136
369
|
book.saved.should be true
|
137
370
|
book.visible.should be true
|
371
|
+
book.ReadOnly.should be true
|
138
372
|
book.writable.should be false
|
139
373
|
end
|
140
374
|
ole_wb = WIN32OLE.connect(@abs_filename)
|
141
375
|
ole_wb.Saved.should be true
|
142
|
-
@ole_e1.Visible.should be
|
376
|
+
@ole_e1.Visible.should be true
|
377
|
+
ole_wb.Windows(ole_wb.Name).Visible.should be false
|
143
378
|
ole_wb.ReadOnly.should be false
|
144
379
|
end
|
145
380
|
|
146
381
|
it "should modify and remain saved-status" do
|
147
|
-
|
382
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
148
383
|
book.saved.should be true
|
149
384
|
book.visible.should be false
|
150
385
|
book.writable.should be true
|
@@ -163,7 +398,7 @@ describe Workbook do
|
|
163
398
|
end
|
164
399
|
|
165
400
|
it "should modify and remain saved-status and not save the new value when writable => false" do
|
166
|
-
|
401
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
167
402
|
book.saved.should be true
|
168
403
|
book.visible.should be false
|
169
404
|
book.writable.should be true
|
@@ -189,13 +424,13 @@ describe Workbook do
|
|
189
424
|
@ole_e1 = WIN32OLE.new('Excel.Application')
|
190
425
|
ws = @ole_e1.Workbooks
|
191
426
|
@abs_filename = General.absolute_path(@simple_file1)
|
192
|
-
@ole_wb = ws.Open(abs_filename)
|
427
|
+
@ole_wb = ws.Open(@abs_filename)
|
193
428
|
@ole_e1.Visible = true
|
194
429
|
@ole_wb.Windows(@ole_wb.Name).Visible = true
|
195
430
|
end
|
196
431
|
|
197
432
|
it "should remain visibility" do
|
198
|
-
|
433
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
199
434
|
book.saved.should be true
|
200
435
|
book.visible.should be true
|
201
436
|
book.writable.should be true
|
@@ -207,7 +442,7 @@ describe Workbook do
|
|
207
442
|
end
|
208
443
|
|
209
444
|
it "should set visible => false and remain visibility" do
|
210
|
-
|
445
|
+
Workbook.unobtrusively(@simple_file1, :visible => false) do |book|
|
211
446
|
book.saved.should be true
|
212
447
|
book.visible.should be false
|
213
448
|
book.writable.should be true
|
@@ -226,17 +461,17 @@ describe Workbook do
|
|
226
461
|
@ole_e1 = WIN32OLE.new('Excel.Application')
|
227
462
|
ws = @ole_e1.Workbooks
|
228
463
|
@abs_filename = General.absolute_path(@simple_file1)
|
229
|
-
@ole_wb = ws.Open(abs_filename)
|
464
|
+
@ole_wb = ws.Open(@abs_filename)
|
230
465
|
@ole_e1.Visible = true
|
231
466
|
@ole_wb.Windows(@ole_wb.Name).Visible = true
|
232
467
|
@old_value = @ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value
|
233
|
-
@ole_wb.Worksheets.Item(
|
468
|
+
@ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value = @old_value = "foo" #== "foo" ? "bar" : "foo"
|
234
469
|
@new_value = @ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value
|
235
470
|
@ole_wb.Saved.should be false
|
236
471
|
end
|
237
472
|
|
238
473
|
it "should connect and remain unsaved" do
|
239
|
-
|
474
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
240
475
|
book.saved.should be false
|
241
476
|
book.visible.should be true
|
242
477
|
book.writable.should be true
|
@@ -247,9 +482,19 @@ describe Workbook do
|
|
247
482
|
ole_wb.ReadOnly.should be false
|
248
483
|
end
|
249
484
|
|
485
|
+
it "should raise error" do
|
486
|
+
expect{
|
487
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book|
|
488
|
+
book.saved.should be false
|
489
|
+
book.visible.should be true
|
490
|
+
book.writable.should be false
|
491
|
+
end
|
492
|
+
}.to raise_error(WorkbookNotSaved)
|
493
|
+
end
|
494
|
+
|
250
495
|
it "should remain writable" do
|
251
|
-
|
252
|
-
book.saved.should be
|
496
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true, :if_unsaved => :save) do |book|
|
497
|
+
book.saved.should be true
|
253
498
|
book.visible.should be true
|
254
499
|
book.writable.should be false
|
255
500
|
end
|
@@ -260,8 +505,8 @@ describe Workbook do
|
|
260
505
|
end
|
261
506
|
|
262
507
|
it "should remain unsaved when modifying" do
|
263
|
-
|
264
|
-
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
508
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
509
|
+
book.sheet(1)[1,1] = "bar" #book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
265
510
|
@new_value = book.sheet(1)[1,1].Value
|
266
511
|
book.saved.should be false
|
267
512
|
book.visible.should be true
|
@@ -271,15 +516,18 @@ describe Workbook do
|
|
271
516
|
ole_wb.Saved.should be false
|
272
517
|
@ole_e1.Visible.should be true
|
273
518
|
ole_wb.ReadOnly.should be false
|
274
|
-
|
519
|
+
Excel.kill_all
|
275
520
|
book2 = Workbook.open(@simple_file1)
|
276
521
|
book2.sheet(1)[1,1].value.should_not == @old_value
|
277
522
|
book2.sheet(1)[1,1].value.should == @new_value
|
278
523
|
end
|
279
524
|
|
280
525
|
it "should not write with :writable => false" do
|
281
|
-
|
282
|
-
|
526
|
+
@ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value = @old_value = "foo"
|
527
|
+
@ole_wb.Save
|
528
|
+
@ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value = @old_value = "foo"
|
529
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
530
|
+
book.sheet(1)[1,1] = "bar" #book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
283
531
|
@new_value = book.sheet(1)[1,1].Value
|
284
532
|
book.saved.should be false
|
285
533
|
book.visible.should be true
|
@@ -289,7 +537,7 @@ describe Workbook do
|
|
289
537
|
ole_wb.Saved.should be false
|
290
538
|
@ole_e1.Visible.should be true
|
291
539
|
ole_wb.ReadOnly.should be false
|
292
|
-
|
540
|
+
Excel.kill_all
|
293
541
|
book2 = Workbook.open(@simple_file1)
|
294
542
|
book2.sheet(1)[1,1].value.should == @old_value
|
295
543
|
book2.sheet(1)[1,1].value.should_not == @new_value
|
@@ -303,14 +551,15 @@ describe Workbook do
|
|
303
551
|
@ole_e1 = WIN32OLE.new('Excel.Application')
|
304
552
|
ws = @ole_e1.Workbooks
|
305
553
|
@abs_filename = General.absolute_path(@simple_file1)
|
306
|
-
@ole_wb = ws.Open(abs_filename, RobustExcelOle::XlUpdateLinksNever, true)
|
554
|
+
@ole_wb = ws.Open(@abs_filename, RobustExcelOle::XlUpdateLinksNever, true)
|
555
|
+
@old_value = @ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value
|
307
556
|
@ole_e1.Visible = true
|
308
557
|
@ole_wb.Windows(@ole_wb.Name).Visible = true
|
309
558
|
@ole_wb.ReadOnly.should be true
|
310
559
|
end
|
311
560
|
|
312
561
|
it "should connect and remain read-only" do
|
313
|
-
|
562
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
314
563
|
book.saved.should be true
|
315
564
|
book.visible.should be true
|
316
565
|
book.writable.should be false
|
@@ -322,8 +571,8 @@ describe Workbook do
|
|
322
571
|
end
|
323
572
|
|
324
573
|
it "should remain read-only" do
|
325
|
-
|
326
|
-
book.saved.should be
|
574
|
+
Workbook.unobtrusively(@simple_file1, :read_only => false) do |book|
|
575
|
+
book.saved.should be true
|
327
576
|
book.visible.should be true
|
328
577
|
book.writable.should be true
|
329
578
|
end
|
@@ -334,7 +583,25 @@ describe Workbook do
|
|
334
583
|
end
|
335
584
|
|
336
585
|
it "should remain read-only when modifying" do
|
337
|
-
|
586
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
587
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
588
|
+
@new_value = book.sheet(1)[1,1].Value
|
589
|
+
book.saved.should be false
|
590
|
+
book.visible.should be true
|
591
|
+
book.writable.should be false
|
592
|
+
end
|
593
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
594
|
+
ole_wb.Saved.should be true
|
595
|
+
@ole_e1.Visible.should be true
|
596
|
+
ole_wb.ReadOnly.should be true
|
597
|
+
ole_wb.Close
|
598
|
+
book2 = Workbook.open(@simple_file1)
|
599
|
+
book2.sheet(1)[1,1].value.should == @old_value
|
600
|
+
book2.sheet(1)[1,1].value.should_not == @new_value
|
601
|
+
end
|
602
|
+
|
603
|
+
it "should remain read-only when modifying" do
|
604
|
+
Workbook.unobtrusively(@simple_file1, :read_only => false) do |book|
|
338
605
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
339
606
|
@new_value = book.sheet(1)[1,1].Value
|
340
607
|
book.saved.should be false
|
@@ -352,7 +619,7 @@ describe Workbook do
|
|
352
619
|
end
|
353
620
|
|
354
621
|
it "should remain read-only when modifying" do
|
355
|
-
|
622
|
+
Workbook.unobtrusively(@simple_file1, :read_only => false, :writable => true) do |book|
|
356
623
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
357
624
|
@new_value = book.sheet(1)[1,1].Value
|
358
625
|
book.saved.should be false
|
@@ -370,7 +637,7 @@ describe Workbook do
|
|
370
637
|
end
|
371
638
|
|
372
639
|
it "should remain read-only when modifying and not save changes, when :writable => false" do
|
373
|
-
|
640
|
+
Workbook.unobtrusively(@simple_file1, :writable => false, :read_only => false) do |book|
|
374
641
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
375
642
|
@new_value = book.sheet(1)[1,1].Value
|
376
643
|
book.saved.should be false
|
@@ -388,7 +655,26 @@ describe Workbook do
|
|
388
655
|
end
|
389
656
|
|
390
657
|
it "should remain read-only when modifying and not save changes, when :writable => false" do
|
391
|
-
|
658
|
+
Workbook.unobtrusively(@simple_file1, :read_only => false, :writable => false) do |book|
|
659
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
660
|
+
@new_value = book.sheet(1)[1,1].Value
|
661
|
+
book.saved.should be false
|
662
|
+
book.visible.should be true
|
663
|
+
book.writable.should be true
|
664
|
+
end
|
665
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
666
|
+
ole_wb.Saved.should be true
|
667
|
+
@ole_e1.Visible.should be true
|
668
|
+
ole_wb.ReadOnly.should be true
|
669
|
+
ole_wb.Close
|
670
|
+
book2 = Workbook.open(@simple_file1)
|
671
|
+
book2.sheet(1)[1,1].value.should == @old_value
|
672
|
+
book2.sheet(1)[1,1].value.should_not == @new_value
|
673
|
+
end
|
674
|
+
|
675
|
+
|
676
|
+
it "should remain read-only when modifying and not save changes, when :writable => false" do
|
677
|
+
Workbook.unobtrusively(@simple_file1, :writable => false, :read_only => false) do |book|
|
392
678
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
393
679
|
@new_value = book.sheet(1)[1,1].Value
|
394
680
|
book.saved.should be false
|
@@ -405,6 +691,43 @@ describe Workbook do
|
|
405
691
|
book2.sheet(1)[1,1].value.should_not == @new_value
|
406
692
|
end
|
407
693
|
|
694
|
+
it "should remain read-only when modifying and not save changes, even if :writable => true" do
|
695
|
+
Workbook.unobtrusively(@simple_file1, :writable => true) do |book|
|
696
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
697
|
+
@new_value = book.sheet(1)[1,1].Value
|
698
|
+
book.saved.should be false
|
699
|
+
book.visible.should be true
|
700
|
+
book.writable.should be false
|
701
|
+
end
|
702
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
703
|
+
ole_wb.Saved.should be true
|
704
|
+
@ole_e1.Visible.should be true
|
705
|
+
ole_wb.ReadOnly.should be true
|
706
|
+
ole_wb.Close
|
707
|
+
book2 = Workbook.open(@simple_file1)
|
708
|
+
book2.sheet(1)[1,1].value.should == @old_value
|
709
|
+
book2.sheet(1)[1,1].value.should_not == @new_value
|
710
|
+
end
|
711
|
+
|
712
|
+
it "should remain read-only when modifying and not save changes, when :writable => false" do
|
713
|
+
Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
|
714
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
715
|
+
@new_value = book.sheet(1)[1,1].Value
|
716
|
+
book.saved.should be false
|
717
|
+
book.visible.should be true
|
718
|
+
book.writable.should be false
|
719
|
+
end
|
720
|
+
ole_wb = WIN32OLE.connect(@abs_filename)
|
721
|
+
ole_wb.Saved.should be true
|
722
|
+
@ole_e1.Visible.should be true
|
723
|
+
ole_wb.ReadOnly.should be true
|
724
|
+
Excel.kill_all
|
725
|
+
book2 = Workbook.open(@simple_file1)
|
726
|
+
book2.sheet(1)[1,1].value.should == @old_value
|
727
|
+
book2.sheet(1)[1,1].value.should_not == @new_value
|
728
|
+
end
|
729
|
+
|
730
|
+
|
408
731
|
end
|
409
732
|
|
410
733
|
end
|
@@ -464,7 +787,7 @@ describe Workbook do
|
|
464
787
|
end
|
465
788
|
Excel.current.Workbooks.Count.should == 0
|
466
789
|
b1 = Workbook.open(@simple_file1)
|
467
|
-
b1.sheet(1)[1,1].Value.
|
790
|
+
b1.sheet(1)[1,1].Value.should == @old_value
|
468
791
|
end
|
469
792
|
|
470
793
|
it "should open as read-write" do
|
@@ -495,8 +818,8 @@ describe Workbook do
|
|
495
818
|
Workbook.unobtrusively(@simple_file, :read_only => true) do |book|
|
496
819
|
book.ReadOnly.should be true
|
497
820
|
@old_value = book.sheet(1)[1,1].Value
|
498
|
-
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
499
|
-
book.Saved.should be false
|
821
|
+
#book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
822
|
+
#book.Saved.should be false
|
500
823
|
end
|
501
824
|
Excel.current.Workbooks.Count.should == 0
|
502
825
|
b1 = Workbook.open(@simple_file1)
|
@@ -577,7 +900,7 @@ describe Workbook do
|
|
577
900
|
end
|
578
901
|
@book.close
|
579
902
|
book2 = Workbook.open(@simple_file1)
|
580
|
-
book2.sheet(1)[1,1].Value.
|
903
|
+
book2.sheet(1)[1,1].Value.should == @old_value
|
581
904
|
end
|
582
905
|
|
583
906
|
it "should open as read-write" do
|
@@ -607,18 +930,20 @@ describe Workbook do
|
|
607
930
|
end
|
608
931
|
|
609
932
|
it "should force to read-only" do
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
book2.sheet(1)[1,1].Value.should == @old_value
|
933
|
+
expect{
|
934
|
+
Workbook.unobtrusively(@simple_file1, :if_unsaved => :forget, :read_only => true) do |book|
|
935
|
+
book.ReadOnly.should be true
|
936
|
+
book.should == @book
|
937
|
+
book.filename.should == @book.filename
|
938
|
+
book.excel.should == @book.excel
|
939
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
940
|
+
end
|
941
|
+
}.to raise_error(WorkbookReadOnly)
|
620
942
|
end
|
621
943
|
|
944
|
+
|
945
|
+
|
946
|
+
|
622
947
|
it "should force to read-only" do
|
623
948
|
Workbook.unobtrusively(@simple_file1, :read_only => true, :writable => false) do |book|
|
624
949
|
book.ReadOnly.should be true
|
@@ -685,7 +1010,7 @@ describe Workbook do
|
|
685
1010
|
|
686
1011
|
it "should open as read-write" do
|
687
1012
|
Workbook.unobtrusively(@simple_file1, :read_only => false) do |book|
|
688
|
-
book.Readonly.should be
|
1013
|
+
book.Readonly.should be false
|
689
1014
|
book.should == @book
|
690
1015
|
book.filename.should == @book.filename
|
691
1016
|
book.excel.should == @book.excel
|
@@ -693,7 +1018,7 @@ describe Workbook do
|
|
693
1018
|
end
|
694
1019
|
@book.close
|
695
1020
|
book2 = Workbook.open(@simple_file1)
|
696
|
-
book2.sheet(1)[1,1].Value.
|
1021
|
+
book2.sheet(1)[1,1].Value.should_not == @old_value
|
697
1022
|
end
|
698
1023
|
|
699
1024
|
it "should open as read-write" do
|
@@ -709,9 +1034,9 @@ describe Workbook do
|
|
709
1034
|
book2.sheet(1)[1,1].Value.should == @old_value
|
710
1035
|
end
|
711
1036
|
|
712
|
-
it "should
|
1037
|
+
it "should remain read-only even if writeble => true" do
|
713
1038
|
Workbook.unobtrusively(@simple_file1, :writable => true) do |book|
|
714
|
-
book.ReadOnly.should be
|
1039
|
+
book.ReadOnly.should be true
|
715
1040
|
book.should == @book
|
716
1041
|
book.filename.should == @book.filename
|
717
1042
|
book.excel.should == @book.excel
|
@@ -719,7 +1044,7 @@ describe Workbook do
|
|
719
1044
|
end
|
720
1045
|
@book.close
|
721
1046
|
book2 = Workbook.open(@simple_file1)
|
722
|
-
book2.sheet(1)[1,1].Value.
|
1047
|
+
book2.sheet(1)[1,1].Value.should == @old_value
|
723
1048
|
end
|
724
1049
|
|
725
1050
|
it "should force to read-write" do
|
@@ -897,7 +1222,7 @@ describe Workbook do
|
|
897
1222
|
end
|
898
1223
|
|
899
1224
|
it "should force to read-only" do
|
900
|
-
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book|
|
1225
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true, :if_unsaved => :save) do |book|
|
901
1226
|
book.ReadOnly.should be true
|
902
1227
|
end
|
903
1228
|
@book.Saved.should be false
|
@@ -906,7 +1231,7 @@ describe Workbook do
|
|
906
1231
|
end
|
907
1232
|
|
908
1233
|
it "should force to read-only with writable false" do
|
909
|
-
Workbook.unobtrusively(@simple_file1, :read_only => true, :writable => false) do |book|
|
1234
|
+
Workbook.unobtrusively(@simple_file1, :if_unsaved => :save, :read_only => true, :writable => false) do |book|
|
910
1235
|
book.ReadOnly.should be true
|
911
1236
|
end
|
912
1237
|
@book.Saved.should be false
|
@@ -955,48 +1280,23 @@ describe Workbook do
|
|
955
1280
|
end
|
956
1281
|
|
957
1282
|
it "should open as read-only" do
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
book.filename.should == @book.filename
|
962
|
-
book.excel.should == @book.excel
|
963
|
-
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
964
|
-
end
|
965
|
-
@book.Saved.should be false
|
966
|
-
@book.ReadOnly.should be true
|
967
|
-
@book.sheet(1)[1,1].Value.should_not == @old_value
|
968
|
-
@book.close
|
969
|
-
book2 = Workbook.open(@simple_file1)
|
970
|
-
book2.sheet(1)[1,1].Value.should_not == @old_value
|
1283
|
+
expect{
|
1284
|
+
Workbook.unobtrusively(@simple_file1, :if_unsaved => :accept, :read_only => false, :writable => false)
|
1285
|
+
}.to raise_error(OptionInvalid)
|
971
1286
|
end
|
972
1287
|
|
973
|
-
it "should
|
974
|
-
Workbook.unobtrusively(@simple_file1, :
|
975
|
-
book.Readonly.should be
|
976
|
-
book.should
|
977
|
-
book.filename.should == @book.filename
|
978
|
-
book.excel.should == @book.excel
|
1288
|
+
it "should remain read-only and not write, even with :writable => true" do
|
1289
|
+
Workbook.unobtrusively(@simple_file1, :writable => true) do |book|
|
1290
|
+
book.Readonly.should be true
|
1291
|
+
book.Saved.should be false
|
979
1292
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
980
1293
|
end
|
981
|
-
@book.Saved.should be false
|
982
1294
|
@book.ReadOnly.should be true
|
983
1295
|
@book.sheet(1)[1,1].Value.should_not == @old_value
|
984
1296
|
@book.close
|
985
1297
|
book2 = Workbook.open(@simple_file1)
|
986
1298
|
book2.sheet(1)[1,1].Value.should_not == @old_value
|
987
1299
|
end
|
988
|
-
|
989
|
-
it "should raise an error" do
|
990
|
-
expect{
|
991
|
-
Workbook.unobtrusively(@simple_file1, :writable => true)
|
992
|
-
}.to raise_error(NotImplementedREOError, "unsaved read-only workbook shall be written")
|
993
|
-
end
|
994
|
-
|
995
|
-
it "should raise an error" do
|
996
|
-
expect{
|
997
|
-
Workbook.unobtrusively(@simple_file1, :writable => true)
|
998
|
-
}.to raise_error(NotImplementedREOError, "unsaved read-only workbook shall be written")
|
999
|
-
end
|
1000
1300
|
|
1001
1301
|
it "should force to read-only" do
|
1002
1302
|
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book|
|
@@ -1097,21 +1397,20 @@ describe Workbook do
|
|
1097
1397
|
book = Workbook.open(@simple_file1)
|
1098
1398
|
book.sheet(1)[1,1].Value.should == @old_value
|
1099
1399
|
end
|
1100
|
-
|
1400
|
+
=begin
|
1101
1401
|
it "should write in the outer and not in the inner block" do
|
1102
|
-
Workbook.unobtrusively(@simple_file1) do |book|
|
1402
|
+
Workbook.unobtrusively(@simple_file1, :if_unsaved => :forget) do |book|
|
1103
1403
|
@old_value = book.sheet(1)[1,1].Value
|
1104
1404
|
book.ReadOnly.should be false
|
1105
1405
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
1106
1406
|
book.Saved.should be false
|
1107
1407
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
1108
|
-
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book2|
|
1408
|
+
Workbook.unobtrusively(@simple_file1, :if_unsaved => :forget, :read_only => true) do |book2|
|
1109
1409
|
book2.should == book
|
1110
1410
|
book2.ReadOnly.should be true
|
1111
|
-
book2.Saved.should be
|
1112
|
-
book2.sheet(1)[1,1].Value.should_not == @old_value
|
1411
|
+
book2.Saved.should be true
|
1113
1412
|
book2.sheet(1)[1,1] = book2.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
1114
|
-
book2.sheet(1)[1,1].Value.
|
1413
|
+
#book2.sheet(1)[1,1].Value.should_not == @old_value
|
1115
1414
|
end
|
1116
1415
|
book.should be_alive
|
1117
1416
|
book.Saved.should be false
|
@@ -1120,7 +1419,7 @@ describe Workbook do
|
|
1120
1419
|
book = Workbook.open(@simple_file1)
|
1121
1420
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
1122
1421
|
end
|
1123
|
-
|
1422
|
+
=end
|
1124
1423
|
it "should write in the outer and not in the inner block" do
|
1125
1424
|
Workbook.unobtrusively(@simple_file1) do |book|
|
1126
1425
|
@old_value = book.sheet(1)[1,1].Value
|
@@ -1143,15 +1442,15 @@ describe Workbook do
|
|
1143
1442
|
book = Workbook.open(@simple_file1)
|
1144
1443
|
book.sheet(1)[1,1].Value.should == @old_value
|
1145
1444
|
end
|
1146
|
-
|
1445
|
+
=begin
|
1147
1446
|
it "should be read-only in the outer and write in the inner block" do
|
1148
|
-
Workbook.unobtrusively(@simple_file1, :read_only => true) do |book|
|
1447
|
+
Workbook.unobtrusively(@simple_file1, :read_only => true, :if_unsaved => :save) do |book|
|
1149
1448
|
@old_value = book.sheet(1)[1,1].Value
|
1150
1449
|
book.ReadOnly.should be true
|
1151
1450
|
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
1152
1451
|
book.Saved.should be false
|
1153
1452
|
book.sheet(1)[1,1].Value.should_not == @old_value
|
1154
|
-
Workbook.unobtrusively(@simple_file1) do |book2|
|
1453
|
+
Workbook.unobtrusively(@simple_file1, :if_unsaved => :save) do |book2|
|
1155
1454
|
book2.should == book
|
1156
1455
|
book2.ReadOnly.should be true
|
1157
1456
|
book2.Saved.should be false
|
@@ -1167,7 +1466,7 @@ describe Workbook do
|
|
1167
1466
|
book = Workbook.open(@simple_file1)
|
1168
1467
|
book.sheet(1)[1,1].Value.should == @old_value
|
1169
1468
|
end
|
1170
|
-
|
1469
|
+
=end
|
1171
1470
|
end
|
1172
1471
|
|
1173
1472
|
end
|
@@ -1235,7 +1534,7 @@ describe Workbook do
|
|
1235
1534
|
book1.ReadOnly.should be true
|
1236
1535
|
book1.close
|
1237
1536
|
book2 = Workbook.open(@simple_file1)
|
1238
|
-
book2.sheet(1)[1,1].Value.
|
1537
|
+
book2.sheet(1)[1,1].Value.should == old_value
|
1239
1538
|
end
|
1240
1539
|
|
1241
1540
|
end
|
@@ -1263,6 +1562,7 @@ describe Workbook do
|
|
1263
1562
|
|
1264
1563
|
it "should remain check-compatibility false" do
|
1265
1564
|
book1 = Workbook.open(@simple_file1, :check_compatibility => false)
|
1565
|
+
book1.CheckCompatibility.should be false
|
1266
1566
|
Workbook.unobtrusively(@simple_file1) do |book|
|
1267
1567
|
end
|
1268
1568
|
book1.CheckCompatibility.should be false
|
@@ -1270,6 +1570,7 @@ describe Workbook do
|
|
1270
1570
|
|
1271
1571
|
it "should remain check-compatibility true" do
|
1272
1572
|
book1 = Workbook.open(@simple_file1, :check_compatibility => true)
|
1573
|
+
book1.CheckCompatibility.should be true
|
1273
1574
|
Workbook.unobtrusively(@simple_file1) do |book|
|
1274
1575
|
end
|
1275
1576
|
book1.CheckCompatibility.should be true
|
@@ -1651,16 +1952,16 @@ describe Workbook do
|
|
1651
1952
|
Workbook.unobtrusively(@simple_file1, :if_closed => :new) do |book|
|
1652
1953
|
book.excel.should_not == @book.excel
|
1653
1954
|
book.excel.should_not == new_excel
|
1654
|
-
book.excel.visible.should be false
|
1655
|
-
book.excel.displayalerts.should == :if_visible
|
1955
|
+
book.excel.properties[:visible].should be false
|
1956
|
+
book.excel.properties[:displayalerts].should == :if_visible
|
1656
1957
|
@another_excel = book.excel
|
1657
1958
|
end
|
1658
1959
|
Workbook.unobtrusively(@simple_file1, :if_closed => :current) do |book|
|
1659
1960
|
book.excel.should_not == @book.excel
|
1660
1961
|
book.excel.should_not == new_excel
|
1661
1962
|
book.excel.should == @another_excel
|
1662
|
-
book.excel.visible.should be false
|
1663
|
-
book.excel.displayalerts.should == :if_visible
|
1963
|
+
book.excel.properties[:visible].should be false
|
1964
|
+
book.excel.properties[:displayalerts].should == :if_visible
|
1664
1965
|
end
|
1665
1966
|
end
|
1666
1967
|
|
@@ -2011,7 +2312,7 @@ describe Workbook do
|
|
2011
2312
|
end
|
2012
2313
|
end
|
2013
2314
|
|
2014
|
-
describe "
|
2315
|
+
describe "type-lifting" do
|
2015
2316
|
|
2016
2317
|
context "with standard" do
|
2017
2318
|
|
@@ -2024,7 +2325,7 @@ describe Workbook do
|
|
2024
2325
|
@book.close
|
2025
2326
|
end
|
2026
2327
|
|
2027
|
-
it "should
|
2328
|
+
it "should type-lift" do
|
2028
2329
|
Workbook.unobtrusively(@ole_workbook) do |book|
|
2029
2330
|
book.should === @book
|
2030
2331
|
book.equal?(@book).should be true
|
@@ -2057,7 +2358,8 @@ describe Workbook do
|
|
2057
2358
|
book.Saved.should be false
|
2058
2359
|
book.excel.should == @book.excel
|
2059
2360
|
end
|
2060
|
-
|
2361
|
+
Excel.kill_all
|
2362
|
+
new_book = Workbook.open(@simple_file1)
|
2061
2363
|
sheet = new_book.sheet(1)
|
2062
2364
|
sheet[1,1].Value.should == @old_cell_value
|
2063
2365
|
end
|
@@ -2071,7 +2373,8 @@ describe Workbook do
|
|
2071
2373
|
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
2072
2374
|
book.excel.should == another_excel
|
2073
2375
|
end
|
2074
|
-
|
2376
|
+
Excel.kill_all
|
2377
|
+
new_book = Workbook.open(@simple_file1)
|
2075
2378
|
sheet = new_book.sheet(1)
|
2076
2379
|
sheet[1,1].Value.should == @old_cell_value
|
2077
2380
|
end
|
@@ -2084,10 +2387,11 @@ describe Workbook do
|
|
2084
2387
|
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
2085
2388
|
book.excel.should_not == @book.excel
|
2086
2389
|
book.excel.should_not == new_excel
|
2087
|
-
book.excel.visible.should be false
|
2088
|
-
book.excel.displayalerts.should == :if_visible
|
2390
|
+
book.excel.properties[:visible].should be false
|
2391
|
+
book.excel.properties[:displayalerts].should == :if_visible
|
2089
2392
|
end
|
2090
|
-
|
2393
|
+
Excel.kill_all
|
2394
|
+
new_book = Workbook.open(@simple_file1)
|
2091
2395
|
sheet = new_book.sheet(1)
|
2092
2396
|
sheet[1,1].Value.should == @old_cell_value
|
2093
2397
|
end
|
@@ -2126,8 +2430,8 @@ describe Workbook do
|
|
2126
2430
|
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
2127
2431
|
book.excel.should_not == @book.excel
|
2128
2432
|
book.excel.should_not == new_excel
|
2129
|
-
book.excel.visible.should be false
|
2130
|
-
book.excel.displayalerts.should == :if_visible
|
2433
|
+
book.excel.properties[:visible].should be false
|
2434
|
+
book.excel.properties[:displayalerts].should == :if_visible
|
2131
2435
|
end
|
2132
2436
|
new_book = Workbook.open(@simple_file1, :visible => true)
|
2133
2437
|
sheet = new_book.sheet(1)
|