robust_excel_ole 1.27 → 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 +36 -2
- data/README.rdoc +121 -19
- data/___dummy_workbook.xls +0 -0
- data/benchmarking/creek_example.rb +1 -1
- data/benchmarking/reo_example.rb +1 -1
- data/benchmarking/reo_example1.rb +1 -1
- data/benchmarking/reo_example2.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/bin/jreo +19 -0
- data/bin/reo +19 -0
- data/docs/README_excel.rdoc +16 -24
- data/docs/README_listobjects.rdoc +176 -0
- data/docs/README_open.rdoc +20 -16
- data/docs/README_ranges.rdoc +72 -55
- data/docs/README_save_close.rdoc +3 -3
- data/docs/README_sheet.rdoc +19 -20
- data/examples/example_ruby_library.rb +2 -2
- data/examples/introductory_examples/example_open.rb +11 -0
- 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.rb +19 -16
- data/lib/robust_excel_ole/address_tool.rb +54 -44
- data/lib/robust_excel_ole/base.rb +9 -6
- data/lib/robust_excel_ole/bookstore.rb +3 -17
- data/lib/robust_excel_ole/cell.rb +17 -22
- data/lib/robust_excel_ole/cygwin.rb +2 -0
- data/lib/robust_excel_ole/excel.rb +136 -201
- data/lib/robust_excel_ole/general.rb +249 -238
- data/lib/robust_excel_ole/list_object.rb +186 -210
- data/lib/robust_excel_ole/list_row.rb +155 -0
- data/lib/robust_excel_ole/range.rb +130 -94
- data/lib/robust_excel_ole/range_owners.rb +54 -135
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +230 -196
- data/lib/robust_excel_ole/worksheet.rb +254 -133
- data/lib/spec_helper.rb +1 -1
- data/robust_excel_ole.gemspec +4 -3
- data/spec/address_tool_spec.rb +2 -2
- data/spec/base_spec.rb +19 -17
- data/spec/bookstore_spec.rb +3 -4
- data/spec/cell_spec.rb +10 -10
- data/spec/cygwin_spec.rb +1 -1
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/excel_spec.rb +133 -86
- data/spec/general_spec.rb +79 -18
- data/spec/list_object_spec.rb +259 -81
- data/spec/list_row_spec.rb +218 -0
- data/spec/range_spec.rb +75 -41
- data/spec/spec_helper.rb +16 -2
- data/spec/workbook_spec.rb +87 -46
- data/spec/workbook_specs/workbook_all_spec.rb +9 -28
- data/spec/workbook_specs/workbook_close_spec.rb +1 -1
- data/spec/workbook_specs/workbook_misc_spec.rb +52 -45
- data/spec/workbook_specs/workbook_open_spec.rb +103 -50
- data/spec/workbook_specs/workbook_save_spec.rb +22 -23
- data/spec/workbook_specs/workbook_sheet_spec.rb +4 -4
- data/spec/workbook_specs/workbook_subclass_spec.rb +1 -1
- data/spec/workbook_specs/workbook_unobtr_spec.rb +553 -395
- data/spec/worksheet_spec.rb +544 -308
- metadata +38 -3
- data/lib/reo_console.rb +0 -42
data/spec/worksheet_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
-
|
3
|
+
require_relative 'spec_helper'
|
4
4
|
|
5
5
|
$VERBOSE = nil
|
6
6
|
|
@@ -23,7 +23,8 @@ describe Worksheet do
|
|
23
23
|
@protected_file = @dir + '/protected_sheet.xls'
|
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, v: true)
|
27
28
|
@sheet = @book.sheet(1)
|
28
29
|
end
|
29
30
|
|
@@ -118,55 +119,352 @@ describe Worksheet do
|
|
118
119
|
|
119
120
|
end
|
120
121
|
|
121
|
-
describe "access sheet name" do
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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'
|
126
131
|
end
|
127
132
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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"
|
133
224
|
end
|
134
225
|
|
135
|
-
it "should
|
136
|
-
@
|
137
|
-
@
|
138
|
-
|
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"/)
|
260
|
+
end
|
261
|
+
|
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
|
139
271
|
expect{
|
140
|
-
|
141
|
-
|
272
|
+
@sheet1["foo"] = 1
|
273
|
+
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range with name or address "foo"/)
|
142
274
|
end
|
143
275
|
end
|
144
|
-
end
|
145
276
|
|
146
|
-
describe 'access
|
277
|
+
describe 'access values of cells' do
|
147
278
|
|
148
279
|
describe "#[,]" do
|
149
280
|
|
150
|
-
context "access [1,1]" do
|
281
|
+
context "access values of [1,1]" do
|
151
282
|
|
152
|
-
it { @sheet[1, 1].should
|
153
|
-
it { @sheet[1, 1].Value.should eq 'foo' }
|
283
|
+
it { @sheet[1, 1].should eq 'foo' }
|
154
284
|
end
|
155
285
|
|
156
|
-
context "access [1, 1], [1, 2], [3, 1]" do
|
286
|
+
context "access values of [1, 1], [1, 2], [3, 1]" do
|
157
287
|
it "should get every values" do
|
158
|
-
@sheet[1, 1].
|
159
|
-
@sheet[1, 2].
|
160
|
-
@sheet[3, 1].
|
288
|
+
@sheet[1, 1].should eq 'foo'
|
289
|
+
@sheet[1, 2].should eq 'workbook'
|
290
|
+
@sheet[3, 1].should eq 'matz'
|
161
291
|
end
|
162
292
|
end
|
163
293
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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
|
170
468
|
|
171
469
|
end
|
172
470
|
|
@@ -179,18 +477,18 @@ describe Worksheet do
|
|
179
477
|
|
180
478
|
it "change a cell to 'bar'" do
|
181
479
|
@sheet[1, 1] = 'bar'
|
182
|
-
@sheet[1, 1].
|
480
|
+
@sheet[1, 1].should eq 'bar'
|
183
481
|
end
|
184
482
|
|
185
483
|
it "should change a cell to nil" do
|
186
484
|
@sheet[1, 1] = nil
|
187
|
-
@sheet[1, 1].
|
485
|
+
@sheet[1, 1].should eq nil
|
188
486
|
end
|
189
487
|
|
190
488
|
it "should raise error for bad ranges" do
|
191
489
|
expect{
|
192
490
|
@sheet[0,0]
|
193
|
-
}.to raise_error(
|
491
|
+
}.to raise_error(RangeNotCreated, /cannot find name or address 0, 0/)
|
194
492
|
expect{
|
195
493
|
@sheet[0,0] = "foo"
|
196
494
|
}.to raise_error(RangeNotEvaluatable, /cannot assign value/)
|
@@ -201,16 +499,97 @@ describe Worksheet do
|
|
201
499
|
it "should set color" do
|
202
500
|
@sheet.set_cellval(1,1,"foo",:color => 42)
|
203
501
|
@sheet.cellval(1,1).should == "foo"
|
204
|
-
@sheet[1,1].Interior.ColorIndex.should == 42
|
502
|
+
@sheet.range([1,1]).Interior.ColorIndex.should == 42
|
205
503
|
end
|
206
504
|
end
|
207
505
|
|
208
|
-
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
|
209
588
|
|
210
589
|
it "should a range with relative r1c1-reference" do
|
211
590
|
@sheet.range([1,1]).Select
|
212
|
-
@sheet.range(
|
213
|
-
@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"
|
214
593
|
end
|
215
594
|
|
216
595
|
it "should a range with relative integer-range-reference" do
|
@@ -218,20 +597,36 @@ describe Worksheet do
|
|
218
597
|
@sheet.range([1..[2],[3]..8]).Address.should == "$D$1:$H$3"
|
219
598
|
end
|
220
599
|
|
221
|
-
it "should
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
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)
|
227
624
|
end
|
228
625
|
|
229
626
|
it "should create a rectangular range" do
|
230
627
|
@sheet.range([1..3,2..4]).values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
231
628
|
@sheet.range([1..3, "B".."D"]).values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
232
|
-
@sheet.range(["B1:D3"]).values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
233
629
|
@sheet.range("B1:D3").values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
234
|
-
@sheet.range(["Z1S2:Z3S4"]).values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
235
630
|
@sheet.range("Z1S2:Z3S4").values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
236
631
|
end
|
237
632
|
|
@@ -240,24 +635,50 @@ describe Worksheet do
|
|
240
635
|
@sheet.range(1..3, "B".."D").values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
|
241
636
|
end
|
242
637
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
638
|
+
end
|
639
|
+
|
640
|
+
describe "table" do
|
641
|
+
|
642
|
+
before do
|
643
|
+
@book = Workbook.open(@listobject_file, :visible => true)
|
644
|
+
@sheet = @book.sheet(3)
|
248
645
|
end
|
249
646
|
|
250
|
-
it "should
|
647
|
+
it "should yield table given number" do
|
648
|
+
table = @sheet.table(1)
|
649
|
+
table.Name.should == "table3"
|
650
|
+
table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
|
651
|
+
table.ListRows.Count.should == 13
|
652
|
+
@sheet[3,4].should == "Number"
|
653
|
+
end
|
654
|
+
|
655
|
+
it "should yield table given name" do
|
656
|
+
table = @sheet.table("table3")
|
657
|
+
table.Name.should == "table3"
|
658
|
+
table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
|
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"]
|
668
|
+
end
|
669
|
+
|
670
|
+
it "should raise error" do
|
251
671
|
expect{
|
252
|
-
@sheet.
|
253
|
-
}.to raise_error(
|
672
|
+
@sheet.table("table4")
|
673
|
+
}.to raise_error(WorksheetREOError)
|
254
674
|
end
|
255
675
|
|
256
676
|
end
|
257
677
|
|
258
|
-
describe '#
|
678
|
+
describe '#each_cell' do
|
679
|
+
|
259
680
|
it "should sort line in order of column" do
|
260
|
-
@sheet.
|
681
|
+
@sheet.each_cell.with_index do |cell, i|
|
261
682
|
case i
|
262
683
|
when 0
|
263
684
|
cell.Value.should eq 'foo'
|
@@ -279,7 +700,7 @@ describe Worksheet do
|
|
279
700
|
include_context "sheet 'open book with blank'"
|
280
701
|
|
281
702
|
it 'should get from ["A1"]' do
|
282
|
-
@sheet_with_blank.
|
703
|
+
@sheet_with_blank.each_cell.with_index do |cell, i|
|
283
704
|
case i
|
284
705
|
when 5
|
285
706
|
cell.Value.should be_nil
|
@@ -296,6 +717,16 @@ describe Worksheet do
|
|
296
717
|
end
|
297
718
|
end
|
298
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
|
+
|
299
730
|
end
|
300
731
|
|
301
732
|
describe "#values" do
|
@@ -306,6 +737,35 @@ describe Worksheet do
|
|
306
737
|
|
307
738
|
end
|
308
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
|
+
|
309
769
|
describe "#each_rowvalue" do
|
310
770
|
|
311
771
|
it "should yield arrays" do
|
@@ -383,9 +843,9 @@ describe Worksheet do
|
|
383
843
|
|
384
844
|
end
|
385
845
|
|
386
|
-
describe "#
|
846
|
+
describe "#each_row.with_index" do
|
387
847
|
it "should read with index" do
|
388
|
-
@sheet.
|
848
|
+
@sheet.each_row.with_index do |rows, idx|
|
389
849
|
case idx
|
390
850
|
when 0
|
391
851
|
rows.values.should eq ['foo', 'workbook', 'sheet1']
|
@@ -397,22 +857,10 @@ describe Worksheet do
|
|
397
857
|
end
|
398
858
|
end
|
399
859
|
|
400
|
-
context "with argument 1" do
|
401
|
-
it "should read from second row, index is started 0" do
|
402
|
-
@sheet.each_row_with_index(1) do |rows, idx|
|
403
|
-
case idx
|
404
|
-
when 0
|
405
|
-
rows.values.should eq ['foo', nil, 'foobaaa']
|
406
|
-
when 1
|
407
|
-
rows.values.should eq ['matz', 'is', 'nice']
|
408
|
-
end
|
409
|
-
end
|
410
|
-
end
|
411
|
-
end
|
412
|
-
|
413
860
|
end
|
414
861
|
|
415
862
|
describe "#each_column" do
|
863
|
+
|
416
864
|
it "items should RobustExcelOle::Range" do
|
417
865
|
@sheet.each_column do |columns|
|
418
866
|
columns.should be_kind_of RobustExcelOle::Range
|
@@ -479,8 +927,9 @@ describe Worksheet do
|
|
479
927
|
end
|
480
928
|
|
481
929
|
describe "#each_column_with_index" do
|
930
|
+
|
482
931
|
it "should read with index" do
|
483
|
-
@sheet.
|
932
|
+
@sheet.each_column.with_index do |columns, idx|
|
484
933
|
case idx
|
485
934
|
when 0
|
486
935
|
columns.values.should eq ['foo', 'foo', 'matz']
|
@@ -491,19 +940,6 @@ describe Worksheet do
|
|
491
940
|
end
|
492
941
|
end
|
493
942
|
end
|
494
|
-
|
495
|
-
context "with argument 1" do
|
496
|
-
it "should read from second column, index is started 0" do
|
497
|
-
@sheet.each_column_with_index(1) do |column_range, idx|
|
498
|
-
case idx
|
499
|
-
when 0
|
500
|
-
column_range.values.should eq ['workbook', nil, 'is']
|
501
|
-
when 1
|
502
|
-
column_range.values.should eq ['sheet1', 'foobaaa', 'nice']
|
503
|
-
end
|
504
|
-
end
|
505
|
-
end
|
506
|
-
end
|
507
943
|
end
|
508
944
|
|
509
945
|
describe "#row_range" do
|
@@ -555,222 +991,7 @@ describe Worksheet do
|
|
555
991
|
end
|
556
992
|
end
|
557
993
|
|
558
|
-
describe "
|
559
|
-
before do
|
560
|
-
@book1 = Workbook.open(@dir + '/another_workbook.xls')
|
561
|
-
@sheet1 = @book1.sheet(1)
|
562
|
-
end
|
563
|
-
|
564
|
-
after do
|
565
|
-
@book1.close(:if_unsaved => :forget)
|
566
|
-
end
|
567
|
-
|
568
|
-
it "should return value of a defined name" do
|
569
|
-
@sheet1["firstcell"].should == "foo"
|
570
|
-
end
|
571
|
-
|
572
|
-
it "should return value of a defined name" do
|
573
|
-
@sheet1["new"].should == "foo"
|
574
|
-
@sheet1["one"].should == 1.0
|
575
|
-
@sheet1["four"].should == [[1,2],[3,4]]
|
576
|
-
@sheet1["firstrow"].should == [[1,2]]
|
577
|
-
end
|
578
|
-
|
579
|
-
it "should return value of a name with coordinates" do
|
580
|
-
@sheet1["A1"].should == "foo"
|
581
|
-
end
|
582
|
-
|
583
|
-
it "should return nil for a range with empty contents" do
|
584
|
-
@sheet1["another"].should == nil
|
585
|
-
end
|
586
|
-
|
587
|
-
#it "should evaluate named formula" do
|
588
|
-
# @sheet1["named_formula"].should == 4
|
589
|
-
#end
|
590
|
-
|
591
|
-
#it "should evaluate a formula" do
|
592
|
-
# @sheet1["another_formula"].should == 5
|
593
|
-
#end
|
594
|
-
|
595
|
-
it "should raise an error if name not defined" do
|
596
|
-
expect {
|
597
|
-
@sheet1["foo"]
|
598
|
-
}.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1/)
|
599
|
-
end
|
600
|
-
|
601
|
-
it "should set a range to a value" do
|
602
|
-
@sheet1[1,1].Value.should == "foo"
|
603
|
-
@sheet1["firstcell"] = "bar"
|
604
|
-
@sheet1[1,1].Value.should == "bar"
|
605
|
-
@sheet1["new"] = "bar"
|
606
|
-
@sheet1["new"].should == "bar"
|
607
|
-
end
|
608
|
-
|
609
|
-
it "should raise an error if name cannot be evaluated" do
|
610
|
-
expect{
|
611
|
-
@sheet1["foo"] = 1
|
612
|
-
}.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1/)
|
613
|
-
end
|
614
|
-
end
|
615
|
-
|
616
|
-
describe "namevalue_glob, set_namevalue_glob" do
|
617
|
-
|
618
|
-
before do
|
619
|
-
@book1 = Workbook.open(@dir + '/another_workbook.xls')
|
620
|
-
@sheet1 = @book1.sheet(1)
|
621
|
-
end
|
622
|
-
|
623
|
-
after do
|
624
|
-
@book1.close(:if_unsaved => :forget)
|
625
|
-
end
|
626
|
-
|
627
|
-
it "should return value of a defined name" do
|
628
|
-
@sheet1.namevalue_glob("firstcell").should == "foo"
|
629
|
-
end
|
630
|
-
|
631
|
-
#it "should evaluate a formula" do
|
632
|
-
# @sheet1.namevalue_glob("another_formula").should == 5
|
633
|
-
#end
|
634
|
-
|
635
|
-
it "should raise an error if name not defined" do
|
636
|
-
expect {
|
637
|
-
@sheet1.namevalue_glob("foo")
|
638
|
-
}.to raise_error(NameNotFound, /name "foo" not in/)
|
639
|
-
end
|
640
|
-
|
641
|
-
it "should raise an error of coordinates are given instead of a defined name" do
|
642
|
-
expect {
|
643
|
-
@sheet1.namevalue_glob("A1")
|
644
|
-
}.to raise_error(NameNotFound, /name "A1" not in/)
|
645
|
-
end
|
646
|
-
|
647
|
-
it "should return default value for a range with empty contents" do
|
648
|
-
@sheet1.namevalue_glob("another", :default => 2) == 2
|
649
|
-
end
|
650
|
-
|
651
|
-
it "should set a range to a value" do
|
652
|
-
@sheet1.namevalue_glob("firstcell").should == "foo"
|
653
|
-
@sheet1[1,1].Value.should == "foo"
|
654
|
-
@sheet1.set_namevalue_glob("firstcell","bar")
|
655
|
-
@sheet1.namevalue_glob("firstcell").should == "bar"
|
656
|
-
@sheet1[1,1].Value.should == "bar"
|
657
|
-
end
|
658
|
-
|
659
|
-
it "should raise an error if name cannot be evaluated" do
|
660
|
-
expect{
|
661
|
-
@sheet1.set_namevalue_glob("foo", 1)
|
662
|
-
}.to raise_error(RangeNotEvaluatable, /cannot assign value/)
|
663
|
-
end
|
664
|
-
|
665
|
-
it "should color the cell (deprecated)" do
|
666
|
-
@sheet1.set_namevalue_glob("new", "bar")
|
667
|
-
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
668
|
-
@sheet1.set_namevalue_glob("new", "bar", :color => 4)
|
669
|
-
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
670
|
-
end
|
671
|
-
|
672
|
-
it "should color the cell" do
|
673
|
-
@sheet1.set_namevalue_glob("new", "bar")
|
674
|
-
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
675
|
-
@sheet1.set_namevalue_glob("new", "bar", :color => 4)
|
676
|
-
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
677
|
-
end
|
678
|
-
|
679
|
-
end
|
680
|
-
|
681
|
-
describe "namevalue, set_namevalue" do
|
682
|
-
|
683
|
-
before do
|
684
|
-
@book1 = Workbook.open(@dir + '/another_workbook.xls')
|
685
|
-
@sheet1 = @book1.sheet(1)
|
686
|
-
@sheet2 = @book1.sheet(2)
|
687
|
-
end
|
688
|
-
|
689
|
-
after do
|
690
|
-
@book1.close(:if_unsaved => :forget)
|
691
|
-
end
|
692
|
-
|
693
|
-
it "should return value of a locally defined name" do
|
694
|
-
@sheet1.namevalue("firstcell").should == "foo"
|
695
|
-
end
|
696
|
-
|
697
|
-
it "should return value of a name with coordinates" do
|
698
|
-
@sheet1.namevalue("A1").should == "foo"
|
699
|
-
end
|
700
|
-
|
701
|
-
it "should return nil for a range with empty contents" do
|
702
|
-
@sheet1.namevalue("another").should == nil
|
703
|
-
end
|
704
|
-
|
705
|
-
it "should return value of a defined name" do
|
706
|
-
@sheet1.namevalue("new").should == "foo"
|
707
|
-
@sheet1.namevalue("one").should == 1.0
|
708
|
-
@sheet1.namevalue("four").should == [[1,2],[3,4]]
|
709
|
-
@sheet1.namevalue("firstrow").should == [[1,2]]
|
710
|
-
end
|
711
|
-
|
712
|
-
it "should return default value if name not defined and default value is given" do
|
713
|
-
@sheet1.namevalue("foo", :default => 2).should == 2
|
714
|
-
end
|
715
|
-
|
716
|
-
it "should raise an error if name not defined for the sheet" do
|
717
|
-
expect {
|
718
|
-
@sheet1.namevalue("foo")
|
719
|
-
}.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1/)
|
720
|
-
expect {
|
721
|
-
@sheet1.namevalue("named_formula")
|
722
|
-
}.to raise_error(NameNotFound, /name "named_formula" not in #<Worksheet: Sheet1/)
|
723
|
-
expect {
|
724
|
-
@sheet2.namevalue("firstcell")
|
725
|
-
}.to raise_error(NameNotFound, /name "firstcell" not in #<Worksheet: Sheet2/)
|
726
|
-
end
|
727
|
-
|
728
|
-
it "should set a range to a value" do
|
729
|
-
@sheet1.namevalue("firstcell").should == "foo"
|
730
|
-
@sheet1[1,1].Value.should == "foo"
|
731
|
-
@sheet1.set_namevalue("firstcell","bar")
|
732
|
-
@sheet1.namevalue("firstcell").should == "bar"
|
733
|
-
@sheet1[1,1].Value.should == "bar"
|
734
|
-
end
|
735
|
-
|
736
|
-
it "should raise an error if name cannot be evaluated" do
|
737
|
-
expect{
|
738
|
-
@sheet1.set_namevalue_glob("foo", 1)
|
739
|
-
}.to raise_error(RangeNotEvaluatable, /cannot assign value/)
|
740
|
-
end
|
741
|
-
|
742
|
-
it "should raise an error if name not defined and default value is not provided" do
|
743
|
-
expect {
|
744
|
-
@sheet1.namevalue("foo", :default => nil)
|
745
|
-
}.to_not raise_error
|
746
|
-
expect {
|
747
|
-
@sheet1.namevalue("foo", :default => :__not_provided)
|
748
|
-
}.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1/)
|
749
|
-
expect {
|
750
|
-
@sheet1.namevalue("foo")
|
751
|
-
}.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1/)
|
752
|
-
@sheet1.namevalue("foo", :default => nil).should be_nil
|
753
|
-
@sheet1.namevalue("foo", :default => 1).should == 1
|
754
|
-
@sheet1.namevalue_glob("empty", :default => 1).should be_nil
|
755
|
-
end
|
756
|
-
|
757
|
-
it "should color the cell (depracated)" do
|
758
|
-
@sheet1.set_namevalue("new", "bar")
|
759
|
-
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
760
|
-
@sheet1.set_namevalue("new", "bar", :color => 4)
|
761
|
-
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
762
|
-
end
|
763
|
-
|
764
|
-
it "should color the cell" do
|
765
|
-
@sheet1.set_namevalue("new", "bar")
|
766
|
-
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
767
|
-
@sheet1.set_namevalue("new", "bar", :color => 4)
|
768
|
-
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
769
|
-
end
|
770
|
-
|
771
|
-
end
|
772
|
-
|
773
|
-
describe "add_name, delete_name, rename_range" do
|
994
|
+
describe "add_name, delete_name, rename_name" do
|
774
995
|
|
775
996
|
context "adding, renaming, deleting the name of a range" do
|
776
997
|
|
@@ -801,7 +1022,7 @@ describe Worksheet do
|
|
801
1022
|
end
|
802
1023
|
|
803
1024
|
it "should rename an already named range with a giving address" do
|
804
|
-
@sheet1[1,1].Name.Name.should == "Sheet1!firstcell"
|
1025
|
+
@sheet1.range([1,1]).Name.Name.should == "Sheet1!firstcell"
|
805
1026
|
@sheet1.add_name("foo",[1..2,3..4])
|
806
1027
|
@sheet1.Range("foo").Address.should == "$C$1:$D$2"
|
807
1028
|
end
|
@@ -814,18 +1035,33 @@ describe Worksheet do
|
|
814
1035
|
|
815
1036
|
it "should rename a range" do
|
816
1037
|
@sheet1.add_name("foo",[1,1])
|
817
|
-
@sheet1.
|
818
|
-
@sheet1.
|
1038
|
+
@sheet1.rename_name("foo","bar")
|
1039
|
+
@sheet1.namevalue_global("bar").should == "foo"
|
1040
|
+
end
|
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"
|
819
1046
|
end
|
820
1047
|
|
1048
|
+
|
821
1049
|
it "should delete a name of a range" do
|
822
1050
|
@sheet1.add_name("foo",[1,1])
|
823
1051
|
@sheet1.delete_name("foo")
|
824
1052
|
expect{
|
825
|
-
@sheet1.
|
1053
|
+
@sheet1.namevalue_global("foo")
|
826
1054
|
}.to raise_error(NameNotFound, /name "foo"/)
|
827
1055
|
end
|
828
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
|
+
|
829
1065
|
it "should add a name of a rectangular range" do
|
830
1066
|
@sheet1.add_name("foo",[1..3,1..4])
|
831
1067
|
@sheet1["foo"].should == [["foo", "workbook", "sheet1", nil], ["foo", 1.0, 2.0, 4.0], ["matz", 3.0, 4.0, 4.0]]
|