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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog +36 -2
  3. data/README.rdoc +121 -19
  4. data/___dummy_workbook.xls +0 -0
  5. data/benchmarking/creek_example.rb +1 -1
  6. data/benchmarking/reo_example.rb +1 -1
  7. data/benchmarking/reo_example1.rb +1 -1
  8. data/benchmarking/reo_example2.rb +1 -1
  9. data/benchmarking/roo_example.rb +1 -1
  10. data/benchmarking/simple_xlsx_reader_example.rb +1 -1
  11. data/benchmarking/spreadsheet_example.rb +1 -1
  12. data/bin/jreo +19 -0
  13. data/bin/reo +19 -0
  14. data/docs/README_excel.rdoc +16 -24
  15. data/docs/README_listobjects.rdoc +176 -0
  16. data/docs/README_open.rdoc +20 -16
  17. data/docs/README_ranges.rdoc +72 -55
  18. data/docs/README_save_close.rdoc +3 -3
  19. data/docs/README_sheet.rdoc +19 -20
  20. data/examples/example_ruby_library.rb +2 -2
  21. data/examples/introductory_examples/example_open.rb +11 -0
  22. data/examples/introductory_examples/example_range.rb +2 -2
  23. data/examples/modifying_sheets/example_access_sheets_and_cells.rb +6 -6
  24. data/examples/modifying_sheets/example_add_names.rb +1 -1
  25. data/examples/modifying_sheets/example_concating.rb +1 -1
  26. data/examples/modifying_sheets/example_copying.rb +2 -2
  27. data/examples/modifying_sheets/example_listobjects.rb +86 -0
  28. data/examples/modifying_sheets/example_naming.rb +1 -1
  29. data/examples/modifying_sheets/example_ranges.rb +1 -1
  30. data/examples/open_save_close/example_control_to_excel.rb +1 -1
  31. data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +1 -1
  32. data/examples/open_save_close/example_if_obstructed_save.rb +3 -3
  33. data/examples/open_save_close/example_if_unsaved_accept.rb +1 -1
  34. data/examples/open_save_close/example_if_unsaved_forget.rb +3 -3
  35. data/examples/open_save_close/example_if_unsaved_forget_more.rb +4 -4
  36. data/examples/open_save_close/example_read_only.rb +1 -1
  37. data/examples/open_save_close/example_simple.rb +1 -1
  38. data/examples/open_save_close/example_unobtrusively.rb +3 -3
  39. data/lib/robust_excel_ole.rb +19 -16
  40. data/lib/robust_excel_ole/address_tool.rb +54 -44
  41. data/lib/robust_excel_ole/base.rb +9 -6
  42. data/lib/robust_excel_ole/bookstore.rb +3 -17
  43. data/lib/robust_excel_ole/cell.rb +17 -22
  44. data/lib/robust_excel_ole/cygwin.rb +2 -0
  45. data/lib/robust_excel_ole/excel.rb +136 -201
  46. data/lib/robust_excel_ole/general.rb +249 -238
  47. data/lib/robust_excel_ole/list_object.rb +186 -210
  48. data/lib/robust_excel_ole/list_row.rb +155 -0
  49. data/lib/robust_excel_ole/range.rb +130 -94
  50. data/lib/robust_excel_ole/range_owners.rb +54 -135
  51. data/lib/robust_excel_ole/version.rb +1 -1
  52. data/lib/robust_excel_ole/workbook.rb +230 -196
  53. data/lib/robust_excel_ole/worksheet.rb +254 -133
  54. data/lib/spec_helper.rb +1 -1
  55. data/robust_excel_ole.gemspec +4 -3
  56. data/spec/address_tool_spec.rb +2 -2
  57. data/spec/base_spec.rb +19 -17
  58. data/spec/bookstore_spec.rb +3 -4
  59. data/spec/cell_spec.rb +10 -10
  60. data/spec/cygwin_spec.rb +1 -1
  61. data/spec/data/more_data/workbook.xls +0 -0
  62. data/spec/excel_spec.rb +133 -86
  63. data/spec/general_spec.rb +79 -18
  64. data/spec/list_object_spec.rb +259 -81
  65. data/spec/list_row_spec.rb +218 -0
  66. data/spec/range_spec.rb +75 -41
  67. data/spec/spec_helper.rb +16 -2
  68. data/spec/workbook_spec.rb +87 -46
  69. data/spec/workbook_specs/workbook_all_spec.rb +9 -28
  70. data/spec/workbook_specs/workbook_close_spec.rb +1 -1
  71. data/spec/workbook_specs/workbook_misc_spec.rb +52 -45
  72. data/spec/workbook_specs/workbook_open_spec.rb +103 -50
  73. data/spec/workbook_specs/workbook_save_spec.rb +22 -23
  74. data/spec/workbook_specs/workbook_sheet_spec.rb +4 -4
  75. data/spec/workbook_specs/workbook_subclass_spec.rb +1 -1
  76. data/spec/workbook_specs/workbook_unobtr_spec.rb +553 -395
  77. data/spec/worksheet_spec.rb +544 -308
  78. metadata +38 -3
  79. data/lib/reo_console.rb +0 -42
