robust_excel_ole 1.8 → 1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,109 +36,6 @@ module RobustExcelOle
36
36
  rm_tmp(@dir)
37
37
  end
38
38
 
39
- describe "Address" do
40
-
41
- it "should read a1-format" do
42
- address = Address.new("A1")
43
- address.rows.should == (1..1)
44
- address.columns.should == (1..1)
45
- end
46
-
47
- it "should read a1-format with brackets" do
48
- address = Address.new(["A1"])
49
- address.rows.should == (1..1)
50
- address.columns.should == (1..1)
51
- end
52
-
53
- it "should read a1-format" do
54
- address = Address.new("ABO15")
55
- address.columns.should == (743..743)
56
- address.rows.should == (15..15)
57
- end
58
-
59
- it "should read a1-format when row and column are given separated" do
60
- address = Address.new([1,"A"])
61
- address.rows.should == (1..1)
62
- address.columns.should == (1..1)
63
- end
64
-
65
- it "should read a1-format with rows as integer range" do
66
- address = Address.new([2..4, "AB"])
67
- address.rows.should == (2..4)
68
- address.columns.should == (28..28)
69
- end
70
-
71
- it "should read a1-format with columns as string range" do
72
- address = Address.new([2, "A".."C"])
73
- address.rows.should == (2..2)
74
- address.columns.should == (1..3)
75
- end
76
-
77
- it "should read a1-format with rows and columns as string range" do
78
- address = Address.new([2..6, "A" .. "C"])
79
- address.rows.should == (2..6)
80
- address.columns.should == (1..3)
81
- end
82
-
83
- it "should read r1c1-format" do
84
- address = Address.new([1,2])
85
- address.rows.should == (1..1)
86
- address.columns.should == (2..2)
87
- end
88
-
89
- it "should read r1c1-format with rows as integer range" do
90
- address = Address.new([1..2,3])
91
- address.rows.should == (1..2)
92
- address.columns.should == (3..3)
93
- end
94
-
95
- it "should read r1c1-format with columns as integer range" do
96
- address = Address.new([1,3..5])
97
- address.rows.should == (1..1)
98
- address.columns.should == (3..5)
99
- end
100
-
101
- it "should read r1c1-format with rows and columns as integer range" do
102
- address = Address.new([1..4,3..5])
103
- address.rows.should == (1..4)
104
- address.columns.should == (3..5)
105
- end
106
-
107
- it "should read a1-format for a rectangular range" do
108
- address = Address.new(["A1:B3"])
109
- address.rows.should == (1..3)
110
- address.columns.should == (1..2)
111
- end
112
-
113
- it "should read a1-format for a rectangular range without brackets" do
114
- address = Address.new("A1:B3")
115
- address.rows == (1..3)
116
- address.columns == (1..2)
117
- end
118
-
119
- it "should read a1-format for a rectangular range with several letters" do
120
- address = Address.new(["S1:DP2"])
121
- address.rows.should == (1..2)
122
- address.columns.should == (19..120)
123
- end
124
-
125
- it "should raise an error" do
126
- expect{
127
- Address.new("1A")
128
- }.to raise_error(AddressInvalid, /not in A1/)
129
- expect{
130
- Address.new("A1B")
131
- }.to raise_error(AddressInvalid, /not in A1/)
132
- expect{
133
- Address.new(["A".."B","C".."D"])
134
- }.to raise_error(AddressInvalid, /not in A1/)
135
- expect{
136
- Address.new(["A",1,2])
137
- }.to raise_error(AddressInvalid, /more than two components/)
138
- end
139
-
140
- end
141
-
142
39
  describe "trace" do
143
40
 
144
41
  it "should put some number" do
@@ -210,7 +210,6 @@ describe Workbook do
210
210
 
211
211
  end
212
212
 
213
-
214
213
  context "with standard options" do
215
214
  before do
216
215
  @book = Workbook.open(@simple_file)
