robust_excel_ole 1.15 → 1.18.2
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 +27 -0
- data/README.rdoc +18 -1
- data/___dummy_workbook.xls +0 -0
- data/docs/README_excel.rdoc +6 -0
- data/docs/README_open.rdoc +18 -2
- data/docs/README_ranges.rdoc +11 -2
- data/examples/example_ruby_library.rb +27 -0
- data/extconf.rb +13 -0
- data/lib/robust_excel_ole.rb +4 -3
- data/lib/robust_excel_ole/{address.rb → address_tool.rb} +23 -22
- data/lib/robust_excel_ole/{reo_common.rb → base.rb} +2 -90
- data/lib/robust_excel_ole/bookstore.rb +14 -77
- data/lib/robust_excel_ole/cell.rb +30 -18
- data/lib/robust_excel_ole/excel.rb +71 -41
- data/lib/robust_excel_ole/general.rb +39 -14
- data/lib/robust_excel_ole/range.rb +42 -19
- data/lib/robust_excel_ole/range_owners.rb +40 -25
- data/lib/robust_excel_ole/vba_objects.rb +30 -0
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +241 -235
- data/lib/robust_excel_ole/worksheet.rb +42 -21
- data/lib/rubygems_plugin.rb +3 -0
- data/robust_excel_ole.gemspec +1 -0
- data/spec/address_tool_spec.rb +175 -0
- data/spec/{reo_common_spec.rb → base_spec.rb} +11 -30
- data/spec/bookstore_spec.rb +3 -3
- data/spec/cell_spec.rb +67 -25
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/excel_spec.rb +41 -275
- data/spec/general_spec.rb +17 -23
- data/spec/range_spec.rb +57 -3
- data/spec/workbook_spec.rb +7 -75
- data/spec/workbook_specs/workbook_misc_spec.rb +11 -21
- data/spec/workbook_specs/workbook_open_spec.rb +570 -30
- data/spec/workbook_specs/workbook_unobtr_spec.rb +33 -33
- data/spec/worksheet_spec.rb +36 -4
- metadata +10 -6
- data/spec/address_spec.rb +0 -174
data/spec/cell_spec.rb
CHANGED
@@ -15,54 +15,66 @@ describe Cell do
|
|
15
15
|
|
16
16
|
before do
|
17
17
|
@dir = create_tmpdir
|
18
|
+
@simple_file = @dir + '/workbook.xls'
|
19
|
+
@merge_cells_file = @dir + '/merge_cells.xls'
|
20
|
+
@book = Workbook.open(@simple_file)
|
21
|
+
@sheet = @book.sheet(1)
|
22
|
+
@cell = @sheet[1, 1]
|
18
23
|
end
|
19
24
|
|
20
25
|
after do
|
26
|
+
Excel.kill_all
|
21
27
|
rm_tmp(@dir)
|
22
28
|
end
|
23
29
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@cell
|
30
|
+
|
31
|
+
describe "values" do
|
32
|
+
|
33
|
+
it "should yield one element values" do
|
34
|
+
@cell.values.should == ["foo"]
|
29
35
|
end
|
30
36
|
|
31
|
-
|
32
|
-
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#[]" do
|
40
|
+
|
41
|
+
it "should access to the cell itself" do
|
42
|
+
@cell[0].should be_kind_of RobustExcelOle::Cell
|
43
|
+
@cell[0].v.should == "foo"
|
33
44
|
end
|
34
45
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
46
|
+
it "should access to the cell itself" do
|
47
|
+
@cell[1].should be_kind_of RobustExcelOle::Cell
|
48
|
+
@cell[1].v.should == 'foo'
|
39
49
|
end
|
50
|
+
|
51
|
+
end
|
40
52
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
53
|
+
describe "#copy" do
|
54
|
+
|
55
|
+
before do
|
56
|
+
@book1 = Workbook.open(@dir + '/workbook.xls')
|
57
|
+
@sheet1 = @book1.sheet(1)
|
58
|
+
@cell1 = @sheet1[1,1]
|
46
59
|
end
|
47
60
|
|
48
|
-
|
49
|
-
|
50
|
-
it { expect { @cell.hogehogefoo }.to raise_error }
|
51
|
-
end
|
61
|
+
after do
|
62
|
+
@book1.close(:if_unsaved => :forget)
|
52
63
|
end
|
53
64
|
|
65
|
+
it "should copy range" do
|
66
|
+
@cell1.copy([2,3])
|
67
|
+
@sheet1.range([1..2,1..3]).v.should == [["foo", "workbook", "sheet1"],["foo", nil, "foo"]]
|
68
|
+
end
|
54
69
|
end
|
55
70
|
|
56
71
|
context "open merge_cells.xls" do
|
72
|
+
|
57
73
|
before do
|
58
|
-
@book = Workbook.open(@
|
74
|
+
@book = Workbook.open(@merge_cells_file, :read_only => true)
|
59
75
|
@sheet = @book.sheet(1)
|
60
76
|
end
|
61
77
|
|
62
|
-
after do
|
63
|
-
@book.close
|
64
|
-
end
|
65
|
-
|
66
78
|
it "merged cell get same value" do
|
67
79
|
@sheet[1, 1].Value.should be_nil
|
68
80
|
@sheet[2, 1].Value.should eq 'first merged'
|
@@ -74,4 +86,34 @@ describe Cell do
|
|
74
86
|
@sheet[2, 2].Value.should eq "set merge cell"
|
75
87
|
end
|
76
88
|
end
|
89
|
+
|
90
|
+
describe "==" do
|
91
|
+
|
92
|
+
it "should check equality of cells" do
|
93
|
+
@cell.should == @sheet[1,1]
|
94
|
+
@cell.should_not == @sheet[1,2]
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#Value" do
|
100
|
+
it "get cell's value" do
|
101
|
+
@cell.Value.should eq 'foo'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#Value=" do
|
106
|
+
it "change cell data to 'fooooo'" do
|
107
|
+
@cell.Value = 'fooooo'
|
108
|
+
@cell.Value.should eq 'fooooo'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#method_missing" do
|
113
|
+
context "unknown method" do
|
114
|
+
it { expect { @cell.hogehogefoo }.to raise_error(NoMethodError) }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
77
118
|
end
|
119
|
+
|
Binary file
|
data/spec/excel_spec.rb
CHANGED
@@ -23,6 +23,11 @@ module RobustExcelOle
|
|
23
23
|
@invalid_name_file = 'b/workbook.xls'
|
24
24
|
@simple_file1 = @simple_file
|
25
25
|
@different_file1 = @different_file
|
26
|
+
@error_unsaved_workbooks = "Excel contains unsaved workbooks" +
|
27
|
+
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
28
|
+
Excel instance without or with saving the unsaved workbooks before, respectively"
|
29
|
+
@error_invalid_option = ":if_unsaved: invalid option: :invalid_option" +
|
30
|
+
"\nHint: Valid values are :raise, :forget, :save and :alert"
|
26
31
|
end
|
27
32
|
|
28
33
|
after do
|
@@ -30,6 +35,22 @@ module RobustExcelOle
|
|
30
35
|
rm_tmp(@dir)
|
31
36
|
end
|
32
37
|
|
38
|
+
context "active_workbook" do
|
39
|
+
|
40
|
+
before do
|
41
|
+
@excel = Excel.create
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should access the active workbook" do
|
45
|
+
@excel.active_workbook.should be nil
|
46
|
+
workbook = Workbook.open(@simple_file1)
|
47
|
+
active_workbook = @excel.active_workbook
|
48
|
+
active_workbook.Fullname.should == workbook.Fullname
|
49
|
+
active_workbook.should == workbook
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
33
54
|
context "with connect and preserving options" do
|
34
55
|
|
35
56
|
before do
|
@@ -627,15 +648,13 @@ module RobustExcelOle
|
|
627
648
|
@excel2 = book2.excel
|
628
649
|
sheet2 = book2.sheet(1)
|
629
650
|
@old_cell_value2 = sheet2[1,1].Value
|
630
|
-
sheet2[1,1] = sheet2[1,1].Value == "foo" ? "bar" : "foo"
|
651
|
+
sheet2[1,1] = sheet2[1,1].Value == "foo" ? "bar" : "foo"
|
631
652
|
end
|
632
653
|
|
633
654
|
it "should close the first Excel without unsaved workbooks and then raise an error" do
|
634
655
|
expect{
|
635
656
|
Excel.close_all(:if_unsaved => :raise)
|
636
|
-
}.to raise_error(UnsavedWorkbooks,
|
637
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
638
|
-
Excel instance without or with saving the unsaved workbooks before, respectively")
|
657
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
639
658
|
sleep 0.2
|
640
659
|
@excel1.should_not be_alive
|
641
660
|
@excel2.should be_alive
|
@@ -648,9 +667,7 @@ module RobustExcelOle
|
|
648
667
|
it "should close the first Excel without unsaved workbooks and then raise an error" do
|
649
668
|
expect{
|
650
669
|
Excel.close_all
|
651
|
-
}.to raise_error(UnsavedWorkbooks,
|
652
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
653
|
-
Excel instance without or with saving the unsaved workbooks before, respectively")
|
670
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
654
671
|
sleep 0.2
|
655
672
|
@excel1.should_not be_alive
|
656
673
|
@excel2.should be_alive
|
@@ -687,8 +704,7 @@ module RobustExcelOle
|
|
687
704
|
it "should raise an error for invalid option" do
|
688
705
|
expect {
|
689
706
|
Excel.close_all(:if_unsaved => :invalid_option)
|
690
|
-
}.to raise_error(OptionInvalid,
|
691
|
-
"\nHint: Valid values are :raise, :forget, :save and :alert")
|
707
|
+
}.to raise_error(OptionInvalid, @error_invalid_option)
|
692
708
|
end
|
693
709
|
end
|
694
710
|
|
@@ -705,9 +721,7 @@ module RobustExcelOle
|
|
705
721
|
it "should close the 1st and 3rd Excel instances that have saved workbooks" do
|
706
722
|
expect{
|
707
723
|
Excel.close_all(:if_unsaved => :raise)
|
708
|
-
}.to raise_error(UnsavedWorkbooks,
|
709
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
710
|
-
Excel instance without or with saving the unsaved workbooks before, respectively")
|
724
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
711
725
|
sleep 0.2
|
712
726
|
@book1.excel.should_not be_alive
|
713
727
|
@book2.excel.should be_alive
|
@@ -732,9 +746,7 @@ module RobustExcelOle
|
|
732
746
|
it "should close three Excel instances that have saved workbooks" do
|
733
747
|
expect{
|
734
748
|
Excel.close_all(:if_unsaved => :raise)
|
735
|
-
}.to raise_error(UnsavedWorkbooks,
|
736
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
737
|
-
Excel instance without or with saving the unsaved workbooks before, respectively")
|
749
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
738
750
|
sleep 0.2
|
739
751
|
expect{
|
740
752
|
@ole_xl.Name
|
@@ -812,17 +824,13 @@ module RobustExcelOle
|
|
812
824
|
it "should raise an error" do
|
813
825
|
expect{
|
814
826
|
@excel.close(:if_unsaved => :raise)
|
815
|
-
}.to raise_error(UnsavedWorkbooks,
|
816
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
817
|
-
Excel instance without or with saving the unsaved workbooks before, respectively")
|
827
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
818
828
|
end
|
819
829
|
|
820
830
|
it "should raise an error per default" do
|
821
831
|
expect{
|
822
832
|
@excel.close(:if_unsaved => :raise)
|
823
|
-
}.to raise_error(UnsavedWorkbooks,
|
824
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
825
|
-
Excel instance without or with saving the unsaved workbooks before, respectively")
|
833
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
826
834
|
end
|
827
835
|
|
828
836
|
it "should close the Excel without saving the workbook" do
|
@@ -865,8 +873,7 @@ module RobustExcelOle
|
|
865
873
|
it "should raise an error for invalid option" do
|
866
874
|
expect {
|
867
875
|
@excel.close(:if_unsaved => :invalid_option)
|
868
|
-
}.to raise_error(OptionInvalid,
|
869
|
-
"\nHint: Valid values are :raise, :forget, :save and :alert")
|
876
|
+
}.to raise_error(OptionInvalid, @error_invalid_option)
|
870
877
|
end
|
871
878
|
end
|
872
879
|
|
@@ -955,18 +962,13 @@ module RobustExcelOle
|
|
955
962
|
it "should raise error" do
|
956
963
|
expect{
|
957
964
|
@excel.close_workbooks(:if_unsaved => :raise)
|
958
|
-
}.to raise_error(UnsavedWorkbooks,
|
959
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
960
|
-
Excel instance without or with saving the unsaved workbooks before, respectively" )
|
961
|
-
|
965
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
962
966
|
end
|
963
967
|
|
964
968
|
it "should raise error per default" do
|
965
969
|
expect{
|
966
970
|
@excel.close_workbooks
|
967
|
-
}.to raise_error(UnsavedWorkbooks,
|
968
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
969
|
-
Excel instance without or with saving the unsaved workbooks before, respectively")
|
971
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
970
972
|
end
|
971
973
|
|
972
974
|
it "should close the workbook with forgetting the workbook" do
|
@@ -994,8 +996,7 @@ module RobustExcelOle
|
|
994
996
|
it "should raise an error for invalid option" do
|
995
997
|
expect {
|
996
998
|
@excel.close_workbooks(:if_unsaved => :invalid_option)
|
997
|
-
}.to raise_error(OptionInvalid,
|
998
|
-
"\nHint: Valid values are :raise, :forget, :save and :alert")
|
999
|
+
}.to raise_error(OptionInvalid, @error_invalid_option)
|
999
1000
|
end
|
1000
1001
|
end
|
1001
1002
|
end
|
@@ -1925,14 +1926,14 @@ module RobustExcelOle
|
|
1925
1926
|
@excel2.Hwnd.should == @excel2.hwnd
|
1926
1927
|
end
|
1927
1928
|
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1929
|
+
# it "should provide the same excel instances" do
|
1930
|
+
# @excel1.should_not == @excel2
|
1931
|
+
# excel3 = Excel.hwnd2excel(@excel1.hwnd)
|
1932
|
+
# excel4 = Excel.hwnd2excel(@excel2.hwnd)
|
1933
|
+
# @excel1.should == excel3
|
1934
|
+
# @excel2.should == excel4
|
1935
|
+
# excel3.should_not == excel4
|
1936
|
+
# end
|
1936
1937
|
|
1937
1938
|
=begin
|
1938
1939
|
# does not work yet
|
@@ -2018,241 +2019,6 @@ module RobustExcelOle
|
|
2018
2019
|
|
2019
2020
|
end
|
2020
2021
|
end
|
2021
|
-
|
2022
|
-
context "setting the name of a range" do
|
2023
|
-
|
2024
|
-
before do
|
2025
|
-
@book1 = Workbook.open(@dir + '/another_workbook.xls', :read_only => true, :visible => true)
|
2026
|
-
@book1.excel.displayalerts = false
|
2027
|
-
@excel1 = @book1.excel
|
2028
|
-
end
|
2029
|
-
|
2030
|
-
after do
|
2031
|
-
@book1.close
|
2032
|
-
end
|
2033
|
-
|
2034
|
-
it "should name an unnamed range with a giving address" do
|
2035
|
-
@excel1.add_name("foo",[1,2])
|
2036
|
-
@excel1.Names.Item("foo").Name.should == "foo"
|
2037
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$B$1:$B$1"
|
2038
|
-
end
|
2039
|
-
|
2040
|
-
it "should rename an already named range with a giving address" do
|
2041
|
-
@excel1.add_name("foo",[1,1])
|
2042
|
-
@excel1.Names.Item("foo").Name.should == "foo"
|
2043
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$A$1:$A$1"
|
2044
|
-
end
|
2045
|
-
|
2046
|
-
it "should raise an error" do
|
2047
|
-
expect{
|
2048
|
-
@excel1.add_name("foo", [-2, 1])
|
2049
|
-
}.to raise_error(RangeNotEvaluatable, /cannot add name "foo" to range/)
|
2050
|
-
end
|
2051
|
-
|
2052
|
-
it "should rename a range" do
|
2053
|
-
@excel1.add_name("foo",[1,1])
|
2054
|
-
@excel1.rename_range("foo","bar")
|
2055
|
-
@excel1.namevalue_glob("bar").should == "foo"
|
2056
|
-
end
|
2057
|
-
|
2058
|
-
it "should delete a name of a range" do
|
2059
|
-
@excel1.add_name("foo",[1,1])
|
2060
|
-
@excel1.delete_name("foo")
|
2061
|
-
expect{
|
2062
|
-
@excel1.namevalue_glob("foo")
|
2063
|
-
}.to raise_error(NameNotFound, /name "foo"/)
|
2064
|
-
end
|
2065
|
-
|
2066
|
-
it "should add a name of a rectangular range" do
|
2067
|
-
@excel1.add_name("foo",[1..3,1..4])
|
2068
|
-
@excel1["foo"].should == [["foo", "workbook", "sheet1", nil], ["foo", 1.0, 2.0, 4.0], ["matz", 3.0, 4.0, 4.0]]
|
2069
|
-
end
|
2070
|
-
|
2071
|
-
it "should accept the old interface" do
|
2072
|
-
@excel1.add_name("foo",1..3,1..4)
|
2073
|
-
@excel1["foo"].should == [["foo", "workbook", "sheet1", nil], ["foo", 1.0, 2.0, 4.0], ["matz", 3.0, 4.0, 4.0]]
|
2074
|
-
end
|
2075
|
-
|
2076
|
-
it "should add a name of an infinite row range" do
|
2077
|
-
@excel1.add_name("foo",[1..3, nil])
|
2078
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$1:$3"
|
2079
|
-
end
|
2080
|
-
|
2081
|
-
it "should add a name of an infinite column range" do
|
2082
|
-
@excel1.add_name("foo",[nil, "A".."C"])
|
2083
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$A:$C"
|
2084
|
-
end
|
2085
|
-
|
2086
|
-
it "should add a name of an infinite row range" do
|
2087
|
-
@excel1.add_name("foo",[nil, 1..3])
|
2088
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$A:$C"
|
2089
|
-
end
|
2090
|
-
|
2091
|
-
it "should add a name of an infinite column range" do
|
2092
|
-
@excel1.add_name("foo",["A:C"])
|
2093
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$A:$C"
|
2094
|
-
end
|
2095
|
-
|
2096
|
-
it "should add a name of an infinite column range" do
|
2097
|
-
@excel1.add_name("foo",["1:2"])
|
2098
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$1:$2"
|
2099
|
-
end
|
2100
|
-
|
2101
|
-
end
|
2102
|
-
|
2103
|
-
describe "namevalue_glob, set_namevalue_glob" do
|
2104
|
-
|
2105
|
-
before do
|
2106
|
-
@book1 = Workbook.open(@dir + '/another_workbook.xls')
|
2107
|
-
@book1.Windows(@book1.Name).Visible = true
|
2108
|
-
@excel1 = @book1.excel
|
2109
|
-
end
|
2110
|
-
|
2111
|
-
after do
|
2112
|
-
@book1.close(:if_unsaved => :forget)
|
2113
|
-
end
|
2114
|
-
|
2115
|
-
it "should return value of a defined name" do
|
2116
|
-
@excel1.namevalue_glob("firstcell").should == "foo"
|
2117
|
-
@excel1["firstcell"].should == "foo"
|
2118
|
-
end
|
2119
|
-
|
2120
|
-
#it "should evaluate a formula" do
|
2121
|
-
# @excel1.namevalue_glob("named_formula").should == 4
|
2122
|
-
# @excel1["named_formula"].should == 4
|
2123
|
-
#end
|
2124
|
-
|
2125
|
-
it "should raise an error if name not defined" do
|
2126
|
-
expect {
|
2127
|
-
@excel1.namevalue_glob("foo")
|
2128
|
-
}.to raise_error(NameNotFound, /name "foo"/)
|
2129
|
-
expect {
|
2130
|
-
@excel1["foo"]
|
2131
|
-
}.to raise_error(NameNotFound, /name "foo"/)
|
2132
|
-
expect {
|
2133
|
-
excel2 = Excel.create
|
2134
|
-
excel2.namevalue_glob("one")
|
2135
|
-
}.to raise_error(NameNotFound, /name "one"/)
|
2136
|
-
expect {
|
2137
|
-
excel3 = Excel.create(:visible => true)
|
2138
|
-
excel3["one"]
|
2139
|
-
}.to raise_error(NameNotFound, /name "one"/)
|
2140
|
-
end
|
2141
|
-
|
2142
|
-
it "should set a range to a value" do
|
2143
|
-
@excel1.namevalue_glob("firstcell").should == "foo"
|
2144
|
-
@excel1.set_namevalue_glob("firstcell","bar")
|
2145
|
-
@excel1.namevalue_glob("firstcell").should == "bar"
|
2146
|
-
@excel1["firstcell"] = "foo"
|
2147
|
-
@excel1.namevalue_glob("firstcell").should == "foo"
|
2148
|
-
end
|
2149
|
-
|
2150
|
-
it "should raise an error if name cannot be evaluated" do
|
2151
|
-
expect{
|
2152
|
-
@excel1.set_namevalue_glob("foo", 1)
|
2153
|
-
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo"/)
|
2154
|
-
expect{
|
2155
|
-
@excel1["foo"] = 1
|
2156
|
-
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo"/)
|
2157
|
-
end
|
2158
|
-
|
2159
|
-
it "should color the cell (deprecated)" do
|
2160
|
-
@excel1.set_namevalue_glob("firstcell", "foo")
|
2161
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == -4142
|
2162
|
-
@excel1.set_namevalue_glob("firstcell", "foo", :color => 4)
|
2163
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 4
|
2164
|
-
@excel1["firstcell"].should == "foo"
|
2165
|
-
@excel1["firstcell"] = "foo"
|
2166
|
-
@excel1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 42
|
2167
|
-
@book1.save
|
2168
|
-
end
|
2169
|
-
|
2170
|
-
it "should color the cell" do
|
2171
|
-
@excel1.set_namevalue_glob("firstcell", "foo")
|
2172
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == -4142
|
2173
|
-
@book1.color_if_modified = 4
|
2174
|
-
@excel1.set_namevalue_glob("firstcell", "foo")
|
2175
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 4
|
2176
|
-
@excel1["firstcell"].should == "foo"
|
2177
|
-
@excel1["firstcell"] = "foo"
|
2178
|
-
@excel1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 42
|
2179
|
-
@book1.save
|
2180
|
-
end
|
2181
|
-
|
2182
|
-
|
2183
|
-
end
|
2184
|
-
|
2185
|
-
describe "namevalue, set_namevalue" do
|
2186
|
-
|
2187
|
-
before do
|
2188
|
-
@book1 = Workbook.open(@another_simple_file)
|
2189
|
-
@excel1 = @book1.excel
|
2190
|
-
# for some reason the workbook must be visible
|
2191
|
-
@book1.visible = true
|
2192
|
-
end
|
2193
|
-
|
2194
|
-
after do
|
2195
|
-
@book1.close(:if_unsaved => :forget)
|
2196
|
-
end
|
2197
|
-
|
2198
|
-
it "should return value of a locally defined name" do
|
2199
|
-
@excel1.namevalue("firstcell").should == "foo"
|
2200
|
-
end
|
2201
|
-
|
2202
|
-
it "should return value of a defined name" do
|
2203
|
-
@excel1.namevalue("new").should == "foo"
|
2204
|
-
@excel1.namevalue("one").should == 1.0
|
2205
|
-
@excel1.namevalue("four").should == [[1,2],[3,4]]
|
2206
|
-
@excel1.namevalue("firstrow").should == [[1,2]]
|
2207
|
-
end
|
2208
|
-
|
2209
|
-
it "should return default value if name not defined and default value is given" do
|
2210
|
-
@excel1.namevalue("foo", :default => 2).should == 2
|
2211
|
-
end
|
2212
|
-
|
2213
|
-
it "should raise an error if name not defined for the sheet" do
|
2214
|
-
expect {
|
2215
|
-
@excel1.namevalue("foo")
|
2216
|
-
}.to raise_error(NameNotFound, /name "foo" not in/)
|
2217
|
-
expect {
|
2218
|
-
@excel1.namevalue("named_formula")
|
2219
|
-
}.to raise_error(NameNotFound, /name "named_formula" not in/)
|
2220
|
-
expect {
|
2221
|
-
excel2 = Excel.create
|
2222
|
-
excel2.namevalue("one")
|
2223
|
-
}.to raise_error(NameNotFound, /name "one" not in/)
|
2224
|
-
end
|
2225
|
-
|
2226
|
-
it "should set a range to a value" do
|
2227
|
-
@excel1.namevalue("firstcell").should == "foo"
|
2228
|
-
@excel1.set_namevalue("firstcell","bar")
|
2229
|
-
@excel1.namevalue("firstcell").should == "bar"
|
2230
|
-
end
|
2231
|
-
|
2232
|
-
it "should raise an error if name cannot be evaluated" do
|
2233
|
-
expect{
|
2234
|
-
@excel1.set_namevalue_glob("foo", 1)
|
2235
|
-
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo" in/)
|
2236
|
-
end
|
2237
|
-
|
2238
|
-
it "should color the cell (depracated)" do
|
2239
|
-
@excel1.set_namevalue("firstcell", "foo")
|
2240
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == -4142
|
2241
|
-
@excel1.set_namevalue("firstcell", "foo", :color => 4)
|
2242
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 4
|
2243
|
-
end
|
2244
|
-
|
2245
|
-
it "should color the cell" do
|
2246
|
-
@excel1.set_namevalue("firstcell", "foo")
|
2247
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == -4142
|
2248
|
-
@book1.color_if_modified = 4
|
2249
|
-
@excel1.set_namevalue("firstcell", "foo")
|
2250
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 4
|
2251
|
-
end
|
2252
|
-
|
2253
|
-
|
2254
|
-
end
|
2255
|
-
|
2256
2022
|
end
|
2257
2023
|
end
|
2258
2024
|
|