data/lib/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  require 'rspec'
3
3
  require 'tmpdir'
4
4
  require 'fileutils'
5
- require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
5
+ require_relative '../lib/robust_excel_ole'
6
6
 
7
7
  # @private
8
8
  module RobustExcelOle::SpecHelpers
@@ -33,8 +33,9 @@ Gem::Specification.new do |s|
33
33
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
34
34
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
35
35
  s.require_paths = ["lib"]
36
- s.add_runtime_dependency "pry", '>= 0.12.1'
37
- s.add_runtime_dependency "pry-bond", '>=0.0.1'
38
- s.add_development_dependency "rspec", '>= 2.6.0'
36
+ s.add_runtime_dependency 'win32api', '~> 0.1'
37
+ s.add_runtime_dependency 'pry', '~> 0.12', '>= 0.12.1'
38
+ s.add_runtime_dependency 'pry-bond', '~> 0.0', '>= 0.0.1'
39
+ s.add_development_dependency 'rspec', '~> 2.6', '>= 2.6.0'
39
40
  s.required_ruby_version = '>= 2.1'
40
41
  end
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require File.join(File.dirname(__FILE__), './spec_helper')
4
- require File.expand_path( '../../lib/robust_excel_ole/base', __FILE__)
3
+ require_relative 'spec_helper'
4
+ require_relative '../lib/robust_excel_ole/base'
5
5
 
6
6
  $VERBOSE = nil
7
7
 
data/spec/base_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require File.join(File.dirname(__FILE__), './spec_helper')
4
- require File.expand_path( '../../lib/robust_excel_ole/base', __FILE__)
3
+ require_relative 'spec_helper'
4
+ require_relative '../lib/robust_excel_ole/base'
5
5
 
6
6
  $VERBOSE = nil
7
7
 
@@ -36,19 +36,6 @@ module RobustExcelOle
36
36
  rm_tmp(@dir)
37
37
  end
38
38
 
39
- describe "trace" do
40
-
41
- it "should put some number" do
42
- a = 4
43
- Base::trace "some text #{a}"
44
- end
45
-
46
- it "should put another text" do
47
- b = Workbook.open(@simple_file)
48
- Base::trace "book: #{b}"
49
- end
50
- end
51
-
52
39
  describe "own_methods" do
53
40
 
54
41
  before do
@@ -57,8 +44,8 @@ module RobustExcelOle
57
44
  ["Activate", "ActiveSheet", "Application", "Close", "FullName", "HasPassword", "Name", "Names",
58
45
  "Password", "Protect", "ProtectSharing", "ProtectStructure", "Protect", "ReadOnly", "Save",
59
46
  "SaveAs", "Saved", "Sheets", "Unprotect"]
60
- @book_methods = ["focus", "add_sheet", "alive?", "close", "filename", "namevalue", "ole_object",
61
- "ole_workbook", "reopen", "save", "save_as", "saved", "set_namevalue"]
47
+ @book_methods = ["focus", "add_sheet", "alive?", "close", "filename", "ole_object",
48
+ "ole_workbook", "reopen", "save", "save_as", "saved"]
62
49
  @ole_excel_methods =
63
50
  ["ActiveCell", "ActiveSheet", "ActiveWorkbook", "Application", "Calculate", "Cells", "Columns",
64
51
  "DisplayAlerts", "Evaluate", "Hwnd", "Name", "Names", "Quit", "Range", "Ready", "Save",
@@ -82,6 +69,21 @@ module RobustExcelOle
82
69
 
83
70
  end
84
71
 
72
+ describe "trace" do
73
+
74
+ it "should put some number" do
75
+ a = 4
76
+ Base::trace "some text #{a}"
77
+ end
78
+
79
+ it "should put another text" do
80
+ b = Workbook.open(@simple_file)
81
+ Base::trace "book: #{b}"
82
+ end
83
+ end
84
+
85
+
86
+
85
87
  describe "misc" do
86
88
 
87
89
  it "should" do
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require File.join(File.dirname(__FILE__), './spec_helper')
3
+ require_relative 'spec_helper'
4
4
 
5
5
  =begin
6
6
  RSpec.configure do |config|
@@ -419,7 +419,7 @@ describe Bookstore do
419
419
  @bookstore.store(@book2)
420
420
  @bookstore.store(@book3)
421
421
  sheet = @book3.sheet(1)
422
- sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
422
+ sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
423
423
  @book.ReadOnly.should be true
424
424
  @book2.ReadOnly.should be false
425
425
  @book3.ReadOnly.should be true
@@ -560,8 +560,7 @@ describe Bookstore do
560
560
  end
561
561
 
562
562
  it "should show books" do
563
- expect{
564
- @bookstore.books}.to_not raise_error
563
+ @bookstore.books.should == [@book, @book2]
565
564
  end
566
565
 
567
566
  end
data/spec/cell_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), './spec_helper')
2
+ require_relative 'spec_helper'
3
3
 