@@ -499,10 +498,20 @@ describe Workbook do
499
498
 
500
499
  context "with non-existing file" do
501
500
 
501
+ it "should create a workbook" do
502
+ File.delete @simple_save_file rescue nil
503
+ book = Workbook.create(@simple_save_file)
504
+ book.should be_a Workbook
505
+ book.ReadOnly.should be false
506
+ book.close
507
+ File.exist?(@simple_save_file).should be true
508
+ end
509
+
502
510
  it "should create a workbook" do
503
511
  File.delete @simple_save_file rescue nil
504
512
  book = Workbook.open(@simple_save_file, :if_absent => :create)
505
513
  book.should be_a Workbook
514
+ book.ReadOnly.should be false
506
515
  book.close
507
516
  File.exist?(@simple_save_file).should be true
508
517
  end
@@ -511,7 +520,8 @@ describe Workbook do
511
520
  File.delete @simple_save_file rescue nil
512
521
  expect {
513
522
  Workbook.open(@simple_save_file)
514
- }.to raise_error(FileNotFound, "file #{General::absolute_path(@simple_save_file).gsub("/","\\").inspect} not found")
523
+ }.to raise_error(FileNotFound, "file nil not found" +
524
+ "\nHint: If you want to create a new file, use option :if_absent => :create or Workbook::create")
515
525
  end
516
526
  end
517
527
 
@@ -142,7 +142,8 @@ describe Workbook do
142
142
  it "should raise an error for invalid option" do
143
143
  expect {
144
144
  @book.close(:if_unsaved => :invalid_option)
145
- }.to raise_error(OptionInvalid, ":if_unsaved: invalid option: :invalid_option")
145
+ }.to raise_error(OptionInvalid, ":if_unsaved: invalid option: :invalid_option" +
146
+ "\nHint: Valid values are :raise, :save, :keep_open, :alert, :excel")
146
147
  end
147
148
 
148
149
 
@@ -1081,12 +1081,12 @@ describe Workbook do
1081
1081
  context "range" do
1082
1082
 
1083
1083
  before do
1084
- @book1 = Workbook.open(@dir + '/another_workbook.xls', :read_only => true, :visible => true)
1085
- @book1.excel.displayalerts = false
1084
+ @book1 = Workbook.open(@dir + '/another_workbook.xls', :visible => true)
1086
1085
  end
1087
1086
 
1088
1087
  it "should create a range from the name" do
1089
1088
  @book1.add_name("foo",[1..3,1..4])
1089
+ @book1.save
1090
1090
  range = @book1.range("foo")
1091
1091
  range.Address.should == "$A$1:$D$3"
1092
1092
  end
@@ -1108,12 +1108,36 @@ describe Workbook do
1108
1108
  @book1.add_name("foo",[1,2])
1109
1109
  @book1.Names.Item("foo").Name.should == "foo"
1110
1110
  @book1.Names.Item("foo").Value.should == "=Sheet1!$B$1:$B$1"
1111
- end
1112
-
1113
- it "should rename an already named range with a giving address" do
1114
- @book1.add_name("foo",[1,1])
1111
+ @book1.add_name("foo",[1..2,2..4])
1112
+ @book1.Names.Item("foo").Name.should == "foo"
1113
+ @book1.Names.Item("foo").Value.should == "=Sheet1!$B$1:$D$2"
1114
+ @book1.add_name("foo","B1")
1115
+ @book1.Names.Item("foo").Name.should == "foo"
1116
+ @book1.Names.Item("foo").Value.should == "=Sheet1!$B$1:$B$1"
1117
+ @book1.add_name("foo","B1:D2")
1118
+ @book1.Names.Item("foo").Name.should == "foo"
1119
+ @book1.Names.Item("foo").Value.should == "=Sheet1!$B$1:$D$2"
1120
+ @book1.add_name("foo","Z1S2")
1121
+ @book1.Names.Item("foo").Name.should == "foo"
1122
+ @book1.Names.Item("foo").Value.should == "=Sheet1!$B$1"
1123
+ @book1.add_name("foo","Z1S2:Z2S4")
1115
1124
  @book1.Names.Item("foo").Name.should == "foo"
