robust_excel_ole 1.14 → 1.18.1
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 +34 -1
- data/README.rdoc +20 -6
- data/___dummy_workbook.xls +0 -0
- data/docs/README_excel.rdoc +7 -1
- data/docs/README_open.rdoc +45 -20
- 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 +105 -64
- data/lib/robust_excel_ole/general.rb +40 -15
- 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 +310 -336
- data/lib/robust_excel_ole/worksheet.rb +51 -25
- data/robust_excel_ole.gemspec +1 -0
- data/spec/address_tool_spec.rb +175 -0
- data/spec/{reo_common_spec.rb → base_spec.rb} +19 -34
- 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 +137 -369
- data/spec/general_spec.rb +21 -27
- data/spec/range_spec.rb +57 -3
- data/spec/workbook_spec.rb +11 -79
- data/spec/workbook_specs/workbook_misc_spec.rb +29 -40
- data/spec/workbook_specs/workbook_open_spec.rb +570 -30
- data/spec/workbook_specs/workbook_unobtr_spec.rb +440 -136
- data/spec/worksheet_spec.rb +36 -4
- metadata +11 -7
- data/spec/address_spec.rb +0 -174
data/spec/bookstore_spec.rb
CHANGED
@@ -159,7 +159,7 @@ describe Bookstore do
|
|
159
159
|
it "should not fetch anything to a not existing network path file" do
|
160
160
|
@book1 = Workbook.open(@hostname_share_path)
|
161
161
|
@bookstore.store(@book1)
|
162
|
-
|
162
|
+
#@bookstore.fetch(@network_path_not_existing).should == nil
|
163
163
|
end
|
164
164
|
|
165
165
|
# nice to have
|
@@ -175,7 +175,7 @@ describe Bookstore do
|
|
175
175
|
it "should not fetch anything to a not existing network path file the stored absolute path file" do
|
176
176
|
@book1 = Workbook.open(@absolute_file_path)
|
177
177
|
@bookstore.store(@book1)
|
178
|
-
|
178
|
+
#@bookstore.fetch(@network_path_not_existing).should == nil
|
179
179
|
end
|
180
180
|
|
181
181
|
it "should fetch to a given hostname share path file the stored network path file" do
|
@@ -581,7 +581,7 @@ describe Bookstore do
|
|
581
581
|
end
|
582
582
|
|
583
583
|
it "should print books" do
|
584
|
-
@bookstore.
|
584
|
+
@bookstore.print_filename2books
|
585
585
|
end
|
586
586
|
|
587
587
|
end
|
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
|
@@ -271,16 +292,16 @@ module RobustExcelOle
|
|
271
292
|
ole_excel = WIN32OLE.new("Excel.Application")
|
272
293
|
reo_excel = Excel.new(ole_excel)
|
273
294
|
reo_excel.ole_excel.Hwnd.should == ole_excel.Hwnd
|
274
|
-
reo_excel.
|
275
|
-
reo_excel.displayalerts.should == :if_visible
|
295
|
+
reo_excel.Visible.should == false
|
296
|
+
reo_excel.properties[:displayalerts].should == :if_visible
|
276
297
|
end
|
277
298
|
|
278
299
|
it "lifts an Excel instance given as WIN32OLE object and set options" do
|
279
300
|
app = WIN32OLE.new('Excel.Application')
|
280
301
|
ole_excel = WIN32OLE.connect("Excel.Application")
|
281
302
|
reo_excel = Excel.new(ole_excel, {:displayalerts => true, :visible => true})
|
282
|
-
ole_excel.
|
283
|
-
ole_excel.
|
303
|
+
ole_excel.Visible.should == true
|
304
|
+
ole_excel.DisplayAlerts.should == true
|
284
305
|
end
|
285
306
|
|
286
307
|
|
@@ -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
|
|
@@ -889,6 +896,8 @@ module RobustExcelOle
|
|
889
896
|
# "Yes" is to the left of "No", which is the default. --> language independent
|
890
897
|
@excel.should be_alive
|
891
898
|
@key_sender.puts "{enter}"
|
899
|
+
@key_sender.puts "{enter}"
|
900
|
+
@key_sender.puts "{enter}"
|
892
901
|
result = @excel.close(:if_unsaved => :alert)
|
893
902
|
@excel.should_not be_alive
|
894
903
|
result.should == 1
|
@@ -920,6 +929,7 @@ module RobustExcelOle
|
|
920
929
|
@book.saved.should be false
|
921
930
|
@key_sender.puts "{left}{enter}"
|
922
931
|
@key_sender.puts "{left}{enter}"
|
932
|
+
@key_sender.puts "{left}{enter}"
|
923
933
|
expect{
|
924
934
|
@excel.close(:if_unsaved => :alert)
|
925
935
|
}.to raise_error(ExcelREOError, "user canceled or runtime error")
|
@@ -952,18 +962,13 @@ module RobustExcelOle
|
|
952
962
|
it "should raise error" do
|
953
963
|
expect{
|
954
964
|
@excel.close_workbooks(:if_unsaved => :raise)
|
955
|
-
}.to raise_error(UnsavedWorkbooks,
|
956
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
957
|
-
Excel instance without or with saving the unsaved workbooks before, respectively" )
|
958
|
-
|
965
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
959
966
|
end
|
960
967
|
|
961
968
|
it "should raise error per default" do
|
962
969
|
expect{
|
963
970
|
@excel.close_workbooks
|
964
|
-
}.to raise_error(UnsavedWorkbooks,
|
965
|
-
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
966
|
-
Excel instance without or with saving the unsaved workbooks before, respectively")
|
971
|
+
}.to raise_error(UnsavedWorkbooks, @error_unsaved_workbooks)
|
967
972
|
end
|
968
973
|
|
969
974
|
it "should close the workbook with forgetting the workbook" do
|
@@ -991,8 +996,7 @@ module RobustExcelOle
|
|
991
996
|
it "should raise an error for invalid option" do
|
992
997
|
expect {
|
993
998
|
@excel.close_workbooks(:if_unsaved => :invalid_option)
|
994
|
-
}.to raise_error(OptionInvalid,
|
995
|
-
"\nHint: Valid values are :raise, :forget, :save and :alert")
|
999
|
+
}.to raise_error(OptionInvalid, @error_invalid_option)
|
996
1000
|
end
|
997
1001
|
end
|
998
1002
|
end
|
@@ -1254,55 +1258,55 @@ module RobustExcelOle
|
|
1254
1258
|
excel2 = Excel.create
|
1255
1259
|
excel1.focus
|
1256
1260
|
excel1.Visible.should be true
|
1257
|
-
excel1.visible.should be true
|
1261
|
+
excel1.properties[:visible].should be true
|
1258
1262
|
end
|
1259
1263
|
|
1260
1264
|
it "should set default values" do
|
1261
1265
|
excel1 = Excel.new
|
1262
1266
|
excel1.Visible.should be false
|
1263
1267
|
excel1.DisplayAlerts.should be false
|
1264
|
-
excel1.visible.should be false
|
1265
|
-
excel1.displayalerts.should == :if_visible
|
1268
|
+
excel1.properties[:visible].should be false
|
1269
|
+
excel1.properties[:displayalerts].should == :if_visible
|
1266
1270
|
end
|
1267
1271
|
|
1268
1272
|
it "should set visible true" do
|
1269
1273
|
excel1 = Excel.new(:visible => true)
|
1270
1274
|
excel1.Visible.should be true
|
1271
1275
|
excel1.DisplayAlerts.should be true
|
1272
|
-
excel1.visible.should be true
|
1273
|
-
excel1.displayalerts.should == :if_visible
|
1276
|
+
excel1.properties[:visible].should be true
|
1277
|
+
excel1.properties[:displayalerts].should == :if_visible
|
1274
1278
|
end
|
1275
1279
|
|
1276
1280
|
it "should set visible false" do
|
1277
1281
|
excel1 = Excel.new(:visible => false)
|
1278
1282
|
excel1.Visible.should be false
|
1279
1283
|
excel1.DisplayAlerts.should be false
|
1280
|
-
excel1.visible.should be false
|
1281
|
-
excel1.displayalerts.should == :if_visible
|
1284
|
+
excel1.properties[:visible].should be false
|
1285
|
+
excel1.properties[:displayalerts].should == :if_visible
|
1282
1286
|
end
|
1283
1287
|
|
1284
1288
|
it "should set displayalerts true" do
|
1285
1289
|
excel1 = Excel.new(:displayalerts => true)
|
1286
1290
|
excel1.Visible.should be false
|
1287
1291
|
excel1.DisplayAlerts.should be true
|
1288
|
-
excel1.visible.should be false
|
1289
|
-
excel1.displayalerts.should be true
|
1292
|
+
excel1.properties[:visible].should be false
|
1293
|
+
excel1.properties[:displayalerts].should be true
|
1290
1294
|
end
|
1291
1295
|
|
1292
1296
|
it "should set displayalerts false" do
|
1293
1297
|
excel1 = Excel.new(:displayalerts => false)
|
1294
1298
|
excel1.Visible.should be false
|
1295
1299
|
excel1.DisplayAlerts.should be false
|
1296
|
-
excel1.visible.should be false
|
1297
|
-
excel1.displayalerts.should be false
|
1300
|
+
excel1.properties[:visible].should be false
|
1301
|
+
excel1.properties[:displayalerts].should be false
|
1298
1302
|
end
|
1299
1303
|
|
1300
1304
|
it "should use values of the current Excel when reusing" do
|
1301
1305
|
excel1 = Excel.create
|
1302
1306
|
excel1.Visible.should be false
|
1303
1307
|
excel1.DisplayAlerts.should be false
|
1304
|
-
excel1.visible.should be false
|
1305
|
-
excel1.displayalerts.should == :if_visible
|
1308
|
+
excel1.properties[:visible].should be false
|
1309
|
+
excel1.properties[:displayalerts].should == :if_visible
|
1306
1310
|
excel1.Visible = true
|
1307
1311
|
excel1.DisplayAlerts = true
|
1308
1312
|
excel1.Visible.should be true
|
@@ -1316,49 +1320,49 @@ module RobustExcelOle
|
|
1316
1320
|
excel1 = Excel.create
|
1317
1321
|
excel2 = Excel.current
|
1318
1322
|
excel2.Visible.should be false
|
1319
|
-
excel2.visible.should be false
|
1323
|
+
excel2.properties[:visible].should be false
|
1320
1324
|
excel2.DisplayAlerts.should be false
|
1321
|
-
excel2.displayalerts.should == :if_visible
|
1325
|
+
excel2.properties[:displayalerts].should == :if_visible
|
1322
1326
|
end
|
1323
1327
|
|
1324
1328
|
it "should take Visible and DisplayAlerts from the connected Excel" do
|
1325
1329
|
excel1 = Excel.create
|
1326
1330
|
excel2 = Excel.current(:visible => true)
|
1327
1331
|
excel2.Visible.should be true
|
1328
|
-
excel2.visible.should be true
|
1332
|
+
excel2.properties[:visible].should be true
|
1329
1333
|
excel2.DisplayAlerts.should be true
|
1330
|
-
excel2.displayalerts.should == :if_visible
|
1334
|
+
excel2.properties[:displayalerts].should == :if_visible
|
1331
1335
|
end
|
1332
1336
|
|
1333
1337
|
it "should set Excel visible and invisible with current" do
|
1334
1338
|
excel1 = Excel.new(:reuse => false, :visible => true)
|
1335
1339
|
excel1.Visible.should be true
|
1336
|
-
excel1.visible.should be true
|
1340
|
+
excel1.properties[:visible].should be true
|
1337
1341
|
excel1.DisplayAlerts.should be true
|
1338
|
-
excel1.displayalerts.should == :if_visible
|
1342
|
+
excel1.properties[:displayalerts].should == :if_visible
|
1339
1343
|
excel1.visible = false
|
1340
1344
|
excel1.Visible.should be false
|
1341
|
-
excel1.visible.should be false
|
1345
|
+
excel1.properties[:visible].should be false
|
1342
1346
|
excel1.DisplayAlerts.should be false
|
1343
|
-
excel1.displayalerts.should == :if_visible
|
1347
|
+
excel1.properties[:displayalerts].should == :if_visible
|
1344
1348
|
excel2 = Excel.current(:visible => true)
|
1345
1349
|
excel2.Visible.should be true
|
1346
|
-
excel2.visible.should be true
|
1347
|
-
excel2.displayalerts.should == :if_visible
|
1350
|
+
excel2.properties[:visible].should be true
|
1351
|
+
excel2.properties[:displayalerts].should == :if_visible
|
1348
1352
|
excel2.DisplayAlerts.should be true
|
1349
1353
|
end
|
1350
1354
|
|
1351
1355
|
it "should set Excel visible and invisible" do
|
1352
1356
|
excel = Excel.new(:reuse => false, :visible => true)
|
1353
1357
|
excel.Visible.should be true
|
1354
|
-
excel.visible.should be true
|
1358
|
+
excel.properties[:visible].should be true
|
1355
1359
|
excel.DisplayAlerts.should be true
|
1356
|
-
excel.displayalerts.should == :if_visible
|
1360
|
+
excel.properties[:displayalerts].should == :if_visible
|
1357
1361
|
excel.visible = false
|
1358
1362
|
excel.Visible.should be false
|
1359
|
-
excel.visible.should be false
|
1363
|
+
excel.properties[:visible].should be false
|
1360
1364
|
excel.DisplayAlerts.should be false
|
1361
|
-
excel.displayalerts.should == :if_visible
|
1365
|
+
excel.properties[:displayalerts].should == :if_visible
|
1362
1366
|
excel7 = Excel.current
|
1363
1367
|
excel7.should === excel
|
1364
1368
|
excel7.Visible.should be false
|
@@ -1366,117 +1370,117 @@ module RobustExcelOle
|
|
1366
1370
|
excel1 = Excel.create(:visible => true)
|
1367
1371
|
excel1.should_not == excel
|
1368
1372
|
excel1.Visible.should be true
|
1369
|
-
excel1.visible.should be true
|
1373
|
+
excel1.properties[:visible].should be true
|
1370
1374
|
excel1.DisplayAlerts.should be true
|
1371
|
-
excel1.displayalerts.should == :if_visible
|
1375
|
+
excel1.properties[:displayalerts].should == :if_visible
|
1372
1376
|
excel2 = Excel.create(:visible => false)
|
1373
1377
|
excel2.Visible.should be false
|
1374
|
-
excel2.visible.should be false
|
1378
|
+
excel2.properties[:visible].should be false
|
1375
1379
|
excel2.DisplayAlerts.should be false
|
1376
|
-
excel2.displayalerts.should == :if_visible
|
1380
|
+
excel2.properties[:displayalerts].should == :if_visible
|
1377
1381
|
excel3 = Excel.current
|
1378
1382
|
excel3.should === excel
|
1379
1383
|
excel3.Visible.should be false
|
1380
|
-
excel3.visible.should be false
|
1384
|
+
excel3.properties[:visible].should be false
|
1381
1385
|
excel3.DisplayAlerts.should be false
|
1382
|
-
excel3.displayalerts.should == :if_visible
|
1386
|
+
excel3.properties[:displayalerts].should == :if_visible
|
1383
1387
|
excel4 = Excel.current(:visible => true)
|
1384
1388
|
excel4.should === excel
|
1385
1389
|
excel4.Visible.should be true
|
1386
|
-
excel4.visible.should be true
|
1390
|
+
excel4.properties[:visible].should be true
|
1387
1391
|
excel4.DisplayAlerts.should be true
|
1388
|
-
excel4.displayalerts.should == :if_visible
|
1392
|
+
excel4.properties[:displayalerts].should == :if_visible
|
1389
1393
|
excel5 = Excel.current(:visible => false)
|
1390
1394
|
excel5.should === excel
|
1391
1395
|
excel5.Visible.should be false
|
1392
|
-
excel5.visible.should be false
|
1396
|
+
excel5.properties[:visible].should be false
|
1393
1397
|
excel5.DisplayAlerts.should be false
|
1394
|
-
excel5.displayalerts.should == :if_visible
|
1398
|
+
excel5.properties[:displayalerts].should == :if_visible
|
1395
1399
|
end
|
1396
1400
|
|
1397
1401
|
it "should enable or disable Excel DispayAlerts" do
|
1398
1402
|
excel = Excel.new(:reuse => false, :displayalerts => true)
|
1399
1403
|
excel.DisplayAlerts.should be true
|
1400
|
-
excel.displayalerts.should be true
|
1404
|
+
excel.properties[:displayalerts].should be true
|
1401
1405
|
excel.Visible.should be false
|
1402
|
-
excel.visible.should be false
|
1406
|
+
excel.properties[:visible].should be false
|
1403
1407
|
excel6 = Excel.current
|
1404
1408
|
excel6.should === excel
|
1405
1409
|
excel6.DisplayAlerts.should be true
|
1406
|
-
excel6.displayalerts.should be true
|
1410
|
+
excel6.properties[:displayalerts].should be true
|
1407
1411
|
excel6.Visible.should be false
|
1408
|
-
excel6.visible.should be false
|
1412
|
+
excel6.properties[:visible].should be false
|
1409
1413
|
excel.displayalerts = false
|
1410
1414
|
excel.DisplayAlerts.should be false
|
1411
|
-
excel.displayalerts.should be false
|
1415
|
+
excel.properties[:displayalerts].should be false
|
1412
1416
|
excel.Visible.should be false
|
1413
|
-
excel.visible.should be false
|
1417
|
+
excel.properties[:visible].should be false
|
1414
1418
|
excel7 = Excel.current
|
1415
1419
|
excel7.should === excel
|
1416
1420
|
excel7.DisplayAlerts.should be false
|
1417
|
-
excel7.displayalerts.should be false
|
1421
|
+
excel7.properties[:displayalerts].should be false
|
1418
1422
|
excel7.Visible.should be false
|
1419
|
-
excel7.visible.should be false
|
1423
|
+
excel7.properties[:visible].should be false
|
1420
1424
|
excel1 = Excel.create(:displayalerts => true)
|
1421
1425
|
excel1.should_not == excel
|
1422
1426
|
excel1.DisplayAlerts.should be true
|
1423
|
-
excel1.displayalerts.should be true
|
1427
|
+
excel1.properties[:displayalerts].should be true
|
1424
1428
|
excel1.Visible.should be false
|
1425
|
-
excel1.visible.should be false
|
1429
|
+
excel1.properties[:visible].should be false
|
1426
1430
|
excel2 = Excel.create(:displayalerts => false)
|
1427
1431
|
excel2.DisplayAlerts.should be false
|
1428
|
-
excel2.displayalerts.should be false
|
1432
|
+
excel2.properties[:displayalerts].should be false
|
1429
1433
|
excel2.Visible.should be false
|
1430
|
-
excel2.visible.should be false
|
1434
|
+
excel2.properties[:visible].should be false
|
1431
1435
|
excel3 = Excel.current
|
1432
1436
|
excel3.should === excel
|
1433
1437
|
excel3.DisplayAlerts.should be false
|
1434
|
-
excel3.displayalerts.should be false
|
1438
|
+
excel3.properties[:displayalerts].should be false
|
1435
1439
|
excel3.Visible.should be false
|
1436
|
-
excel3.visible.should be false
|
1440
|
+
excel3.properties[:visible].should be false
|
1437
1441
|
excel4 = Excel.current(:displayalerts => true)
|
1438
1442
|
excel4.should === excel
|
1439
1443
|
excel4.DisplayAlerts.should be true
|
1440
|
-
excel4.displayalerts.should be true
|
1444
|
+
excel4.properties[:displayalerts].should be true
|
1441
1445
|
excel4.Visible.should be false
|
1442
|
-
excel4.visible.should be false
|
1446
|
+
excel4.properties[:visible].should be false
|
1443
1447
|
excel5 = Excel.current(:displayalerts => false)
|
1444
1448
|
excel5.should === excel
|
1445
1449
|
excel5.DisplayAlerts.should be false
|
1446
|
-
excel5.displayalerts.should be false
|
1450
|
+
excel5.properties[:displayalerts].should be false
|
1447
1451
|
excel5.Visible.should be false
|
1448
|
-
excel5.visible.should be false
|
1452
|
+
excel5.properties[:visible].should be false
|
1449
1453
|
end
|
1450
1454
|
|
1451
1455
|
it "should set Excel visible and displayalerts" do
|
1452
1456
|
excel = Excel.new(:reuse => false, :visible => true, :displayalerts => true)
|
1453
1457
|
excel.DisplayAlerts.should be true
|
1454
|
-
excel.displayalerts.should be true
|
1458
|
+
excel.properties[:displayalerts].should be true
|
1455
1459
|
excel.Visible.should be true
|
1456
|
-
excel.visible.should be true
|
1460
|
+
excel.properties[:visible].should be true
|
1457
1461
|
excel6 = Excel.current
|
1458
1462
|
excel6.should === excel
|
1459
1463
|
excel6.DisplayAlerts.should be true
|
1460
|
-
excel6.displayalerts.should be true
|
1464
|
+
excel6.properties[:displayalerts].should be true
|
1461
1465
|
excel6.Visible.should be true
|
1462
|
-
excel6.visible.should be true
|
1466
|
+
excel6.properties[:visible].should be true
|
1463
1467
|
excel.displayalerts = false
|
1464
1468
|
excel.DisplayAlerts.should be false
|
1465
|
-
excel.displayalerts.should be false
|
1469
|
+
excel.properties[:displayalerts].should be false
|
1466
1470
|
excel.Visible.should be true
|
1467
|
-
excel.visible.should be true
|
1471
|
+
excel.properties[:visible].should be true
|
1468
1472
|
excel7 = Excel.current
|
1469
1473
|
excel7.should === excel
|
1470
1474
|
excel7.DisplayAlerts.should be false
|
1471
|
-
excel7.displayalerts.should be false
|
1475
|
+
excel7.properties[:displayalerts].should be false
|
1472
1476
|
excel7.Visible.should be true
|
1473
|
-
excel7.visible.should be true
|
1477
|
+
excel7.properties[:visible].should be true
|
1474
1478
|
excel2 = Excel.new(:reuse => false, :visible => true, :displayalerts => true)
|
1475
1479
|
excel2.visible = false
|
1476
1480
|
excel2.DisplayAlerts.should be true
|
1477
|
-
excel2.displayalerts.should be true
|
1481
|
+
excel2.properties[:displayalerts].should be true
|
1478
1482
|
excel2.Visible.should be false
|
1479
|
-
excel2.visible.should be false
|
1483
|
+
excel2.properties[:visible].should be false
|
1480
1484
|
excel3 = Excel.new(:reuse => false, :visible => true, :displayalerts => false)
|
1481
1485
|
excel3.Visible.should be true
|
1482
1486
|
excel3.DisplayAlerts.should be false
|
@@ -1488,21 +1492,21 @@ module RobustExcelOle
|
|
1488
1492
|
excel3.DisplayAlerts.should be false
|
1489
1493
|
excel4 = Excel.create(:visible => true, :displayalerts => true)
|
1490
1494
|
excel4.DisplayAlerts.should be true
|
1491
|
-
excel4.displayalerts.should be true
|
1495
|
+
excel4.properties[:displayalerts].should be true
|
1492
1496
|
excel4.Visible.should be true
|
1493
|
-
excel4.visible.should be true
|
1497
|
+
excel4.properties[:visible].should be true
|
1494
1498
|
excel5 = Excel.current(:visible => true, :displayalerts => false)
|
1495
1499
|
excel5.should === excel
|
1496
1500
|
excel5.DisplayAlerts.should be false
|
1497
|
-
excel5.displayalerts.should be false
|
1501
|
+
excel5.properties[:displayalerts].should be false
|
1498
1502
|
excel5.Visible.should be true
|
1499
|
-
excel5.visible.should be true
|
1503
|
+
excel5.properties[:visible].should be true
|
1500
1504
|
excel6 = Excel.current(:visible => false, :displayalerts => true)
|
1501
1505
|
excel6.should === excel
|
1502
1506
|
excel6.DisplayAlerts.should be true
|
1503
|
-
excel6.displayalerts.should be true
|
1507
|
+
excel6.properties[:displayalerts].should be true
|
1504
1508
|
excel6.Visible.should be false
|
1505
|
-
excel6.visible.should be false
|
1509
|
+
excel6.properties[:visible].should be false
|
1506
1510
|
end
|
1507
1511
|
|
1508
1512
|
it "should work with displayalerts == if_visible" do
|
@@ -1623,17 +1627,17 @@ module RobustExcelOle
|
|
1623
1627
|
|
1624
1628
|
it "should create and reuse Excel with calculation mode" do
|
1625
1629
|
excel1 = Excel.create(:calculation => :manual)
|
1626
|
-
excel1.calculation.should == :manual
|
1630
|
+
excel1.properties[:calculation].should == :manual
|
1627
1631
|
excel2 = Excel.create(:calculation => :automatic)
|
1628
|
-
excel2.calculation.should == :automatic
|
1632
|
+
excel2.properties[:calculation].should == :automatic
|
1629
1633
|
excel3 = Excel.current
|
1630
|
-
excel3.calculation.should == :manual
|
1634
|
+
excel3.properties[:calculation].should == :manual
|
1631
1635
|
excel4 = Excel.current(:calculation => :automatic)
|
1632
|
-
excel4.calculation.should == :automatic
|
1636
|
+
excel4.properties[:calculation].should == :automatic
|
1633
1637
|
excel5 = Excel.new(:reuse => false)
|
1634
|
-
excel5.calculation.should == nil
|
1638
|
+
excel5.properties[:calculation].should == nil
|
1635
1639
|
excel6 = Excel.new(:reuse => false, :calculation => :manual)
|
1636
|
-
excel6.calculation.should == :manual
|
1640
|
+
excel6.properties[:calculation].should == :manual
|
1637
1641
|
end
|
1638
1642
|
|
1639
1643
|
=begin
|
@@ -1657,11 +1661,11 @@ module RobustExcelOle
|
|
1657
1661
|
old_calculation_mode = @excel1.Calculation
|
1658
1662
|
old_calculatebeforesave = @excel1.CalculateBeforeSave
|
1659
1663
|
@excel1.calculation = :automatic
|
1660
|
-
@excel1.calculation.should == :automatic
|
1664
|
+
@excel1.properties[:calculation].should == :automatic
|
1661
1665
|
@excel1.Calculation.should == old_calculation_mode
|
1662
1666
|
@excel1.CalculateBeforeSave.should == old_calculatebeforesave
|
1663
1667
|
@excel1.calculation = :manual
|
1664
|
-
@excel1.calculation.should == :manual
|
1668
|
+
@excel1.properties[:calculation].should == :manual
|
1665
1669
|
@excel1.Calculation.should == old_calculation_mode
|
1666
1670
|
@excel1.CalculateBeforeSave.should == old_calculatebeforesave
|
1667
1671
|
end
|
@@ -1673,7 +1677,7 @@ module RobustExcelOle
|
|
1673
1677
|
book1 = Workbook.open(@simple_file1, :visible => false)
|
1674
1678
|
expect( book1.Windows(1).Visible ).to be true # false
|
1675
1679
|
expect { excel1.calculation = :manual
|
1676
|
-
}.to change{ excel1.calculation
|
1680
|
+
}.to change{ excel1.properties[:calculation]
|
1677
1681
|
}.from( :automatic
|
1678
1682
|
).to( :manual )
|
1679
1683
|
end
|
@@ -1683,7 +1687,7 @@ module RobustExcelOle
|
|
1683
1687
|
book1 = Workbook.open(@simple_file1, :visible => false)
|
1684
1688
|
expect( book1.Windows(1).Visible ).to be true # false
|
1685
1689
|
expect { excel1.calculation = :automatic
|
1686
|
-
}.to change{ excel1.calculation
|
1690
|
+
}.to change{ excel1.properties[:calculation]
|
1687
1691
|
}.from( :manual
|
1688
1692
|
).to( :automatic )
|
1689
1693
|
end
|
@@ -1694,7 +1698,7 @@ module RobustExcelOle
|
|
1694
1698
|
book = Workbook.open(@simple_file, :visible => true)
|
1695
1699
|
old_calculation_mode = @excel1.Calculation
|
1696
1700
|
@excel1.with_calculation(:manual) do
|
1697
|
-
@excel1.calculation.should == :manual
|
1701
|
+
@excel1.properties[:calculation].should == :manual
|
1698
1702
|
@excel1.Calculation.should == XlCalculationManual
|
1699
1703
|
@excel1.CalculateBeforeSave.should be false
|
1700
1704
|
book.Saved.should be true
|
@@ -1702,7 +1706,7 @@ module RobustExcelOle
|
|
1702
1706
|
@excel1.Calculation.should == old_calculation_mode
|
1703
1707
|
@excel1.CalculateBeforeSave.should be false
|
1704
1708
|
@excel1.with_calculation(:automatic) do
|
1705
|
-
@excel1.calculation.should == :automatic
|
1709
|
+
@excel1.properties[:calculation].should == :automatic
|
1706
1710
|
@excel1.Calculation.should == XlCalculationAutomatic
|
1707
1711
|
@excel1.CalculateBeforeSave.should be false
|
1708
1712
|
book.Saved.should be false
|
@@ -1717,7 +1721,7 @@ module RobustExcelOle
|
|
1717
1721
|
book.Saved.should be true
|
1718
1722
|
book.Windows(book.Name).Visible = true
|
1719
1723
|
@excel1.calculation = :manual
|
1720
|
-
@excel1.calculation.should == :manual
|
1724
|
+
@excel1.properties[:calculation].should == :manual
|
1721
1725
|
@excel1.Calculation.should == XlCalculationManual
|
1722
1726
|
@excel1.CalculateBeforeSave.should be false
|
1723
1727
|
book.Saved.should be true
|
@@ -1728,7 +1732,7 @@ module RobustExcelOle
|
|
1728
1732
|
book = Workbook.open(@simple_file, :visible => true)
|
1729
1733
|
book.Saved.should be true
|
1730
1734
|
@excel1.calculation = :automatic
|
1731
|
-
@excel1.calculation.should == :automatic
|
1735
|
+
@excel1.properties[:calculation].should == :automatic
|
1732
1736
|
@excel1.Calculation.should == XlCalculationAutomatic
|
1733
1737
|
@excel1.CalculateBeforeSave.should be false
|
1734
1738
|
book.Saved.should be true
|
@@ -1741,7 +1745,7 @@ module RobustExcelOle
|
|
1741
1745
|
book.Saved.should be false
|
1742
1746
|
book.Windows(book.Name).Visible = true
|
1743
1747
|
@excel1.calculation = :manual
|
1744
|
-
@excel1.calculation.should == :manual
|
1748
|
+
@excel1.properties[:calculation].should == :manual
|
1745
1749
|
@excel1.Calculation.should == XlCalculationManual
|
1746
1750
|
@excel1.CalculateBeforeSave.should be false
|
1747
1751
|
book.Saved.should be false
|
@@ -1753,7 +1757,7 @@ module RobustExcelOle
|
|
1753
1757
|
book.sheet(1)[1,1] = "foo"
|
1754
1758
|
book.Saved.should be false
|
1755
1759
|
@excel1.calculation = :automatic
|
1756
|
-
@excel1.calculation.should == :automatic
|
1760
|
+
@excel1.properties[:calculation].should == :automatic
|
1757
1761
|
@excel1.Calculation.should == XlCalculationAutomatic
|
1758
1762
|
@excel1.CalculateBeforeSave.should be false
|
1759
1763
|
book.Saved.should be false
|
@@ -1770,7 +1774,7 @@ module RobustExcelOle
|
|
1770
1774
|
@excel1 = Excel.new
|
1771
1775
|
b = Workbook.open(@simple_file, :visible => true)
|
1772
1776
|
@excel1.Calculation = XlCalculationManual
|
1773
|
-
@excel1.calculation.should == :manual
|
1777
|
+
@excel1.properties[:calculation].should == :manual
|
1774
1778
|
@excel1.Calculation.should == XlCalculationManual
|
1775
1779
|
end
|
1776
1780
|
|
@@ -1778,7 +1782,7 @@ module RobustExcelOle
|
|
1778
1782
|
@excel1 = Excel.new
|
1779
1783
|
b = Workbook.open(@simple_file, :visible => true)
|
1780
1784
|
@excel1.Calculation = XlCalculationAutomatic
|
1781
|
-
@excel1.calculation.should == :automatic
|
1785
|
+
@excel1.properties[:calculation].should == :automatic
|
1782
1786
|
@excel1.Calculation.should == XlCalculationAutomatic
|
1783
1787
|
end
|
1784
1788
|
|
@@ -1922,14 +1926,14 @@ module RobustExcelOle
|
|
1922
1926
|
@excel2.Hwnd.should == @excel2.hwnd
|
1923
1927
|
end
|
1924
1928
|
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
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
|
1933
1937
|
|
1934
1938
|
=begin
|
1935
1939
|
# does not work yet
|
@@ -2015,242 +2019,6 @@ module RobustExcelOle
|
|
2015
2019
|
|
2016
2020
|
end
|
2017
2021
|
end
|
2018
|
-
|
2019
|
-
context "setting the name of a range" do
|
2020
|
-
|
2021
|
-
before do
|
2022
|
-
@book1 = Workbook.open(@dir + '/another_workbook.xls', :read_only => true, :visible => true)
|
2023
|
-
@book1.excel.displayalerts = false
|
2024
|
-
@excel1 = @book1.excel
|
2025
|
-
end
|
2026
|
-
|
2027
|
-
after do
|
2028
|
-
@book1.close
|
2029
|
-
end
|
2030
|
-
|
2031
|
-
it "should name an unnamed range with a giving address" do
|
2032
|
-
@excel1.add_name("foo",[1,2])
|
2033
|
-
@excel1.Names.Item("foo").Name.should == "foo"
|
2034
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$B$1:$B$1"
|
2035
|
-
end
|
2036
|
-
|
2037
|
-
it "should rename an already named range with a giving address" do
|
2038
|
-
@excel1.add_name("foo",[1,1])
|
2039
|
-
@excel1.Names.Item("foo").Name.should == "foo"
|
2040
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$A$1:$A$1"
|
2041
|
-
end
|
2042
|
-
|
2043
|
-
it "should raise an error" do
|
2044
|
-
expect{
|
2045
|
-
@excel1.add_name("foo", [-2, 1])
|
2046
|
-
}.to raise_error(RangeNotEvaluatable, /cannot add name "foo" to range/)
|
2047
|
-
end
|
2048
|
-
|
2049
|
-
it "should rename a range" do
|
2050
|
-
@excel1.add_name("foo",[1,1])
|
2051
|
-
@excel1.rename_range("foo","bar")
|
2052
|
-
@excel1.namevalue_glob("bar").should == "foo"
|
2053
|
-
end
|
2054
|
-
|
2055
|
-
it "should delete a name of a range" do
|
2056
|
-
@excel1.add_name("foo",[1,1])
|
2057
|
-
@excel1.delete_name("foo")
|
2058
|
-
expect{
|
2059
|
-
@excel1.namevalue_glob("foo")
|
2060
|
-
}.to raise_error(NameNotFound, /name "foo"/)
|
2061
|
-
end
|
2062
|
-
|
2063
|
-
it "should add a name of a rectangular range" do
|
2064
|
-
@excel1.add_name("foo",[1..3,1..4])
|
2065
|
-
@excel1["foo"].should == [["foo", "workbook", "sheet1", nil], ["foo", 1.0, 2.0, 4.0], ["matz", 3.0, 4.0, 4.0]]
|
2066
|
-
end
|
2067
|
-
|
2068
|
-
it "should accept the old interface" do
|
2069
|
-
@excel1.add_name("foo",1..3,1..4)
|
2070
|
-
@excel1["foo"].should == [["foo", "workbook", "sheet1", nil], ["foo", 1.0, 2.0, 4.0], ["matz", 3.0, 4.0, 4.0]]
|
2071
|
-
end
|
2072
|
-
|
2073
|
-
it "should add a name of an infinite row range" do
|
2074
|
-
@excel1.add_name("foo",[1..3, nil])
|
2075
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$1:$3"
|
2076
|
-
end
|
2077
|
-
|
2078
|
-
it "should add a name of an infinite column range" do
|
2079
|
-
@excel1.add_name("foo",[nil, "A".."C"])
|
2080
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$A:$C"
|
2081
|
-
end
|
2082
|
-
|
2083
|
-
it "should add a name of an infinite row range" do
|
2084
|
-
@excel1.add_name("foo",[nil, 1..3])
|
2085
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$A:$C"
|
2086
|
-
end
|
2087
|
-
|
2088
|
-
it "should add a name of an infinite column range" do
|
2089
|
-
@excel1.add_name("foo",["A:C"])
|
2090
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$A:$C"
|
2091
|
-
end
|
2092
|
-
|
2093
|
-
it "should add a name of an infinite column range" do
|
2094
|
-
@excel1.add_name("foo",["1:2"])
|
2095
|
-
@excel1.Names.Item("foo").Value.should == "=Sheet1!$1:$2"
|
2096
|
-
end
|
2097
|
-
|
2098
|
-
end
|
2099
|
-
|
2100
|
-
|
2101
|
-
describe "namevalue_glob, set_namevalue_glob" do
|
2102
|
-
|
2103
|
-
before do
|
2104
|
-
@book1 = Workbook.open(@dir + '/another_workbook.xls')
|
2105
|
-
@book1.Windows(@book1.Name).Visible = true
|
2106
|
-
@excel1 = @book1.excel
|
2107
|
-
end
|
2108
|
-
|
2109
|
-
after do
|
2110
|
-
@book1.close(:if_unsaved => :forget)
|
2111
|
-
end
|
2112
|
-
|
2113
|
-
it "should return value of a defined name" do
|
2114
|
-
@excel1.namevalue_glob("firstcell").should == "foo"
|
2115
|
-
@excel1["firstcell"].should == "foo"
|
2116
|
-
end
|
2117
|
-
|
2118
|
-
#it "should evaluate a formula" do
|
2119
|
-
# @excel1.namevalue_glob("named_formula").should == 4
|
2120
|
-
# @excel1["named_formula"].should == 4
|
2121
|
-
#end
|
2122
|
-
|
2123
|
-
it "should raise an error if name not defined" do
|
2124
|
-
expect {
|
2125
|
-
@excel1.namevalue_glob("foo")
|
2126
|
-
}.to raise_error(NameNotFound, /name "foo"/)
|
2127
|
-
expect {
|
2128
|
-
@excel1["foo"]
|
2129
|
-
}.to raise_error(NameNotFound, /name "foo"/)
|
2130
|
-
expect {
|
2131
|
-
excel2 = Excel.create
|
2132
|
-
excel2.namevalue_glob("one")
|
2133
|
-
}.to raise_error(NameNotFound, /name "one"/)
|
2134
|
-
expect {
|
2135
|
-
excel3 = Excel.create(:visible => true)
|
2136
|
-
excel3["one"]
|
2137
|
-
}.to raise_error(NameNotFound, /name "one"/)
|
2138
|
-
end
|
2139
|
-
|
2140
|
-
it "should set a range to a value" do
|
2141
|
-
@excel1.namevalue_glob("firstcell").should == "foo"
|
2142
|
-
@excel1.set_namevalue_glob("firstcell","bar")
|
2143
|
-
@excel1.namevalue_glob("firstcell").should == "bar"
|
2144
|
-
@excel1["firstcell"] = "foo"
|
2145
|
-
@excel1.namevalue_glob("firstcell").should == "foo"
|
2146
|
-
end
|
2147
|
-
|
2148
|
-
it "should raise an error if name cannot be evaluated" do
|
2149
|
-
expect{
|
2150
|
-
@excel1.set_namevalue_glob("foo", 1)
|
2151
|
-
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo"/)
|
2152
|
-
expect{
|
2153
|
-
@excel1["foo"] = 1
|
2154
|
-
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo"/)
|
2155
|
-
end
|
2156
|
-
|
2157
|
-
it "should color the cell (deprecated)" do
|
2158
|
-
@excel1.set_namevalue_glob("firstcell", "foo")
|
2159
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == -4142
|
2160
|
-
@excel1.set_namevalue_glob("firstcell", "foo", :color => 4)
|
2161
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 4
|
2162
|
-
@excel1["firstcell"].should == "foo"
|
2163
|
-
@excel1["firstcell"] = "foo"
|
2164
|
-
@excel1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 42
|
2165
|
-
@book1.save
|
2166
|
-
end
|
2167
|
-
|
2168
|
-
it "should color the cell" do
|
2169
|
-
@excel1.set_namevalue_glob("firstcell", "foo")
|
2170
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == -4142
|
2171
|
-
@book1.color_if_modified = 4
|
2172
|
-
@excel1.set_namevalue_glob("firstcell", "foo")
|
2173
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 4
|
2174
|
-
@excel1["firstcell"].should == "foo"
|
2175
|
-
@excel1["firstcell"] = "foo"
|
2176
|
-
@excel1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 42
|
2177
|
-
@book1.save
|
2178
|
-
end
|
2179
|
-
|
2180
|
-
|
2181
|
-
end
|
2182
|
-
|
2183
|
-
describe "namevalue, set_namevalue" do
|
2184
|
-
|
2185
|
-
before do
|
2186
|
-
@book1 = Workbook.open(@another_simple_file)
|
2187
|
-
@excel1 = @book1.excel
|
2188
|
-
# for some reason the workbook must be visible
|
2189
|
-
@book1.visible = true
|
2190
|
-
end
|
2191
|
-
|
2192
|
-
after do
|
2193
|
-
@book1.close(:if_unsaved => :forget)
|
2194
|
-
end
|
2195
|
-
|
2196
|
-
it "should return value of a locally defined name" do
|
2197
|
-
@excel1.namevalue("firstcell").should == "foo"
|
2198
|
-
end
|
2199
|
-
|
2200
|
-
it "should return value of a defined name" do
|
2201
|
-
@excel1.namevalue("new").should == "foo"
|
2202
|
-
@excel1.namevalue("one").should == 1.0
|
2203
|
-
@excel1.namevalue("four").should == [[1,2],[3,4]]
|
2204
|
-
@excel1.namevalue("firstrow").should == [[1,2]]
|
2205
|
-
end
|
2206
|
-
|
2207
|
-
it "should return default value if name not defined and default value is given" do
|
2208
|
-
@excel1.namevalue("foo", :default => 2).should == 2
|
2209
|
-
end
|
2210
|
-
|
2211
|
-
it "should raise an error if name not defined for the sheet" do
|
2212
|
-
expect {
|
2213
|
-
@excel1.namevalue("foo")
|
2214
|
-
}.to raise_error(NameNotFound, /name "foo" not in/)
|
2215
|
-
expect {
|
2216
|
-
@excel1.namevalue("named_formula")
|
2217
|
-
}.to raise_error(NameNotFound, /name "named_formula" not in/)
|
2218
|
-
expect {
|
2219
|
-
excel2 = Excel.create
|
2220
|
-
excel2.namevalue("one")
|
2221
|
-
}.to raise_error(NameNotFound, /name "one" not in/)
|
2222
|
-
end
|
2223
|
-
|
2224
|
-
it "should set a range to a value" do
|
2225
|
-
@excel1.namevalue("firstcell").should == "foo"
|
2226
|
-
@excel1.set_namevalue("firstcell","bar")
|
2227
|
-
@excel1.namevalue("firstcell").should == "bar"
|
2228
|
-
end
|
2229
|
-
|
2230
|
-
it "should raise an error if name cannot be evaluated" do
|
2231
|
-
expect{
|
2232
|
-
@excel1.set_namevalue_glob("foo", 1)
|
2233
|
-
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo" in/)
|
2234
|
-
end
|
2235
|
-
|
2236
|
-
it "should color the cell (depracated)" do
|
2237
|
-
@excel1.set_namevalue("firstcell", "foo")
|
2238
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == -4142
|
2239
|
-
@excel1.set_namevalue("firstcell", "foo", :color => 4)
|
2240
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 4
|
2241
|
-
end
|
2242
|
-
|
2243
|
-
it "should color the cell" do
|
2244
|
-
@excel1.set_namevalue("firstcell", "foo")
|
2245
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == -4142
|
2246
|
-
@book1.color_if_modified = 4
|
2247
|
-
@excel1.set_namevalue("firstcell", "foo")
|
2248
|
-
@book1.Names.Item("firstcell").RefersToRange.Interior.ColorIndex.should == 4
|
2249
|
-
end
|
2250
|
-
|
2251
|
-
|
2252
|
-
end
|
2253
|
-
|
2254
2022
|
end
|
2255
2023
|
end
|
2256
2024
|
|