4
4
  include RobustExcelOle
5
5
  include General
@@ -19,7 +19,7 @@ describe Cell do
19
19
  @merge_cells_file = @dir + '/merge_cells.xls'
20
20
  @book = Workbook.open(@simple_file)
21
21
  @sheet = @book.sheet(1)
22
- @cell = @sheet[1, 1]
22
+ @cell = @sheet.range([1, 1])
23
23
  end
24
24
 
25
25
  after do
@@ -55,7 +55,7 @@ describe Cell do
55
55
  before do
56
56
  @book1 = Workbook.open(@dir + '/workbook.xls')
57
57
  @sheet1 = @book1.sheet(1)
58
- @cell1 = @sheet1[1,1]
58
+ @cell1 = @sheet1.range([1,1])
59
59
  end
60
60
 
61
61
  after do
@@ -76,22 +76,22 @@ describe Cell do
76
76
  end
77
77
 
78
78
  it "merged cell get same value" do
79
- @sheet[1, 1].Value.should be_nil
80
- @sheet[2, 1].Value.should eq 'first merged'
79
+ @sheet[1, 1].should be_nil
80
+ @sheet[2, 1].should eq 'first merged'
81
81
  end
82
82
 
83
83
  it "set merged cell" do
84
- @sheet[2, 1].Value = "set merge cell"
85
- @sheet[2, 1].Value.should eq "set merge cell"
86
- @sheet[2, 2].Value.should eq "set merge cell"
84
+ @sheet[2, 1] = "set merge cell"
85
+ @sheet[2, 1].should eq "set merge cell"
86
+ @sheet[2, 2].should eq "set merge cell"
87
87
  end
88
88
  end
89
89
 
90
90
  describe "==" do
91
91
 
92
92
  it "should check equality of cells" do
93
- @cell.should == @sheet[1,1]
94
- @cell.should_not == @sheet[1,2]
93
+ @cell.should == @sheet.range([1,1])
94
+ @cell.should_not == @sheet.range([1,2])
95
95
  end
96
96
 
97
97
  end
data/spec/cygwin_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), './spec_helper')
2
+ require_relative 'spec_helper'
3
3
 
4
4
  describe "on cygwin", :if => RUBY_PLATFORM =~ /cygwin/ do
5
5
  describe ".cygpath" do
Binary file
data/spec/excel_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require File.join(File.dirname(__FILE__), './spec_helper')
3
+ require_relative 'spec_helper'
4
4
 
5
5
  $VERBOSE = nil
6
6
 
@@ -154,7 +154,7 @@ module RobustExcelOle
154
154
  excel1.should_not be_alive
155
155
  excel2.should be_alive
156
156
  excel2.ole_excel.Hwnd.should == @ole_excel1.Hwnd
157
- Excel.excels_number.should == 2
157
+ Excel.instance_count.should == 2
158
158
  end
159
159
 
160
160
  it "should make the Excel instance not alive if the Excel that was connected with was closed" do
@@ -219,7 +219,7 @@ module RobustExcelOle
219
219
  excel1.should be_alive
220
220
  excel1.ole_excel.Hwnd.should_not == @ole_excel1.Hwnd
221
221
  excel1.ole_excel.Hwnd.should_not == @ole_excel2.Hwnd
222
- Excel.excels_number.should == 3
222
+ Excel.instance_count.should == 3
223
223
  end
224
224
 
225
225
  end
@@ -378,7 +378,7 @@ module RobustExcelOle
378
378
  excel2 = Excel.current
379
379
  excel1.should_not be_alive
380
380
  excel2.should be_alive
381
- Excel.excels_number.should == 1
381
+ Excel.instance_count.should == 1
382
382
  end
383
383
 
384
384
  it "should make the Excel instance not alive if the Excel that was connected with was closed" do
@@ -389,7 +389,7 @@ module RobustExcelOle
389
389
  excel1.should_not be_alive
390
390
  excel2.should_not be_alive
391
391
  sleep 0.2
392
- Excel.excels_number.should == 0
392
+ Excel.instance_count.should == 0
393
393
  end
394
394
 
395
395
  it "should reuse the first opened Excel instance if not the first opened Excel instance was closed" do
@@ -417,11 +417,11 @@ module RobustExcelOle
417
417
  it "should return right number of excel instances" do
418
418
  Excel.kill_all
419
419
  sleep 0.2
420
- n1 = Excel.excels_number
420
+ n1 = Excel.instance_count
421
421
  e1 = Excel.create
422
- Excel.excels_number.should == n1 + 1
422
+ Excel.instance_count.should == n1 + 1
423
423
  e2 = Excel.create
424
- Excel.excels_number.should == n1 + 2
424
+ Excel.instance_count.should == n1 + 2
425
425
  end
426
426
  end
427
427
 
@@ -611,8 +611,8 @@ module RobustExcelOle
611
611
  book1 = Workbook.open(@simple_file1, :visible => true)