1116
- @book1.Names.Item("foo").Value.should == "=Sheet1!$A$1:$A$1"
1125
+ @book1.Names.Item("foo").Value.should == "=Sheet1!$B$1:$D$2"
1126
+ @book1.add_name("foo","A:B")
1127
+ @book1.Names.Item("foo").Name.should == "foo"
1128
+ @book1.Names.Item("foo").Value.should == "=Sheet1!$A:$B"
1129
+ @book1.add_name("foo","1:2")
1130
+ @book1.Names.Item("foo").Name.should == "foo"
1131
+ @book1.Names.Item("foo").Value.should == "=Sheet1!$1:$2"
1132
+ @book1.add_name("foo",[1..2,nil])
1133
+ @book1.Names.Item("foo").Name.should == "foo"
1134
+ @book1.Names.Item("foo").Value.should == "=Sheet1!$1:$2"
1135
+ @book1.add_name("foo",[nil,1..2])
1136
+ @book1.Names.Item("foo").Name.should == "foo"
1137
+ @book1.Names.Item("foo").Value.should == "=Sheet1!$A:$B"
1138
+ @book1.add_name("foo",[nil,"A".."B"])
1139
+ @book1.Names.Item("foo").Name.should == "foo"
1140
+ @book1.Names.Item("foo").Value.should == "=Sheet1!$A:$B"
1117
1141
  end
1118
1142
 
1119
1143
  it "should raise an error" do
@@ -1140,6 +1164,16 @@ describe Workbook do
1140
1164
  @book1["foo"].should == [["foo", "workbook", "sheet1", nil], ["foo", 1.0, 2.0, 4.0], ["matz", 3.0, 4.0, 4.0]]
1141
1165
  end
1142
1166
 
1167
+ it "should add a name of an infinite row range" do
1168
+ @book1.add_name("foo",[1..3, nil])
1169
+ @book1.Names.Item("foo").Value.should == "=Sheet1!$1:$3"
1170
+ end
1171
+
1172
+ it "should add a name of an infinite column range" do
1173
+ @book1.add_name("foo",[nil, "A".."C"])
1174
+ @book1.Names.Item("foo").Value.should == "=Sheet1!$A:$C"
1175
+ end
1176
+
1143
1177
  end
1144
1178
 
1145
1179
  context "with compatibility" do
@@ -1936,7 +1936,10 @@ describe Workbook do
1936
1936
  it "should raise an error, if :if_obstructed is invalid option" do
1937
1937
  expect {
1938
1938
  new_book = Workbook.open(@simple_file1, :if_obstructed => :invalid_option)
1939
- }.to raise_error(OptionInvalid, ":if_obstructed: invalid option: :invalid_option")
1939
+ }.to raise_error(OptionInvalid, ":if_obstructed: invalid option: :invalid_option" +
1940
+ "\nHint: Use the option :if_obstructed with values :forget or :save,
1941
+ to close the old workbook, without or with saving before, respectively,
1942
+ and to open the new workbook")
1940
1943
  end
1941
1944
  end
1942
1945
  end
@@ -1992,7 +1995,8 @@ describe Workbook do
1992
1995
  File.delete @simple_save_file rescue nil
1993
1996
  expect {
1994
1997
  Workbook.open(@simple_save_file, :if_absent => :raise)
1995
- }.to raise_error(FileNotFound, "file #{General::absolute_path(@simple_save_file).gsub("/","\\").inspect} not found")
1998
+ }.to raise_error(FileNotFound, "file #{General::absolute_path(@simple_save_file).gsub("/","\\").inspect} not found" +
1999
+ "\nHint: If you want to create a new file, use option :if_absent => :create or Workbook::create")
1996
2000
  end
1997
2001
 
