robust_excel_ole 1.3 → 1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +6 -0
- data/README.rdoc +1 -1
- data/docs/README_open.rdoc +1 -1
- data/docs/README_ranges.rdoc +60 -57
- data/docs/README_sheet.rdoc +1 -1
- data/examples/introducing_examples/example_introducing.rb +42 -0
- data/examples/introducing_examples/example_open.rb +49 -0
- data/examples/introducing_examples/example_range.rb +67 -0
- data/examples/{edit_sheets → modifying_sheets}/example_access_sheets_and_cells.rb +0 -0
- data/examples/{edit_sheets → modifying_sheets}/example_adding_sheets.rb +0 -0
- data/examples/{edit_sheets → modifying_sheets}/example_concating.rb +1 -1
- data/examples/{edit_sheets → modifying_sheets}/example_copying.rb +1 -1
- data/examples/{edit_sheets → modifying_sheets}/example_expanding.rb +1 -1
- data/examples/{edit_sheets → modifying_sheets}/example_naming.rb +1 -1
- data/examples/{edit_sheets → modifying_sheets}/example_ranges.rb +1 -1
- data/examples/{edit_sheets → modifying_sheets}/example_saving.rb +1 -1
- data/examples/open_save_close/example_control_to_excel.rb +2 -2
- data/examples/open_save_close/example_if_obstructed_save.rb +2 -2
- data/examples/open_save_close/example_if_unsaved_accept.rb +1 -1
- data/examples/open_save_close/example_if_unsaved_forget.rb +3 -3
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +4 -4
- data/examples/open_save_close/example_read_only.rb +1 -1
- data/examples/open_save_close/example_rename_cells.rb +1 -1
- data/examples/open_save_close/example_simple.rb +1 -1
- data/examples/open_save_close/example_unobtrusively.rb +3 -3
- data/lib/robust_excel_ole.rb +2 -2
- data/lib/robust_excel_ole/bookstore.rb +1 -1
- data/lib/robust_excel_ole/cell.rb +15 -2
- data/lib/robust_excel_ole/excel.rb +14 -12
- data/lib/robust_excel_ole/general.rb +12 -0
- data/lib/robust_excel_ole/range.rb +37 -20
- data/lib/robust_excel_ole/reo_common.rb +63 -37
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/{book.rb → workbook.rb} +35 -33
- data/lib/robust_excel_ole/{sheet.rb → worksheet.rb} +22 -22
- data/spec/bookstore_spec.rb +38 -38
- data/spec/cell_spec.rb +10 -10
- data/spec/data/another_workbook.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +113 -105
- data/spec/general_spec.rb +37 -5
- data/spec/range_spec.rb +34 -19
- data/spec/reo_common_spec.rb +58 -48
- data/spec/{book_spec.rb → workbook_spec.rb} +198 -198
- data/spec/workbook_specs/workbook_all_spec.rb +33 -0
- data/spec/{book_specs/book_close_spec.rb → workbook_specs/workbook_close_spec.rb} +10 -10
- data/spec/{book_specs/book_misc_spec.rb → workbook_specs/workbook_misc_spec.rb} +148 -128
- data/spec/{book_specs/book_open_spec.rb → workbook_specs/workbook_open_spec.rb} +427 -427
- data/spec/{book_specs/book_save_spec.rb → workbook_specs/workbook_save_spec.rb} +44 -44
- data/spec/{book_specs/book_sheet_spec.rb → workbook_specs/workbook_sheet_spec.rb} +19 -19
- data/spec/{book_specs/book_subclass_spec.rb → workbook_specs/workbook_subclass_spec.rb} +5 -6
- data/spec/{book_specs/book_unobtr_spec.rb → workbook_specs/workbook_unobtr_spec.rb} +339 -344
- data/spec/{sheet_spec.rb → worksheet_spec.rb} +85 -55
- metadata +25 -22
- data/spec/book_specs/book_all_spec.rb +0 -22
data/spec/general_spec.rb
CHANGED
@@ -35,10 +35,42 @@ module RobustExcelOle
|
|
35
35
|
rm_tmp(@dir)
|
36
36
|
end
|
37
37
|
|
38
|
+
describe "to_reo" do
|
39
|
+
|
40
|
+
before do
|
41
|
+
@book1 = Workbook.open(@simple_file)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should promote an Excel" do
|
45
|
+
excel = @book1.excel.ole_excel.to_reo
|
46
|
+
excel.class.should == RobustExcelOle::Excel
|
47
|
+
excel.should be_alive
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should promote a workbook" do
|
51
|
+
workbook = @book1.ole_workbook.to_reo
|
52
|
+
workbook.should be_a Workbook
|
53
|
+
workbook.should be_alive
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should promote a worksheet" do
|
57
|
+
worksheet = @book1.sheet(1).ole_worksheet.to_reo
|
58
|
+
worksheet.should be_kind_of Worksheet
|
59
|
+
worksheet.name.should == "Sheet1"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should promote a range" do
|
63
|
+
range = @book1.sheet(1).range([1,1]).ole_range.to_reo
|
64
|
+
range.should be_kind_of Range
|
65
|
+
range.Value.should == "foo"
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
38
70
|
describe "methods, own_methods, respond_to?" do
|
39
71
|
|
40
72
|
before do
|
41
|
-
@book1 =
|
73
|
+
@book1 = Workbook.open(@simple_file)
|
42
74
|
@ole_workbook_methods =
|
43
75
|
["Activate", "ActiveSheet", "Application", "Close", "FullName", "HasPassword", "Name", "Names",
|
44
76
|
"Password", "Protect", "ProtectSharing", "ProtectStructure", "Protect", "ReadOnly", "Save",
|
@@ -49,11 +81,11 @@ module RobustExcelOle
|
|
49
81
|
["ActiveCell", "ActiveSheet", "ActiveWorkbook", "Application", "Calculate", "Cells", "Columns",
|
50
82
|
"DisplayAlerts", "Evaluate", "Hwnd", "Name", "Names", "Quit", "Range", "Ready", "Save",
|
51
83
|
"Sheets", "UserName", "Value", "Visible", "Workbooks", "Worksheets"]
|
52
|
-
@excel_methods = ["alive?", "
|
84
|
+
@excel_methods = ["alive?", "workbook_class", "close", "displayalerts", "recreate", "visible",
|
53
85
|
"with_displayalerts"]
|
54
86
|
@ole_sheet_methods = []
|
55
87
|
# ["Activate", "Calculate", "Copy", "Name", "Select", "Evaluate", "Protect", "Unprotect"]
|
56
|
-
@sheet_methods = ["
|
88
|
+
@sheet_methods = ["workbook_class", "col_range", "each", "each_column", "each_column_with_index",
|
57
89
|
"each_row", "each_row_with_index", "nameval", "namevalue",
|
58
90
|
"set_namevalue", "row_range", "set_nameval"]
|
59
91
|
end
|
@@ -194,7 +226,7 @@ module RobustExcelOle
|
|
194
226
|
describe "Object methods" do
|
195
227
|
|
196
228
|
before do
|
197
|
-
@book =
|
229
|
+
@book = Workbook.open(@simple_file)
|
198
230
|
@sheet = @book.sheet(1)
|
199
231
|
end
|
200
232
|
|
@@ -205,7 +237,7 @@ module RobustExcelOle
|
|
205
237
|
it "should raise an error when asking excel of a sheet" do
|
206
238
|
expect{
|
207
239
|
@sheet.excel
|
208
|
-
}.to raise_error(TypeREOError, "receiver instance is neither an Excel nor a
|
240
|
+
}.to raise_error(TypeREOError, "receiver instance is neither an Excel nor a Workbook")
|
209
241
|
end
|
210
242
|
end
|
211
243
|
end
|
data/spec/range_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe RobustExcelOle::Range do
|
|
14
14
|
|
15
15
|
before do
|
16
16
|
@dir = create_tmpdir
|
17
|
-
@book =
|
17
|
+
@book = Workbook.open(@dir + '/workbook.xls', :force_excel => :new)
|
18
18
|
@sheet = @book.sheet(2)
|
19
19
|
@range = RobustExcelOle::Range.new(@sheet.ole_worksheet.UsedRange.Rows(1))
|
20
20
|
end
|
@@ -60,7 +60,7 @@ describe RobustExcelOle::Range do
|
|
60
60
|
|
61
61
|
context "read 'merge_cells.xls'" do
|
62
62
|
before do
|
63
|
-
@merge_cells_book =
|
63
|
+
@merge_cells_book = Workbook.open("#{@dir}/merge_cells.xls", :force_excel => :new)
|
64
64
|
@merge_cells_sheet = @merge_cells_book.sheet(1)
|
65
65
|
end
|
66
66
|
|
@@ -103,18 +103,18 @@ describe RobustExcelOle::Range do
|
|
103
103
|
describe "#[]" do
|
104
104
|
context "access [0]" do
|
105
105
|
it { @range[0].should be_kind_of RobustExcelOle::Cell }
|
106
|
-
it { @range[0].
|
106
|
+
it { @range[0].Value.should eq 'simple' }
|
107
107
|
end
|
108
108
|
|
109
109
|
context "access [2]" do
|
110
|
-
it { @range[2].
|
110
|
+
it { @range[2].Value.should eq 'sheet2' }
|
111
111
|
end
|
112
112
|
|
113
113
|
context "access [0] and [1] and [2]" do
|
114
114
|
it "should get every values" do
|
115
|
-
@range[0].
|
116
|
-
@range[1].
|
117
|
-
@range[2].
|
115
|
+
@range[0].Value.should eq 'simple'
|
116
|
+
@range[1].Value.should eq 'file'
|
117
|
+
@range[2].Value.should eq 'sheet2'
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|
@@ -122,10 +122,10 @@ describe RobustExcelOle::Range do
|
|
122
122
|
describe "#copy" do
|
123
123
|
|
124
124
|
before do
|
125
|
-
@book2 =
|
125
|
+
@book2 = Workbook.open(@dir + '/different_workbook.xls')
|
126
126
|
@sheet2 = @book.sheet(1)
|
127
|
-
@range2 = @sheet2.range(1..2,1..3)
|
128
|
-
@book3 =
|
127
|
+
@range2 = @sheet2.range([1..2,1..3])
|
128
|
+
@book3 = Workbook.open(@dir + '/another_workbook.xls', :force => {:excel => :new})
|
129
129
|
end
|
130
130
|
|
131
131
|
after do
|
@@ -133,31 +133,46 @@ describe RobustExcelOle::Range do
|
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should copy range at a cell" do
|
136
|
-
@range2.copy(4,4)
|
137
|
-
@sheet2.range(4..5,4..6).values.should == ["foo", "workbook", "sheet1", "foo", nil, "foobaaa"]
|
136
|
+
@range2.copy([4,4])
|
137
|
+
@sheet2.range([4..5,4..6]).values.should == ["foo", "workbook", "sheet1", "foo", nil, "foobaaa"]
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should copy range at a cell" do
|
141
|
+
@range2.copy(["D4"])
|
142
|
+
@sheet2.range([4..5,4..6]).values.should == ["foo", "workbook", "sheet1", "foo", nil, "foobaaa"]
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should copy range at a cell" do
|
146
|
+
@range2.copy("D4")
|
147
|
+
@sheet2.range([4..5,4..6]).values.should == ["foo", "workbook", "sheet1", "foo", nil, "foobaaa"]
|
138
148
|
end
|
139
149
|
|
140
150
|
it "should copy range into a certain worksheet of another workbook" do
|
151
|
+
@range2.copy([4,4],@book2.sheet(3))
|
152
|
+
@book2.sheet(3).range([4..5,4..6]).values.should == ["foo", "workbook", "sheet1", "foo", nil, "foobaaa"]
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should accept old interface" do
|
141
156
|
@range2.copy(4,4,@book2.sheet(3))
|
142
|
-
@book2.sheet(3).range(4..5,4..6).values.should == ["foo", "workbook", "sheet1", "foo", nil, "foobaaa"]
|
157
|
+
@book2.sheet(3).range([4..5,4..6]).values.should == ["foo", "workbook", "sheet1", "foo", nil, "foobaaa"]
|
143
158
|
end
|
144
159
|
|
145
160
|
it "should copy range at a cell into a worksheet in another Excel instance" do
|
146
161
|
Excel.kill_all
|
147
162
|
sleep 1
|
148
|
-
book1 =
|
149
|
-
book2 =
|
163
|
+
book1 = Workbook.open(@dir + '/workbook.xls', :force_excel => :new)
|
164
|
+
book2 = Workbook.open(@dir + '/different_workbook.xls', :force_excel => :new)
|
150
165
|
sheet1 = book1.sheet(1)
|
151
|
-
range1 = sheet1.range(1..2,1..3)
|
152
|
-
range1.copy(4,4,book2.sheet(1))
|
153
|
-
book2.sheet(1).range(4..5,4..6).values.should == ["foo", "workbook", "sheet1", "foo", nil, "foobaaa"]
|
166
|
+
range1 = sheet1.range([1..2,1..3])
|
167
|
+
range1.copy([4,4],book2.sheet(1))
|
168
|
+
book2.sheet(1).range([4..5,4..6]).values.should == ["foo", "workbook", "sheet1", "foo", nil, "foobaaa"]
|
154
169
|
end
|
155
170
|
|
156
171
|
end
|
157
172
|
|
158
173
|
describe "#method_missing" do
|
159
174
|
it "can access COM method" do
|
160
|
-
@range.Range(@range.Cells.Item(1), @range.Cells.Item(3)).
|
175
|
+
@range.Range(@range.Cells.Item(1), @range.Cells.Item(3)).Value.should eq [@range.values(0..2)]
|
161
176
|
end
|
162
177
|
|
163
178
|
context "unknown method" do
|
data/spec/reo_common_spec.rb
CHANGED
@@ -40,87 +40,97 @@ module RobustExcelOle
|
|
40
40
|
|
41
41
|
it "should read a1-format" do
|
42
42
|
address = Address.new("A1")
|
43
|
-
address.rows.should == 1
|
44
|
-
address.columns.should ==
|
45
|
-
|
43
|
+
address.rows.should == (1..1)
|
44
|
+
address.columns.should == (1..1)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should read a1-format with brackets" do
|
48
|
+
address = Address.new(["A1"])
|
49
|
+
address.rows.should == (1..1)
|
50
|
+
address.columns.should == (1..1)
|
46
51
|
end
|
47
52
|
|
48
53
|
it "should read a1-format" do
|
49
54
|
address = Address.new("ABO15")
|
50
|
-
address.
|
51
|
-
address.
|
52
|
-
address.a1format.should be_true
|
55
|
+
address.columns.should == (743..743)
|
56
|
+
address.rows.should == (15..15)
|
53
57
|
end
|
54
58
|
|
55
59
|
it "should read a1-format when row and column are given separated" do
|
56
|
-
address = Address.new("A"
|
57
|
-
address.rows.should == 1..1
|
58
|
-
address.columns.should ==
|
59
|
-
address.a1format.should be_true
|
60
|
+
address = Address.new([1,"A"])
|
61
|
+
address.rows.should == (1..1)
|
62
|
+
address.columns.should == (1..1)
|
60
63
|
end
|
61
64
|
|
62
65
|
it "should read a1-format with rows as integer range" do
|
63
|
-
address = Address.new("AB"
|
64
|
-
address.rows.should == 2..4
|
65
|
-
address.columns.should ==
|
66
|
-
address.a1format.should be_true
|
66
|
+
address = Address.new([2..4, "AB"])
|
67
|
+
address.rows.should == (2..4)
|
68
|
+
address.columns.should == (28..28)
|
67
69
|
end
|
68
70
|
|
69
71
|
it "should read a1-format with columns as string range" do
|
70
|
-
address = Address.new("A".."C"
|
71
|
-
address.rows.should == 2
|
72
|
-
address.columns.should ==
|
73
|
-
address.a1format.should be_true
|
72
|
+
address = Address.new([2, "A".."C"])
|
73
|
+
address.rows.should == (2..2)
|
74
|
+
address.columns.should == (1..3)
|
74
75
|
end
|
75
76
|
|
76
77
|
it "should read a1-format with rows and columns as string range" do
|
77
|
-
address = Address.new("A".."C"
|
78
|
-
address.rows.should == 2..6
|
79
|
-
address.columns.should ==
|
80
|
-
address.a1format.should be_true
|
78
|
+
address = Address.new([2..6, "A" .. "C"])
|
79
|
+
address.rows.should == (2..6)
|
80
|
+
address.columns.should == (1..3)
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should read r1c1-format" do
|
84
|
-
address = Address.new(1,2)
|
85
|
-
address.rows.should == 1
|
86
|
-
address.columns.should == 2
|
87
|
-
address.a1format.should be_false
|
84
|
+
address = Address.new([1,2])
|
85
|
+
address.rows.should == (1..1)
|
86
|
+
address.columns.should == (2..2)
|
88
87
|
end
|
89
88
|
|
90
89
|
it "should read r1c1-format with rows as integer range" do
|
91
|
-
address = Address.new(1..2,3)
|
92
|
-
address.rows.should == 1..2
|
93
|
-
address.columns.should == 3..3
|
94
|
-
address.a1format.should be_false
|
90
|
+
address = Address.new([1..2,3])
|
91
|
+
address.rows.should == (1..2)
|
92
|
+
address.columns.should == (3..3)
|
95
93
|
end
|
96
94
|
|
97
95
|
it "should read r1c1-format with columns as integer range" do
|
98
|
-
address = Address.new(1,3..5)
|
99
|
-
address.rows.should == 1..1
|
100
|
-
address.columns.should == 3..5
|
101
|
-
address.a1format.should be_false
|
96
|
+
address = Address.new([1,3..5])
|
97
|
+
address.rows.should == (1..1)
|
98
|
+
address.columns.should == (3..5)
|
102
99
|
end
|
103
100
|
|
104
101
|
it "should read r1c1-format with rows and columns as integer range" do
|
105
|
-
address = Address.new(1..4,3..5)
|
106
|
-
address.rows.should == 1..4
|
107
|
-
address.columns.should == 3..5
|
108
|
-
|
102
|
+
address = Address.new([1..4,3..5])
|
103
|
+
address.rows.should == (1..4)
|
104
|
+
address.columns.should == (3..5)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should read a1-format for a rectangular range" do
|
108
|
+
address = Address.new(["A1:B3"])
|
109
|
+
address.rows.should == (1..3)
|
110
|
+
address.columns.should == (1..2)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should read a1-format for a rectangular range without brackets" do
|
114
|
+
address = Address.new("A1:B3")
|
115
|
+
address.rows == (1..3)
|
116
|
+
address.columns == (1..2)
|
109
117
|
end
|
110
118
|
|
111
119
|
it "should raise an error" do
|
112
120
|
expect{
|
113
121
|
Address.new("1A")
|
114
|
-
}.to raise_error(AddressInvalid, /
|
122
|
+
}.to raise_error(AddressInvalid, /not in A1/)
|
115
123
|
expect{
|
116
124
|
Address.new("A1B")
|
117
|
-
}.to raise_error(AddressInvalid, /
|
125
|
+
}.to raise_error(AddressInvalid, /not in A1/)
|
118
126
|
expect{
|
119
|
-
Address.new("A".."B","C".."D")
|
120
|
-
}.to raise_error(AddressInvalid, /
|
127
|
+
Address.new(["A".."B","C".."D"])
|
128
|
+
}.to raise_error(AddressInvalid, /not in A1/)
|
129
|
+
expect{
|
130
|
+
Address.new(["A",1,2])
|
131
|
+
}.to raise_error(AddressInvalid, /more than two components/)
|
121
132
|
end
|
122
133
|
|
123
|
-
|
124
134
|
end
|
125
135
|
|
126
136
|
describe "trace" do
|
@@ -131,7 +141,7 @@ module RobustExcelOle
|
|
131
141
|
end
|
132
142
|
|
133
143
|
it "should put another text" do
|
134
|
-
b =
|
144
|
+
b = Workbook.open(@simple_file)
|
135
145
|
REOCommon::trace "book: #{b}"
|
136
146
|
end
|
137
147
|
end
|
@@ -139,7 +149,7 @@ module RobustExcelOle
|
|
139
149
|
describe "own_methods" do
|
140
150
|
|
141
151
|
before do
|
142
|
-
@book1 =
|
152
|
+
@book1 = Workbook.open(@simple_file)
|
143
153
|
@ole_workbook_methods =
|
144
154
|
["Activate", "ActiveSheet", "Application", "Close", "FullName", "HasPassword", "Name", "Names",
|
145
155
|
"Password", "Protect", "ProtectSharing", "ProtectStructure", "Protect", "ReadOnly", "Save",
|
@@ -150,7 +160,7 @@ module RobustExcelOle
|
|
150
160
|
["ActiveCell", "ActiveSheet", "ActiveWorkbook", "Application", "Calculate", "Cells", "Columns",
|
151
161
|
"DisplayAlerts", "Evaluate", "Hwnd", "Name", "Names", "Quit", "Range", "Ready", "Save",
|
152
162
|
"Sheets", "UserName", "Value", "Visible", "Workbooks", "Worksheets"]
|
153
|
-
@excel_methods = ["alive?", "
|
163
|
+
@excel_methods = ["alive?", "workbook_class", "close", "displayalerts", "recreate", "visible", "with_displayalerts"]
|
154
164
|
end
|
155
165
|
|
156
166
|
after do
|
@@ -172,7 +182,7 @@ module RobustExcelOle
|
|
172
182
|
describe "Object methods" do
|
173
183
|
|
174
184
|
before do
|
175
|
-
@book =
|
185
|
+
@book = Workbook.open(@simple_file)
|
176
186
|
@sheet = @book.sheet(1)
|
177
187
|
end
|
178
188
|
|
@@ -183,7 +193,7 @@ module RobustExcelOle
|
|
183
193
|
it "should raise an error when asking excel of a sheet" do
|
184
194
|
expect{
|
185
195
|
@sheet.excel
|
186
|
-
}.to raise_error(TypeREOError, "receiver instance is neither an Excel nor a
|
196
|
+
}.to raise_error(TypeREOError, "receiver instance is neither an Excel nor a Workbook")
|
187
197
|
end
|
188
198
|
|
189
199
|
end
|
@@ -8,7 +8,7 @@ include General
|
|
8
8
|
|
9
9
|
module RobustExcelOle
|
10
10
|
|
11
|
-
describe
|
11
|
+
describe Workbook do
|
12
12
|
|
13
13
|
before(:all) do
|
14
14
|
excel = Excel.new(:reuse => true)
|
@@ -41,89 +41,89 @@ describe Book do
|
|
41
41
|
context "with standard" do
|
42
42
|
it "open an existing file" do
|
43
43
|
expect {
|
44
|
-
@book =
|
44
|
+
@book = Workbook.open(@simple_file)
|
45
45
|
}.to_not raise_error
|
46
|
-
@book.should be_a
|
46
|
+
@book.should be_a Workbook
|
47
47
|
@book.close
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
describe "
|
52
|
+
describe "Workbook::save" do
|
53
53
|
|
54
54
|
it "should save a file, if it is open" do
|
55
|
-
@book =
|
55
|
+
@book = Workbook.open(@simple_file)
|
56
56
|
@book.add_sheet(@sheet, :as => 'a_name')
|
57
57
|
@new_sheet_count = @book.ole_workbook.Worksheets.Count
|
58
58
|
expect {
|
59
|
-
|
59
|
+
Workbook.save(@simple_file)
|
60
60
|
}.to_not raise_error
|
61
61
|
@book.ole_workbook.Worksheets.Count.should == @new_sheet_count
|
62
62
|
@book.close
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should not save a file, if it is not open" do
|
66
|
-
@book =
|
66
|
+
@book = Workbook.open(@simple_file)
|
67
67
|
@book.add_sheet(@sheet, :as => 'a_name')
|
68
68
|
@new_sheet_count = @book.ole_workbook.Worksheets.Count
|
69
69
|
@book.close(:if_unsaved => :forget)
|
70
70
|
expect {
|
71
|
-
|
71
|
+
Workbook.save(@simple_file)
|
72
72
|
}.to_not raise_error
|
73
73
|
end
|
74
74
|
|
75
75
|
end
|
76
76
|
|
77
|
-
describe "
|
77
|
+
describe "Workbook::save_as" do
|
78
78
|
|
79
79
|
it "should save to 'simple_save_file.xls'" do
|
80
|
-
book =
|
81
|
-
|
80
|
+
book = Workbook.open(@simple_file1)
|
81
|
+
Workbook.save_as(@simple_file1, @simple_save_file1, :if_exists => :overwrite)
|
82
82
|
File.exist?(@simple_save_file1).should be true
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
describe "
|
86
|
+
describe "Workbook::close" do
|
87
87
|
|
88
88
|
it "should close the book if it is open" do
|
89
|
-
book =
|
90
|
-
|
89
|
+
book = Workbook.open(@simple_file1)
|
90
|
+
Workbook.close(@simple_file1)
|
91
91
|
book.should_not be_alive
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should not close the book if it is not open" do
|
95
|
-
book =
|
95
|
+
book = Workbook.open(@simple_file1, :visible => true)
|
96
96
|
book.close
|
97
|
-
|
97
|
+
Workbook.close(@simple_file1)
|
98
98
|
book.should_not be_alive
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should raise error if the book is unsaved and open" do
|
102
|
-
book =
|
102
|
+
book = Workbook.open(@simple_file1)
|
103
103
|
sheet = book.sheet(1)
|
104
104
|
book.add_sheet(sheet, :as => 'a_name')
|
105
105
|
expect{
|
106
|
-
|
106
|
+
Workbook.close(@simple_file1)
|
107
107
|
}.to raise_error(WorkbookNotSaved, /workbook is unsaved: "workbook.xls"/)
|
108
108
|
expect{
|
109
|
-
|
109
|
+
Workbook.close(@simple_file, :if_unsaved => :raise)
|
110
110
|
}.to raise_error(WorkbookNotSaved, /workbook is unsaved: "workbook.xls"/)
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should save and close the book" do
|
114
|
-
book =
|
114
|
+
book = Workbook.open(@simple_file1)
|
115
115
|
sheet_count = book.ole_workbook.Worksheets.Count
|
116
116
|
sheet = book.sheet(1)
|
117
117
|
book.add_sheet(sheet, :as => 'a_name')
|
118
118
|
ole_workbook = book.ole_workbook
|
119
119
|
excel = book.excel
|
120
120
|
excel.Workbooks.Count.should == 1
|
121
|
-
|
121
|
+
Workbook.close(@simple_file1, {:if_unsaved => :save})
|
122
122
|
excel.Workbooks.Count.should == 0
|
123
123
|
book.ole_workbook.should == nil
|
124
124
|
book.should_not be_alive
|
125
125
|
#expect{ole_workbook.Name}.to raise_error(WIN32OLERuntimeError)
|
126
|
-
new_book =
|
126
|
+
new_book = Workbook.open(@simple_file1)
|
127
127
|
begin
|
128
128
|
new_book.ole_workbook.Worksheets.Count.should == sheet_count + 1
|
129
129
|
ensure
|
@@ -137,7 +137,7 @@ describe Book do
|
|
137
137
|
context "with various file formats" do
|
138
138
|
|
139
139
|
it "should open linked workbook" do
|
140
|
-
book =
|
140
|
+
book = Workbook.open(@linked_file, :visible => true)
|
141
141
|
book.close
|
142
142
|
end
|
143
143
|
end
|
@@ -156,7 +156,7 @@ describe Book do
|
|
156
156
|
it "should open in a new Excel" do
|
157
157
|
book2 = Workbook.open(@simple_file, :force => {:excel => :new})
|
158
158
|
book2.should be_alive
|
159
|
-
book2.should be_a
|
159
|
+
book2.should be_a Workbook
|
160
160
|
book2.excel.should_not == @book.excel
|
161
161
|
book2.should_not == @book
|
162
162
|
@book.Readonly.should be false
|
@@ -165,21 +165,21 @@ describe Book do
|
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
|
-
context "lift a workbook to a
|
168
|
+
context "lift a workbook to a Workbook object" do
|
169
169
|
|
170
170
|
before do
|
171
|
-
@book =
|
171
|
+
@book = Workbook.open(@simple_file)
|
172
172
|
end
|
173
173
|
|
174
174
|
after do
|
175
175
|
@book.close
|
176
176
|
end
|
177
177
|
|
178
|
-
it "should yield an identical
|
178
|
+
it "should yield an identical Workbook and set visible and displayalerts values" do
|
179
179
|
workbook = @book.ole_workbook
|
180
|
-
new_book =
|
180
|
+
new_book = Workbook.new(workbook, :visible => true)
|
181
181
|
new_book.excel.displayalerts = true
|
182
|
-
new_book.should be_a
|
182
|
+
new_book.should be_a Workbook
|
183
183
|
new_book.should be_alive
|
184
184
|
new_book.should == @book
|
185
185
|
new_book.filename.should == @book.filename
|
@@ -195,7 +195,7 @@ describe Book do
|
|
195
195
|
|
196
196
|
context "with standard options" do
|
197
197
|
before do
|
198
|
-
@book =
|
198
|
+
@book = Workbook.open(@simple_file)
|
199
199
|
end
|
200
200
|
|
201
201
|
after do
|
@@ -210,29 +210,29 @@ describe Book do
|
|
210
210
|
context "with identity transperence" do
|
211
211
|
|
212
212
|
before do
|
213
|
-
@book =
|
213
|
+
@book = Workbook.open(@simple_file)
|
214
214
|
end
|
215
215
|
|
216
216
|
after do
|
217
217
|
@book.close
|
218
218
|
end
|
219
219
|
|
220
|
-
it "should yield identical
|
220
|
+
it "should yield identical Workbook objects for identical Excel books when reopening" do
|
221
221
|
@book.should be_alive
|
222
222
|
@book.close
|
223
223
|
@book.should_not be_alive
|
224
|
-
book2 =
|
224
|
+
book2 = Workbook.open(@simple_file)
|
225
225
|
book2.should === @book
|
226
226
|
book2.should be_alive
|
227
227
|
book2.close
|
228
228
|
end
|
229
229
|
|
230
|
-
it "should yield different
|
230
|
+
it "should yield different Workbook objects when reopening in a new Excel" do
|
231
231
|
@book.should be_alive
|
232
232
|
old_excel = @book.excel
|
233
233
|
@book.close
|
234
234
|
@book.should_not be_alive
|
235
|
-
book2 =
|
235
|
+
book2 = Workbook.open(@simple_file, :force => {:excel => :new})
|
236
236
|
book2.should_not === @book
|
237
237
|
book2.should be_alive
|
238
238
|
book2.excel.should_not == old_excel
|
@@ -243,7 +243,7 @@ describe Book do
|
|
243
243
|
context "with :force_excel" do
|
244
244
|
|
245
245
|
before do
|
246
|
-
@book =
|
246
|
+
@book = Workbook.open(@simple_file)
|
247
247
|
end
|
248
248
|
|
249
249
|
after do
|
@@ -251,9 +251,9 @@ describe Book do
|
|
251
251
|
end
|
252
252
|
|
253
253
|
it "should open in a new Excel" do
|
254
|
-
book2 =
|
254
|
+
book2 = Workbook.open(@simple_file, :force => {:excel => :new})
|
255
255
|
book2.should be_alive
|
256
|
-
book2.should be_a
|
256
|
+
book2.should be_a Workbook
|
257
257
|
book2.excel.should_not == @book.excel
|
258
258
|
book2.should_not == @book
|
259
259
|
@book.Readonly.should be false
|
@@ -262,24 +262,24 @@ describe Book do
|
|
262
262
|
end
|
263
263
|
|
264
264
|
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
|
265
|
-
book2 =
|
265
|
+
book2 = Workbook.open(@simple_file1, :force => {:excel => :new})
|
266
266
|
book2.excel.should_not == @book.excel
|
267
|
-
book3 =
|
267
|
+
book3 = Workbook.open(@simple_file1, :force => {:excel => :new})
|
268
268
|
book3.excel.should_not == book2.excel
|
269
269
|
book3.excel.should_not == @book.excel
|
270
270
|
book2.close
|
271
271
|
book3.close
|
272
272
|
@book.close
|
273
|
-
book4 =
|
273
|
+
book4 = Workbook.open(@simple_file1, :force => {:excel => book2.excel}, :read_only => true)
|
274
274
|
book4.should be_alive
|
275
|
-
book4.should be_a
|
275
|
+
book4.should be_a Workbook
|
276
276
|
book4.excel.should == book2.excel
|
277
277
|
book4.ReadOnly.should be true
|
278
278
|
book4.should == book2
|
279
279
|
book4.close
|
280
|
-
book5 =
|
280
|
+
book5 = Workbook.open(@simple_file1, :force => {:excel => book2}, :read_only => true)
|
281
281
|
book5.should be_alive
|
282
|
-
book5.should be_a
|
282
|
+
book5.should be_a Workbook
|
283
283
|
book5.excel.should == book2.excel
|
284
284
|
book5.ReadOnly.should be true
|
285
285
|
book5.should == book2
|
@@ -292,7 +292,7 @@ describe Book do
|
|
292
292
|
|
293
293
|
before do
|
294
294
|
excel = Excel.new(:reuse => false)
|
295
|
-
@book =
|
295
|
+
@book = Workbook.open(@simple_file)
|
296
296
|
end
|
297
297
|
|
298
298
|
after do
|
@@ -302,9 +302,9 @@ describe Book do
|
|
302
302
|
it "should reopen the book in the excel instance where it was opened before" do
|
303
303
|
excel = Excel.new(:reuse => false)
|
304
304
|
@book.close
|
305
|
-
book2 =
|
305
|
+
book2 = Workbook.open(@simple_file)
|
306
306
|
book2.should be_alive
|
307
|
-
book2.should be_a
|
307
|
+
book2.should be_a Workbook
|
308
308
|
book2.excel.should == @book.excel
|
309
309
|
book2.excel.should_not == excel
|
310
310
|
book2.filename.should == @book.filename
|
@@ -316,28 +316,28 @@ describe Book do
|
|
316
316
|
it "should open a new excel, if the book cannot be reopened" do
|
317
317
|
@book.close
|
318
318
|
new_excel = Excel.new(:reuse => false)
|
319
|
-
book2 =
|
319
|
+
book2 = Workbook.open(@different_file, :default => {:excel => :new})
|
320
320
|
book2.should be_alive
|
321
|
-
book2.should be_a
|
321
|
+
book2.should be_a Workbook
|
322
322
|
book2.excel.should_not == new_excel
|
323
323
|
book2.excel.should_not == @book.excel
|
324
324
|
book2.close
|
325
325
|
end
|
326
326
|
|
327
|
-
it "should open in a given Excel provided as Excel,
|
328
|
-
book2 =
|
327
|
+
it "should open in a given Excel provided as Excel, Workbook, or WIN32OLE representing an Excel or Workbook" do
|
328
|
+
book2 = Workbook.open(@another_simple_file)
|
329
329
|
different_file1 = @different_file
|
330
|
-
book3 =
|
330
|
+
book3 = Workbook.open(different_file1, :default => {:excel => book2.excel})
|
331
331
|
book3.excel.should === book2.excel
|
332
332
|
book3.close
|
333
|
-
book4 =
|
333
|
+
book4 = Workbook.open(different_file1, :default => {:excel => book2})
|
334
334
|
book4.excel.should === book2.excel
|
335
335
|
book4.close
|
336
|
-
book5 =
|
336
|
+
book5 = Workbook.open(different_file1, :default_excel => book2.ole_workbook)
|
337
337
|
book5.excel.should === book2.excel
|
338
338
|
book5.close
|
339
339
|
win32ole_excel1 = WIN32OLE.connect(book2.ole_workbook.Fullname).Application
|
340
|
-
book6 =
|
340
|
+
book6 = Workbook.open(different_file1, :default => {:excel => win32ole_excel1})
|
341
341
|
book6.excel.should === book2.excel
|
342
342
|
book6.close
|
343
343
|
end
|
@@ -348,7 +348,7 @@ describe Book do
|
|
348
348
|
context "with :if_unsaved" do
|
349
349
|
|
350
350
|
before do
|
351
|
-
@book =
|
351
|
+
@book = Workbook.open(@simple_file)
|
352
352
|
@sheet = @book.sheet(1)
|
353
353
|
@book.add_sheet(@sheet, :as => 'a_name')
|
354
354
|
end
|
@@ -360,13 +360,13 @@ describe Book do
|
|
360
360
|
|
361
361
|
it "should raise an error, if :if_unsaved is :raise" do
|
362
362
|
expect {
|
363
|
-
@new_book =
|
363
|
+
@new_book = Workbook.open(@simple_file, :if_unsaved => :raise)
|
364
364
|
}.to raise_error(WorkbookNotSaved, /workbook is already open but not saved: "workbook.xls"/)
|
365
365
|
end
|
366
366
|
|
367
367
|
it "should let the book open, if :if_unsaved is :accept" do
|
368
368
|
expect {
|
369
|
-
@new_book =
|
369
|
+
@new_book = Workbook.open(@simple_file, :if_unsaved => :accept)
|
370
370
|
}.to_not raise_error
|
371
371
|
@book.should be_alive
|
372
372
|
@new_book.should be_alive
|
@@ -385,7 +385,7 @@ describe Book do
|
|
385
385
|
it "should open the new book and close the unsaved book, if user answers 'yes'" do
|
386
386
|
# "Yes" is the default. --> language independent
|
387
387
|
@key_sender.puts "{enter}"
|
388
|
-
@new_book =
|
388
|
+
@new_book = Workbook.open(@simple_file1, :if_unsaved => :alert)
|
389
389
|
@new_book.should be_alive
|
390
390
|
@new_book.filename.downcase.should == @simple_file1.downcase
|
391
391
|
@book.should_not be_alive
|
@@ -399,7 +399,7 @@ describe Book do
|
|
399
399
|
@key_sender.puts "{right}{enter}"
|
400
400
|
@key_sender.puts "{right}{enter}"
|
401
401
|
expect{
|
402
|
-
|
402
|
+
Workbook.open(@simple_file, :if_unsaved => :alert)
|
403
403
|
}.to raise_error(UnexpectedREOError)
|
404
404
|
@book.should be_alive
|
405
405
|
end
|
@@ -407,7 +407,7 @@ describe Book do
|
|
407
407
|
it "should open the new book and close the unsaved book, if user answers 'yes'" do
|
408
408
|
# "Yes" is the default. --> language independent
|
409
409
|
@key_sender.puts "{enter}"
|
410
|
-
@new_book =
|
410
|
+
@new_book = Workbook.open(@simple_file1, :if_unsaved => :excel)
|
411
411
|
@new_book.should be_alive
|
412
412
|
@new_book.filename.downcase.should == @simple_file1.downcase
|
413
413
|
#@book.should_not be_alive
|
@@ -421,7 +421,7 @@ describe Book do
|
|
421
421
|
@key_sender.puts "{right}{enter}"
|
422
422
|
@key_sender.puts "{right}{enter}"
|
423
423
|
expect{
|
424
|
-
|
424
|
+
Workbook.open(@simple_file, :if_unsaved => :excel)
|
425
425
|
}.to raise_error(UnexpectedREOError)
|
426
426
|
@book.should be_alive
|
427
427
|
end
|
@@ -437,10 +437,10 @@ describe Book do
|
|
437
437
|
|
438
438
|
before do
|
439
439
|
if i == 1 then
|
440
|
-
book_before =
|
440
|
+
book_before = Workbook.open(@simple_file)
|
441
441
|
book_before.close
|
442
442
|
end
|
443
|
-
@book =
|
443
|
+
@book = Workbook.open(@simple_file_other_path1)
|
444
444
|
@sheet_count = @book.ole_workbook.Worksheets.Count
|
445
445
|
@sheet = @book.sheet(1)
|
446
446
|
@book.add_sheet(@sheet, :as => 'a_name')
|
@@ -452,11 +452,11 @@ describe Book do
|
|
452
452
|
end
|
453
453
|
|
454
454
|
it "should save the old book, close it, and open the new book, if :if_obstructed is :save" do
|
455
|
-
@new_book =
|
455
|
+
@new_book = Workbook.open(@simple_file1, :if_obstructed => :save)
|
456
456
|
@book.should_not be_alive
|
457
457
|
@new_book.should be_alive
|
458
458
|
@new_book.filename.downcase.should == @simple_file1.downcase
|
459
|
-
old_book =
|
459
|
+
old_book = Workbook.open(@simple_file_other_path1, :if_obstructed => :forget)
|
460
460
|
old_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
|
461
461
|
old_book.close
|
462
462
|
end
|
@@ -464,14 +464,14 @@ describe Book do
|
|
464
464
|
it "should raise an error, if the old book is unsaved, and close the old book and open the new book,
|
465
465
|
if :if_obstructed is :close_if_saved" do
|
466
466
|
expect{
|
467
|
-
@new_book =
|
467
|
+
@new_book = Workbook.open(@simple_file1, :if_obstructed => :close_if_saved)
|
468
468
|
}.to raise_error(WorkbookBlocked, /workbook with the same name in a different path is unsaved/)
|
469
469
|
@book.save
|
470
|
-
@new_book =
|
470
|
+
@new_book = Workbook.open(@simple_file1, :if_obstructed => :close_if_saved)
|
471
471
|
@book.should_not be_alive
|
472
472
|
@new_book.should be_alive
|
473
473
|
@new_book.filename.downcase.should == @simple_file1.downcase
|
474
|
-
old_book =
|
474
|
+
old_book = Workbook.open(@simple_file_other_path1, :if_obstructed => :forget)
|
475
475
|
old_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
|
476
476
|
old_book.close
|
477
477
|
end
|
@@ -483,8 +483,8 @@ describe Book do
|
|
483
483
|
|
484
484
|
it "should create a workbook" do
|
485
485
|
File.delete @simple_save_file rescue nil
|
486
|
-
book =
|
487
|
-
book.should be_a
|
486
|
+
book = Workbook.open(@simple_save_file, :if_absent => :create)
|
487
|
+
book.should be_a Workbook
|
488
488
|
book.close
|
489
489
|
File.exist?(@simple_save_file).should be true
|
490
490
|
end
|
@@ -492,7 +492,7 @@ describe Book do
|
|
492
492
|
it "should raise an exception by default" do
|
493
493
|
File.delete @simple_save_file rescue nil
|
494
494
|
expect {
|
495
|
-
|
495
|
+
Workbook.open(@simple_save_file)
|
496
496
|
}.to raise_error(FileNotFound, "file #{General::absolute_path(@simple_save_file).gsub("/","\\").inspect} not found")
|
497
497
|
end
|
498
498
|
end
|
@@ -500,27 +500,27 @@ describe Book do
|
|
500
500
|
context "with :read_only" do
|
501
501
|
|
502
502
|
it "should reopen the book with writable (unsaved changes from readonly will not be saved)" do
|
503
|
-
book =
|
503
|
+
book = Workbook.open(@simple_file1, :read_only => true)
|
504
504
|
book.ReadOnly.should be true
|
505
505
|
book.should be_alive
|
506
506
|
sheet = book.sheet(1)
|
507
|
-
old_cell_value = sheet[1,1].
|
508
|
-
sheet[1,1] = sheet[1,1].
|
507
|
+
old_cell_value = sheet[1,1].Value
|
508
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
509
509
|
book.Saved.should be false
|
510
|
-
new_book =
|
510
|
+
new_book = Workbook.open(@simple_file1, :read_only => false, :if_unsaved => :accept)
|
511
511
|
new_book.ReadOnly.should be false
|
512
512
|
new_book.should be_alive
|
513
513
|
book.should be_alive
|
514
514
|
new_book.should == book
|
515
515
|
new_sheet = new_book.sheet(1)
|
516
|
-
new_cell_value = new_sheet[1,1].
|
516
|
+
new_cell_value = new_sheet[1,1].Value
|
517
517
|
new_cell_value.should == old_cell_value
|
518
518
|
end
|
519
519
|
|
520
520
|
context "with block" do
|
521
|
-
it 'block parameter should be instance of
|
522
|
-
|
523
|
-
book.should be_a
|
521
|
+
it 'block parameter should be instance of Workbook' do
|
522
|
+
Workbook.open(@simple_file) do |book|
|
523
|
+
book.should be_a Workbook
|
524
524
|
end
|
525
525
|
end
|
526
526
|
end
|
@@ -531,7 +531,7 @@ describe Book do
|
|
531
531
|
context "with standard" do
|
532
532
|
|
533
533
|
before do
|
534
|
-
@book =
|
534
|
+
@book = Workbook.open(@simple_file)
|
535
535
|
end
|
536
536
|
|
537
537
|
after do
|
@@ -544,7 +544,7 @@ describe Book do
|
|
544
544
|
@book.close
|
545
545
|
@book.should_not be_alive
|
546
546
|
@book.reopen
|
547
|
-
@book.should be_a
|
547
|
+
@book.should be_a Workbook
|
548
548
|
@book.should be_alive
|
549
549
|
@book.should === book1
|
550
550
|
end
|
@@ -556,7 +556,7 @@ describe Book do
|
|
556
556
|
context "with standard" do
|
557
557
|
|
558
558
|
before do
|
559
|
-
@book =
|
559
|
+
@book = Workbook.open(@simple_file)
|
560
560
|
end
|
561
561
|
|
562
562
|
after do
|
@@ -565,8 +565,8 @@ describe Book do
|
|
565
565
|
|
566
566
|
it "should uplift a workbook to a book with an open book" do
|
567
567
|
workbook = @book.ole_workbook
|
568
|
-
book1 =
|
569
|
-
book1.should be_a
|
568
|
+
book1 = Workbook.new(workbook)
|
569
|
+
book1.should be_a Workbook
|
570
570
|
book1.should be_alive
|
571
571
|
book1.should == @book
|
572
572
|
end
|
@@ -577,41 +577,41 @@ describe Book do
|
|
577
577
|
|
578
578
|
it "should preserve :visible if they are not set" do
|
579
579
|
excel1 = Excel.create(:visible => true)
|
580
|
-
book1 =
|
580
|
+
book1 = Workbook.open(@simple_file)
|
581
581
|
book1.excel.Visible.should be true
|
582
582
|
book1.close
|
583
583
|
end
|
584
584
|
|
585
585
|
it "should preserve :visible if they are not set" do
|
586
586
|
excel1 = Excel.create
|
587
|
-
book1 =
|
587
|
+
book1 = Workbook.open(@simple_file, :visible => true)
|
588
588
|
book1.excel.Visible.should be true
|
589
589
|
end
|
590
590
|
|
591
591
|
it "should preserve :visible if they are not set" do
|
592
592
|
excel1 = Excel.create(:visible => true)
|
593
|
-
book1 =
|
593
|
+
book1 = Workbook.open(@different_file, :default => {:excel => :new})
|
594
594
|
book1.excel.Visible.should be false
|
595
595
|
end
|
596
596
|
|
597
597
|
it "should preserve :visible if they are not set" do
|
598
598
|
excel1 = Excel.create(:visible => true)
|
599
599
|
excel2 = Excel.create(:visible => true)
|
600
|
-
book1 =
|
600
|
+
book1 = Workbook.open(@different_file, :force => {:excel => excel2})
|
601
601
|
book1.excel.Visible.should be true
|
602
602
|
book1.close
|
603
603
|
end
|
604
604
|
|
605
|
-
it "should let an open
|
606
|
-
@book =
|
607
|
-
|
608
|
-
book.should be_a
|
605
|
+
it "should let an open Workbook open" do
|
606
|
+
@book = Workbook.open(@simple_file, :visible => true)
|
607
|
+
Workbook.unobtrusively(@simple_file) do |book|
|
608
|
+
book.should be_a Workbook
|
609
609
|
book.should be_alive
|
610
610
|
book.excel.should == @book.excel
|
611
611
|
book.excel.Visible.should be true
|
612
612
|
end
|
613
613
|
@book.should be_alive
|
614
|
-
@book.should be_a
|
614
|
+
@book.should be_a Workbook
|
615
615
|
@book.excel.Visible.should be true
|
616
616
|
@book.close(:if_unsaved => :forget)
|
617
617
|
@book2.close(:if_unsaved => :forget) rescue nil
|
@@ -622,10 +622,10 @@ describe Book do
|
|
622
622
|
describe "unobtrusively" do
|
623
623
|
|
624
624
|
def unobtrusively_ok? # :nodoc: #
|
625
|
-
|
626
|
-
book.should be_a
|
625
|
+
Workbook.unobtrusively(@simple_file) do |book|
|
626
|
+
book.should be_a Workbook
|
627
627
|
sheet = book.sheet(1)
|
628
|
-
sheet[1,1] = sheet[1,1].
|
628
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
629
629
|
book.should be_alive
|
630
630
|
book.Saved.should be false
|
631
631
|
end
|
@@ -659,8 +659,8 @@ describe Book do
|
|
659
659
|
end
|
660
660
|
|
661
661
|
it "should open unobtrusively in a new Excel" do
|
662
|
-
|
663
|
-
book.should be_a
|
662
|
+
Workbook.unobtrusively(@simple_file, :if_closed => :current) do |book|
|
663
|
+
book.should be_a Workbook
|
664
664
|
book.should be_alive
|
665
665
|
book.excel.should == @excel1
|
666
666
|
book.excel.should_not == @excel2
|
@@ -668,8 +668,8 @@ describe Book do
|
|
668
668
|
end
|
669
669
|
|
670
670
|
it "should open unobtrusively in a given Excel" do
|
671
|
-
|
672
|
-
book.should be_a
|
671
|
+
Workbook.unobtrusively(@simple_file, :if_closed => @excel2) do |book|
|
672
|
+
book.should be_a Workbook
|
673
673
|
book.should be_alive
|
674
674
|
book.excel.should_not == @excel1
|
675
675
|
book.excel.should == @excel2
|
@@ -680,7 +680,7 @@ describe Book do
|
|
680
680
|
context "with an open book" do
|
681
681
|
|
682
682
|
before do
|
683
|
-
@book =
|
683
|
+
@book = Workbook.open(@simple_file1)
|
684
684
|
end
|
685
685
|
|
686
686
|
after do
|
@@ -688,51 +688,51 @@ describe Book do
|
|
688
688
|
@book2.close(:if_unsaved => :forget) rescue nil
|
689
689
|
end
|
690
690
|
|
691
|
-
it "should let an open
|
692
|
-
book2 =
|
691
|
+
it "should let an open Workbook open if two workbooks have been opened and one has been closed and opened again" do
|
692
|
+
book2 = Workbook.open(@different_file, :force => {:excel => :new})
|
693
693
|
@book.close
|
694
694
|
book2.close
|
695
695
|
@book.reopen
|
696
|
-
|
697
|
-
book.should be_a
|
696
|
+
Workbook.unobtrusively(@simple_file1) do |book|
|
697
|
+
book.should be_a Workbook
|
698
698
|
book.should be_alive
|
699
699
|
book.excel.should == @book.excel
|
700
700
|
end
|
701
701
|
@book.should be_alive
|
702
|
-
@book.should be_a
|
702
|
+
@book.should be_a Workbook
|
703
703
|
end
|
704
704
|
|
705
705
|
it "should let a saved book saved" do
|
706
706
|
@book.Saved.should be true
|
707
707
|
@book.should be_alive
|
708
708
|
sheet = @book.sheet(1)
|
709
|
-
old_cell_value = sheet[1,1].
|
709
|
+
old_cell_value = sheet[1,1].Value
|
710
710
|
unobtrusively_ok?
|
711
711
|
@book.Saved.should be true
|
712
712
|
@book.should be_alive
|
713
713
|
sheet = @book.sheet(1)
|
714
|
-
sheet[1,1].
|
714
|
+
sheet[1,1].Value.should_not == old_cell_value
|
715
715
|
end
|
716
716
|
|
717
717
|
it "should let the unsaved book unsaved" do
|
718
718
|
sheet = @book.sheet(1)
|
719
|
-
sheet[1,1] = sheet[1,1].
|
720
|
-
old_cell_value = sheet[1,1].
|
719
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
720
|
+
old_cell_value = sheet[1,1].Value
|
721
721
|
@book.Saved.should be false
|
722
722
|
unobtrusively_ok?
|
723
723
|
@book.should be_alive
|
724
724
|
@book.Saved.should be false
|
725
725
|
@book.close(:if_unsaved => :forget)
|
726
|
-
@book2 =
|
726
|
+
@book2 = Workbook.open(@simple_file1)
|
727
727
|
sheet2 = @book2.sheet(1)
|
728
|
-
sheet2[1,1].
|
728
|
+
sheet2[1,1].Value.should_not == old_cell_value
|
729
729
|
end
|
730
730
|
end
|
731
731
|
|
732
732
|
context "with a closed book" do
|
733
733
|
|
734
734
|
before do
|
735
|
-
@book =
|
735
|
+
@book = Workbook.open(@simple_file1)
|
736
736
|
end
|
737
737
|
|
738
738
|
after do
|
@@ -741,12 +741,12 @@ describe Book do
|
|
741
741
|
|
742
742
|
it "should let the closed book closed by default" do
|
743
743
|
sheet = @book.sheet(1)
|
744
|
-
old_cell_value = sheet[1,1].
|
744
|
+
old_cell_value = sheet[1,1].Value
|
745
745
|
@book.close
|
746
746
|
@book.should_not be_alive
|
747
747
|
unobtrusively_ok?
|
748
748
|
@book.should_not be_alive
|
749
|
-
book2 =
|
749
|
+
book2 = Workbook.open(@simple_file1)
|
750
750
|
sheet = book2.sheet(1)
|
751
751
|
sheet[1,1].Value.should_not == old_cell_value
|
752
752
|
end
|
@@ -755,45 +755,45 @@ describe Book do
|
|
755
755
|
it "should use the excel of the book and keep open the book" do
|
756
756
|
excel = Excel.new(:reuse => false)
|
757
757
|
sheet = @book.sheet(1)
|
758
|
-
old_cell_value = sheet[1,1].
|
758
|
+
old_cell_value = sheet[1,1].Value
|
759
759
|
@book.close
|
760
760
|
@book.should_not be_alive
|
761
|
-
|
762
|
-
book.should be_a
|
761
|
+
Workbook.unobtrusively(@simple_file1, :keep_open => true) do |book|
|
762
|
+
book.should be_a Workbook
|
763
763
|
book.excel.should == @book.excel
|
764
764
|
book.excel.should_not == excel
|
765
765
|
sheet = book.sheet(1)
|
766
766
|
cell = sheet[1,1]
|
767
|
-
sheet[1,1] = cell.
|
767
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
768
768
|
book.Saved.should be false
|
769
769
|
end
|
770
770
|
@book.should be_alive
|
771
771
|
@book.close
|
772
|
-
new_book =
|
772
|
+
new_book = Workbook.open(@simple_file1)
|
773
773
|
sheet = new_book.sheet(1)
|
774
|
-
sheet[1,1].
|
774
|
+
sheet[1,1].Value.should_not == old_cell_value
|
775
775
|
end
|
776
776
|
|
777
777
|
it "should use the excel of the book and keep open the book" do
|
778
778
|
excel = Excel.new(:reuse => false)
|
779
779
|
sheet = @book.sheet(1)
|
780
|
-
old_cell_value = sheet[1,1].
|
780
|
+
old_cell_value = sheet[1,1].Value
|
781
781
|
@book.close
|
782
782
|
@book.should_not be_alive
|
783
|
-
|
784
|
-
book.should be_a
|
783
|
+
Workbook.unobtrusively(@simple_file1, :if_closed => :current) do |book|
|
784
|
+
book.should be_a Workbook
|
785
785
|
book.should be_alive
|
786
786
|
book.excel.should == @book.excel
|
787
787
|
book.excel.should_not == excel
|
788
788
|
sheet = book.sheet(1)
|
789
789
|
cell = sheet[1,1]
|
790
|
-
sheet[1,1] = cell.
|
790
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
791
791
|
book.Saved.should be false
|
792
792
|
end
|
793
793
|
@book.should_not be_alive
|
794
|
-
new_book =
|
794
|
+
new_book = Workbook.open(@simple_file1)
|
795
795
|
sheet = new_book.sheet(1)
|
796
|
-
sheet[1,1].
|
796
|
+
sheet[1,1].Value.should_not == old_cell_value
|
797
797
|
end
|
798
798
|
end
|
799
799
|
|
@@ -801,7 +801,7 @@ describe Book do
|
|
801
801
|
context "with a read_only book" do
|
802
802
|
|
803
803
|
before do
|
804
|
-
@book =
|
804
|
+
@book = Workbook.open(@simple_file1, :read_only => true)
|
805
805
|
end
|
806
806
|
|
807
807
|
after do
|
@@ -809,17 +809,17 @@ describe Book do
|
|
809
809
|
end
|
810
810
|
|
811
811
|
it "should open unobtrusively the book in a new Excel such that the book is writable" do
|
812
|
-
book2 =
|
812
|
+
book2 = Workbook.open(@simple_file1, :force => {:excel => :new}, :read_only => true)
|
813
813
|
@book.ReadOnly.should be true
|
814
814
|
book2.Readonly.should be true
|
815
815
|
sheet = @book.sheet(1)
|
816
|
-
cell_value = sheet[1,1].
|
817
|
-
|
818
|
-
book.should be_a
|
816
|
+
cell_value = sheet[1,1].Value
|
817
|
+
Workbook.unobtrusively(@simple_file1, :rw_change_excel => :new, :if_closed => :current, :writable => true) do |book|
|
818
|
+
book.should be_a Workbook
|
819
819
|
book.excel.should_not == book2.excel
|
820
820
|
book.excel.should_not == @book.excel
|
821
821
|
sheet = book.sheet(1)
|
822
|
-
sheet[1,1] = sheet[1,1].
|
822
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
823
823
|
book.should be_alive
|
824
824
|
book.Saved.should be false
|
825
825
|
end
|
@@ -827,16 +827,16 @@ describe Book do
|
|
827
827
|
@book.ReadOnly.should be true
|
828
828
|
@book.close
|
829
829
|
book2.close
|
830
|
-
book3 =
|
830
|
+
book3 = Workbook.open(@simple_file1)
|
831
831
|
new_sheet = book3.sheet(1)
|
832
|
-
new_sheet[1,1].
|
832
|
+
new_sheet[1,1].Value.should_not == cell_value
|
833
833
|
book3.close
|
834
834
|
end
|
835
835
|
end
|
836
836
|
|
837
|
-
context "with a virgin
|
837
|
+
context "with a virgin Workbook class" do
|
838
838
|
before do
|
839
|
-
class
|
839
|
+
class Workbook # :nodoc: #
|
840
840
|
@@bookstore = nil
|
841
841
|
end
|
842
842
|
end
|
@@ -847,10 +847,10 @@ describe Book do
|
|
847
847
|
|
848
848
|
context "with a book never opened before" do
|
849
849
|
before do
|
850
|
-
class
|
850
|
+
class Workbook # :nodoc: #
|
851
851
|
@@bookstore = nil
|
852
852
|
end
|
853
|
-
other_book =
|
853
|
+
other_book = Workbook.open(@different_file)
|
854
854
|
end
|
855
855
|
it "should open the book" do
|
856
856
|
expect{ unobtrusively_ok? }.to_not raise_error
|
@@ -859,7 +859,7 @@ describe Book do
|
|
859
859
|
|
860
860
|
context "with block result" do
|
861
861
|
before do
|
862
|
-
@book1 =
|
862
|
+
@book1 = Workbook.open(@simple_file)
|
863
863
|
end
|
864
864
|
|
865
865
|
after do
|
@@ -868,7 +868,7 @@ describe Book do
|
|
868
868
|
|
869
869
|
it "should yield the block result true" do
|
870
870
|
result =
|
871
|
-
|
871
|
+
Workbook.unobtrusively(@simple_file) do |book|
|
872
872
|
@book1.Saved.should be true
|
873
873
|
end
|
874
874
|
result.should == true
|
@@ -878,12 +878,12 @@ describe Book do
|
|
878
878
|
context "with several Excel instances" do
|
879
879
|
|
880
880
|
before do
|
881
|
-
@book1 =
|
882
|
-
@book2 =
|
881
|
+
@book1 = Workbook.open(@simple_file1)
|
882
|
+
@book2 = Workbook.open(@simple_file1, :force => {:excel => :new})
|
883
883
|
@book1.Readonly.should == false
|
884
884
|
@book2.Readonly.should == true
|
885
885
|
old_sheet = @book1.sheet(1)
|
886
|
-
@old_cell_value = old_sheet[1,1].
|
886
|
+
@old_cell_value = old_sheet[1,1].Value
|
887
887
|
@book1.close
|
888
888
|
@book2.close
|
889
889
|
@book1.should_not be_alive
|
@@ -891,31 +891,31 @@ describe Book do
|
|
891
891
|
end
|
892
892
|
|
893
893
|
it "should open unobtrusively the closed book in the most recent Excel where it was open before" do
|
894
|
-
|
894
|
+
Workbook.unobtrusively(@simple_file) do |book|
|
895
895
|
book.excel.should_not == @book2.excel
|
896
896
|
book.excel.should == @book1.excel
|
897
897
|
book.ReadOnly.should == false
|
898
898
|
sheet = book.sheet(1)
|
899
899
|
cell = sheet[1,1]
|
900
|
-
sheet[1,1] = cell.
|
900
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
901
901
|
book.Saved.should be false
|
902
902
|
end
|
903
|
-
new_book =
|
903
|
+
new_book = Workbook.open(@simple_file1)
|
904
904
|
sheet = new_book.sheet(1)
|
905
|
-
sheet[1,1].
|
905
|
+
sheet[1,1].Value.should_not == @old_cell_value
|
906
906
|
end
|
907
907
|
|
908
908
|
it "should open unobtrusively the closed book in the new hidden Excel" do
|
909
|
-
|
909
|
+
Workbook.unobtrusively(@simple_file, :if_closed => :current) do |book|
|
910
910
|
book.excel.should_not == @book2.excel
|
911
911
|
book.excel.should == @book1.excel
|
912
912
|
book.ReadOnly.should == false
|
913
913
|
sheet = book.sheet(1)
|
914
914
|
cell = sheet[1,1]
|
915
|
-
sheet[1,1] = cell.
|
915
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
916
916
|
book.Saved.should be false
|
917
917
|
end
|
918
|
-
new_book =
|
918
|
+
new_book = Workbook.open(@simple_file1)
|
919
919
|
sheet = new_book.sheet(1)
|
920
920
|
sheet[1,1].Value.should_not == @old_cell_value
|
921
921
|
end
|
@@ -926,21 +926,21 @@ describe Book do
|
|
926
926
|
context "with :hidden" do
|
927
927
|
|
928
928
|
before do
|
929
|
-
@book1 =
|
929
|
+
@book1 = Workbook.open(@simple_file1)
|
930
930
|
@book1.close
|
931
931
|
end
|
932
932
|
|
933
933
|
it "should create a new hidden Excel instance and use this afterwards" do
|
934
934
|
hidden_excel = nil
|
935
|
-
|
936
|
-
book.should be_a
|
935
|
+
Workbook.unobtrusively(@simple_file1, :hidden) do |book|
|
936
|
+
book.should be_a Workbook
|
937
937
|
book.should be_alive
|
938
938
|
book.excel.Visible.should be false
|
939
939
|
book.excel.DisplayAlerts.should be false
|
940
940
|
hidden_excel = book.excel
|
941
941
|
end
|
942
|
-
|
943
|
-
book.should be_a
|
942
|
+
Workbook.unobtrusively(@different_file, :hidden) do |book|
|
943
|
+
book.should be_a Workbook
|
944
944
|
book.should be_alive
|
945
945
|
book.excel.Visible.should be false
|
946
946
|
book.excel.DisplayAlerts.should be false
|
@@ -956,24 +956,24 @@ describe Book do
|
|
956
956
|
context "open unobtrusively for reading and modifying" do
|
957
957
|
|
958
958
|
before do
|
959
|
-
@book =
|
959
|
+
@book = Workbook.open(@simple_file1)
|
960
960
|
sheet = @book.sheet(1)
|
961
|
-
@old_cell_value = sheet[1,1].
|
961
|
+
@old_cell_value = sheet[1,1].Value
|
962
962
|
@book.close
|
963
963
|
end
|
964
964
|
|
965
965
|
it "should not change the value" do
|
966
|
-
|
967
|
-
book.should be_a
|
966
|
+
Workbook.for_reading(@simple_file) do |book|
|
967
|
+
book.should be_a Workbook
|
968
968
|
book.should be_alive
|
969
969
|
book.Saved.should be true
|
970
970
|
sheet = book.sheet(1)
|
971
971
|
cell = sheet[1,1]
|
972
|
-
sheet[1,1] = cell.
|
972
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
973
973
|
book.Saved.should be false
|
974
974
|
book.excel.should == @book.excel
|
975
975
|
end
|
976
|
-
new_book =
|
976
|
+
new_book = Workbook.open(@simple_file1, :visible => true)
|
977
977
|
sheet = new_book.sheet(1)
|
978
978
|
sheet[1,1].Value.should == @old_cell_value
|
979
979
|
end
|
@@ -981,28 +981,28 @@ describe Book do
|
|
981
981
|
|
982
982
|
it "should not change the value and use the hidden Excel instance" do
|
983
983
|
new_excel = Excel.new(:reuse => false)
|
984
|
-
|
984
|
+
Workbook.for_reading(@simple_file1, :if_closed => :new) do |book|
|
985
985
|
sheet = book.sheet(1)
|
986
986
|
cell = sheet[1,1]
|
987
|
-
sheet[1,1] = cell.
|
987
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
988
988
|
book.excel.should_not == @book.excel
|
989
989
|
book.excel.should_not == new_excel
|
990
990
|
book.excel.visible.should be false
|
991
991
|
book.excel.displayalerts.should == :if_visible
|
992
992
|
end
|
993
|
-
new_book =
|
993
|
+
new_book = Workbook.open(@simple_file1, :visible => true)
|
994
994
|
sheet = new_book.sheet(1)
|
995
995
|
sheet[1,1].Value.should == @old_cell_value
|
996
996
|
end
|
997
997
|
|
998
998
|
it "should change the value" do
|
999
|
-
|
999
|
+
Workbook.for_modifying(@simple_file1) do |book|
|
1000
1000
|
sheet = book.sheet(1)
|
1001
1001
|
cell = sheet[1,1]
|
1002
|
-
sheet[1,1] = cell.
|
1002
|
+
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1003
1003
|
book.excel.should == @book.excel
|
1004
1004
|
end
|
1005
|
-
new_book =
|
1005
|
+
new_book = Workbook.open(@simple_file1, :visible => true)
|
1006
1006
|
sheet = new_book.sheet(1)
|
1007
1007
|
sheet[1,1].Value.should_not == @old_cell_value
|
1008
1008
|
end
|
@@ -1013,7 +1013,7 @@ describe Book do
|
|
1013
1013
|
|
1014
1014
|
context "with standard" do
|
1015
1015
|
before do
|
1016
|
-
@book =
|
1016
|
+
@book = Workbook.open(@simple_file)
|
1017
1017
|
end
|
1018
1018
|
|
1019
1019
|
after do
|
@@ -1029,7 +1029,7 @@ describe Book do
|
|
1029
1029
|
describe "nameval, set_nameval, [], []=" do
|
1030
1030
|
|
1031
1031
|
before do
|
1032
|
-
@book1 =
|
1032
|
+
@book1 = Workbook.open(@another_simple_file)
|
1033
1033
|
end
|
1034
1034
|
|
1035
1035
|
after do
|
@@ -1082,7 +1082,7 @@ describe Book do
|
|
1082
1082
|
|
1083
1083
|
context "with unsaved read_only book" do
|
1084
1084
|
before do
|
1085
|
-
@book =
|
1085
|
+
@book = Workbook.open(@simple_file, :read_only => true)
|
1086
1086
|
@sheet_count = @book.ole_workbook.Worksheets.Count
|
1087
1087
|
@book.add_sheet(@sheet, :as => 'a_name')
|
1088
1088
|
end
|
@@ -1091,7 +1091,7 @@ describe Book do
|
|
1091
1091
|
expect{
|
1092
1092
|
@book.close
|
1093
1093
|
}.to_not raise_error
|
1094
|
-
new_book =
|
1094
|
+
new_book = Workbook.open(@simple_file)
|
1095
1095
|
new_book.ole_workbook.Worksheets.Count.should == @sheet_count
|
1096
1096
|
new_book.close
|
1097
1097
|
end
|
@@ -1099,7 +1099,7 @@ describe Book do
|
|
1099
1099
|
|
1100
1100
|
context "with unsaved book" do
|
1101
1101
|
before do
|
1102
|
-
@book =
|
1102
|
+
@book = Workbook.open(@simple_file)
|
1103
1103
|
@sheet_count = @book.ole_workbook.Worksheets.Count
|
1104
1104
|
@book.add_sheet(@sheet, :as => 'a_name')
|
1105
1105
|
@sheet = @book.sheet(1)
|
@@ -1125,7 +1125,7 @@ describe Book do
|
|
1125
1125
|
@book.should_not be_alive
|
1126
1126
|
#expect{
|
1127
1127
|
# ole_workbook.Name}.to raise_error(WIN32OLERuntimeError)
|
1128
|
-
new_book =
|
1128
|
+
new_book = Workbook.open(@simple_file)
|
1129
1129
|
begin
|
1130
1130
|
new_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
|
1131
1131
|
ensure
|
@@ -1140,7 +1140,7 @@ describe Book do
|
|
1140
1140
|
context "with simple save" do
|
1141
1141
|
|
1142
1142
|
it "should save for a file opened without :read_only" do
|
1143
|
-
@book =
|
1143
|
+
@book = Workbook.open(@simple_file)
|
1144
1144
|
@book.add_sheet(@sheet, :as => 'a_name')
|
1145
1145
|
@new_sheet_count = @book.ole_workbook.Worksheets.Count
|
1146
1146
|
expect {
|
@@ -1153,7 +1153,7 @@ describe Book do
|
|
1153
1153
|
|
1154
1154
|
context "with argument" do
|
1155
1155
|
before do
|
1156
|
-
|
1156
|
+
Workbook.open(@simple_file) do |book|
|
1157
1157
|
book.save_as(@simple_save_file, :if_exists => :overwrite)
|
1158
1158
|
end
|
1159
1159
|
end
|
@@ -1169,7 +1169,7 @@ describe Book do
|
|
1169
1169
|
context "with alive?" do
|
1170
1170
|
|
1171
1171
|
before do
|
1172
|
-
@book =
|
1172
|
+
@book = Workbook.open(@simple_file)
|
1173
1173
|
end
|
1174
1174
|
|
1175
1175
|
after do
|
@@ -1190,7 +1190,7 @@ describe Book do
|
|
1190
1190
|
context "with filename" do
|
1191
1191
|
|
1192
1192
|
before do
|
1193
|
-
@book =
|
1193
|
+
@book = Workbook.open(@simple_file)
|
1194
1194
|
end
|
1195
1195
|
|
1196
1196
|
after do
|
@@ -1206,7 +1206,7 @@ describe Book do
|
|
1206
1206
|
context "with ==" do
|
1207
1207
|
|
1208
1208
|
before do
|
1209
|
-
@book =
|
1209
|
+
@book = Workbook.open(@simple_file)
|
1210
1210
|
end
|
1211
1211
|
|
1212
1212
|
after do
|
@@ -1215,7 +1215,7 @@ describe Book do
|
|
1215
1215
|
end
|
1216
1216
|
|
1217
1217
|
it "should be true with two identical books" do
|
1218
|
-
@new_book =
|
1218
|
+
@new_book = Workbook.open(@simple_file)
|
1219
1219
|
@new_book.should == @book
|
1220
1220
|
end
|
1221
1221
|
end
|
@@ -1224,8 +1224,8 @@ describe Book do
|
|
1224
1224
|
|
1225
1225
|
before do
|
1226
1226
|
@key_sender = IO.popen 'ruby "' + File.join(File.dirname(__FILE__), '/helpers/key_sender.rb') + '" "Microsoft Excel" ' , "w"
|
1227
|
-
@book =
|
1228
|
-
@book2 =
|
1227
|
+
@book = Workbook.open(@simple_file, :visible => true)
|
1228
|
+
@book2 = Workbook.open(@another_simple_file, :visible => true)
|
1229
1229
|
end
|
1230
1230
|
|
1231
1231
|
after do
|
@@ -1262,7 +1262,7 @@ describe Book do
|
|
1262
1262
|
|
1263
1263
|
describe "#add_sheet" do
|
1264
1264
|
before do
|
1265
|
-
@book =
|
1265
|
+
@book = Workbook.open(@simple_file)
|
1266
1266
|
@sheet = @book.sheet(1)
|
1267
1267
|
end
|
1268
1268
|
|
@@ -1327,7 +1327,7 @@ describe Book do
|
|
1327
1327
|
|
1328
1328
|
describe 'access sheet' do
|
1329
1329
|
before do
|
1330
|
-
@book =
|
1330
|
+
@book = Workbook.open(@simple_file)
|
1331
1331
|
end
|
1332
1332
|
|
1333
1333
|
after do
|
@@ -1337,22 +1337,22 @@ describe Book do
|
|
1337
1337
|
context "standard" do
|
1338
1338
|
|
1339
1339
|
it 'with sheet name' do
|
1340
|
-
@book.sheet('Sheet1').should be_kind_of
|
1340
|
+
@book.sheet('Sheet1').should be_kind_of Worksheet
|
1341
1341
|
end
|
1342
1342
|
|
1343
1343
|
it 'with integer' do
|
1344
|
-
@book.sheet(1).should be_kind_of
|
1344
|
+
@book.sheet(1).should be_kind_of Worksheet
|
1345
1345
|
end
|
1346
1346
|
|
1347
1347
|
it 'with block' do
|
1348
1348
|
@book.each do |sheet|
|
1349
|
-
sheet.should be_kind_of
|
1349
|
+
sheet.should be_kind_of Worksheet
|
1350
1350
|
end
|
1351
1351
|
end
|
1352
1352
|
|
1353
1353
|
it 'with each_with_index' do
|
1354
1354
|
@book.each_with_index do |sheet,i|
|
1355
|
-
sheet.should be_kind_of
|
1355
|
+
sheet.should be_kind_of Worksheet
|
1356
1356
|
end
|
1357
1357
|
end
|
1358
1358
|
end
|
@@ -1360,7 +1360,7 @@ describe Book do
|
|
1360
1360
|
describe "with retain_saved" do
|
1361
1361
|
|
1362
1362
|
before do
|
1363
|
-
@book =
|
1363
|
+
@book = Workbook.open(@simple_file)
|
1364
1364
|
end
|
1365
1365
|
|
1366
1366
|
after do
|
@@ -1369,7 +1369,7 @@ describe Book do
|
|
1369
1369
|
|
1370
1370
|
it "should keep the save state 'unsaved'" do
|
1371
1371
|
sheet = @book.sheet(1)
|
1372
|
-
sheet[1,1] = sheet[1,1].
|
1372
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
1373
1373
|
@book.Saved.should be false
|
1374
1374
|
@book.retain_saved do
|
1375
1375
|
sheet = @book.sheet(1)
|
@@ -1381,7 +1381,7 @@ describe Book do
|
|
1381
1381
|
|
1382
1382
|
it "should keep the save state 'unsaved' even when the workbook was saved before" do
|
1383
1383
|
sheet = @book.sheet(1)
|
1384
|
-
sheet[1,1] = sheet[1,1].
|
1384
|
+
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
1385
1385
|
@book.Saved.should be false
|
1386
1386
|
@book.retain_saved do
|
1387
1387
|
@book.save
|
@@ -1395,16 +1395,16 @@ describe Book do
|
|
1395
1395
|
context "with test what happens with save-status when setting calculation status" do
|
1396
1396
|
|
1397
1397
|
it "should keep the save status" do
|
1398
|
-
book1 =
|
1398
|
+
book1 = Workbook.open(@simple_file, :visible => true)
|
1399
1399
|
book1.Saved.should be true
|
1400
|
-
book2 =
|
1400
|
+
book2 = Workbook.open(@another_simple_file, :visible => true)
|
1401
1401
|
book1.Saved.should be true
|
1402
1402
|
book2.Saved.should be true
|
1403
1403
|
sheet2 = book2.sheet(1)
|
1404
|
-
sheet2[1,1] = sheet2[1,1].
|
1404
|
+
sheet2[1,1] = sheet2[1,1].Value == "foo" ? "bar" : "foo"
|
1405
1405
|
book1.Saved.should be true
|
1406
1406
|
book2.Saved.should be false
|
1407
|
-
book3 =
|
1407
|
+
book3 = Workbook.open(@different_file, :visible => true)
|
1408
1408
|
book1.Saved.should be true
|
1409
1409
|
book2.Saved.should be false
|
1410
1410
|
book3.Saved.should be true
|
@@ -1414,8 +1414,8 @@ describe Book do
|
|
1414
1414
|
|
1415
1415
|
context 'open with block' do
|
1416
1416
|
it {
|
1417
|
-
|
1418
|
-
book.sheet('Sheet1').should be_a
|
1417
|
+
Workbook.open(@simple_file) do |book|
|
1418
|
+
book.sheet('Sheet1').should be_a Worksheet
|
1419
1419
|
end
|
1420
1420
|
}
|
1421
1421
|
end
|