612
612
  @excel1 = book1.excel
613
613
  sheet1 = book1.sheet(1)
614
- @old_cell_value1 = sheet1[1,1].Value
615
- sheet1[1,1] = sheet1[1,1].Value == "foo" ? "bar" : "foo"
614
+ @old_cell_value1 = sheet1[1,1]
615
+ sheet1[1,1] = sheet1[1,1] == "foo" ? "bar" : "foo"
616
616
  book1.Saved.should be false
617
617
  end
618
618
 
@@ -622,7 +622,7 @@ module RobustExcelOle
622
622
  @excel1.should_not be_alive
623
623
  new_book1 = Workbook.open(@simple_file1)
624
624
  new_sheet1 = new_book1.sheet(1)
625
- new_sheet1[1,1].Value.should_not == @old_cell_value1
625
+ new_sheet1[1,1].should_not == @old_cell_value1
626
626
  new_book1.close
627
627
  result.should == [1,0]
628
628
  end
@@ -633,7 +633,7 @@ module RobustExcelOle
633
633
  @excel1.should_not be_alive
634
634
  new_book1 = Workbook.open(@simple_file1)
635
635
  new_sheet1 = new_book1.sheet(1)
636
- new_sheet1[1,1].Value.should == @old_cell_value1
636
+ new_sheet1[1,1].should == @old_cell_value1
637
637
  new_book1.close
638
638
  result.should == [1,0]
639
639
  end
@@ -647,8 +647,8 @@ module RobustExcelOle
647
647
  @excel1 = book1.excel
648
648
  @excel2 = book2.excel
649
649
  sheet2 = book2.sheet(1)
650
- @old_cell_value2 = sheet2[1,1].Value
651
- sheet2[1,1] = sheet2[1,1].Value == "foo" ? "bar" : "foo"
650
+ @old_cell_value2 = sheet2[1,1]
651
+ sheet2[1,1] = sheet2[1,1] == "foo" ? "bar" : "foo"
652
652
  end
653
653
 
654
654
  it "should close the first Excel without unsaved workbooks and then raise an error" do
@@ -684,7 +684,7 @@ module RobustExcelOle
684
684
  @excel2.should_not be_alive
685
685
  new_book2 = Workbook.open(@different_file1)
686
686
  new_sheet2 = new_book2.sheet(1)
687
- new_sheet2[1,1].Value.should_not == @old_cell_value2
687
+ new_sheet2[1,1].should_not == @old_cell_value2
688
688
  new_book2.close
689
689
  result.should == [2,0]
690
690
  end
@@ -696,7 +696,7 @@ module RobustExcelOle
696
696
  @excel2.should_not be_alive
697
697
  new_book2 = Workbook.open(@different_file1)
698
698
  new_sheet2 = new_book2.sheet(1)
699
- new_sheet2[1,1].Value.should == @old_cell_value2
699
+ new_sheet2[1,1].should == @old_cell_value2
700
700
  new_book2.close
701
701
  result.should == [2,0]
702
702
  end
@@ -714,7 +714,7 @@ module RobustExcelOle
714
714
  @book1 = Workbook.open(@simple_file1, :force_excel => :new)
715
715
  @book2 = Workbook.open(@another_simple_file, :force_excel => :new)
716
716
  @book3 = Workbook.open(@different_file, :force_excel => :new)
717
- old_cell_value1 = @book2.sheet(1)[1,1].Value
717
+ old_cell_value1 = @book2.sheet(1)[1,1]
718
718
  @book2.sheet(1)[1,1] = old_cell_value1 == "foo" ? "bar" : "foo"
719
719
  end
720
720
 
@@ -739,7 +739,7 @@ module RobustExcelOle
739
739
  @book1 = Workbook.open(@simple_file1, :force_excel => :new)
740
740
  @book2 = Workbook.open(@another_simple_file, :force_excel => :new)
741
741
  @book3 = Workbook.open(@different_file, :force_excel => :new)
742
- old_cell_value1 = @book2.sheet(1)[1,1].Value
742
+ old_cell_value1 = @book2.sheet(1)[1,1]
743
743
  @book2.sheet(1)[1,1] = old_cell_value1 == "foo" ? "bar" : "foo"
744
744
  end
745
745
 
@@ -808,12 +808,12 @@ module RobustExcelOle
808
808
  @excel = Excel.create
809
809
  @book = Workbook.open(@simple_file)
810
810
  sheet = @book.sheet(1)
811
- @old_cell_value = sheet[1,1].Value
812
- sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
811
+ @old_cell_value = sheet[1,1]
812
+ sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
813
813
  @book2 = Workbook.open(@another_simple_file)
814
814
  sheet2 = @book2.sheet(1)
815
- @old_cell_value2 = sheet2[1,1].Value
816
- sheet2[1,1] = sheet2[1,1].Value == "foo" ? "bar" : "foo"
815
+ @old_cell_value2 = sheet2[1,1]
816
+ sheet2[1,1] = sheet2[1,1] == "foo" ? "bar" : "foo"
817
817
  @excel.should be_alive