1998
2002
  it "should create a workbook" do
@@ -2196,7 +2200,8 @@ describe Workbook do
2196
2200
  expected_path = Regexp.new(File.expand_path(path).gsub(/\//, "."))
2197
2201
  expect {
2198
2202
  Workbook.open(path)
2199
- }.to raise_error(FileNotFound, "file #{General::absolute_path(path).gsub("/","\\").inspect} not found")
2203
+ }.to raise_error(FileNotFound, "file #{General::absolute_path(path).gsub("/","\\").inspect} not found" +
2204
+ "\nHint: If you want to create a new file, use option :if_absent => :create or Workbook::create")
2200
2205
  end
2201
2206
  end
2202
2207
  end
@@ -267,7 +267,8 @@ describe Workbook do
267
267
  File.exist?(@simple_file_other_path1).should be true
268
268
  expect{
269
269
  @book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :invalid)
270
- }.to raise_error(OptionInvalid, ":if_obstructed: invalid option: :invalid")
270
+ }.to raise_error(OptionInvalid, ":if_obstructed: invalid option: :invalid" +
271
+ "\nHint: Valid values are :raise, :overwrite, :alert, :excel")
271
272
  end
272
273
 
273
274
  it "should raise an error by default" do
@@ -322,7 +323,7 @@ describe Workbook do
322
323
  book_save = Workbook.open(@simple_save_file1, :excel => :new)
323
324
  expect{
324
325
  @book.save_as(@simple_save_file1, :if_exists => :overwrite)
325
- }.to raise_error(WorkbookBeingUsed, "workbook is open and used in Excel")
326
+ }.to raise_error(WorkbookBeingUsed, "workbook is open and being used in an Excel instance")
326
327
  book_save.close
327
328
  end
328
329
 
@@ -506,7 +507,8 @@ describe Workbook do
506
507
  @book.save_as(@simple_save_file1)
507
508
  expect {
508
509
  @book.save_as(@simple_save_file1, :if_exists => :invalid)
509
- }.to raise_error(OptionInvalid, ':if_exists: invalid option: :invalid')
510
+ }.to raise_error(OptionInvalid, ':if_exists: invalid option: :invalid' +
511
+ "\nHint: Valid values are :raise, :overwrite, :alert, :excel")
510
512
  end
511
513
  end
512
514
  end
@@ -192,10 +192,21 @@ describe Worksheet do
192
192
 
193
193
  describe "range" do
194
194
 
195
+ it "should a range with relative r1c1-reference" do
196
+ @sheet.range(["Z1S[3]:Z[2]S8"]).Address.should == "$D$1:$H$3"
197
+ @sheet.range(["Z1S3:Z2S8"]).Address.should == "$C$1:$H$2"
198
+ end
199
+
200
+ it "should a range with relative integer-range-reference" do
201
+ @sheet.range([1..[2],[3]..8]).Address.should == "$D$1:$H$3"
202
+ end
203
+
195
204
  it "should create a range of one cell" do
196
205
  @sheet.range([1,2]).values.should == ["workbook"]
197
206
  @sheet.range(["B1"]).values.should == ["workbook"]
198
207
  @sheet.range("B1").values.should == ["workbook"]
208
+ @sheet.range(["Z1S2"]).values.should == ["workbook"]
209
+ @sheet.range("Z1S2").values.should == ["workbook"]
199
210
  end
200
211
 
201
212
  it "should create a rectangular range" do
@@ -203,6 +214,8 @@ describe Worksheet do
203
214
  @sheet.range([1..3, "B".."D"]).values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
204
215
  @sheet.range(["B1:D3"]).values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
205
216
  @sheet.range("B1:D3").values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
217
+ @sheet.range(["Z1S2:Z3S4"]).values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
218
+ @sheet.range("Z1S2:Z3S4").values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
206
219
  end
207
220
 
208
221
  it "should accept old interface" do
@@ -210,10 +223,17 @@ describe Worksheet do
210
223
  @sheet.range(1..3, "B".."D").values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
