robust_excel_ole 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +1 -0
  2. data/Changelog +15 -0
  3. data/README.rdoc +128 -63
  4. data/README_detail.rdoc +130 -60
  5. data/examples/edit_sheets/example_access_sheets_and_cells.rb +1 -1
  6. data/examples/edit_sheets/example_adding_sheets.rb +2 -2
  7. data/examples/edit_sheets/example_copying.rb +1 -1
  8. data/examples/edit_sheets/example_expanding.rb +1 -1
  9. data/examples/edit_sheets/example_ranges.rb +1 -1
  10. data/examples/edit_sheets/example_saving.rb +2 -2
  11. data/examples/open_save_close/example_control_to_excel.rb +1 -1
  12. data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +2 -2
  13. data/examples/open_save_close/example_if_obstructed_save.rb +2 -2
  14. data/examples/open_save_close/example_if_unsaved_accept.rb +1 -1
  15. data/examples/open_save_close/example_if_unsaved_forget.rb +2 -2
  16. data/examples/open_save_close/example_if_unsaved_forget_more.rb +3 -3
  17. data/examples/open_save_close/example_read_only.rb +1 -1
  18. data/examples/open_save_close/example_rename_cells.rb +1 -1
  19. data/examples/open_save_close/example_simple.rb +1 -1
  20. data/examples/open_save_close/example_unobtrusively.rb +3 -3
  21. data/lib/robust_excel_ole.rb +1 -0
  22. data/lib/robust_excel_ole/book.rb +249 -193
  23. data/lib/robust_excel_ole/bookstore.rb +1 -1
  24. data/lib/robust_excel_ole/cell.rb +1 -1
  25. data/lib/robust_excel_ole/excel.rb +125 -4
  26. data/lib/robust_excel_ole/general.rb +1 -92
  27. data/lib/robust_excel_ole/range.rb +1 -1
  28. data/lib/robust_excel_ole/reo_common.rb +37 -0
  29. data/lib/robust_excel_ole/sheet.rb +77 -24
  30. data/lib/robust_excel_ole/version.rb +1 -1
  31. data/spec/book_spec.rb +112 -82
  32. data/spec/book_specs/book_close_spec.rb +44 -1
  33. data/spec/book_specs/book_misc_spec.rb +97 -92
  34. data/spec/book_specs/book_open_spec.rb +40 -8
  35. data/spec/book_specs/book_save_spec.rb +77 -7
  36. data/spec/book_specs/book_sheet_spec.rb +290 -66
  37. data/spec/book_specs/book_unobtr_spec.rb +99 -73
  38. data/spec/bookstore_spec.rb +1 -1
  39. data/spec/cell_spec.rb +2 -2
  40. data/spec/data/another_workbook.xls +0 -0
  41. data/spec/data/workbook.xls +0 -0
  42. data/spec/excel_spec.rb +174 -23
  43. data/spec/general_spec.rb +3 -18
  44. data/spec/range_spec.rb +3 -3
  45. data/spec/reo_common_spec.rb +104 -0
  46. data/spec/sheet_spec.rb +101 -60
  47. metadata +6 -4
@@ -23,7 +23,7 @@ describe Sheet do
23
23
  @blank_file = @dir + '/book_with_blank.xls'
24
24
  @merge_file = @dir + '/merge_cells.xls'
25
25
  @book = Book.open(@simple_file)
26
- @sheet = @book[0]
26
+ @sheet = @book.sheet(1)
27
27
  end
28
28
 
29
29
  after do
@@ -38,7 +38,7 @@ describe Sheet do
38
38
  @key_sender = IO.popen 'ruby "' + File.join(File.dirname(__FILE__), '/helpers/key_sender.rb') + '" "Microsoft Office Excel" ' , "w"
39
39
  @book_protect = Book.open(@protected_file, :visible => true, :read_only => true, :force_excel => :new)
40
40
  @key_sender.puts "{p}{r}{o}{t}{e}{c}{t}{enter}"
41
- @protected_sheet = @book_protect['protect']
41
+ @protected_sheet = @book_protect.sheet('protect')
42
42
  end
43
43
 
44
44
  after do
@@ -60,7 +60,7 @@ describe Sheet do
60
60
  shared_context "sheet 'open book with blank'" do
61
61
  before do
62
62
  @book_with_blank = Book.open(@blank_file, :read_only => true)
63
- @sheet_with_blank = @book_with_blank[0]
63
+ @sheet_with_blank = @book_with_blank.sheet(1)
64
64
  end