818
818
  @book.should be_alive
819
819
  @book.saved.should be false
@@ -840,7 +840,7 @@ module RobustExcelOle
840
840
  result.should == 1
841
841
  new_book = Workbook.open(@simple_file)
842
842
  new_sheet = new_book.sheet(1)
843
- new_sheet[1,1].Value.should == @old_cell_value
843
+ new_sheet[1,1].should == @old_cell_value
844
844
  new_book.close
845
845
  end
846
846
 
@@ -854,7 +854,7 @@ module RobustExcelOle
854
854
  @excel.should_not be_alive
855
855
  new_book = Workbook.open(@simple_file)
856
856
  new_sheet = new_book.sheet(1)
857
- new_sheet[1,1].Value.should == @old_cell_value
857
+ new_sheet[1,1].should == @old_cell_value
858
858
  new_book.close
859
859
  end
860
860
 
@@ -866,7 +866,7 @@ module RobustExcelOle
866
866
  @excel.should_not be_alive
867
867
  new_book = Workbook.open(@simple_file)
868
868
  new_sheet = new_book.sheet(1)
869
- new_sheet[1,1].Value.should_not == @old_cell_value
869
+ new_sheet[1,1].should_not == @old_cell_value
870
870
  new_book.close
871
871
  end
872
872
 
@@ -884,8 +884,8 @@ module RobustExcelOle
884
884
  @excel = Excel.create(:visible => true)
885
885
  @book = Workbook.open(@simple_file, :visible => true)
886
886
  sheet = @book.sheet(1)
887
- @old_cell_value = sheet[1,1].Value
888
- sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
887
+ @old_cell_value = sheet[1,1]
888
+ sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
889
889
  end
890
890
 
891
891
  after do
@@ -903,7 +903,7 @@ module RobustExcelOle
903
903
  result.should == 1
904
904
  new_book = Workbook.open(@simple_file)
905
905
  new_sheet = new_book.sheet(1)
906
- new_sheet[1,1].Value.should_not == @old_cell_value
906
+ new_sheet[1,1].should_not == @old_cell_value
907
907
  new_book.close
908
908
  end
909
909
 
@@ -918,7 +918,7 @@ module RobustExcelOle
918
918
  @book.should_not be_alive
919
919
  new_book = Workbook.open(@simple_file)
920
920
  new_sheet = new_book.sheet(1)
921
- new_sheet[1,1].Value.should == @old_cell_value
921
+ new_sheet[1,1].should == @old_cell_value
922
922
  new_book.close
923
923
  end
924
924
 
@@ -944,11 +944,11 @@ module RobustExcelOle
944
944
  before do
945
945
  @book = Workbook.open(@simple_file)
946
946
  sheet = @book.sheet(1)
947
- @old_cell_value = sheet[1,1].Value
948
- sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
947
+ @old_cell_value = sheet[1,1]
948
+ sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
949
949
  @book3 = Workbook.open(@different_file, :read_only => true)
950
950
  sheet3 = @book3.sheet(1)
951
- sheet3[1,1] = sheet3[1,1].Value == "foo" ? "bar" : "foo"
951
+ sheet3[1,1] = sheet3[1,1] == "foo" ? "bar" : "foo"
952
952
  @excel = @book.excel
953
953
  @book2 = Workbook.open(@another_simple_file, :force_excel => :new)
954
954
  end
@@ -978,7 +978,7 @@ module RobustExcelOle
978
978
  @excel.Workbooks.Count.should == 0
979
979
  new_book = Workbook.open(@simple_file)
980
980
  new_sheet = new_book.sheet(1)
981
- new_sheet[1,1].Value.should == @old_cell_value
981
+ new_sheet[1,1].should == @old_cell_value
982
982
  new_book.close
983
983
  end
984
984
 
@@ -989,7 +989,7 @@ module RobustExcelOle
989
989
  @excel.Workbooks.Count.should == 0
990
990
  new_book = Workbook.open(@simple_file)
991
991
  new_sheet = new_book.sheet(1)
992
- new_sheet[1,1].Value.should_not == @old_cell_value
992
+ new_sheet[1,1].should_not == @old_cell_value
993
993
  new_book.close
994
994
  end
995
995
 
@@ -1038,10 +1038,10 @@ module RobustExcelOle
1038
1038
  before do
1039
1039
  @book = Workbook.open(@simple_file)
1040
1040
  sheet = @book.sheet(1)
1041
- sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
1041
+ sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
1042
1042
  @book3 = Workbook.open(@different_file, :read_only => true)
1043
1043
  sheet3 = @book3.sheet(1)
1044
- sheet3[1,1] = sheet3[1,1].Value == "foo" ? "bar" : "foo"
1044
+ sheet3[1,1] = sheet3[1,1] == "foo" ? "bar" : "foo"
1045
1045
  @book.Saved.should be false
1046
1046
  @book3.Saved.should be false
1047
1047
  end
@@ -1060,20 +1060,39 @@ module RobustExcelOle
1060
1060
  end
