robust_excel_ole 1.31 → 1.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Changelog +20 -1
- data/README.rdoc +118 -18
- data/___dummy_workbook.xls +0 -0
- data/benchmarking/creek_example.rb +1 -1
- data/benchmarking/roo_example.rb +1 -1
- data/benchmarking/simple_xlsx_reader_example.rb +1 -1
- data/benchmarking/spreadsheet_example.rb +1 -1
- data/docs/README_excel.rdoc +16 -24
- data/docs/README_listobjects.rdoc +176 -0
- data/docs/README_open.rdoc +12 -12
- data/docs/README_ranges.rdoc +72 -55
- data/docs/README_save_close.rdoc +3 -3
- data/docs/README_sheet.rdoc +18 -13
- data/examples/example_ruby_library.rb +2 -2
- data/examples/introductory_examples/example_range.rb +2 -2
- data/examples/modifying_sheets/example_access_sheets_and_cells.rb +6 -6
- data/examples/modifying_sheets/example_add_names.rb +1 -1
- data/examples/modifying_sheets/example_concating.rb +1 -1
- data/examples/modifying_sheets/example_copying.rb +2 -2
- data/examples/modifying_sheets/example_listobjects.rb +86 -0
- data/examples/modifying_sheets/example_naming.rb +1 -1
- data/examples/modifying_sheets/example_ranges.rb +1 -1
- data/examples/open_save_close/example_control_to_excel.rb +1 -1
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +1 -1
- data/examples/open_save_close/example_if_obstructed_save.rb +3 -3
- 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_simple.rb +1 -1
- data/examples/open_save_close/example_unobtrusively.rb +3 -3
- data/lib/robust_excel_ole/address_tool.rb +54 -44
- data/lib/robust_excel_ole/base.rb +4 -6
- data/lib/robust_excel_ole/bookstore.rb +2 -16
- data/lib/robust_excel_ole/cell.rb +16 -21
- data/lib/robust_excel_ole/excel.rb +131 -186
- data/lib/robust_excel_ole/general.rb +82 -55
- data/lib/robust_excel_ole/list_object.rb +182 -109
- data/lib/robust_excel_ole/list_row.rb +65 -38
- data/lib/robust_excel_ole/range.rb +125 -93
- data/lib/robust_excel_ole/range_owners.rb +52 -66
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +168 -176
- data/lib/robust_excel_ole/worksheet.rb +177 -141
- data/robust_excel_ole.gemspec +4 -3
- data/spec/bookstore_spec.rb +2 -3
- data/spec/cell_spec.rb +9 -9
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/excel_spec.rb +132 -85
- data/spec/general_spec.rb +47 -15
- data/spec/list_object_spec.rb +258 -145
- data/spec/list_row_spec.rb +218 -0
- data/spec/range_spec.rb +76 -29
- data/spec/spec_helper.rb +15 -1
- data/spec/workbook_spec.rb +75 -34
- data/spec/workbook_specs/workbook_all_spec.rb +2 -1
- data/spec/workbook_specs/workbook_misc_spec.rb +20 -13
- data/spec/workbook_specs/workbook_open_spec.rb +47 -45
- data/spec/workbook_specs/workbook_save_spec.rb +21 -22
- data/spec/workbook_specs/workbook_sheet_spec.rb +3 -3
- data/spec/workbook_specs/workbook_unobtr_spec.rb +303 -303
- data/spec/worksheet_spec.rb +522 -318
- metadata +37 -2
data/spec/worksheet_spec.rb
CHANGED
@@ -24,7 +24,7 @@ describe Worksheet do
|
|
24
24
|
@blank_file = @dir + '/book_with_blank.xls'
|
25
25
|
@merge_file = @dir + '/merge_cells.xls'
|
26
26
|
@listobject_file = @dir + '/workbook_listobjects.xlsx'
|
27
|
-
@book = Workbook.open(@simple_file)
|
27
|
+
@book = Workbook.open(@simple_file, v: true)
|
28
28
|
@sheet = @book.sheet(1)
|
29
29
|
end
|
30
30
|
|
@@ -119,55 +119,352 @@ describe Worksheet do
|
|
119
119
|
|
120
120
|
end
|
121
121
|
|
122
|
-
describe "access sheet name" do
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
122
|
+
describe "get and access sheet name" do
|
123
|
+
|
124
|
+
it 'get sheet1 name' do
|
125
|
+
@sheet.name.should eq 'Sheet1'
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'change sheet1 name to foo' do
|
129
|
+
@sheet.name = 'foo'
|
130
|
+
@sheet.name.should eq 'foo'
|
127
131
|
end
|
128
132
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
133
|
+
it "should raise error when adding the same name" do
|
134
|
+
@sheet.name = 'foo'
|
135
|
+
@sheet.name.should eq 'foo'
|
136
|
+
new_sheet = @book.add_sheet @sheet
|
137
|
+
expect{
|
138
|
+
new_sheet.name = 'foo'
|
139
|
+
}.to raise_error(NameAlreadyExists, /sheet name "foo" already exists/)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should get and set name with umlaut" do
|
143
|
+
@sheet.name = "Straße"
|
144
|
+
@sheet.name.should == "Straße"
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should set and get numbers as name" do
|
148
|
+
@sheet.name = 1
|
149
|
+
@sheet.name.should == "1"
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "#[]" do
|
155
|
+
|
156
|
+
it "should yield values of a rectangular range [1..2,1..3]" do
|
157
|
+
value1 = [["foo", "workbook", "sheet1"], ["foo", nil, "foobaaa"]]
|
158
|
+
@sheet[1..2,1..3].should == value1
|
159
|
+
@sheet[1..2, "A".."C"].should == value1
|
160
|
+
@sheet["A1:C2"].should == value1
|
161
|
+
@sheet["Z1S1:Z2S3"].should == value1
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should yield values of a range [1,1..3]" do
|
165
|
+
@sheet[1,1..3].should == [["foo", "workbook", "sheet1"]]
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should yield values of range [1..2,1]" do
|
169
|
+
@sheet[1..2,1].should == [["foo"], ["foo"]]
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should yield values of row 1" do
|
173
|
+
@sheet[1].should == [["foo", "workbook", "sheet1"]]
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should yield value of a cell [1,2]" do
|
177
|
+
@sheet[1,2].should == "workbook"
|
178
|
+
@sheet["Z1S2"].should == @sheet[1,2]
|
179
|
+
@sheet["B1"].should == @sheet[1,2]
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should a range with relative r1c1-reference" do
|
183
|
+
@sheet.range([1,1]).Select
|
184
|
+
@sheet["Z1S[3]:Z[2]S8"].should == @sheet["Z1S4:Z3S8"]
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should a range with relative integer-range-reference" do
|
188
|
+
@sheet.range([1,1]).Select
|
189
|
+
@sheet[1..[2],[3]..8].should == @sheet["Z1S4:Z3S8"]
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should return value of a defined name" do
|
193
|
+
@book2 = Workbook.open(@dir + '/another_workbook.xls')
|
194
|
+
@sheet2 = @book2.sheet(1)
|
195
|
+
@sheet2["firstcell"].should == "foo"
|
196
|
+
@sheet2["new"].should == "foo"
|
197
|
+
@sheet2["one"].should == 1.0
|
198
|
+
@sheet2["four"].should == [[1,2],[3,4]]
|
199
|
+
@sheet2["firstrow"].should == [[1,2]]
|
200
|
+
@sheet2["another"].should == nil
|
201
|
+
expect {
|
202
|
+
@sheet2["foo"]
|
203
|
+
}.to raise_error(RangeNotCreated)
|
204
|
+
@book2.close(:if_unsaved => :forget)
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "#[]=" do
|
210
|
+
|
211
|
+
before do
|
212
|
+
@book1 = Workbook.open(@dir + '/another_workbook.xls')
|
213
|
+
@sheet1 = @book1.sheet(1)
|
214
|
+
end
|
215
|
+
|
216
|
+
after do
|
217
|
+
@book1.close(:if_unsaved => :forget)
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should set value of a defined name" do
|
221
|
+
@sheet1["firstcell"].should == "foo"
|
222
|
+
@sheet1["firstcell"] = "bar"
|
223
|
+
@sheet1["firstcell"].should == "bar"
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should set value of a defined name with several values" do
|
227
|
+
@sheet1["four"].should == [[1,2],[3,4]]
|
228
|
+
@sheet1["four"] = [[4,3],[2,1]]
|
229
|
+
@sheet1["four"].should == [[4,3],[2,1]]
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should set value of a defined name with one value" do
|
233
|
+
@sheet1["four"].should == [[1,2],[3,4]]
|
234
|
+
@sheet1["four"] = 2
|
235
|
+
@sheet1["four"].should == [[2,2],[2,2]]
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should set value given an address" do
|
239
|
+
@sheet1[1..2,1..3].should == [["foo", "workbook", "sheet1"], ["foo", 1.0, 2.0]]
|
240
|
+
@sheet1[1..2,1..3] = [["foo", 1.0, 2.0], ["foo", "workbook", "sheet1"]]
|
241
|
+
@sheet1[1..2,1..3].should == [["foo", 1.0, 2.0], ["foo", "workbook", "sheet1"]]
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should return nil for a range with empty contents" do
|
245
|
+
@sheet1["another"].should == nil
|
246
|
+
end
|
247
|
+
|
248
|
+
#it "should evaluate named formula" do
|
249
|
+
# @sheet1["named_formula"].should == 4
|
250
|
+
#end
|
251
|
+
|
252
|
+
#it "should evaluate a formula" do
|
253
|
+
# @sheet1["another_formula"].should == 5
|
254
|
+
#end
|
255
|
+
|
256
|
+
it "should raise an error if name not defined" do
|
257
|
+
expect {
|
258
|
+
@sheet1["foo"]
|
259
|
+
}.to raise_error(RangeNotCreated, /cannot find name or address "foo"/)
|
134
260
|
end
|
135
261
|
|
136
|
-
it "should
|
137
|
-
@
|
138
|
-
@
|
139
|
-
|
262
|
+
it "should set a range to a value" do
|
263
|
+
@sheet1[1,1].should == "foo"
|
264
|
+
@sheet1["firstcell"] = "bar"
|
265
|
+
@sheet1[1,1].should == "bar"
|
266
|
+
@sheet1["new"] = "bar"
|
267
|
+
@sheet1["new"].should == "bar"
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should raise an error if name cannot be evaluated" do
|
140
271
|
expect{
|
141
|
-
|
142
|
-
|
272
|
+
@sheet1["foo"] = 1
|
273
|
+
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range with name or address "foo"/)
|
143
274
|
end
|
144
275
|
end
|
145
|
-
end
|
146
276
|
|
147
|
-
describe 'access
|
277
|
+
describe 'access values of cells' do
|
148
278
|
|
149
279
|
describe "#[,]" do
|
150
280
|
|
151
|
-
context "access [1,1]" do
|
281
|
+
context "access values of [1,1]" do
|
152
282
|
|
153
|
-
it { @sheet[1, 1].should
|
154
|
-
it { @sheet[1, 1].Value.should eq 'foo' }
|
283
|
+
it { @sheet[1, 1].should eq 'foo' }
|
155
284
|
end
|
156
285
|
|
157
|
-
context "access [1, 1], [1, 2], [3, 1]" do
|
286
|
+
context "access values of [1, 1], [1, 2], [3, 1]" do
|
158
287
|
it "should get every values" do
|
159
|
-
@sheet[1, 1].
|
160
|
-
@sheet[1, 2].
|
161
|
-
@sheet[3, 1].
|
288
|
+
@sheet[1, 1].should eq 'foo'
|
289
|
+
@sheet[1, 2].should eq 'workbook'
|
290
|
+
@sheet[3, 1].should eq 'matz'
|
162
291
|
end
|
163
292
|
end
|
164
293
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
294
|
+
end
|
295
|
+
|
296
|
+
describe "namevalue_global, set_namevalue_global" do
|
297
|
+
|
298
|
+
before do
|
299
|
+
@book1 = Workbook.open(@dir + '/another_workbook.xls')
|
300
|
+
@sheet1 = @book1.sheet(1)
|
301
|
+
end
|
302
|
+
|
303
|
+
after do
|
304
|
+
@book1.close(:if_unsaved => :forget)
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should return value of a defined name" do
|
308
|
+
@sheet1.namevalue_global("firstcell").should == "foo"
|
309
|
+
end
|
310
|
+
|
311
|
+
#it "should evaluate a formula" do
|
312
|
+
# @sheet1.namevalue_global("another_formula").should == 5
|
313
|
+
#end
|
314
|
+
|
315
|
+
it "should raise an error if name not defined" do
|
316
|
+
expect {
|
317
|
+
@sheet1.namevalue_global("foo")
|
318
|
+
}.to raise_error(NameNotFound, /name "foo" not in/)
|
319
|
+
end
|
320
|
+
|
321
|
+
it "should raise an error of coordinates are given instead of a defined name" do
|
322
|
+
expect {
|
323
|
+
@sheet1.namevalue_global("A1")
|
324
|
+
}.to raise_error(NameNotFound, /name "A1" not in/)
|
325
|
+
end
|
326
|
+
|
327
|
+
it "should return default value for a range with empty contents" do
|
328
|
+
@sheet1.namevalue_global("another", :default => 2) == 2
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should set a range to a value" do
|
332
|
+
@sheet1.namevalue_global("firstcell").should == "foo"
|
333
|
+
@sheet1[1,1].should == "foo"
|
334
|
+
@sheet1.set_namevalue_global("firstcell","bar")
|
335
|
+
@sheet1.namevalue_global("firstcell").should == "bar"
|
336
|
+
@sheet1[1,1].should == "bar"
|
337
|
+
end
|
338
|
+
|
339
|
+
it "should raise an error if name cannot be evaluated" do
|
340
|
+
expect{
|
341
|
+
@sheet1.set_namevalue_global("foo", 1)
|
342
|
+
}.to raise_error(RangeNotEvaluatable, /cannot assign value/)
|
343
|
+
end
|
344
|
+
|
345
|
+
it "should color the cell (deprecated)" do
|
346
|
+
@sheet1.set_namevalue_global("new", "bar")
|
347
|
+
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
348
|
+
@sheet1.set_namevalue_global("new", "bar", :color => 4)
|
349
|
+
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
350
|
+
end
|
351
|
+
|
352
|
+
it "should color the cell" do
|
353
|
+
@sheet1.set_namevalue_global("new", "bar")
|
354
|
+
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
355
|
+
@sheet1.set_namevalue_global("new", "bar", :color => 4)
|
356
|
+
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
357
|
+
end
|
358
|
+
|
359
|
+
it "should set a range to a value with umlauts" do
|
360
|
+
@sheet1.add_name("lösung", [1,1])
|
361
|
+
@sheet1.namevalue_global("lösung").should == "foo"
|
362
|
+
@sheet1[1,1].should == "foo"
|
363
|
+
@sheet1.set_namevalue_global("lösung","bar")
|
364
|
+
@sheet1.namevalue_global("lösung").should == "bar"
|
365
|
+
@sheet1[1,1].should == "bar"
|
366
|
+
end
|
367
|
+
|
368
|
+
end
|
369
|
+
|
370
|
+
describe "namevalue, set_namevalue" do
|
371
|
+
|
372
|
+
before do
|
373
|
+
@book1 = Workbook.open(@dir + '/another_workbook.xls')
|
374
|
+
@sheet1 = @book1.sheet(1)
|
375
|
+
@sheet2 = @book1.sheet(2)
|
376
|
+
end
|
377
|
+
|
378
|
+
after do
|
379
|
+
@book1.close(:if_unsaved => :forget)
|
380
|
+
end
|
381
|
+
|
382
|
+
it "should return value of a locally defined name" do
|
383
|
+
@sheet1.namevalue("firstcell").should == "foo"
|
384
|
+
end
|
385
|
+
|
386
|
+
it "should return value of a name with coordinates" do
|
387
|
+
@sheet1.namevalue("A1").should == "foo"
|
388
|
+
end
|
389
|
+
|
390
|
+
it "should return nil for a range with empty contents" do
|
391
|
+
@sheet1.namevalue("another").should == nil
|
392
|
+
end
|
393
|
+
|
394
|
+
it "should return value of a defined name" do
|
395
|
+
@sheet1.namevalue("new").should == "foo"
|
396
|
+
@sheet1.namevalue("one").should == 1.0
|
397
|
+
@sheet1.namevalue("four").should == [[1,2],[3,4]]
|
398
|
+
@sheet1.namevalue("firstrow").should == [[1,2]]
|
399
|
+
end
|
400
|
+
|
401
|
+
it "should return default value if name not defined and default value is given" do
|
402
|
+
@sheet1.namevalue("foo", :default => 2).should == 2
|
403
|
+
end
|
404
|
+
|
405
|
+
it "should raise an error if name not defined for the sheet" do
|
406
|
+
expect {
|
407
|
+
@sheet1.namevalue("foo")
|
408
|
+
}.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1/)
|
409
|
+
expect {
|
410
|
+
@sheet1.namevalue("named_formula")
|
411
|
+
}.to raise_error(NameNotFound, /name "named_formula" not in #<Worksheet: Sheet1/)
|
412
|
+
expect {
|
413
|
+
@sheet2.namevalue("firstcell")
|
414
|
+
}.to raise_error(NameNotFound, /name "firstcell" not in #<Worksheet: Sheet2/)
|
415
|
+
end
|
416
|
+
|
417
|
+
it "should set a range to a value" do
|
418
|
+
@sheet1.namevalue("firstcell").should == "foo"
|
419
|
+
@sheet1[1,1].should == "foo"
|
420
|
+
@sheet1.set_namevalue("firstcell","bar")
|
421
|
+
@sheet1.namevalue("firstcell").should == "bar"
|
422
|
+
@sheet1[1,1].should == "bar"
|
423
|
+
end
|
424
|
+
|
425
|
+
it "should set a range to a value with umlauts" do
|
426
|
+
@sheet1.add_name("lösung", [1,1])
|
427
|
+
@sheet1.namevalue("lösung").should == "foo"
|
428
|
+
@sheet1[1,1].should == "foo"
|
429
|
+
@sheet1.set_namevalue("lösung","bar")
|
430
|
+
@sheet1.namevalue("lösung").should == "bar"
|
431
|
+
@sheet1[1,1].should == "bar"
|
432
|
+
end
|
433
|
+
|
434
|
+
it "should raise an error if name cannot be evaluated" do
|
435
|
+
expect{
|
436
|
+
@sheet1.set_namevalue_global("foo", 1)
|
437
|
+
}.to raise_error(RangeNotEvaluatable, /cannot assign value/)
|
438
|
+
end
|
439
|
+
|
440
|
+
it "should raise an error if name not defined and default value is not provided" do
|
441
|
+
expect {
|
442
|
+
@sheet1.namevalue("foo", :default => nil)
|
443
|
+
}.to_not raise_error
|
444
|
+
expect {
|
445
|
+
@sheet1.namevalue("foo", :default => :__not_provided)
|
446
|
+
}.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1/)
|
447
|
+
expect {
|
448
|
+
@sheet1.namevalue("foo")
|
449
|
+
}.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1/)
|
450
|
+
@sheet1.namevalue("foo", :default => nil).should be_nil
|
451
|
+
@sheet1.namevalue("foo", :default => 1).should == 1
|
452
|
+
@sheet1.namevalue_global("empty", :default => 1).should be_nil
|
453
|
+
end
|
454
|
+
|
455
|
+
it "should color the cell (depracated)" do
|
456
|
+
@sheet1.set_namevalue("new", "bar")
|
457
|
+
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
458
|
+
@sheet1.set_namevalue("new", "bar", :color => 4)
|
459
|
+
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
460
|
+
end
|
461
|
+
|
462
|
+
it "should color the cell" do
|
463
|
+
@sheet1.set_namevalue("new", "bar")
|
464
|
+
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
465
|
+
@sheet1.set_namevalue("new", "bar", :color => 4)
|
466
|
+
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
467
|
+
end
|
171
468
|
|
172
469
|
end
|
173
470
|
|
@@ -180,18 +477,18 @@ describe Worksheet do
|
|
180
477
|
|
181
478
|
it "change a cell to 'bar'" do
|
182
479
|
@sheet[1, 1] = 'bar'
|
183
|
-
@sheet[1, 1].
|
480
|
+
@sheet[1, 1].should eq 'bar'
|
184
481
|
end
|
185
482
|
|
186
483
|
it "should change a cell to nil" do
|
187
484
|
@sheet[1, 1] = nil
|
188
|
-
@sheet[1, 1].
|
485
|
+
@sheet[1, 1].should eq nil
|
189
486
|
end
|
190
487
|
|
191
488
|
it "should raise error for bad ranges" do
|
192
489
|
expect{
|
193
490
|
@sheet[0,0]
|
194
|
-
}.to raise_error(
|
491
|
+
}.to raise_error(RangeNotCreated, /cannot find name or address 0, 0/)
|
195
492
|
expect{
|
196
493
|
@sheet[0,0] = "foo"
|
197
494
|
}.to raise_error(RangeNotEvaluatable, /cannot assign value/)
|
@@ -202,16 +499,97 @@ describe Worksheet do
|
|
202
499
|
it "should set color" do
|
203
500
|
@sheet.set_cellval(1,1,"foo",:color => 42)
|
204
501
|
@sheet.cellval(1,1).should == "foo"
|
205
|
-
@sheet[1,1].Interior.ColorIndex.should == 42
|
502
|
+
@sheet.range([1,1]).Interior.ColorIndex.should == 42
|
206
503
|
end
|
207
504
|
end
|
208
505
|
|
209
|
-
describe "range" do
|
506
|
+
describe "#range" do
|
507
|
+
|
508
|
+
it "should access a rectangular range [1..2,1..3]" do
|
509
|
+
range1 = @sheet.range(1..2,1..3)
|
510
|
+
range1.should be_kind_of RobustExcelOle::Range
|
511
|
+
range1.Address.should == "$A$1:$C$2"
|
512
|
+
range1.Value.should == [["foo", "workbook", "sheet1"], ["foo", nil, "foobaaa"]]
|
513
|
+
range2 = @sheet.range(1..2, "A".."C")
|
514
|
+
range2.Address.should == range1.Address
|
515
|
+
range3 = @sheet.range("A1:C2")
|
516
|
+
range3.Address.should == range1.Address
|
517
|
+
range4 = @sheet.range(["A1:C2"])
|
518
|
+
range4.Address.should == range1.Address
|
519
|
+
range5 = @sheet.range("Z1S1:Z2S3")
|
520
|
+
range5.Address.should == range1.Address
|
521
|
+
range6 = @sheet.range([1..2,1..3])
|
522
|
+
range6.should be_kind_of RobustExcelOle::Range
|
523
|
+
range6.Address.should == "$A$1:$C$2"
|
524
|
+
range6.Value.should == [["foo", "workbook", "sheet1"], ["foo", nil, "foobaaa"]]
|
525
|
+
range7 = @sheet.range([1..2, "A".."C"])
|
526
|
+
range7.Address.should == range1.Address
|
527
|
+
end
|
528
|
+
|
529
|
+
it "should access a range [1,1..3]" do
|
530
|
+
range1 = @sheet.range(1,1..3)
|
531
|
+
range1.should be_kind_of RobustExcelOle::Range
|
532
|
+
range1.Address.should == "$A$1:$C$1"
|
533
|
+
range1.Value.should == [["foo", "workbook", "sheet1"]]
|
534
|
+
range2 = @sheet.range([1,1..3])
|
535
|
+
range2.Address.should == range1.Address
|
536
|
+
end
|
537
|
+
|
538
|
+
it "should access a range [1..2,1]" do
|
539
|
+
range1 = @sheet.range(1..2,1)
|
540
|
+
range1.should be_kind_of RobustExcelOle::Range
|
541
|
+
range1.Address.should == "$A$1:$A$2"
|
542
|
+
range1.Value.should == [["foo"], ["foo"]]
|
543
|
+
range2 = @sheet.range([1..2,1])
|
544
|
+
range2.Address.should == range1.Address
|
545
|
+
end
|
546
|
+
|
547
|
+
it "should access a row 1" do
|
548
|
+
range1 = @sheet.range(1)
|
549
|
+
range1.should be_kind_of RobustExcelOle::Range
|
550
|
+
range1.Address.should == "$1:$1"
|
551
|
+
range1.Value.first.size.should == 256
|
552
|
+
range1.value.should == [["foo", "workbook", "sheet1"]]
|
553
|
+
range2 = @sheet.range([1])
|
554
|
+
range2.Address.should == range1.Address
|
555
|
+
end
|
556
|
+
|
557
|
+
it "should access several rows" do
|
558
|
+
@sheet.range([1..3]).Address.should == "$1:$3"
|
559
|
+
@sheet.range(1..3).Address.should == "$1:$3"
|
560
|
+
@sheet.range([1..3,nil]).Address.should == "$1:$3"
|
561
|
+
@sheet.range(1..3,nil).Address.should == "$1:$3"
|
562
|
+
end
|
563
|
+
|
564
|
+
it "should access several columns" do
|
565
|
+
@sheet.range([nil,2..4]).Address.should == "$B:$D"
|
566
|
+
@sheet.range(nil,2..4).Address.should == "$B:$D"
|
567
|
+
@sheet.range([nil,"B".."D"]).Address.should == "$B:$D"
|
568
|
+
@sheet.range(nil,"B".."D").Address.should == "$B:$D"
|
569
|
+
end
|
570
|
+
|
571
|
+
it "should create infinite ranges" do
|
572
|
+
@sheet.range("1:3").Address.should == "$1:$3"
|
573
|
+
@sheet.range("B:D").Address.should == "$B:$D"
|
574
|
+
end
|
575
|
+
|
576
|
+
it "should access a cell [1,2]" do
|
577
|
+
cell1 = @sheet.range(1,2)
|
578
|
+
cell1.should be_kind_of Cell
|
579
|
+
cell1.Address.should == "$B$1"
|
580
|
+
cell1.Value.should == "workbook"
|
581
|
+
cell2 = @sheet.range("B1")
|
582
|
+
cell1.should be_kind_of Cell
|
583
|
+
cell2.Address.should == cell1.Address
|
584
|
+
cell3 = @sheet.range("Z1S2")
|
585
|
+
cell1.should be_kind_of Cell
|
586
|
+
cell3.Address.should == cell1.Address
|
587
|
+
end
|
210
588
|
|
211
589
|
it "should a range with relative r1c1-reference" do
|
212
590
|
@sheet.range([1,1]).Select
|
213
|
-
@sheet.range(
|
214
|
-
@sheet.range(
|
591
|
+
@sheet.range("Z1S[3]:Z[2]S8").Address.should == "$D$1:$H$3"
|
592
|
+
@sheet.range("Z1S3:Z2S8").Address.should == "$C$1:$H$2"
|
215
593
|
end
|
216
594
|
|
217
595
|
it "should a range with relative integer-range-reference" do
|
@@ -219,39 +597,42 @@ describe Worksheet do
|
|
219
597
|
@sheet.range([1..[2],[3]..8]).Address.should == "$D$1:$H$3"
|
220
598
|
end
|
221
599
|
|
222
|
-
it "should
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
600
|
+
it "should raise an error" do
|
601
|
+
expect{
|
602
|
+
@sheet.range([0,0])
|
603
|
+
}.to raise_error(RangeNotCreated, /cannot find/)
|
604
|
+
expect{
|
605
|
+
@sheet.range([0..3,4])
|
606
|
+
}.to raise_error(RangeNotCreated, /cannot find/)
|
607
|
+
end
|
608
|
+
|
609
|
+
it "should return value of a defined name" do
|
610
|
+
@book2 = Workbook.open(@dir + '/another_workbook.xls')
|
611
|
+
@sheet2 = @book2.sheet(1)
|
612
|
+
range1 = @sheet2.range("firstcell")
|
613
|
+
range1.should be_kind_of Cell
|
614
|
+
range1.Value.should == "foo"
|
615
|
+
@sheet2.range("new").Value.should == "foo"
|
616
|
+
@sheet2.range("one").Value.should == 1.0
|
617
|
+
@sheet2.range("four").Value.should == [[1,2],[3,4]]
|
618
|
+
@sheet2.range("firstrow").Value.should == [[1,2]]
|
619
|
+
@sheet2.range("another").Value.should == nil
|
620
|
+
expect {
|
621
|
+
@sheet2.range("foo")
|
622
|
+
}.to raise_error(RangeNotCreated)
|
623
|
+
@book2.close(:if_unsaved => :forget)
|
228
624
|
end
|
229
625
|
|
230
626
|
it "should create a rectangular range" do
|
231
627
|
@sheet.range([1..3,2..4]).values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
232
628
|
@sheet.range([1..3, "B".."D"]).values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
233
|
-
@sheet.range(["B1:D3"]).values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
234
629
|
@sheet.range("B1:D3").values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
235
|
-
@sheet.range(["Z1S2:Z3S4"]).values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
236
630
|
@sheet.range("Z1S2:Z3S4").values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
237
631
|
end
|
238
|
-
|
239
|
-
it "should accept old interface" do
|
240
|
-
@sheet.range(1..3,2..4).values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
241
|
-
@sheet.range(1..3, "B".."D").values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should create infinite ranges" do
|
245
|
-
@sheet.range([1..3,nil]).Address.should == "$1:$3"
|
246
|
-
@sheet.range(nil,"B".."D").Address.should == "$B:$D"
|
247
|
-
@sheet.range("1:3").Address.should == "$1:$3"
|
248
|
-
@sheet.range("B:D").Address.should == "$B:$D"
|
249
|
-
end
|
250
|
-
|
251
|
-
it "should raise an error" do
|
252
|
-
expect{
|
253
|
-
@sheet.range([0,0])
|
254
|
-
}.to raise_error(RangeNotCreated, /cannot create/)
|
632
|
+
|
633
|
+
it "should accept old interface" do
|
634
|
+
@sheet.range(1..3,2..4).values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
635
|
+
@sheet.range(1..3, "B".."D").values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
255
636
|
end
|
256
637
|
|
257
638
|
end
|
@@ -267,16 +648,23 @@ describe Worksheet do
|
|
267
648
|
table = @sheet.table(1)
|
268
649
|
table.Name.should == "table3"
|
269
650
|
table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
|
270
|
-
table.ListRows.Count.should ==
|
271
|
-
@sheet[3,4].
|
651
|
+
table.ListRows.Count.should == 13
|
652
|
+
@sheet[3,4].should == "Number"
|
272
653
|
end
|
273
654
|
|
274
655
|
it "should yield table given name" do
|
275
656
|
table = @sheet.table("table3")
|
276
657
|
table.Name.should == "table3"
|
277
658
|
table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
|
278
|
-
table.ListRows.Count.should ==
|
279
|
-
@sheet[3,4].
|
659
|
+
table.ListRows.Count.should == 13
|
660
|
+
@sheet[3,4].should == "Number"
|
661
|
+
end
|
662
|
+
|
663
|
+
it "should yield table given name with umlauts" do
|
664
|
+
table = Table.new(@sheet, "lösung", [1,1], 3, ["Verkäufer","Straße"])
|
665
|
+
table2 = @sheet.table("lösung")
|
666
|
+
table2.Name.encode_value.should == "lösung"
|
667
|
+
table2.HeaderRowRange.Value.first.encode_value.should == ["Verkäufer","Straße"]
|
280
668
|
end
|
281
669
|
|
282
670
|
it "should raise error" do
|
@@ -287,9 +675,10 @@ describe Worksheet do
|
|
287
675
|
|
288
676
|
end
|
289
677
|
|
290
|
-
describe '#
|
678
|
+
describe '#each_cell' do
|
679
|
+
|
291
680
|
it "should sort line in order of column" do
|
292
|
-
@sheet.
|
681
|
+
@sheet.each_cell.with_index do |cell, i|
|
293
682
|
case i
|
294
683
|
when 0
|
295
684
|
cell.Value.should eq 'foo'
|
@@ -311,7 +700,7 @@ describe Worksheet do
|
|
311
700
|
include_context "sheet 'open book with blank'"
|
312
701
|
|
313
702
|
it 'should get from ["A1"]' do
|
314
|
-
@sheet_with_blank.
|
703
|
+
@sheet_with_blank.each_cell.with_index do |cell, i|
|
315
704
|
case i
|
316
705
|
when 5
|
317
706
|
cell.Value.should be_nil
|
@@ -328,6 +717,16 @@ describe Worksheet do
|
|
328
717
|
end
|
329
718
|
end
|
330
719
|
|
720
|
+
it "should access each cell" do
|
721
|
+
cells = []
|
722
|
+
@sheet.each_cell do |cell|
|
723
|
+
cells << cell
|
724
|
+
end
|
725
|
+
cells.should == [@sheet.range(1,1), @sheet.range(1,2), @sheet.range(1,3),
|
726
|
+
@sheet.range(2,1), @sheet.range(2,2), @sheet.range(2,3),
|
727
|
+
@sheet.range(3,1), @sheet.range(3,2), @sheet.range(3,3)]
|
728
|
+
end
|
729
|
+
|
331
730
|
end
|
332
731
|
|
333
732
|
describe "#values" do
|
@@ -338,6 +737,35 @@ describe Worksheet do
|
|
338
737
|
|
339
738
|
end
|
340
739
|
|
740
|
+
describe "#names" do
|
741
|
+
|
742
|
+
before do
|
743
|
+
@book1 = Workbook.open(@dir + '/another_workbook.xls')
|
744
|
+
@sheet1 = @book1.sheet(1)
|
745
|
+
end
|
746
|
+
|
747
|
+
it "should yield defined names" do
|
748
|
+
@sheet1.names.should == ["Sheet1!another_formula", "Sheet1!firstcell", "Sheet1!localname", "Sheet1!simple"]
|
749
|
+
end
|
750
|
+
|
751
|
+
end
|
752
|
+
|
753
|
+
describe "#each" do
|
754
|
+
|
755
|
+
it "should yield rows" do
|
756
|
+
@sheet.each.with_index do |row, i|
|
757
|
+
row.should == ["foo", "workbook", "sheet1"] if i == 0
|
758
|
+
row.should == ["foo", nil, "foobaaa"] if i == 1
|
759
|
+
row.should == ["matz", "is", "nice"] if i == 2
|
760
|
+
end
|
761
|
+
end
|
762
|
+
|
763
|
+
it "should do map" do
|
764
|
+
@sheet.map{|r| r}.should == [["foo", "workbook", "sheet1"], ["foo", nil, "foobaaa"], ["matz", "is", "nice"]]
|
765
|
+
end
|
766
|
+
|
767
|
+
end
|
768
|
+
|
341
769
|
describe "#each_rowvalue" do
|
342
770
|
|
343
771
|
it "should yield arrays" do
|
@@ -415,9 +843,9 @@ describe Worksheet do
|
|
415
843
|
|
416
844
|
end
|
417
845
|
|
418
|
-
describe "#
|
846
|
+
describe "#each_row.with_index" do
|
419
847
|
it "should read with index" do
|
420
|
-
@sheet.
|
848
|
+
@sheet.each_row.with_index do |rows, idx|
|
421
849
|
case idx
|
422
850
|
when 0
|
423
851
|
rows.values.should eq ['foo', 'workbook', 'sheet1']
|
@@ -429,22 +857,10 @@ describe Worksheet do
|
|
429
857
|
end
|
430
858
|
end
|
431
859
|
|
432
|
-
context "with argument 1" do
|
433
|
-
it "should read from second row, index is started 0" do
|
434
|
-
@sheet.each_row_with_index(1) do |rows, idx|
|
435
|
-
case idx
|
436
|
-
when 0
|
437
|
-
rows.values.should eq ['foo', nil, 'foobaaa']
|
438
|
-
when 1
|
439
|
-
rows.values.should eq ['matz', 'is', 'nice']
|
440
|
-
end
|
441
|
-
end
|
442
|
-
end
|
443
|
-
end
|
444
|
-
|
445
860
|
end
|
446
861
|
|
447
862
|
describe "#each_column" do
|
863
|
+
|
448
864
|
it "items should RobustExcelOle::Range" do
|
449
865
|
@sheet.each_column do |columns|
|
450
866
|
columns.should be_kind_of RobustExcelOle::Range
|
@@ -511,8 +927,9 @@ describe Worksheet do
|
|
511
927
|
end
|
512
928
|
|
513
929
|
describe "#each_column_with_index" do
|
930
|
+
|
514
931
|
it "should read with index" do
|
515
|
-
@sheet.
|
932
|
+
@sheet.each_column.with_index do |columns, idx|
|
516
933
|
case idx
|
517
934
|
when 0
|
518
935
|
columns.values.should eq ['foo', 'foo', 'matz']
|
@@ -523,19 +940,6 @@ describe Worksheet do
|
|
523
940
|
end
|
524
941
|
end
|
525
942
|
end
|
526
|
-
|
527
|
-
context "with argument 1" do
|
528
|
-
it "should read from second column, index is started 0" do
|
529
|
-
@sheet.each_column_with_index(1) do |column_range, idx|
|
530
|
-
case idx
|
531
|
-
when 0
|
532
|
-
column_range.values.should eq ['workbook', nil, 'is']
|
533
|
-
when 1
|
534
|
-
column_range.values.should eq ['sheet1', 'foobaaa', 'nice']
|
535
|
-
end
|
536
|
-
end
|
537
|
-
end
|
538
|
-
end
|
539
943
|
end
|
540
944
|
|
541
945
|
describe "#row_range" do
|
@@ -587,222 +991,7 @@ describe Worksheet do
|
|
587
991
|
end
|
588
992
|
end
|
589
993
|
|
590
|
-
describe "
|
591
|
-
before do
|
592
|
-
@book1 = Workbook.open(@dir + '/another_workbook.xls')
|
593
|
-
@sheet1 = @book1.sheet(1)
|
594
|
-
end
|
595
|
-
|
596
|
-
after do
|
597
|
-
@book1.close(:if_unsaved => :forget)
|
598
|
-
end
|
599
|
-
|
600
|
-
it "should return value of a defined name" do
|
601
|
-
@sheet1["firstcell"].should == "foo"
|
602
|
-
end
|
603
|
-
|
604
|
-
it "should return value of a defined name" do
|
605
|
-
@sheet1["new"].should == "foo"
|
606
|
-
@sheet1["one"].should == 1.0
|
607
|
-
@sheet1["four"].should == [[1,2],[3,4]]
|
608
|
-
@sheet1["firstrow"].should == [[1,2]]
|
609
|
-
end
|
610
|
-
|
611
|
-
it "should return value of a name with coordinates" do
|
612
|
-
@sheet1["A1"].should == "foo"
|
613
|
-
end
|
614
|
-
|
615
|
-
it "should return nil for a range with empty contents" do
|
616
|
-
@sheet1["another"].should == nil
|
617
|
-
end
|
618
|
-
|
619
|
-
#it "should evaluate named formula" do
|
620
|
-
# @sheet1["named_formula"].should == 4
|
621
|
-
#end
|
622
|
-
|
623
|
-
#it "should evaluate a formula" do
|
624
|
-
# @sheet1["another_formula"].should == 5
|
625
|
-
#end
|
626
|
-
|
627
|
-
it "should raise an error if name not defined" do
|
628
|
-
expect {
|
629
|
-
@sheet1["foo"]
|
630
|
-
}.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1/)
|
631
|
-
end
|
632
|
-
|
633
|
-
it "should set a range to a value" do
|
634
|
-
@sheet1[1,1].Value.should == "foo"
|
635
|
-
@sheet1["firstcell"] = "bar"
|
636
|
-
@sheet1[1,1].Value.should == "bar"
|
637
|
-
@sheet1["new"] = "bar"
|
638
|
-
@sheet1["new"].should == "bar"
|
639
|
-
end
|
640
|
-
|
641
|
-
it "should raise an error if name cannot be evaluated" do
|
642
|
-
expect{
|
643
|
-
@sheet1["foo"] = 1
|
644
|
-
}.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1/)
|
645
|
-
end
|
646
|
-
end
|
647
|
-
|
648
|
-
describe "namevalue_global, set_namevalue_global" do
|
649
|
-
|
650
|
-
before do
|
651
|
-
@book1 = Workbook.open(@dir + '/another_workbook.xls')
|
652
|
-
@sheet1 = @book1.sheet(1)
|
653
|
-
end
|
654
|
-
|
655
|
-
after do
|
656
|
-
@book1.close(:if_unsaved => :forget)
|
657
|
-
end
|
658
|
-
|
659
|
-
it "should return value of a defined name" do
|
660
|
-
@sheet1.namevalue_global("firstcell").should == "foo"
|
661
|
-
end
|
662
|
-
|
663
|
-
#it "should evaluate a formula" do
|
664
|
-
# @sheet1.namevalue_global("another_formula").should == 5
|
665
|
-
#end
|
666
|
-
|
667
|
-
it "should raise an error if name not defined" do
|
668
|
-
expect {
|
669
|
-
@sheet1.namevalue_global("foo")
|
670
|
-
}.to raise_error(NameNotFound, /name "foo" not in/)
|
671
|
-
end
|
672
|
-
|
673
|
-
it "should raise an error of coordinates are given instead of a defined name" do
|
674
|
-
expect {
|
675
|
-
@sheet1.namevalue_global("A1")
|
676
|
-
}.to raise_error(NameNotFound, /name "A1" not in/)
|
677
|
-
end
|
678
|
-
|
679
|
-
it "should return default value for a range with empty contents" do
|
680
|
-
@sheet1.namevalue_global("another", :default => 2) == 2
|
681
|
-
end
|
682
|
-
|
683
|
-
it "should set a range to a value" do
|
684
|
-
@sheet1.namevalue_global("firstcell").should == "foo"
|
685
|
-
@sheet1[1,1].Value.should == "foo"
|
686
|
-
@sheet1.set_namevalue_global("firstcell","bar")
|
687
|
-
@sheet1.namevalue_global("firstcell").should == "bar"
|
688
|
-
@sheet1[1,1].Value.should == "bar"
|
689
|
-
end
|
690
|
-
|
691
|
-
it "should raise an error if name cannot be evaluated" do
|
692
|
-
expect{
|
693
|
-
@sheet1.set_namevalue_global("foo", 1)
|
694
|
-
}.to raise_error(RangeNotEvaluatable, /cannot assign value/)
|
695
|
-
end
|
696
|
-
|
697
|
-
it "should color the cell (deprecated)" do
|
698
|
-
@sheet1.set_namevalue_global("new", "bar")
|
699
|
-
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
700
|
-
@sheet1.set_namevalue_global("new", "bar", :color => 4)
|
701
|
-
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
702
|
-
end
|
703
|
-
|
704
|
-
it "should color the cell" do
|
705
|
-
@sheet1.set_namevalue_global("new", "bar")
|
706
|
-
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
707
|
-
@sheet1.set_namevalue_global("new", "bar", :color => 4)
|
708
|
-
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
709
|
-
end
|
710
|
-
|
711
|
-
end
|
712
|
-
|
713
|
-
describe "namevalue, set_namevalue" do
|
714
|
-
|
715
|
-
before do
|
716
|
-
@book1 = Workbook.open(@dir + '/another_workbook.xls')
|
717
|
-
@sheet1 = @book1.sheet(1)
|
718
|
-
@sheet2 = @book1.sheet(2)
|
719
|
-
end
|
720
|
-
|
721
|
-
after do
|
722
|
-
@book1.close(:if_unsaved => :forget)
|
723
|
-
end
|
724
|
-
|
725
|
-
it "should return value of a locally defined name" do
|
726
|
-
@sheet1.namevalue("firstcell").should == "foo"
|
727
|
-
end
|
728
|
-
|
729
|
-
it "should return value of a name with coordinates" do
|
730
|
-
@sheet1.namevalue("A1").should == "foo"
|
731
|
-
end
|
732
|
-
|
733
|
-
it "should return nil for a range with empty contents" do
|
734
|
-
@sheet1.namevalue("another").should == nil
|
735
|
-
end
|
736
|
-
|
737
|
-
it "should return value of a defined name" do
|
738
|
-
@sheet1.namevalue("new").should == "foo"
|
739
|
-
@sheet1.namevalue("one").should == 1.0
|
740
|
-
@sheet1.namevalue("four").should == [[1,2],[3,4]]
|
741
|
-
@sheet1.namevalue("firstrow").should == [[1,2]]
|
742
|
-
end
|
743
|
-
|
744
|
-
it "should return default value if name not defined and default value is given" do
|
745
|
-
@sheet1.namevalue("foo", :default => 2).should == 2
|
746
|
-
end
|
747
|
-
|
748
|
-
it "should raise an error if name not defined for the sheet" do
|
749
|
-
expect {
|
750
|
-
@sheet1.namevalue("foo")
|
751
|
-
}.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1/)
|
752
|
-
expect {
|
753
|
-
@sheet1.namevalue("named_formula")
|
754
|
-
}.to raise_error(NameNotFound, /name "named_formula" not in #<Worksheet: Sheet1/)
|
755
|
-
expect {
|
756
|
-
@sheet2.namevalue("firstcell")
|
757
|
-
}.to raise_error(NameNotFound, /name "firstcell" not in #<Worksheet: Sheet2/)
|
758
|
-
end
|
759
|
-
|
760
|
-
it "should set a range to a value" do
|
761
|
-
@sheet1.namevalue("firstcell").should == "foo"
|
762
|
-
@sheet1[1,1].Value.should == "foo"
|
763
|
-
@sheet1.set_namevalue("firstcell","bar")
|
764
|
-
@sheet1.namevalue("firstcell").should == "bar"
|
765
|
-
@sheet1[1,1].Value.should == "bar"
|
766
|
-
end
|
767
|
-
|
768
|
-
it "should raise an error if name cannot be evaluated" do
|
769
|
-
expect{
|
770
|
-
@sheet1.set_namevalue_global("foo", 1)
|
771
|
-
}.to raise_error(RangeNotEvaluatable, /cannot assign value/)
|
772
|
-
end
|
773
|
-
|
774
|
-
it "should raise an error if name not defined and default value is not provided" do
|
775
|
-
expect {
|
776
|
-
@sheet1.namevalue("foo", :default => nil)
|
777
|
-
}.to_not raise_error
|
778
|
-
expect {
|
779
|
-
@sheet1.namevalue("foo", :default => :__not_provided)
|
780
|
-
}.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1/)
|
781
|
-
expect {
|
782
|
-
@sheet1.namevalue("foo")
|
783
|
-
}.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1/)
|
784
|
-
@sheet1.namevalue("foo", :default => nil).should be_nil
|
785
|
-
@sheet1.namevalue("foo", :default => 1).should == 1
|
786
|
-
@sheet1.namevalue_global("empty", :default => 1).should be_nil
|
787
|
-
end
|
788
|
-
|
789
|
-
it "should color the cell (depracated)" do
|
790
|
-
@sheet1.set_namevalue("new", "bar")
|
791
|
-
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
792
|
-
@sheet1.set_namevalue("new", "bar", :color => 4)
|
793
|
-
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
794
|
-
end
|
795
|
-
|
796
|
-
it "should color the cell" do
|
797
|
-
@sheet1.set_namevalue("new", "bar")
|
798
|
-
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
799
|
-
@sheet1.set_namevalue("new", "bar", :color => 4)
|
800
|
-
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
801
|
-
end
|
802
|
-
|
803
|
-
end
|
804
|
-
|
805
|
-
describe "add_name, delete_name, rename_range" do
|
994
|
+
describe "add_name, delete_name, rename_name" do
|
806
995
|
|
807
996
|
context "adding, renaming, deleting the name of a range" do
|
808
997
|
|
@@ -833,7 +1022,7 @@ describe Worksheet do
|
|
833
1022
|
end
|
834
1023
|
|
835
1024
|
it "should rename an already named range with a giving address" do
|
836
|
-
@sheet1[1,1].Name.Name.should == "Sheet1!firstcell"
|
1025
|
+
@sheet1.range([1,1]).Name.Name.should == "Sheet1!firstcell"
|
837
1026
|
@sheet1.add_name("foo",[1..2,3..4])
|
838
1027
|
@sheet1.Range("foo").Address.should == "$C$1:$D$2"
|
839
1028
|
end
|
@@ -846,10 +1035,17 @@ describe Worksheet do
|
|
846
1035
|
|
847
1036
|
it "should rename a range" do
|
848
1037
|
@sheet1.add_name("foo",[1,1])
|
849
|
-
@sheet1.
|
1038
|
+
@sheet1.rename_name("foo","bar")
|
850
1039
|
@sheet1.namevalue_global("bar").should == "foo"
|
851
1040
|
end
|
852
1041
|
|
1042
|
+
it "should rename a range with umlauts" do
|
1043
|
+
@sheet1.add_name("lösung",[1,1])
|
1044
|
+
@sheet1.rename_name("lösung","bär")
|
1045
|
+
@sheet1.namevalue_global("bär").should == "foo"
|
1046
|
+
end
|
1047
|
+
|
1048
|
+
|
853
1049
|
it "should delete a name of a range" do
|
854
1050
|
@sheet1.add_name("foo",[1,1])
|
855
1051
|
@sheet1.delete_name("foo")
|
@@ -858,6 +1054,14 @@ describe Worksheet do
|
|
858
1054
|
}.to raise_error(NameNotFound, /name "foo"/)
|
859
1055
|
end
|
860
1056
|
|
1057
|
+
it "should delete a name of a range with umlauts" do
|
1058
|
+
@sheet1.add_name("lösung",[1,1])
|
1059
|
+
@sheet1.delete_name("lösung")
|
1060
|
+
expect{
|
1061
|
+
@sheet1.namevalue_global("lösung")
|
1062
|
+
}.to raise_error(NameNotFound, /name/)
|
1063
|
+
end
|
1064
|
+
|
861
1065
|
it "should add a name of a rectangular range" do
|
862
1066
|
@sheet1.add_name("foo",[1..3,1..4])
|
863
1067
|
@sheet1["foo"].should == [["foo", "workbook", "sheet1", nil], ["foo", 1.0, 2.0, 4.0], ["matz", 3.0, 4.0, 4.0]]
|