65
65
 
66
66
  after do
@@ -289,7 +289,7 @@ describe Sheet do
289
289
  context "read sheet which last cell is merged" do
290
290
  before do
291
291
  @book_merge_cells = Book.open(@merge_file)
292
- @sheet_merge_cell = @book_merge_cells[0]
292
+ @sheet_merge_cell = @book_merge_cells.sheet(1)
293
293
  end
294
294
 
295
295
  after do
@@ -388,73 +388,114 @@ describe Sheet do
388
388
  end
389
389
  end
390
390
 
391
- describe "nvalue" do
391
+ describe "nameval, set_nameval, [], []=" do
392
392
 
393
- context "returning the value of a range" do
394
-
395
- before do
396
- @book1 = Book.open(@dir + '/another_workbook.xls')
397
- @sheet1 = @book1[0]
398
- end
399
-
400
- after do
401
- @book1.close
402
- end
393
+ before do
394
+ @book1 = Book.open(@dir + '/another_workbook.xls')
395
+ @sheet1 = @book1.sheet(1)
396
+ end
403
397
 
404
- it "should return value of a range with nvalue and brackets operator" do
405
- @sheet1.nvalue("firstcell").should == "foo"
406
- @sheet1["firstcell"].should == "foo"
407
- end
398
+ after do
399
+ @book1.close(:if_unsaved => :forget)
400
+ end
408
401
 
409
- it "should raise an error if name not defined" do
410
- expect {
411
- value = @sheet1.nvalue("foo")
412
- }.to raise_error(SheetError, /cannot evaluate name "foo" in sheet/)
413
- expect {
414
- @sheet1["foo"]
415
- }.to raise_error(SheetError, /cannot evaluate name "foo" in sheet/)
416
- end
402
+ it "should return value of a defined name" do
403
+ @sheet1.nameval("firstcell").should == "foo"
404
+ @sheet1["firstcell"].should == "foo"
405
+ end
417
406
 
418
- it "should return default value if name not defined and default value is given" do
419
- @sheet1.nvalue("foo", :default => 2).should == 2
420
- end
407
+ it "should return default value if name not defined and default value is given" do
408
+ @sheet1.nameval("foo", :default => 2).should == 2
409
+ end
421
410
 
422
- it "should evaluate a formula" do
423
- @sheet1.nvalue("named_formula").should == 4
424
- end
411
+ it "should evaluate a formula" do
412
+ @sheet1.nameval("named_formula").should == 4
413
+ @sheet1["named_formula"].should == 4
425
414
  end
426
- end
427
415
 
428
- describe "set_nvalue" do
416
+ it "should raise an error if name not defined" do
417
+ expect {
418
+ @sheet1.nameval("foo")
419
+ }.to raise_error(SheetError, /cannot find or evaluate name "foo" in Sheet1/)
420
+ expect {
421
+ @sheet1["foo"]
422
+ }.to raise_error(SheetError, /cannot find or evaluate name "foo" in Sheet1/)
423
+ end
429
424
 
430
- context "setting the value of a range" do
431
-
432
- before do
433
- @book1 = Book.open(@dir + '/another_workbook.xls', :read_only => true)
434
- @sheet1 = @book1[0]
435
- end
425
+ it "should set a range to a value" do
426
+ @sheet1.nameval("firstcell").should == "foo"
427
+ @sheet1[1,1].Value.should == "foo"
428
+ @sheet1.set_nameval("firstcell","bar")
429
+ @sheet1.nameval("firstcell").should == "bar"
430
+ @sheet1[1,1].Value.should == "bar"
431
+ @sheet1["firstcell"] = "foo"
432
+ @sheet1.nameval("firstcell").should == "foo"
433
+ @sheet1[1,1].Value.should == "foo"
434
+ end
436
435
 
437
- after do
438
- @book1.close
439
- end
436
+ it "should raise an error if name cannot be evaluated" do
437
+ expect{
438
+ @sheet1.set_nameval("foo", 1)
439
+ }.to raise_error(SheetError, /name "foo" not in Sheet1/)
440
+ expect{
441
+ @sheet1["foo"] = 1
442
+ }.to raise_error(SheetError, /name "foo" not in Sheet1/)
443
+ end
444
+ end
440
445
 