1061
1061
  end
1062
1062
 
1063
- describe "workbooks, each, each_with_index" do
1063
+ describe "each, each_with_index, workbooks" do
1064
1064
 
1065
- before do
1065
+ before do
1066
1066
  @excel = Excel.create
1067
- @book1 = Workbook.open(@simple_file)
1068
- @book2 = Workbook.open(@different_file)
1067
+ end
1068
+
1069
+ it "should yield empty list" do
1070
+ @excel.count.should == 0
1071
+ @excel.workbooks.should be_empty
1069
1072
  end
1070
1073
 
1071
1074
  it "should list workbooks" do
1075
+ @book1 = Workbook.open(@simple_file)
1076
+ @book2 = Workbook.open(@different_file)
1072
1077
  workbooks = @excel.workbooks
1073
1078
  workbooks.should == [@book1,@book2]
1074
1079
  end
1075
1080
 
1081
+ it "should concatenate" do
1082
+ @book1 = Workbook.open(@simple_file)
1083
+ @book2 = Workbook.open(@different_file)
1084
+ i = 0
1085
+ @excel.each.with_index do |workbook,i|
1086
+ workbook.should be_alive
1087
+ workbook.should be_a Workbook
1088
+ workbook.filename.should == @simple_file if i == 0
1089
+ workbook.filename.should == @different_file if i == 1
1090
+ end
1091
+ end
1092
+
1076
1093
  it "should each_workbook" do
1094
+ @book1 = Workbook.open(@simple_file)
1095
+ @book2 = Workbook.open(@different_file)
1077
1096
  i = 0
1078
1097
  @excel.each_workbook do |workbook|
1079
1098
  workbook.should be_alive
@@ -1085,6 +1104,9 @@ module RobustExcelOle
1085
1104
  end
1086
1105
 
1087
1106
  it "should each_workbook_with_index" do
1107
+ @book1 = Workbook.open(@simple_file)
1108
+ @book2 = Workbook.open(@different_file)
1109
+ i = 0
1088
1110
  @excel.each_workbook_with_index do |workbook,i|
1089
1111
  workbook.should be_alive
1090
1112
  workbook.should be_a Workbook
@@ -1094,6 +1116,8 @@ module RobustExcelOle
1094
1116
  end
1095
1117
 
1096
1118
  it "should each_workbook with options" do
1119
+ @book1 = Workbook.open(@simple_file)
1120
+ @book2 = Workbook.open(@different_file)
1097
1121
  i = 0
1098
1122
  @excel.each_workbook(:visible => true) do |workbook|
1099
1123
  workbook.should be_alive
@@ -1106,6 +1130,8 @@ module RobustExcelOle
1106
1130
  end
1107
1131
 
1108
1132
  it "should set options" do
1133
+ @book1 = Workbook.open(@simple_file)
1134
+ @book2 = Workbook.open(@different_file)
1109
1135
  @excel.each_workbook(:visible => true)
1110
1136
  [1,2].each do |i|
1111
1137
  ole_workbook = @excel.Workbooks.Item(i)
@@ -1113,7 +1139,6 @@ module RobustExcelOle
1113
1139
  end
1114
1140
  end
1115
1141
 
1116
-
1117
1142
  end
1118
1143
 
1119
1144
  describe "unsaved_known_workbooks" do
@@ -1124,32 +1149,24 @@ module RobustExcelOle
1124
1149
 
1125
1150
  it "should return empty list for first Excel instance" do
1126
1151
  book = Workbook.open(@simple_file)
1127
- Excel.unsaved_known_workbooks.should == [[]]
1152
+ Excel.unsaved_known_workbooks.should be_empty
1128
1153
  book.close
1129
1154
  end
1130
1155
 
1131
1156
  it "should return one unsaved book" do
1132
1157
  book = Workbook.open(@simple_file)
1133
1158
  sheet = book.sheet(1)
1134
- sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
1135
- # Excel.unsaved_known_workbooks.should == [[book.ole_workbook]]
1159
+ sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
1136
1160
  unsaved_known_wbs = Excel.unsaved_known_workbooks
1137
1161
  unsaved_known_wbs.size.should == 1
1138
- unsaved_known_wbs.each do |ole_wb_list|
1139
- ole_wb_list.size.should == 1
1140
- ole_wb_list.each do |ole_workbook|
1141
- ole_workbook.Fullname.tr('\\','/').should == @simple_file
1142
- end
1162
+ unsaved_known_wbs.each do |ole_wb|
1163
+ ole_wb.Fullname.tr('\\','/').should == @simple_file
1143
1164
  end
1144
1165
  book2 = Workbook.open(@another_simple_file)
1145
- # Excel.unsaved_known_workbooks.should == [[book.ole_workbook]]
1146
1166
  unsaved_known_wbs = Excel.unsaved_known_workbooks
1147
1167
  unsaved_known_wbs.size.should == 1