211
224
  end
212
225
 
226
+ it "should create infinite ranges" do
227
+ @sheet.range([1..3,nil]).Address.should == "$1:$3"
228
+ @sheet.range(nil,"B".."D").Address.should == "$B:$D"
229
+ @sheet.range("1:3").Address.should == "$1:$3"
230
+ @sheet.range("B:D").Address.should == "$B:$D"
231
+ end
232
+
213
233
  it "should raise an error" do
214
234
  expect{
215
235
  @sheet.range([0,0])
216
- }.to raise_error(AddressInvalid, /not in/)
236
+ }.to raise_error(RangeNotCreated, /cannot create/)
217
237
  end
218
238
 
219
239
  end
@@ -659,10 +679,10 @@ describe Worksheet do
659
679
  }.to_not raise_error
660
680
  expect {
661
681
  @sheet1.namevalue("foo", :default => :__not_provided)
662
- }.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1 another_workbook/)
682
+ }.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1/)
663
683
  expect {
664
684
  @sheet1.namevalue("foo")
665
- }.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1 another_workbook/)
685
+ }.to raise_error(NameNotFound, /name "foo" not in #<Worksheet: Sheet1/)
666
686
  @sheet1.namevalue("foo", :default => nil).should be_nil
667
687
  @sheet1.namevalue("foo", :default => 1).should == 1
668
688
  @sheet1.namevalue_glob("empty", :default => 1).should be_nil
@@ -681,20 +701,28 @@ describe Worksheet do
681
701
 
682
702
  context "adding, renaming, deleting the name of a range" do
683
703
 
684
- before do
685
- @book1 = Workbook.open(@dir + '/another_workbook.xls', :read_only => true, :visible => true)
686
- @book1.excel.displayalerts = false
704
+ before do
705
+ @book1 = Workbook.open(@dir + '/another_workbook.xls', :visible => true)
687
706
  @sheet1 = @book1.sheet(1)
688
707
  end
689
708
 
690
709
  after do
691
- @book1.close
710
+ @book1.close(:if_unsaved => :forget)
711
+ end
712
+
713
+ it "should add a name of a rectangular range using relative int-range-reference" do
714
+ @sheet1.add_name("foo",[[1]..3,1..[2]])
715
+ @sheet1.range("foo").Address.should == "$A$3:$D$5"
692
716
  end
693
717
 
718
+ it "should add a name of a rectangular range using relative r1c1-reference" do
719
+ @sheet1.add_name("foo","Z[1]S3:Z1S[2]")
720
+ @sheet1.range("foo").Address.should == "$C$1:$D$5"
721
+ @sheet1.add_name("bar","Z[-3]S[-2]")
722
+ @sheet1.range("bar").Address.should == "$IV$1"
723
+ end
724
+
694
725
  it "should name an unnamed range with a giving address" do
695
- expect{
696
- @sheet1[1,2].Name.Name
697
- }.to raise_error
698
726
  @sheet1.add_name("foo",[1,2])
699
727
  @sheet1.Range("foo").Address.should == "$B$1"
700
728
  end
@@ -750,6 +778,51 @@ describe Worksheet do
750
778
  @sheet1["foo"].should == [["foo", "workbook", "sheet1", nil], ["foo", 1.0, 2.0, 4.0], ["matz", 3.0, 4.0, 4.0]]
751
779
  end
752
780
 
781
+ it "should add a name of another rectangular range" do
782
+ @sheet1.add_name("foo",[1..3, "A"])
783
+ @sheet1["foo"].should == [["foo"], ["foo"],["matz"]]
784
+ @sheet1.Range("foo").Address.should == "$A$1:$A$3"
785
+ end
786
+
787
+ it "should add a name of an infinite row range" do
788
+ @sheet1.add_name("foo",[1..3, nil])
789
+ @sheet1.Range("foo").Address.should == "$1:$3"
790
+ end
791
+
792
+ it "should add a name of an infinite column range" do
793
+ @sheet1.add_name("foo",[nil, "A".."C"])
794
+ @sheet1.Range("foo").Address.should == "$A:$C"
795
+ end
796
+
797
+ it "should add a name of an infinite column range" do
798
+ @sheet1.add_name("foo",[nil, 1..3])
799
+ @sheet1.Range("foo").Address.should == "$A:$C"
800
+ end
801
+
802
+ it "should add a name of an infinite column range" do
803
+ @sheet1.add_name("foo","A:C")
804
+ @sheet1.Range("foo").Address.should == "$A:$C"
805
+ end
806
+
807
+ it "should add a name of an infinite column range" do
808
+ @sheet1.add_name("foo","1:2")
809
+ @sheet1.Range("foo").Address.should == "$1:$2"
810
+ end
811
+
812
+ it "should name an range with a relative columns" do
813
+ @sheet1.add_name("foo",[1,2])
814
+ @sheet1.Range("foo").Address.should == "$B$1"
815
+ @sheet1.add_name("bar","Z3S[4]")
816
+ @sheet1.Range("bar").Address.should == "$E$3"
817
+ end
818
+
819
+ it "should name an range with a relative row" do
820
+ @sheet1.add_name("foo",[1,2])
821
+ @sheet1.Range("foo").Address.should == "$B$1"
822
+ @sheet1.add_name("bar","Z[3]S4")
823
+ @sheet1.Range("bar").Address.should == "$D$4"
824
+ end
825
+
753
826
  end
754
827
  end
755
828
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robust_excel_ole
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.8'
4
+ version: '1.9'
5
5
  platform: ruby
6
6
  authors:
7
7
  - traths
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-31 00:00:00.000000000 Z
11
+ date: 2019-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -57,6 +57,7 @@ files:
57
57
  - examples/introducing_examples/example_open.rb
58
58
  - examples/introducing_examples/example_range.rb
59
59
  - examples/modifying_sheets/example_access_sheets_and_cells.rb
60
+ - examples/modifying_sheets/example_add_names.rb
60
61
  - examples/modifying_sheets/example_adding_sheets.rb
61
62
  - examples/modifying_sheets/example_concating.rb
62
63
  - examples/modifying_sheets/example_copying.rb
@@ -80,12 +81,14 @@ files:
80
81
  - examples/open_save_close/example_unobtrusively.rb
81
82
  - lib/reo_console.rb
82
83
  - lib/robust_excel_ole.rb
84
+ - lib/robust_excel_ole/address.rb
83
85
  - lib/robust_excel_ole/bookstore.rb
84
86
  - lib/robust_excel_ole/cell.rb
85
87
  - lib/robust_excel_ole/cygwin.rb
86
88
  - lib/robust_excel_ole/excel.rb
87
89
  - lib/robust_excel_ole/general.rb
88
90
  - lib/robust_excel_ole/range.rb
91
+ - lib/robust_excel_ole/range_owners.rb
89
92
  - lib/robust_excel_ole/reo_common.rb
90
93
  - lib/robust_excel_ole/robustexcelole.sublime-project
91
94
  - lib/robust_excel_ole/robustexcelole.sublime-workspace
@@ -95,6 +98,7 @@ files:
95
98
  - lib/spec_helper.rb
96
99
  - reo.bat
97
100
  - robust_excel_ole.gemspec
101
+ - spec/address_spec.rb
98
102
  - spec/bookstore_spec.rb
99
103
  - spec/cell_spec.rb
100
104
  - spec/cygwin_spec.rb
@@ -154,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
158
  version: '0'
155
159
  requirements: []
156
160
  rubyforge_project: robust_excel_ole
157
- rubygems_version: 2.4.5.2
161
+ rubygems_version: 2.7.6
158
162
  signing_key:
159
163
  specification_version: 4
160
164
  summary: RobustExcelOle automates processing Excel workbooks in Windows by using the