441
- it "should set a range to a value" do
442
- @sheet1.nvalue("firstcell").should == "foo"
443
- @sheet1[1,1].Value.should == "foo"
444
- @sheet1.set_nvalue("firstcell","foo")
445
- @sheet1.nvalue("firstcell").should == "foo"
446
- @sheet1[1,1].Value.should == "foo"
447
- @sheet1["firstcell"] = "bar"
448
- @sheet1.nvalue("firstcell").should == "bar"
449
- @sheet1[1,1].Value.should == "bar"
450
- end
446
+ describe "rangeval, set_rangeval" do
447
+
448
+ before do
449
+ @book1 = Book.open(@dir + '/another_workbook.xls')
450
+ @sheet1 = @book1.sheet(1)
451
+ @sheet2 = @book1.sheet(2)
452
+ end
451
453
 
452
- it "should raise an error" do
453
- expect{
454
- @sheet1.nvalue("foo")
455
- }.to raise_error(SheetError, /cannot evaluate name "foo" in sheet/)
456
- end
454
+ after do
455
+ @book1.close(:if_unsaved => :forget)
456
+ end
457
+
458
+ it "should return value of a locally defined name" do
459
+ @sheet1.rangeval("firstcell").should == "foo"
460
+ end
461
+
462
+ it "should return value of a defined name" do
463
+ @sheet1.rangeval("new").should == "foo"
464
+ @sheet1.rangeval("one").should == 1.0
465
+ @sheet1.rangeval("four").should == [[1,2],[3,4]]
466
+ @sheet1.rangeval("firstrow").should == [[1,2]]
467
+ end
468
+
469
+ it "should return default value if name not defined and default value is given" do
470
+ @sheet1.rangeval("foo", :default => 2).should == 2
471
+ end
472
+
473
+ it "should raise an error if name not defined for the sheet" do
474
+ expect {
475
+ @sheet1.rangeval("foo")
476
+ }.to raise_error(SheetError, /name "foo" not in Sheet1/)
477
+ expect {
478
+ @sheet1.rangeval("named_formula")
479
+ }.to raise_error(SheetError, /name "named_formula" not in Sheet1/)
480
+ expect {
481
+ @sheet2.rangeval("firstcell")
482
+ }.to raise_error(SheetError, /name "firstcell" not in Sheet2/)
483
+ end
484
+
485
+ it "should set a range to a value" do
486
+ @sheet1.rangeval("firstcell").should == "foo"
487
+ @sheet1[1,1].Value.should == "foo"
488
+ @sheet1.set_rangeval("firstcell","bar")
489
+ @sheet1.rangeval("firstcell").should == "bar"
490
+ @sheet1[1,1].Value.should == "bar"
491
+ end
492
+
493
+ it "should raise an error if name cannot be evaluated" do
494
+ expect{
495
+ @sheet1.set_nameval("foo", 1)
496
+ }.to raise_error(SheetError, /name "foo" not in Sheet1/)
457
497
  end
498
+
458
499
  end
459
500
 
460
501
  describe "set_name" do
@@ -463,7 +504,7 @@ describe Sheet do
463
504
 
464
505
  before do
465
506
  @book1 = Book.open(@dir + '/another_workbook.xls', :read_only => true, :visible => true)
466
- @sheet1 = @book1[0]
507
+ @sheet1 = @book1.sheet(1)
467
508
  end
468
509
 
469
510
  after do
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robust_excel_ole
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
9
- version: "0.4"
8
+ - 5
9
+ version: "0.5"
10
10
  platform: ruby
11
11
  authors:
12
12
  - traths
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2016-03-16 00:00:00 +01:00
17
+ date: 2016-06-07 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -85,6 +85,7 @@ files:
85
85
  - lib/robust_excel_ole/excel.rb
86
86
  - lib/robust_excel_ole/general.rb
87
87
  - lib/robust_excel_ole/range.rb
88
+ - lib/robust_excel_ole/reo_common.rb
88
89
  - lib/robust_excel_ole/robustexcelole.sublime-project
89
90
  - lib/robust_excel_ole/robustexcelole.sublime-workspace
90
91
  - lib/robust_excel_ole/sheet.rb
@@ -121,6 +122,7 @@ files:
121
122
  - spec/helpers/create_temporary_dir.rb
122
123
  - spec/helpers/key_sender.rb
123
124
  - spec/range_spec.rb
125
+ - spec/reo_common_spec.rb
124
126
  - spec/sheet_spec.rb
125
127
  - spec/spec_helper.rb
126
128
  - version.rb