1148
- unsaved_known_wbs.each do |ole_wb_list|
1149
- ole_wb_list.size.should == 1
1150
- ole_wb_list.each do |ole_workbook|
1151
- ole_workbook.Fullname.tr('\\','/').should == @simple_file
1152
- end
1168
+ unsaved_known_wbs.each do |ole_wb|
1169
+ ole_wb.Fullname.tr('\\','/').should == @simple_file
1153
1170
  end
1154
1171
  book2.close
1155
1172
  book.close(:if_unsaved => :forget)
@@ -1158,18 +1175,15 @@ module RobustExcelOle
1158
1175
  it "should return two unsaved books" do
1159
1176
  book = Workbook.open(@simple_file)
1160
1177
  sheet = book.sheet(1)
1161
- sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
1178
+ sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
1162
1179
  book2 = Workbook.open(@another_simple_file)
1163
1180
  sheet2 = book2.sheet(1)
1164
- sheet2[1,1] = sheet2[1,1].Value == "foo" ? "bar" : "foo"
1165
- #Excel.unsaved_known_workbooks.should == [[book.ole_workbook, book2.ole_workbook]]
1181
+ sheet2[1,1] = sheet2[1,1] == "foo" ? "bar" : "foo"
1166
1182
  unsaved_known_wbs = Excel.unsaved_known_workbooks
1167
- unsaved_known_wbs.size.should == 1
1168
- unsaved_known_wbs.each do |ole_wb_list|
1169
- ole_wb_list.size.should == 2
1170
- ole_workbook1, ole_workbook2 = ole_wb_list
1171
- ole_workbook1.Fullname.tr('\\','/').should == @simple_file
1172
- ole_workbook2.Fullname.tr('\\','/').should == @another_simple_file
1183
+ unsaved_known_wbs.size.should == 2
1184
+ unsaved_known_wbs.each_with_index do |ole_wb, ind|
1185
+ ole_wb.Fullname.tr('\\','/').should == @simple_file if ind == 0
1186
+ ole_wb.Fullname.tr('\\','/').should == @another_simple_file if ind == 1
1173
1187
  end
1174
1188
  book2.close(:if_unsaved => :forget)
1175
1189
  book.close(:if_unsaved => :forget)
@@ -1182,9 +1196,8 @@ module RobustExcelOle
1182
1196
  begin
1183
1197
  open_books.each do |wb|
1184
1198
  sheet = wb.sheet(1)
1185
- sheet[1,1] = (sheet[1,1].Value == "foo") ? "bar" : "foo"
1199
+ sheet[1,1] = (sheet[1,1] == "foo") ? "bar" : "foo"
1186
1200
  end
1187
- #Excel.unsaved_known_workbooks.should == [[book.ole_workbook], [book2.ole_workbook]]
1188
1201
  unsaved_known_wbs = Excel.unsaved_known_workbooks
1189
1202
  unsaved_known_wbs.size.should == 2
1190
1203
  unsaved_known_wbs.flatten.map{|ole_wb| ole_wb.Fullname.tr('\\','/') }.sort.should == open_books.map{|b| b.filename}.sort
@@ -1809,7 +1822,7 @@ module RobustExcelOle
1809
1822
 
1810
1823
  end
1811
1824
 
1812
- describe "for_this_instance" do
1825
+ describe "set_options" do
1813
1826
 
1814
1827
  before do
1815
1828
  @excel = Excel.new(:reuse => false)
@@ -1819,7 +1832,7 @@ module RobustExcelOle
1819
1832
  end
1820
1833
 
1821
1834
  it "should set options in the Excel instance" do
1822
- @excel.for_this_instance(:displayalerts => true, :visible => true, :screenupdating => true, :calculation => :manual)
1835
+ @excel.set_options(:displayalerts => true, :visible => true, :screenupdating => true, :calculation => :manual)
1823
1836
  @excel.DisplayAlerts.should be true
1824
1837
  @excel.Visible.should be true
1825
1838
  @excel.ScreenUpdating.should be true
@@ -1832,25 +1845,25 @@ module RobustExcelOle
1832
1845
 
1833
1846
  end
1834
1847
 
1835
- context "for_all_workbooks" do
1848
+ context "each_workbook" do
1836
1849
 
1837
1850
  it "should not raise an error for an empty Excel instance" do
1838
1851
  excel = Excel.create
1839
1852
  expect{
1840
- excel.for_all_workbooks(:visible => true, :read_only => true, :check_compatibility => true)
1853
+ excel.each_workbook(:visible => true, :read_only => true, :check_compatibility => true)
1841
1854
  }.to_not raise_error
1842
1855
  end
1843
1856
 
1844
1857
  it "should set options to true for a workbook" do
1845
1858
  book1 = Workbook.open(@simple_file1)
1846
1859
  excel1 = book1.excel
1847
- excel1.for_all_workbooks(:visible => true, :read_only => true, :check_compatibility => true)
1860
+ excel1.each_workbook(:visible => true, :read_only => true, :check_compatibility => true)
1848
1861
  excel1.Visible.should be true
1849
1862
  ole_workbook1 = book1.ole_workbook
