robust_excel_ole 1.8 → 1.9
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 +5 -5
- data/Changelog +8 -0
- data/README.rdoc +17 -3
- data/docs/README_excel.rdoc +23 -0
- data/docs/README_ranges.rdoc +73 -5
- data/examples/modifying_sheets/example_add_names.rb +57 -0
- data/examples/modifying_sheets/example_adding_sheets.rb +1 -1
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +1 -1
- data/examples/open_save_close/example_if_unsaved_forget.rb +1 -1
- data/examples/open_save_close/example_reuse.rb +1 -1
- data/lib/robust_excel_ole.rb +2 -0
- data/lib/robust_excel_ole/address.rb +114 -0
- data/lib/robust_excel_ole/excel.rb +81 -53
- data/lib/robust_excel_ole/general.rb +37 -3
- data/lib/robust_excel_ole/range.rb +20 -20
- data/lib/robust_excel_ole/range_owners.rb +236 -0
- data/lib/robust_excel_ole/reo_common.rb +18 -276
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +177 -91
- data/lib/robust_excel_ole/worksheet.rb +12 -4
- data/reo.bat +1 -1
- data/spec/address_spec.rb +174 -0
- data/spec/data/another_workbook.xls +0 -0
- data/spec/data/different_workbook.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +168 -29
- data/spec/reo_common_spec.rb +0 -103
- data/spec/workbook_spec.rb +12 -2
- data/spec/workbook_specs/workbook_close_spec.rb +2 -1
- data/spec/workbook_specs/workbook_misc_spec.rb +41 -7
- data/spec/workbook_specs/workbook_open_spec.rb +8 -3
- data/spec/workbook_specs/workbook_save_spec.rb +5 -3
- data/spec/worksheet_spec.rb +83 -10
- metadata +7 -3
data/reo.bat
CHANGED
@@ -0,0 +1,174 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), './spec_helper')
|
4
|
+
require File.expand_path( '../../lib/robust_excel_ole/reo_common', __FILE__)
|
5
|
+
|
6
|
+
$VERBOSE = nil
|
7
|
+
|
8
|
+
include General
|
9
|
+
include RobustExcelOle
|
10
|
+
|
11
|
+
module RobustExcelOle
|
12
|
+
|
13
|
+
describe Address do
|
14
|
+
|
15
|
+
before(:all) do
|
16
|
+
excel = Excel.new(:reuse => true)
|
17
|
+
open_books = excel == nil ? 0 : excel.Workbooks.Count
|
18
|
+
puts "*** open books *** : #{open_books}" if open_books > 0
|
19
|
+
Excel.kill_all
|
20
|
+
@dir = create_tmpdir
|
21
|
+
@simple_file = @dir + '/workbook.xls'
|
22
|
+
@book = Workbook.open(@simple_file)
|
23
|
+
end
|
24
|
+
|
25
|
+
after(:all) do
|
26
|
+
@book.close
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should transform relative r1c1-reference into r1c1-format" do
|
30
|
+
Address.r1c1("Z1S[2]:Z[-1]S4").should == "Z1S(2):Z(-1)S4"
|
31
|
+
Address.r1c1("Z[1]S2:Z3S[4]").should == "Z(1)S2:Z3S(4)"
|
32
|
+
Address.r1c1("Z1S[2]").should == "Z1S(2)"
|
33
|
+
Address.r1c1("Z[-1]S4").should == "Z(-1)S4"
|
34
|
+
Address.r1c1("Z[3]").should == "Z(3)"
|
35
|
+
Address.r1c1("S[-2]").should == "S(-2)"
|
36
|
+
end
|
37
|
+
|
38
|
+
# test for 1.8.6
|
39
|
+
it "should transform relative int_range-reference into r1c1-format" do
|
40
|
+
Address.r1c1([1..2,[3]..4]).should == "Z1S(3):Z2S4"
|
41
|
+
Address.r1c1([[1]..2,3..4]).should == "Z(1)S3:Z2S4"
|
42
|
+
Address.r1c1([[1]..2,nil]).should == "Z(1):Z2"
|
43
|
+
Address.r1c1([nil,[1]..2]).should == "S(1):S2"
|
44
|
+
Address.r1c1([nil,[1]]).should == "S(1):S(1)"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should transform relative int_range-reference into r1c1-format" do
|
48
|
+
Address.r1c1([1..[-2],[3]..4]).should == "Z1S(3):Z(-2)S4"
|
49
|
+
Address.r1c1([[1]..2,3..[4]]).should == "Z(1)S3:Z2S(4)"
|
50
|
+
Address.r1c1([1..[-2],nil]).should == "Z1:Z(-2)"
|
51
|
+
Address.r1c1([nil,[-1]..2]).should == "S(-1):S2"
|
52
|
+
Address.r1c1([[3]..[3],nil]).should == "Z(3):Z(3)"
|
53
|
+
Address.r1c1([nil,[-2]..[-2]]).should == "S(-2):S(-2)"
|
54
|
+
Address.r1c1([[3],nil]).should == "Z(3):Z(3)"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should transform relative r1c1-reference into r1c1-format" do
|
58
|
+
Address.int_range("Z1S[2]:Z[3]S4").should == [1..[3],[2]..4]
|
59
|
+
Address.int_range("Z[1]S2:Z3S[4]").should == [[1]..3,2..[4]]
|
60
|
+
Address.int_range("Z1S[2]").should == [1..1,[2]..[2]]
|
61
|
+
Address.int_range("Z[3]S4").should == [[3]..[3],4..4]
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should transform a1-format" do
|
65
|
+
Address.a1("A2").should == "A2"
|
66
|
+
Address.r1c1("A2").should == "Z2S1:Z2S1"
|
67
|
+
Address.int_range("A2").should == [2..2,1..1]
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should transform several-letter-a1-format" do
|
71
|
+
Address.a1("ABO15").should == "ABO15"
|
72
|
+
Address.r1c1("ABO15").should == "Z15S743:Z15S743"
|
73
|
+
Address.int_range("ABO15").should == [15..15,743..743]
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should transform complex a1-format" do
|
77
|
+
Address.a1("A2:B3").should == "A2:B3"
|
78
|
+
Address.r1c1("A2:B3").should == "Z2S1:Z3S2"
|
79
|
+
Address.int_range("A2:B3").should == [2..3,1..2]
|
80
|
+
Address.a1("S1:DP2").should == "S1:DP2"
|
81
|
+
Address.r1c1("S1:DP2").should == "Z1S19:Z2S120"
|
82
|
+
Address.int_range("S1:DP2").should == [1..2,19..120]
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should transform infinite a1-format" do
|
86
|
+
Address.a1("A:B").should == "A:B"
|
87
|
+
Address.r1c1("A:B").should == "S1:S2"
|
88
|
+
Address.int_range("A:B").should == [nil,1..2]
|
89
|
+
Address.a1("1:3").should == "1:3"
|
90
|
+
Address.r1c1("1:3").should == "Z1:Z3"
|
91
|
+
Address.int_range("1:3").should == [1..3,nil]
|
92
|
+
Address.a1("B").should == "B"
|
93
|
+
Address.r1c1("B").should == "S2:S2"
|
94
|
+
Address.int_range("B").should == [nil,2..2]
|
95
|
+
Address.a1("3").should == "3"
|
96
|
+
Address.r1c1("3").should == "Z3:Z3"
|
97
|
+
Address.int_range("3").should == [3..3,nil]
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should transform r1c1-format" do
|
101
|
+
Address.r1c1("Z2S1").should == "Z2S1"
|
102
|
+
Address.int_range("Z2S1").should == [2..2,1..1]
|
103
|
+
expect{
|
104
|
+
Address.a1("Z2S1")
|
105
|
+
}.to raise_error(NotImplementedREOError)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should transform complex r1c1-format" do
|
109
|
+
Address.r1c1("Z2S1:Z3S2").should == "Z2S1:Z3S2"
|
110
|
+
Address.int_range("Z2S1:Z3S2").should == [2..3,1..2]
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should transform int_range format" do
|
114
|
+
Address.int_range([2..2,1..1]).should == [2..2,1..1]
|
115
|
+
Address.r1c1([2..2,1..1]).should == "Z2S1:Z2S1"
|
116
|
+
expect{
|
117
|
+
Address.a1([2..2,1..1])
|
118
|
+
}.to raise_error(NotImplementedREOError)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should transform simple int_range format" do
|
122
|
+
Address.int_range([2,1]).should == [2..2,1..1]
|
123
|
+
Address.r1c1([2,1]).should == "Z2S1:Z2S1"
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should transform complex int_range format" do
|
127
|
+
Address.int_range([2,"A"]).should == [2..2,1..1]
|
128
|
+
Address.r1c1([2,"A"]).should == "Z2S1:Z2S1"
|
129
|
+
Address.int_range([2,"A".."B"]).should == [2..2,1..2]
|
130
|
+
Address.r1c1([2,"A".."B"]).should == "Z2S1:Z2S2"
|
131
|
+
Address.int_range([1..2,"C"]).should == [1..2,3..3]
|
132
|
+
Address.r1c1([1..2,"C"]).should == "Z1S3:Z2S3"
|
133
|
+
Address.int_range([1..2,"C".."E"]).should == [1..2,3..5]
|
134
|
+
Address.r1c1([1..2,"C".."E"]).should == "Z1S3:Z2S5"
|
135
|
+
Address.int_range([2,3..5]).should == [2..2,3..5]
|
136
|
+
Address.r1c1([2,3..5]).should == "Z2S3:Z2S5"
|
137
|
+
Address.int_range([1..2,3..5]).should == [1..2,3..5]
|
138
|
+
Address.r1c1([1..2,3..5]).should == "Z1S3:Z2S5"
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should transform infinite int_range format" do
|
142
|
+
Address.int_range([nil,1..2]).should == [nil,1..2]
|
143
|
+
Address.r1c1([nil,1..2]).should == "S1:S2"
|
144
|
+
Address.int_range([1..3,nil]).should == [1..3,nil]
|
145
|
+
Address.r1c1([1..3,nil]).should == "Z1:Z3"
|
146
|
+
Address.int_range([nil,2]).should == [nil,2..2]
|
147
|
+
Address.r1c1([nil,2]).should == "S2:S2"
|
148
|
+
Address.int_range([3,nil]).should == [3..3,nil]
|
149
|
+
Address.r1c1([3,nil]).should == "Z3:Z3"
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should raise an error" do
|
153
|
+
expect{
|
154
|
+
Address.a1("1A")
|
155
|
+
}.to raise_error(AddressInvalid, /format not correct/)
|
156
|
+
expect{
|
157
|
+
Address.r1c1("A1B")
|
158
|
+
}.to raise_error(AddressInvalid, /format not correct/)
|
159
|
+
#expect{
|
160
|
+
# Address.int_range(["A".."B","C".."D"])
|
161
|
+
#}.to raise_error(AddressInvalid, /format not correct/)
|
162
|
+
#expect{
|
163
|
+
# Address.int_range(["A".."B",1..2])
|
164
|
+
#}.to raise_error(AddressInvalid, /format not correct/)
|
165
|
+
#expect{
|
166
|
+
# Address.int_range(["A".."B",nil])
|
167
|
+
#}.to raise_error(AddressInvalid, /format not correct/)
|
168
|
+
expect{
|
169
|
+
Address.int_range(["A",1,2])
|
170
|
+
}.to raise_error(AddressInvalid, /more than two components/)
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
end
|
Binary file
|
Binary file
|
data/spec/data/workbook.xls
CHANGED
Binary file
|
data/spec/excel_spec.rb
CHANGED
@@ -538,7 +538,9 @@ module RobustExcelOle
|
|
538
538
|
it "should close the first Excel without unsaved workbooks and then raise an error" do
|
539
539
|
expect{
|
540
540
|
Excel.close_all(:if_unsaved => :raise)
|
541
|
-
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks"
|
541
|
+
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks" +
|
542
|
+
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
543
|
+
Excel instance without or with saving the unsaved workbooks before, respectively")
|
542
544
|
sleep 0.2
|
543
545
|
@excel1.should_not be_alive
|
544
546
|
@excel2.should be_alive
|
@@ -551,7 +553,9 @@ module RobustExcelOle
|
|
551
553
|
it "should close the first Excel without unsaved workbooks and then raise an error" do
|
552
554
|
expect{
|
553
555
|
Excel.close_all
|
554
|
-
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks"
|
556
|
+
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks" +
|
557
|
+
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
558
|
+
Excel instance without or with saving the unsaved workbooks before, respectively")
|
555
559
|
sleep 0.2
|
556
560
|
@excel1.should_not be_alive
|
557
561
|
@excel2.should be_alive
|
@@ -588,7 +592,8 @@ module RobustExcelOle
|
|
588
592
|
it "should raise an error for invalid option" do
|
589
593
|
expect {
|
590
594
|
Excel.close_all(:if_unsaved => :invalid_option)
|
591
|
-
}.to raise_error(OptionInvalid, ":if_unsaved: invalid option: :invalid_option"
|
595
|
+
}.to raise_error(OptionInvalid, ":if_unsaved: invalid option: :invalid_option" +
|
596
|
+
"\nHint: Valid values are :raise, :forget, :save and :alert")
|
592
597
|
end
|
593
598
|
end
|
594
599
|
|
@@ -605,7 +610,9 @@ module RobustExcelOle
|
|
605
610
|
it "should close the 1st and 3rd Excel instances that have saved workbooks" do
|
606
611
|
expect{
|
607
612
|
Excel.close_all(:if_unsaved => :raise)
|
608
|
-
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks"
|
613
|
+
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks" +
|
614
|
+
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
615
|
+
Excel instance without or with saving the unsaved workbooks before, respectively")
|
609
616
|
sleep 0.2
|
610
617
|
@book1.excel.should_not be_alive
|
611
618
|
@book2.excel.should be_alive
|
@@ -630,7 +637,9 @@ module RobustExcelOle
|
|
630
637
|
it "should close three Excel instances that have saved workbooks" do
|
631
638
|
expect{
|
632
639
|
Excel.close_all(:if_unsaved => :raise)
|
633
|
-
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks"
|
640
|
+
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks" +
|
641
|
+
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
642
|
+
Excel instance without or with saving the unsaved workbooks before, respectively")
|
634
643
|
sleep 0.2
|
635
644
|
expect{
|
636
645
|
@ole_xl.Name
|
@@ -708,13 +717,17 @@ module RobustExcelOle
|
|
708
717
|
it "should raise an error" do
|
709
718
|
expect{
|
710
719
|
@excel.close(:if_unsaved => :raise)
|
711
|
-
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks"
|
720
|
+
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks" +
|
721
|
+
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
722
|
+
Excel instance without or with saving the unsaved workbooks before, respectively")
|
712
723
|
end
|
713
724
|
|
714
725
|
it "should raise an error per default" do
|
715
726
|
expect{
|
716
727
|
@excel.close(:if_unsaved => :raise)
|
717
|
-
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks"
|
728
|
+
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks" +
|
729
|
+
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
730
|
+
Excel instance without or with saving the unsaved workbooks before, respectively")
|
718
731
|
end
|
719
732
|
|
720
733
|
it "should close the Excel without saving the workbook" do
|
@@ -757,7 +770,8 @@ module RobustExcelOle
|
|
757
770
|
it "should raise an error for invalid option" do
|
758
771
|
expect {
|
759
772
|
@excel.close(:if_unsaved => :invalid_option)
|
760
|
-
}.to raise_error(OptionInvalid, ":if_unsaved: invalid option: :invalid_option"
|
773
|
+
}.to raise_error(OptionInvalid, ":if_unsaved: invalid option: :invalid_option" +
|
774
|
+
"\nHint: Valid values are :raise, :forget, :save and :alert")
|
761
775
|
end
|
762
776
|
end
|
763
777
|
|
@@ -843,13 +857,18 @@ module RobustExcelOle
|
|
843
857
|
it "should raise error" do
|
844
858
|
expect{
|
845
859
|
@excel.close_workbooks(:if_unsaved => :raise)
|
846
|
-
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks"
|
860
|
+
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks" +
|
861
|
+
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
862
|
+
Excel instance without or with saving the unsaved workbooks before, respectively" )
|
863
|
+
|
847
864
|
end
|
848
865
|
|
849
866
|
it "should raise error per default" do
|
850
867
|
expect{
|
851
868
|
@excel.close_workbooks
|
852
|
-
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks"
|
869
|
+
}.to raise_error(UnsavedWorkbooks, "Excel contains unsaved workbooks" +
|
870
|
+
"\nHint: Use option :if_unsaved with values :forget and :save to close the
|
871
|
+
Excel instance without or with saving the unsaved workbooks before, respectively")
|
853
872
|
end
|
854
873
|
|
855
874
|
it "should close the workbook with forgetting the workbook" do
|
@@ -877,11 +896,13 @@ module RobustExcelOle
|
|
877
896
|
it "should raise an error for invalid option" do
|
878
897
|
expect {
|
879
898
|
@excel.close_workbooks(:if_unsaved => :invalid_option)
|
880
|
-
}.to raise_error(OptionInvalid, ":if_unsaved: invalid option: :invalid_option"
|
899
|
+
}.to raise_error(OptionInvalid, ":if_unsaved: invalid option: :invalid_option" +
|
900
|
+
"\nHint: Valid values are :raise, :forget, :save and :alert")
|
881
901
|
end
|
882
902
|
end
|
883
903
|
end
|
884
904
|
|
905
|
+
=begin
|
885
906
|
describe "retain_saved_workbooks" do
|
886
907
|
|
887
908
|
before do
|
@@ -909,6 +930,8 @@ module RobustExcelOle
|
|
909
930
|
end
|
910
931
|
end
|
911
932
|
|
933
|
+
=end
|
934
|
+
|
912
935
|
describe "unsaved_workbooks" do
|
913
936
|
|
914
937
|
context "with standard" do
|
@@ -938,6 +961,62 @@ module RobustExcelOle
|
|
938
961
|
end
|
939
962
|
end
|
940
963
|
|
964
|
+
describe "workbooks, each, each_with_index" do
|
965
|
+
|
966
|
+
before do
|
967
|
+
@excel = Excel.create
|
968
|
+
@book1 = Workbook.open(@simple_file)
|
969
|
+
@book2 = Workbook.open(@different_file)
|
970
|
+
end
|
971
|
+
|
972
|
+
it "should list workbooks" do
|
973
|
+
workbooks = @excel.workbooks
|
974
|
+
workbooks.should == [@book1,@book2]
|
975
|
+
end
|
976
|
+
|
977
|
+
it "should each_workbook" do
|
978
|
+
i = 0
|
979
|
+
@excel.each_workbook do |workbook|
|
980
|
+
workbook.should be_alive
|
981
|
+
workbook.should be_a Workbook
|
982
|
+
workbook.filename.should == @simple_file if i == 0
|
983
|
+
workbook.filename.should == @different_file if i == 1
|
984
|
+
i += 1
|
985
|
+
end
|
986
|
+
end
|
987
|
+
|
988
|
+
it "should each_workbook_with_index" do
|
989
|
+
@excel.each_workbook_with_index do |workbook,i|
|
990
|
+
workbook.should be_alive
|
991
|
+
workbook.should be_a Workbook
|
992
|
+
workbook.filename.should == @simple_file if i == 0
|
993
|
+
workbook.filename.should == @different_file if i == 1
|
994
|
+
end
|
995
|
+
end
|
996
|
+
|
997
|
+
it "should each_workbook with options" do
|
998
|
+
i = 0
|
999
|
+
@excel.each_workbook(:visible => true) do |workbook|
|
1000
|
+
workbook.should be_alive
|
1001
|
+
workbook.should be_a Workbook
|
1002
|
+
workbook.visible.should be true
|
1003
|
+
workbook.filename.should == @simple_file if i == 0
|
1004
|
+
workbook.filename.should == @different_file if i == 1
|
1005
|
+
i += 1
|
1006
|
+
end
|
1007
|
+
end
|
1008
|
+
|
1009
|
+
it "should set options" do
|
1010
|
+
@excel.each_workbook(:visible => true)
|
1011
|
+
[1,2].each do |i|
|
1012
|
+
ole_workbook = @excel.Workbooks.Item(i)
|
1013
|
+
ole_workbook.Windows(ole_workbook.Name).Visible.should be true
|
1014
|
+
end
|
1015
|
+
end
|
1016
|
+
|
1017
|
+
|
1018
|
+
end
|
1019
|
+
|
941
1020
|
describe "unsaved_known_workbooks" do
|
942
1021
|
|
943
1022
|
it "should return empty list" do
|
@@ -1492,6 +1571,29 @@ module RobustExcelOle
|
|
1492
1571
|
@excel1.CalculateBeforeSave.should == old_calculatebeforesave
|
1493
1572
|
end
|
1494
1573
|
|
1574
|
+
context "with no visible workbook" do
|
1575
|
+
|
1576
|
+
it "should set calculation mode (change from automatic to manual)" do
|
1577
|
+
excel1 = Excel.create(:calculation => :automatic)
|
1578
|
+
book1 = Workbook.open(@simple_file1, :visible => false)
|
1579
|
+
expect( book1.Windows(1).Visible ).to be false
|
1580
|
+
expect { excel1.calculation = :manual
|
1581
|
+
}.to change{ excel1.calculation
|
1582
|
+
}.from( :automatic
|
1583
|
+
).to( :manual )
|
1584
|
+
end
|
1585
|
+
|
1586
|
+
it "should set calculation mode (change from manual to automatic)" do
|
1587
|
+
excel1 = Excel.create(:calculation => :manual)
|
1588
|
+
book1 = Workbook.open(@simple_file1, :visible => false)
|
1589
|
+
expect( book1.Windows(1).Visible ).to be false
|
1590
|
+
expect { excel1.calculation = :automatic
|
1591
|
+
}.to change{ excel1.calculation
|
1592
|
+
}.from( :manual
|
1593
|
+
).to( :automatic )
|
1594
|
+
end
|
1595
|
+
end
|
1596
|
+
|
1495
1597
|
it "should do with_calculation with workbook" do
|
1496
1598
|
@excel1 = Excel.new
|
1497
1599
|
book = Workbook.open(@simple_file, :visible => true)
|
@@ -1517,6 +1619,7 @@ module RobustExcelOle
|
|
1517
1619
|
it "should set calculation mode to manual with workbook" do
|
1518
1620
|
@excel1 = Excel.new
|
1519
1621
|
book = Workbook.open(@simple_file, :visible => true)
|
1622
|
+
book.Saved.should be true
|
1520
1623
|
book.Windows(book.Name).Visible = true
|
1521
1624
|
@excel1.calculation = :manual
|
1522
1625
|
@excel1.calculation.should == :manual
|
@@ -1528,6 +1631,32 @@ module RobustExcelOle
|
|
1528
1631
|
it "should set calculation mode to automatic with workbook" do
|
1529
1632
|
@excel1 = Excel.new
|
1530
1633
|
book = Workbook.open(@simple_file, :visible => true)
|
1634
|
+
book.Saved.should be true
|
1635
|
+
@excel1.calculation = :automatic
|
1636
|
+
@excel1.calculation.should == :automatic
|
1637
|
+
@excel1.Calculation.should == XlCalculationAutomatic
|
1638
|
+
@excel1.CalculateBeforeSave.should be false
|
1639
|
+
book.Saved.should be true
|
1640
|
+
end
|
1641
|
+
|
1642
|
+
it "should set calculation mode to manual with unsaved workbook" do
|
1643
|
+
@excel1 = Excel.new
|
1644
|
+
book = Workbook.open(@simple_file, :visible => true)
|
1645
|
+
book.sheet(1)[1,1] = "foo"
|
1646
|
+
book.Saved.should be false
|
1647
|
+
book.Windows(book.Name).Visible = true
|
1648
|
+
@excel1.calculation = :manual
|
1649
|
+
@excel1.calculation.should == :manual
|
1650
|
+
@excel1.Calculation.should == XlCalculationManual
|
1651
|
+
@excel1.CalculateBeforeSave.should be false
|
1652
|
+
book.Saved.should be false
|
1653
|
+
end
|
1654
|
+
|
1655
|
+
it "should set calculation mode to automatic with unsaved workbook" do
|
1656
|
+
@excel1 = Excel.new
|
1657
|
+
book = Workbook.open(@simple_file, :visible => true)
|
1658
|
+
book.sheet(1)[1,1] = "foo"
|
1659
|
+
book.Saved.should be false
|
1531
1660
|
@excel1.calculation = :automatic
|
1532
1661
|
@excel1.calculation.should == :automatic
|
1533
1662
|
@excel1.Calculation.should == XlCalculationAutomatic
|
@@ -1742,7 +1871,7 @@ module RobustExcelOle
|
|
1742
1871
|
|
1743
1872
|
it "should generate a workbook" do
|
1744
1873
|
workbook = @excel1.generate_workbook(@file_name)
|
1745
|
-
workbook.should be_a
|
1874
|
+
workbook.should be_a Workbook
|
1746
1875
|
workbook.Name.should == File.basename(@file_name)
|
1747
1876
|
workbook.FullName.should == General::absolute_path(@file_name)
|
1748
1877
|
workbook.Saved.should be true
|
@@ -1752,26 +1881,11 @@ module RobustExcelOle
|
|
1752
1881
|
workbooks.Count.should == 1
|
1753
1882
|
end
|
1754
1883
|
|
1755
|
-
|
1756
|
-
workbook = @excel1.generate_workbook(@file_name)
|
1757
|
-
workbook.should be_a WIN32OLE
|
1758
|
-
workbook.Name.should == File.basename(@file_name)
|
1759
|
-
workbook.FullName.should == General::absolute_path(@file_name)
|
1760
|
-
workbook.Saved.should be true
|
1761
|
-
workbook.ReadOnly.should be false
|
1762
|
-
workbook.Sheets.Count.should == 3
|
1763
|
-
workbooks = @excel1.Workbooks
|
1764
|
-
workbooks.Count.should == 1
|
1765
|
-
workbook2 = @excel1.generate_workbook(@file_name)
|
1766
|
-
workbook2.should be_a WIN32OLE
|
1767
|
-
workbooks = @excel1.Workbooks
|
1768
|
-
workbooks.Count.should == 2
|
1769
|
-
end
|
1770
|
-
|
1884
|
+
|
1771
1885
|
it "should generate a workbook if one is already existing" do
|
1772
1886
|
book = Workbook.open(@simple_file)
|
1773
1887
|
workbook = @excel1.generate_workbook(@file_name)
|
1774
|
-
workbook.should be_a
|
1888
|
+
workbook.should be_a Workbook
|
1775
1889
|
workbook.Name.should == File.basename(@file_name)
|
1776
1890
|
workbook.FullName.should == General::absolute_path(@file_name)
|
1777
1891
|
workbook.Saved.should be true
|
@@ -1850,6 +1964,31 @@ module RobustExcelOle
|
|
1850
1964
|
@excel1["foo"].should == [["foo", "workbook", "sheet1", nil], ["foo", 1.0, 2.0, 4.0], ["matz", 3.0, 4.0, 4.0]]
|
1851
1965
|
end
|
1852
1966
|
|
1967
|
+
it "should add a name of an infinite row range" do
|
1968
|
+
@excel1.add_name("foo",[1..3, nil])
|
1969
|
+
@excel1.Names.Item("foo").Value.should == "=Sheet1!$1:$3"
|
1970
|
+
end
|
1971
|
+
|
1972
|
+
it "should add a name of an infinite column range" do
|
1973
|
+
@excel1.add_name("foo",[nil, "A".."C"])
|
1974
|
+
@excel1.Names.Item("foo").Value.should == "=Sheet1!$A:$C"
|
1975
|
+
end
|
1976
|
+
|
1977
|
+
it "should add a name of an infinite row range" do
|
1978
|
+
@excel1.add_name("foo",[nil, 1..3])
|
1979
|
+
@excel1.Names.Item("foo").Value.should == "=Sheet1!$A:$C"
|
1980
|
+
end
|
1981
|
+
|
1982
|
+
it "should add a name of an infinite column range" do
|
1983
|
+
@excel1.add_name("foo",["A:C"])
|
1984
|
+
@excel1.Names.Item("foo").Value.should == "=Sheet1!$A:$C"
|
1985
|
+
end
|
1986
|
+
|
1987
|
+
it "should add a name of an infinite column range" do
|
1988
|
+
@excel1.add_name("foo",["1:2"])
|
1989
|
+
@excel1.Names.Item("foo").Value.should == "=Sheet1!$1:$2"
|
1990
|
+
end
|
1991
|
+
|
1853
1992
|
end
|
1854
1993
|
|
1855
1994
|
|