1850
1863
  ole_workbook1.Windows(ole_workbook1.Name).Visible.should be true
1851
1864
  ole_workbook1.ReadOnly.should be true
1852
1865
  ole_workbook1.CheckCompatibility.should be true
1853
- excel1.for_all_workbooks(:visible => false, :read_only => false, :check_compatibility => false)
1866
+ excel1.each_workbook(:visible => false, :read_only => false, :check_compatibility => false)
1854
1867
  excel1.Visible.should be true
1855
1868
  ole_workbook1 = book1.ole_workbook
1856
1869
  ole_workbook1.Windows(ole_workbook1.Name).Visible.should be false
@@ -1862,7 +1875,7 @@ module RobustExcelOle
1862
1875
  book1 = Workbook.open(@simple_file1)
1863
1876
  book2 = Workbook.open(@different_file1)
1864
1877
  excel = book1.excel
1865
- excel.for_all_workbooks(:visible => true, :check_compatibility => true, :read_only => true)
1878
+ excel.each_workbook(:visible => true, :check_compatibility => true, :read_only => true)
1866
1879
  excel.Visible.should be true
1867
1880
  ole_workbook1 = book1.ole_workbook
1868
1881
  ole_workbook2 = book2.ole_workbook
@@ -1872,7 +1885,7 @@ module RobustExcelOle
1872
1885
  ole_workbook2.CheckCompatibility.should be true
1873
1886
  ole_workbook1.ReadOnly.should be true
1874
1887
  ole_workbook2.ReadOnly.should be true
1875
- excel.for_all_workbooks(:visible => false, :check_compatibility => false, :read_only => false)
1888
+ excel.each_workbook(:visible => false, :check_compatibility => false, :read_only => false)
1876
1889
  excel.Visible.should be true
1877
1890
  ole_workbook1 = book1.ole_workbook
1878
1891
  ole_workbook2 = book2.ole_workbook
@@ -1886,29 +1899,46 @@ module RobustExcelOle
1886
1899
 
1887
1900
  end
1888
1901
 
1889
- describe "known_excel_instances" do
1902
+ describe "known_running_instance" do
1903
+
1904
+ before do
1905
+ @excel1 = Excel.create
1906
+ @excel2 = Excel.create
1907
+ end
1908
+
1909
+ it "should yield an Excel instance" do
1910
+ Excel.known_running_instance.should == @excel1
1911
+ end
1912
+
1913
+ end
1914
+
1915
+ describe "known_running_instances" do
1890
1916
 
1891
1917
  it "should return empty list" do
1892
- Excel.known_excel_instances.should be_empty
1918
+ Excel.known_running_instances.size.should == 0
1893
1919
  end
1894
1920
 
1895
1921
  it "should return list of one Excel process" do
1896
1922
  excel = Excel.new
1897
- Excel.known_excel_instances.should == [excel]
1898
- excel.close
1923
+ excel_instances = Excel.known_running_instances
1924
+ excel_instances.size.should == 1
1925
+ excel_instances.first.should == excel
1926
+ excel_instances.to_a.should == [excel]
1927
+ res = []
1928
+ excel_instances.each.with_index{|e,i| res << [e,i]}
1929
+ res.should == [[excel,0]]
1899
1930
  end
1900
1931
 
1901
1932
  it "should return list of two Excel processes" do
1902
1933
  excel1 = Excel.create
1903
1934
  excel2 = Excel.create
1904
- Excel.known_excel_instances.should == [excel1,excel2]
1905
- end
1906
-
1907
- it "should return list of two Excel processes" do
1908
- excel1 = Excel.new
1909
- excel2 = Excel.current
1910
- excel3 = Excel.create
1911
- Excel.known_excel_instances.should == [excel1,excel3]
1935
+ excel_instances = Excel.known_running_instances
1936
+ excel_instances.size.should == 2
1937
+ excel_instances.first.should == excel1
1938
+ excel_instances.to_a.should == [excel1, excel2]
1939
+ res = []
1940
+ excel_instances.each.with_index{|e,i| res << [e,i]}
1941
+ res.should == [[excel1,0],[excel2,1]]
1912
1942
  end
1913
1943
 
1914
1944
  end
@@ -1969,6 +1999,23 @@ module RobustExcelOle
1969
1999
  end
1970
2000
  =end
1971
2001
  end
2002
+
2003
+ describe "set_options" do
2004
+
2005
+ before do
2006
+ workbook = Workbook.open(@simple_file1, visible: false)
2007
+ @excel1 = workbook.excel
2008
+ end
2009
+
2010
+ it "should set options" do
2011
+ @excel1.DisplayAlerts.should be false
2012
+ @excel1.Visible.should be false
2013
+ @excel1.set_options(displayalerts: true, visible: true)
2014
+ @excel1.DisplayAlerts.should be true
2015
+ @excel1.Visible.should be true
2016
+ end
2017
+
2018
+ end
1972
2019
 
1973
2020
  describe "generate workbook" do
1974
2021