robust_excel_ole 1.31 → 1.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Changelog +20 -1
- data/README.rdoc +118 -18
- data/___dummy_workbook.xls +0 -0
- data/benchmarking/creek_example.rb +1 -1
- data/benchmarking/roo_example.rb +1 -1
- data/benchmarking/simple_xlsx_reader_example.rb +1 -1
- data/benchmarking/spreadsheet_example.rb +1 -1
- data/docs/README_excel.rdoc +16 -24
- data/docs/README_listobjects.rdoc +176 -0
- data/docs/README_open.rdoc +12 -12
- data/docs/README_ranges.rdoc +72 -55
- data/docs/README_save_close.rdoc +3 -3
- data/docs/README_sheet.rdoc +18 -13
- data/examples/example_ruby_library.rb +2 -2
- data/examples/introductory_examples/example_range.rb +2 -2
- data/examples/modifying_sheets/example_access_sheets_and_cells.rb +6 -6
- data/examples/modifying_sheets/example_add_names.rb +1 -1
- data/examples/modifying_sheets/example_concating.rb +1 -1
- data/examples/modifying_sheets/example_copying.rb +2 -2
- data/examples/modifying_sheets/example_listobjects.rb +86 -0
- data/examples/modifying_sheets/example_naming.rb +1 -1
- data/examples/modifying_sheets/example_ranges.rb +1 -1
- data/examples/open_save_close/example_control_to_excel.rb +1 -1
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +1 -1
- data/examples/open_save_close/example_if_obstructed_save.rb +3 -3
- data/examples/open_save_close/example_if_unsaved_accept.rb +1 -1
- data/examples/open_save_close/example_if_unsaved_forget.rb +3 -3
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +4 -4
- data/examples/open_save_close/example_read_only.rb +1 -1
- data/examples/open_save_close/example_simple.rb +1 -1
- data/examples/open_save_close/example_unobtrusively.rb +3 -3
- data/lib/robust_excel_ole/address_tool.rb +54 -44
- data/lib/robust_excel_ole/base.rb +4 -6
- data/lib/robust_excel_ole/bookstore.rb +2 -16
- data/lib/robust_excel_ole/cell.rb +16 -21
- data/lib/robust_excel_ole/excel.rb +131 -186
- data/lib/robust_excel_ole/general.rb +82 -55
- data/lib/robust_excel_ole/list_object.rb +182 -109
- data/lib/robust_excel_ole/list_row.rb +65 -38
- data/lib/robust_excel_ole/range.rb +125 -93
- data/lib/robust_excel_ole/range_owners.rb +52 -66
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +168 -176
- data/lib/robust_excel_ole/worksheet.rb +177 -141
- data/robust_excel_ole.gemspec +4 -3
- data/spec/bookstore_spec.rb +2 -3
- data/spec/cell_spec.rb +9 -9
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/excel_spec.rb +132 -85
- data/spec/general_spec.rb +47 -15
- data/spec/list_object_spec.rb +258 -145
- data/spec/list_row_spec.rb +218 -0
- data/spec/range_spec.rb +76 -29
- data/spec/spec_helper.rb +15 -1
- data/spec/workbook_spec.rb +75 -34
- data/spec/workbook_specs/workbook_all_spec.rb +2 -1
- data/spec/workbook_specs/workbook_misc_spec.rb +20 -13
- data/spec/workbook_specs/workbook_open_spec.rb +47 -45
- data/spec/workbook_specs/workbook_save_spec.rb +21 -22
- data/spec/workbook_specs/workbook_sheet_spec.rb +3 -3
- data/spec/workbook_specs/workbook_unobtr_spec.rb +303 -303
- data/spec/worksheet_spec.rb +522 -318
- metadata +37 -2
data/spec/general_spec.rb
CHANGED
@@ -11,6 +11,7 @@ module RobustExcelOle
|
|
11
11
|
|
12
12
|
using StringRefinement
|
13
13
|
using ToReoRefinement
|
14
|
+
using FindAllIndicesRefinement
|
14
15
|
|
15
16
|
describe General do
|
16
17
|
|
@@ -45,15 +46,25 @@ module RobustExcelOle
|
|
45
46
|
rm_tmp(@dir)
|
46
47
|
end
|
47
48
|
|
48
|
-
describe "
|
49
|
-
|
50
|
-
it "should" do
|
51
|
-
|
49
|
+
describe "find_all_indices" do
|
50
|
+
|
51
|
+
it "should find all occurrences" do
|
52
|
+
[1,2,3,1].find_all_indices(1).should == [0,3]
|
53
|
+
[1,2,3,1].find_all_indices(4).should be_empty
|
54
|
+
["a","b","c","a"].find_all_indices("a").should == [0,3]
|
55
|
+
["a","b","c","a"].find_all_indices("d").should be_empty
|
56
|
+
["a","ö","ß","a"].find_all_indices("a").should == [0,3]
|
57
|
+
["a","b","c","d"].find_all_indices("ä").should be_empty
|
58
|
+
["ä","ö","ß","ä"].find_all_indices("ä").should == [0,3]
|
59
|
+
["stück","öl","straße","stück"].find_all_indices("stück").should == [0,3]
|
52
60
|
end
|
53
61
|
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "relace_umlauts, underscore" do
|
65
|
+
|
54
66
|
it "should replace umlauts" do
|
55
|
-
|
56
|
-
new_word.should == "BeforeAeOeUeaeoeuessAfter"
|
67
|
+
"BeforeÄÖÜäöüß²³After".replace_umlauts.should == "BeforeAeOeUeaeoeuess23After"
|
57
68
|
end
|
58
69
|
|
59
70
|
it "should underscore" do
|
@@ -69,14 +80,25 @@ module RobustExcelOle
|
|
69
80
|
@book2 = Workbook.open(@listobject_file)
|
70
81
|
end
|
71
82
|
|
83
|
+
it "should type-lift an ListRow" do
|
84
|
+
worksheet = @book2.sheet(3)
|
85
|
+
ole_table = worksheet.ListObjects.Item(1)
|
86
|
+
table = Table.new(ole_table)
|
87
|
+
listrow = table[1]
|
88
|
+
listrow.values.should == [3.0, "John", 50.0, 0.5, 30.0]
|
89
|
+
type_lifted_listrow = listrow.ole_tablerow.to_reo
|
90
|
+
type_lifted_listrow.should be_a ListRow
|
91
|
+
type_lifted_listrow.values.should == [3.0, "John", 50.0, 0.5, 30.0]
|
92
|
+
end
|
93
|
+
|
72
94
|
it "should type-lift an ListObject" do
|
73
95
|
worksheet = @book2.sheet(3)
|
74
96
|
ole_table = worksheet.ListObjects.Item(1)
|
75
97
|
table = Table.new(ole_table)
|
76
98
|
table.Name.should == "table3"
|
77
99
|
table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
|
78
|
-
table.ListRows.Count.should ==
|
79
|
-
worksheet[3,4].
|
100
|
+
table.ListRows.Count.should == 13
|
101
|
+
worksheet[3,4].should == "Number"
|
80
102
|
end
|
81
103
|
|
82
104
|
it "should type-lift an Excel" do
|
@@ -114,6 +136,15 @@ module RobustExcelOle
|
|
114
136
|
@book1.sheet(1).to_reo.should == @book1.sheet(1)
|
115
137
|
@book1.excel.to_reo.should == @book1.excel
|
116
138
|
@book1.sheet(1).range([1,1]).to_reo.should == @book1.sheet(1).range([1,1])
|
139
|
+
@book2.sheet(3).table(1).to_reo.should == @book2.sheet(3).table(1)
|
140
|
+
@book2.sheet(3).table(1).should == @book2.sheet(3).table(1)
|
141
|
+
@book2.sheet(3).table(1)[1].to_reo.should == @book2.sheet(3).table(1)[1]
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should raise error" do
|
145
|
+
expect{
|
146
|
+
WIN32OLE.new('WScript.Network').to_reo
|
147
|
+
}.to raise_error(TypeREOError)
|
117
148
|
end
|
118
149
|
|
119
150
|
end
|
@@ -124,6 +155,14 @@ module RobustExcelOle
|
|
124
155
|
@book1 = Workbook.open(@simple_file, :visible => true)
|
125
156
|
end
|
126
157
|
|
158
|
+
it "should not overwrite methods" do
|
159
|
+
RobustExcelOle::Excel.define_method(:ComputerName){ "computer" }
|
160
|
+
network = WIN32OLE.new('WScript.Network')
|
161
|
+
computername = network.ComputerName
|
162
|
+
General.init_reo_for_win32ole
|
163
|
+
network.ComputerName.should == computername
|
164
|
+
end
|
165
|
+
|
127
166
|
it "should apply reo-methods to win32ole objects" do
|
128
167
|
ole_book1 = @book1.ole_workbook
|
129
168
|
sheet1 = ole_book1.sheet(1)
|
@@ -270,13 +309,6 @@ module RobustExcelOle
|
|
270
309
|
canonize("this../.i.s/.../..the/..../pa.th/").should == "this../.i.s/.../..the/..../pa.th"
|
271
310
|
end
|
272
311
|
|
273
|
-
=begin
|
274
|
-
it "should downcase" do
|
275
|
-
canonize("/This/IS/tHe/path").should == "/this/is/the/path"
|
276
|
-
canonize("///THIS/.///./////iS//the/../PatH/////").should == "/this/is/path"
|
277
|
-
end
|
278
|
-
=end
|
279
|
-
|
280
312
|
it "should raise an error for no strings" do
|
281
313
|
expect{
|
282
314
|
canonize(1)
|
data/spec/list_object_spec.rb
CHANGED
@@ -10,7 +10,7 @@ include General
|
|
10
10
|
describe ListObject do
|
11
11
|
|
12
12
|
before(:all) do
|
13
|
-
excel = Excel.new(:
|
13
|
+
excel = Excel.new(reuse: true)
|
14
14
|
open_books = excel == nil ? 0 : excel.Workbooks.Count
|
15
15
|
puts "*** open books *** : #{open_books}" if open_books > 0
|
16
16
|
Excel.kill_all
|
@@ -19,16 +19,30 @@ describe ListObject do
|
|
19
19
|
before do
|
20
20
|
@dir = create_tmpdir
|
21
21
|
@listobject_file = @dir + '/workbook_listobjects.xlsx'
|
22
|
-
@book = Workbook.open(@listobject_file, :
|
22
|
+
@book = Workbook.open(@listobject_file, visible: true)
|
23
23
|
@sheet = @book.sheet(3)
|
24
24
|
end
|
25
25
|
|
26
26
|
after do
|
27
|
-
@book.close(:
|
27
|
+
@book.close(if_unsaved: :forget)
|
28
28
|
Excel.kill_all
|
29
29
|
rm_tmp(@dir)
|
30
30
|
end
|
31
31
|
|
32
|
+
describe "accessing a table" do
|
33
|
+
|
34
|
+
it "should access a table via its number" do
|
35
|
+
table = @sheet.table(1)
|
36
|
+
table.Name.should == "table3"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should access a table via its name" do
|
40
|
+
table = @sheet.table("table3")
|
41
|
+
table.Name.should == "table3"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
32
46
|
describe "creating" do
|
33
47
|
|
34
48
|
context "with standard" do
|
@@ -38,7 +52,15 @@ describe ListObject do
|
|
38
52
|
table.Name.should == "table_name"
|
39
53
|
table.HeaderRowRange.Value.first.should == ["Person","Amount"]
|
40
54
|
table.ListRows.Count.should == 3
|
41
|
-
@sheet[1,1].
|
55
|
+
@sheet[1,1].should == "Person"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should create a new table with umlauts" do
|
59
|
+
table = Table.new(@sheet, "lösung", [1,1], 3, ["Verkäufer","Straße"])
|
60
|
+
table.Name.encode_value.should == "lösung"
|
61
|
+
table.HeaderRowRange.Value.first.encode_value.should == ["Verkäufer","Straße"]
|
62
|
+
table.ListRows.Count.should == 3
|
63
|
+
@sheet[1,1].encode_value.should == "Verkäufer"
|
42
64
|
end
|
43
65
|
|
44
66
|
it "should do the idempotence" do
|
@@ -53,8 +75,9 @@ describe ListObject do
|
|
53
75
|
table = Table.new(ole_table)
|
54
76
|
table.Name.should == "table3"
|
55
77
|
table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
|
56
|
-
table.ListRows.Count.should ==
|
57
|
-
@sheet[3,4].
|
78
|
+
table.ListRows.Count.should == 13
|
79
|
+
@sheet[3,4].should == "Number"
|
80
|
+
table.position.should == [3,4]
|
58
81
|
end
|
59
82
|
|
60
83
|
it "should type-lift a Win32ole list object into a RobustExcelOle list object with table name" do
|
@@ -62,8 +85,8 @@ describe ListObject do
|
|
62
85
|
table = Table.new(@sheet, "table3")
|
63
86
|
table.Name.should == "table3"
|
64
87
|
table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
|
65
|
-
table.ListRows.Count.should ==
|
66
|
-
@sheet[3,4].
|
88
|
+
table.ListRows.Count.should == 13
|
89
|
+
@sheet[3,4].should == "Number"
|
67
90
|
end
|
68
91
|
|
69
92
|
it "should type-lift a Win32ole list object into a RobustExcelOle list object with item number" do
|
@@ -71,8 +94,8 @@ describe ListObject do
|
|
71
94
|
table = Table.new(@sheet, 1)
|
72
95
|
table.Name.should == "table3"
|
73
96
|
table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
|
74
|
-
table.ListRows.Count.should ==
|
75
|
-
@sheet[3,4].
|
97
|
+
table.ListRows.Count.should == 13
|
98
|
+
@sheet[3,4].should == "Number"
|
76
99
|
end
|
77
100
|
|
78
101
|
it "should simply create a new table from a ole-worksheet" do
|
@@ -80,7 +103,7 @@ describe ListObject do
|
|
80
103
|
table.Name.should == "table_name"
|
81
104
|
table.HeaderRowRange.Value.first.should == ["Person","Amount"]
|
82
105
|
table.ListRows.Count.should == 3
|
83
|
-
@sheet[1,1].
|
106
|
+
@sheet[1,1].should == "Person"
|
84
107
|
end
|
85
108
|
|
86
109
|
it "should type-lift a Win32ole list object into a RobustExcelOle list object with table name" do
|
@@ -88,8 +111,8 @@ describe ListObject do
|
|
88
111
|
table = Table.new(@sheet.ole_worksheet, "table3")
|
89
112
|
table.Name.should == "table3"
|
90
113
|
table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
|
91
|
-
table.ListRows.Count.should ==
|
92
|
-
@sheet[3,4].
|
114
|
+
table.ListRows.Count.should == 13
|
115
|
+
@sheet[3,4].should == "Number"
|
93
116
|
end
|
94
117
|
|
95
118
|
it "should type-lift a Win32ole list object into a RobustExcelOle list object with item number" do
|
@@ -97,125 +120,151 @@ describe ListObject do
|
|
97
120
|
table = Table.new(@sheet.ole_worksheet, 1)
|
98
121
|
table.Name.should == "table3"
|
99
122
|
table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
|
100
|
-
table.ListRows.Count.should ==
|
101
|
-
@sheet[3,4].
|
123
|
+
table.ListRows.Count.should == 13
|
124
|
+
@sheet[3,4].should == "Number"
|
102
125
|
end
|
103
126
|
|
104
127
|
end
|
105
128
|
|
106
129
|
end
|
107
130
|
|
108
|
-
describe "
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
before do
|
115
|
-
@table = Table.new(@sheet, "table_name", [12,1], 3, ["Person1","Win/Sales", "xiq-Xs", "OrderID", "YEAR", "length in m", "Amo%untSal___es"])
|
116
|
-
@table_row1 = @table[1]
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should read and set values via alternative column names" do
|
120
|
-
@table_row1.person1.should be nil
|
121
|
-
@table_row1.person1 = "John"
|
122
|
-
@table_row1.person1.should == "John"
|
123
|
-
@sheet[13,1].Value.should == "John"
|
124
|
-
@table_row1.Person1 = "Herbert"
|
125
|
-
@table_row1.Person1.should == "Herbert"
|
126
|
-
@sheet[13,1].Value.should == "Herbert"
|
127
|
-
@table_row1.win_sales.should be nil
|
128
|
-
@table_row1.win_sales = 42
|
129
|
-
@table_row1.win_sales.should == 42
|
130
|
-
@sheet[13,2].Value.should == 42
|
131
|
-
@table_row1.Win_Sales = 80
|
132
|
-
@table_row1.Win_Sales.should == 80
|
133
|
-
@sheet[13,2].Value.should == 80
|
134
|
-
@table_row1.xiq_xs.should == nil
|
135
|
-
@table_row1.xiq_xs = 90
|
136
|
-
@table_row1.xiq_xs.should == 90
|
137
|
-
@sheet[13,3].Value.should == 90
|
138
|
-
@table_row1.xiq_Xs = 100
|
139
|
-
@table_row1.xiq_Xs.should == 100
|
140
|
-
@sheet[13,3].Value.should == 100
|
141
|
-
@table_row1.order_id.should == nil
|
142
|
-
@table_row1.order_id = 1
|
143
|
-
@table_row1.order_id.should == 1
|
144
|
-
@sheet[13,4].Value.should == 1
|
145
|
-
@table_row1.OrderID = 2
|
146
|
-
@table_row1.OrderID.should == 2
|
147
|
-
@sheet[13,4].Value.should == 2
|
148
|
-
@table_row1.year = 1984
|
149
|
-
@table_row1.year.should == 1984
|
150
|
-
@sheet[13,5].Value.should == 1984
|
151
|
-
@table_row1.YEAR = 2020
|
152
|
-
@table_row1.YEAR.should == 2020
|
153
|
-
@sheet[13,5].Value.should == 2020
|
154
|
-
@table_row1.length_in_m.should == nil
|
155
|
-
@table_row1.length_in_m = 20
|
156
|
-
@table_row1.length_in_m.should == 20
|
157
|
-
@sheet[13,6].Value.should == 20
|
158
|
-
@table_row1.length_in_m = 40
|
159
|
-
@table_row1.length_in_m.should == 40
|
160
|
-
@sheet[13,6].Value.should == 40
|
161
|
-
@table_row1.amo_unt_sal___es.should == nil
|
162
|
-
@table_row1.amo_unt_sal___es = 80
|
163
|
-
@table_row1.amo_unt_sal___es.should == 80
|
164
|
-
@sheet[13,7].Value.should == 80
|
165
|
-
end
|
131
|
+
describe "each" do
|
132
|
+
|
133
|
+
before do
|
134
|
+
@table1 = @sheet.table(1)
|
135
|
+
end
|
166
136
|
|
137
|
+
it "should traverse through list rows" do
|
138
|
+
@table1.each.with_index do |listrow, i|
|
139
|
+
listrow.values.should == [3.0, "John", 50.0, 0.5, 30] if i == 0
|
140
|
+
listrow.values.should == [2.0, "Fred", nil, 0.5416666666666666, 40] if i == 1
|
141
|
+
listrow.values.should == [nil, nil, nil, nil, nil] if i == 2
|
167
142
|
end
|
143
|
+
end
|
168
144
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
@table = Table.new(@sheet, "table_name", [1,1], 3, ["Verkäufer", "Straße", "area in m²"])
|
173
|
-
@table_row1 = @table[1]
|
174
|
-
end
|
175
|
-
|
176
|
-
it "should read and set values via alternative column names" do
|
177
|
-
@table_row1.verkaeufer.should be nil
|
178
|
-
@table_row1.verkaeufer = "John"
|
179
|
-
@table_row1.verkaeufer.should == "John"
|
180
|
-
@sheet[2,1].Value.should == "John"
|
181
|
-
@table_row1.Verkaeufer = "Herbert"
|
182
|
-
@table_row1.Verkaeufer.should == "Herbert"
|
183
|
-
@sheet[2,1].Value.should == "Herbert"
|
184
|
-
@table_row1.strasse.should be nil
|
185
|
-
@table_row1.strasse = 42
|
186
|
-
@table_row1.strasse.should == 42
|
187
|
-
@sheet[2,2].Value.should == 42
|
188
|
-
@table_row1.Strasse = 80
|
189
|
-
@table_row1.Strasse.should == 80
|
190
|
-
@sheet[2,2].Value.should == 80
|
191
|
-
@table_row1.area_in_m3.should be nil
|
192
|
-
@table_row1.area_in_m3 = 10
|
193
|
-
@table_row1.area_in_m3.should == 10
|
194
|
-
@sheet[2,3].Value.should == 10
|
195
|
-
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "benchmarking for accessing a listrow" do
|
196
148
|
|
149
|
+
it "should access the last row" do
|
150
|
+
rows = 150
|
151
|
+
table = Table.new(@sheet.ole_worksheet, "table_name", [20,1], rows, ["Index","Person", "Time", "Price", "Sales", "Length", "Size", "Width", "Weight", "Income", "Outcome", "Holiday", "Gender", "Sex", "Tallness", "Kindness", "Music", "Activity", "Goal", "Need"])
|
152
|
+
(1..rows).each do |row|
|
153
|
+
table[row].values = [12345678, "Johnason", 12345678, "Johnason", 12345678, "Johnason", 12345678, "Johnason", 12345678, "Johnason", 12345678, "Johnason", 12345678, "Johnason", 12345678, "Johnason", 12345678, "Johnason", 12345678, "Johnason"]
|
197
154
|
end
|
155
|
+
table[rows].values = [12345123, "Peterson", 12345678, "Johnason", 12345678, "Johnason", 12345678, "Johnason", 12345678, "Johnason", 12345678, "Johnason", 12345678, "Johnason", 12345678, "Johnason", 12345678, "Johnason", 12345678, "Johnason"]
|
156
|
+
sleep 1
|
157
|
+
start_time = Time.now
|
158
|
+
listrow = table[{"Index" => 12345123, "Person" => "Peterson"}]
|
159
|
+
end_time = Time.now
|
160
|
+
duration = end_time - start_time
|
161
|
+
puts "duration: #{duration}"
|
162
|
+
puts "listrow.values: #{listrow.values}"
|
163
|
+
end
|
198
164
|
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "accessing a listrow" do
|
168
|
+
|
169
|
+
before do
|
170
|
+
@table1 = @sheet.table(1)
|
199
171
|
end
|
200
172
|
|
201
|
-
|
173
|
+
it "should access a listrow given its number" do
|
174
|
+
listrow = @table1[2]
|
175
|
+
listrow.should be_a ListRow
|
176
|
+
listrow.values.should == [2.0, "Fred", nil, 0.5416666666666666, 40]
|
177
|
+
end
|
202
178
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
179
|
+
it "should access a listrow via a multiple-column key" do
|
180
|
+
listrow = @table1[{"Number" => 3, "Person" => "Angel"}]
|
181
|
+
listrow.should be_a ListRow
|
182
|
+
listrow.values.should == [3.0, "Angel", 100, 0.6666666666666666, 60]
|
183
|
+
end
|
208
184
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
185
|
+
it "should access a listrow with key not case-sensitive or symbol" do
|
186
|
+
@table1[{"Person" => "Angel"}].values.should == [3.0, "Angel", 100, 0.6666666666666666, 60]
|
187
|
+
@table1[{"PERSON" => "Angel"}].values.should == [3.0, "Angel", 100, 0.6666666666666666, 60]
|
188
|
+
@table1[{"person" => "Angel"}].values.should == [3.0, "Angel", 100, 0.6666666666666666, 60]
|
189
|
+
@table1[{:person => "Angel"}].values.should == [3.0, "Angel", 100, 0.6666666666666666, 60]
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should yield nil if there is no match" do
|
193
|
+
@table1[{"Number" => 5, "Person" => "Angel"}].should == nil
|
194
|
+
@table1[{"Number" => 5, "Person" => "Angel"}, limit: :first].should == nil
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should yield nil if there is no match" do
|
198
|
+
@table1[{"Number" => 5, "Person" => "Angel"}, limit: 1].should == []
|
199
|
+
end
|
200
|
+
|
201
|
+
#it "should raise an error if the key contains no existing columns" do
|
202
|
+
# expect{
|
203
|
+
# @table1[{"Number" => 3, "Persona" => "Angel"}]
|
204
|
+
# }.to raise_error(TableError)
|
205
|
+
#end
|
206
|
+
|
207
|
+
it "should access one matching listrow" do
|
208
|
+
@table1[{"Number" => 3}, limit: :first].values.should == [3.0, "John", 50.0, 0.5, 30]
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should access one matching listrow" do
|
212
|
+
@table1[{"Number" => 3}, limit: 1].map{|l| l.values}.should == [[3.0, "John", 50.0, 0.5, 30]]
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should access two matching listrows" do
|
216
|
+
@table1[{"Number" => 3}, limit: 2].map{|l| l.values}.should == [[3.0, "John", 50.0, 0.5, 30],[3.0, "Angel", 100, 0.6666666666666666, 60]]
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should access four matching listrows" do
|
220
|
+
@table1[{"Number" => 3}, limit: 4].map{|l| l.values}.should == [[3.0, "John", 50.0, 0.5, 30],[3.0, "Angel", 100, 0.6666666666666666, 60],
|
221
|
+
[3.0, "Eiffel", 50.0, 0.5, 30], [3.0, "Berta", nil, 0.5416666666666666, 40]]
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should access all matching listrows" do
|
225
|
+
@table1[{"Number" => 3}, limit: nil].map{|l| l.values}.should == [[3.0, "John", 50.0, 0.5, 30],
|
226
|
+
[3.0, "Angel", 100, 0.6666666666666666, 60],
|
227
|
+
[3.0, "Eiffel", 50.0, 0.5, 30],
|
228
|
+
[3.0, "Berta", nil, 0.5416666666666666, 40],
|
229
|
+
[3.0, "Martha", nil, nil, nil],
|
230
|
+
[3.0, "Paul", 40.0, 0.5, 80]]
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should access listrows containing umlauts" do
|
234
|
+
#@table1[1].values = [1, "Sören", 20.0, 0.1, 40]
|
235
|
+
#@table1[{"Number" => 1, "Person" => "Sören"}].values.encode_value.should == [1, "Sören", 20.0, 0.1, 40]
|
236
|
+
@table1.add_column("Straße", 3, ["ä","ö","ü","ß","²","³","g","h","i","j","k","l","m"])
|
237
|
+
@table1[1].values = [1, "Sören", "Lösung", 20.0, 0.1, 40]
|
238
|
+
@table1[1].values.should == [1, "Sören", "Lösung", 20.0, 0.1, 40]
|
239
|
+
@table1[{"Number" => 1, "Person" => "Sören"}].values.encode_value.should == [1, "Sören", "Lösung", 20.0, 0.1, 40]
|
240
|
+
@table1[{"Number" => 1, "Straße" => "Lösung"}].values.encode_value.should == [1, "Sören", "Lösung", 20.0, 0.1, 40]
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
describe "#value" do
|
246
|
+
|
247
|
+
before do
|
248
|
+
@table1 = @sheet.table(1)
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should return values" do
|
252
|
+
table_value = [
|
253
|
+
["Number", "Person", "Amount", "Time", "Price"],
|
254
|
+
[3.0, "John", 50.0, 0.5, 30.0],
|
255
|
+
[2.0, "Fred", nil, 0.5416666666666666, 40.0],
|
256
|
+
[nil, nil, nil, nil, nil],
|
257
|
+
[3.0, "Angel", 100.0, 0.6666666666666666, 60.0],
|
258
|
+
[nil, nil, nil, nil, nil],
|
259
|
+
[1.0, "Werner", 40.0, 0.5, 80.0],
|
260
|
+
[3.0, "Eiffel", 50.0, 0.5, 30.0],
|
261
|
+
[3.0, "Berta", nil, 0.5416666666666666, 40.0],
|
262
|
+
[nil, nil, nil, nil, nil],
|
263
|
+
[nil, nil, nil, nil, nil],
|
264
|
+
[3.0, "Martha", nil, nil, nil],
|
265
|
+
[3.0, "Paul", 40.0, 0.5, 80.0],
|
266
|
+
[1.0, "Napoli", 20.0, 0.4166666666666667, 70.0]]
|
267
|
+
@table1.value.should == table_value
|
219
268
|
end
|
220
269
|
|
221
270
|
end
|
@@ -228,17 +277,17 @@ describe ListObject do
|
|
228
277
|
end
|
229
278
|
|
230
279
|
it "should read contents of a column" do
|
231
|
-
@table.column_values("Person").should == ["John","Fred",nil,"Angel",nil,"Werner"]
|
280
|
+
@table.column_values("Person").should == ["John","Fred",nil,"Angel",nil,"Werner","Eiffel","Berta",nil,nil,"Martha","Paul","Napoli"]
|
232
281
|
expect{
|
233
282
|
@table.column_values("P")
|
234
283
|
}.to raise_error(TableError)
|
235
284
|
end
|
236
285
|
|
237
286
|
it "should set contents of a column" do
|
238
|
-
@table.set_column_values("Person",["H",nil,nil,nil,"G","W"])
|
239
|
-
@table.ListColumns.Item(2).Range.Value.should == [["Person"],["H"],[nil],[nil],[nil],["G"],["W"]]
|
287
|
+
@table.set_column_values("Person",["H",nil,nil,nil,"G","W",nil,nil,nil,nil,nil,nil,nil])
|
288
|
+
@table.ListColumns.Item(2).Range.Value.should == [["Person"],["H"],[nil],[nil],[nil],["G"],["W"],[nil],[nil],[nil],[nil],[nil],[nil],[nil]]
|
240
289
|
@table.set_column_values("Person",["T","Z"])
|
241
|
-
@table.ListColumns.Item(2).Range.Value.should == [["Person"],["T"],["Z"],[nil],[nil],["G"],["W"]]
|
290
|
+
@table.ListColumns.Item(2).Range.Value.should == [["Person"],["T"],["Z"],[nil],[nil],["G"],["W"],[nil],[nil],[nil],[nil],[nil],[nil],[nil]]
|
242
291
|
expect{
|
243
292
|
@table.set_column_values("P",["H",nil,nil,nil,"G","W"])
|
244
293
|
}.to raise_error(TableError)
|
@@ -248,7 +297,7 @@ describe ListObject do
|
|
248
297
|
@table.row_values(1).should == [3.0, "John", 50.0, 0.5, 30]
|
249
298
|
@table[1].values.should == [3.0, "John", 50.0, 0.5, 30]
|
250
299
|
expect{
|
251
|
-
@table.row_values(
|
300
|
+
@table.row_values(14)
|
252
301
|
}.to raise_error(TableError)
|
253
302
|
end
|
254
303
|
|
@@ -261,10 +310,21 @@ describe ListObject do
|
|
261
310
|
@table[1].set_values([4, "John"])
|
262
311
|
@table.ListRows.Item(1).Range.Value.first.should == [4, "John", 20.0, 0.1, 40]
|
263
312
|
expect{
|
264
|
-
@table.set_row_values(
|
313
|
+
@table.set_row_values(14, [5, "George", 30.0, 0.2, 50])
|
265
314
|
}.to raise_error(TableError)
|
266
315
|
end
|
267
316
|
|
317
|
+
it "should set contents of an incomplete row " do
|
318
|
+
@table[1].values = [2, "Merlin", 20.0, 0.1, 40]
|
319
|
+
@table[1].values = [4, "John"]
|
320
|
+
@table.ListRows.Item(1).Range.Value.first.should == [4, "John", 20.0, 0.1, 40]
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should set contents of a row with umlauts" do
|
324
|
+
@table[1].values = [1, "Sören", 20.0, 0.1, 40]
|
325
|
+
@table.ListRows.Item(1).Range.Value.first.encode_value.should == [1, "Sören", 20.0, 0.1, 40]
|
326
|
+
end
|
327
|
+
|
268
328
|
end
|
269
329
|
|
270
330
|
describe "renaming, adding and deleting columns and rows" do
|
@@ -297,9 +357,15 @@ describe ListObject do
|
|
297
357
|
end
|
298
358
|
|
299
359
|
it "should add a column with contents" do
|
300
|
-
@table.add_column("column_name", 3, ["a","b","c","d","e","f"])
|
360
|
+
@table.add_column("column_name", 3, ["a","b","c","d","e","f","g","h","i","j","k","l","m"])
|
301
361
|
column_names = @table.HeaderRowRange.Value.first.should == ["Number","Person","column_name","Amount","Time","Price"]
|
302
|
-
@table.ListColumns.Item(3).Range.Value.should == [["column_name"],["a"],["b"],["c"],["d"],["e"],["f"]]
|
362
|
+
@table.ListColumns.Item(3).Range.Value.should == [["column_name"],["a"],["b"],["c"],["d"],["e"],["f"],["g"],["h"],["i"],["j"],["k"],["l"],["m"]]
|
363
|
+
end
|
364
|
+
|
365
|
+
it "should add a column with umlauts" do
|
366
|
+
@table.add_column("Sören", 3, ["ä","ö","ü","ß","²","³","g","h","i","j","k","l","m"])
|
367
|
+
column_names = @table.HeaderRowRange.Value.first.encode_value.should == ["Number","Person","Sören","Amount","Time","Price"]
|
368
|
+
@table.ListColumns.Item(3).Range.Value.map{|v| v.encode_value}.should == [["Sören"],["ä"],["ö"],["ü"],["ß"],["²"],["³"],["g"],["h"],["i"],["j"],["k"],["l"],["m"]]
|
303
369
|
end
|
304
370
|
|
305
371
|
it "should delete a column" do
|
@@ -323,7 +389,7 @@ describe ListObject do
|
|
323
389
|
listrows.Item(2).Range.Value.first.should == [nil,nil,nil,nil,nil]
|
324
390
|
listrows.Item(3).Range.Value.first.should == [2.0, "Fred", nil, 0.5416666666666666, 40]
|
325
391
|
expect{
|
326
|
-
@table.add_row(
|
392
|
+
@table.add_row(16)
|
327
393
|
}.to raise_error(TableError)
|
328
394
|
end
|
329
395
|
|
@@ -335,24 +401,29 @@ describe ListObject do
|
|
335
401
|
listrows.Item(3).Range.Value.first.should == [2.0, "Fred", nil, 0.5416666666666666, 40]
|
336
402
|
end
|
337
403
|
|
404
|
+
it "should add a row with contents with umlauts" do
|
405
|
+
@table.add_row(1, [2.0, "Sören", 30.0, 0.25, 40])
|
406
|
+
@table.ListRows.Item(1).Range.Value.first.encode_value.should == [2.0, "Sören", 30.0, 0.25, 40]
|
407
|
+
end
|
408
|
+
|
338
409
|
it "should delete a row" do
|
339
410
|
@table.delete_row(4)
|
340
411
|
listrows = @table.ListRows
|
341
412
|
listrows.Item(5).Range.Value.first.should == [1,"Werner",40,0.5, 80]
|
342
413
|
listrows.Item(4).Range.Value.first.should == [nil,nil,nil,nil,nil]
|
343
414
|
expect{
|
344
|
-
@table.delete_row(
|
415
|
+
@table.delete_row(15)
|
345
416
|
}.to raise_error(TableError)
|
346
417
|
end
|
347
418
|
|
348
419
|
it "should delete the contents of a column" do
|
349
|
-
@table.ListColumns.Item(3).Range.Value.should == [["Amount"],[50],[nil],[nil],[100],[nil],[40]]
|
420
|
+
@table.ListColumns.Item(3).Range.Value.should == [["Amount"],[50],[nil],[nil],[100],[nil],[40],[50],[nil],[nil],[nil],[nil],[40],[20]]
|
350
421
|
@table.delete_column_values(3)
|
351
422
|
@table.HeaderRowRange.Value.first.should == ["Number","Person", "Amount", "Time","Price"]
|
352
|
-
@table.ListColumns.Item(3).Range.Value.should == [["Amount"],[nil],[nil],[nil],[nil],[nil],[nil]]
|
353
|
-
@table.ListColumns.Item(1).Range.Value.should == [["Number"],[3],[2],[nil],[3],[nil],[1]]
|
423
|
+
@table.ListColumns.Item(3).Range.Value.should == [["Amount"],[nil],[nil],[nil],[nil],[nil],[nil],[nil],[nil],[nil],[nil],[nil],[nil],[nil]]
|
424
|
+
@table.ListColumns.Item(1).Range.Value.should == [["Number"],[3],[2],[nil],[3],[nil],[1],[3],[3],[nil],[nil],[3],[3],[1]]
|
354
425
|
@table.delete_column_values("Number")
|
355
|
-
@table.ListColumns.Item(1).Range.Value.should == [["Number"],[nil],[nil],[nil],[nil],[nil],[nil]]
|
426
|
+
@table.ListColumns.Item(1).Range.Value.should == [["Number"],[nil],[nil],[nil],[nil],[nil],[nil],[nil],[nil],[nil],[nil],[nil],[nil],[nil]]
|
356
427
|
expect{
|
357
428
|
@table.delete_column_values("N")
|
358
429
|
}.to raise_error(TableError)
|
@@ -366,13 +437,13 @@ describe ListObject do
|
|
366
437
|
@table[1].delete_values
|
367
438
|
@table.ListRows.Item(1).Range.Value.first.should == [nil,nil,nil,nil,nil]
|
368
439
|
expect{
|
369
|
-
@table.delete_row_values(
|
440
|
+
@table.delete_row_values(14)
|
370
441
|
}.to raise_error(TableError)
|
371
442
|
end
|
372
443
|
|
373
444
|
it "should delete empty rows" do
|
374
445
|
@table.delete_empty_rows
|
375
|
-
@table.ListRows.Count.should ==
|
446
|
+
@table.ListRows.Count.should == 9
|
376
447
|
@table.ListRows.Item(1).Range.Value.first.should == [3.0, "John", 50.0, 0.5, 30]
|
377
448
|
@table.ListRows.Item(2).Range.Value.first.should == [2.0, "Fred", nil, 0.5416666666666666, 40]
|
378
449
|
@table.ListRows.Item(3).Range.Value.first.should == [3, "Angel", 100, 0.6666666666666666, 60]
|
@@ -391,21 +462,58 @@ describe ListObject do
|
|
391
462
|
|
392
463
|
describe "find all cells of a given value" do
|
393
464
|
|
394
|
-
|
395
|
-
|
396
|
-
|
465
|
+
context "with standard" do
|
466
|
+
|
467
|
+
before do
|
468
|
+
ole_table = @sheet.ListObjects.Item(1)
|
469
|
+
@table = Table.new(ole_table)
|
470
|
+
end
|
471
|
+
|
472
|
+
it "should find all cells" do
|
473
|
+
cells = @table.find_cells(40)
|
474
|
+
cells[0].Row.should == 5
|
475
|
+
cells[0].Column.should == 8
|
476
|
+
cells[1].Row.should == 9
|
477
|
+
cells[1].Column.should == 6
|
478
|
+
end
|
479
|
+
|
397
480
|
end
|
398
481
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
482
|
+
context "with umlauts" do
|
483
|
+
|
484
|
+
before do
|
485
|
+
@table = Table.new(@sheet, "lösung", [1,1], 3, ["Verkäufer","Straße"])
|
486
|
+
@table[1].values = ["sören", "stück"]
|
487
|
+
@table[2].values = ["stück", "glück"]
|
488
|
+
@table[3].values = ["soße", "stück"]
|
489
|
+
end
|
490
|
+
|
491
|
+
it "should find all cells" do
|
492
|
+
cells = @table.find_cells("stück")
|
493
|
+
cells[0].Row.should == 2
|
494
|
+
cells[0].Column.should == 2
|
495
|
+
cells[1].Row.should == 3
|
496
|
+
cells[1].Column.should == 1
|
497
|
+
cells[2].Row.should == 4
|
498
|
+
cells[2].Column.should == 2
|
499
|
+
end
|
500
|
+
|
405
501
|
end
|
406
502
|
|
407
503
|
end
|
408
504
|
|
505
|
+
describe "==" do
|
506
|
+
|
507
|
+
it "should yield true" do
|
508
|
+
(@sheet.table(1) == @sheet.table(1)).should be true
|
509
|
+
end
|
510
|
+
|
511
|
+
it "should yield false" do
|
512
|
+
table2 = Table.new(@sheet, "lösung", [1,1], 3, ["Verkäufer","Straße"])
|
513
|
+
(table2 == @sheet.table(1)).should be false
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
409
517
|
describe "sort the table" do
|
410
518
|
|
411
519
|
before do
|
@@ -415,10 +523,15 @@ describe ListObject do
|
|
415
523
|
|
416
524
|
it "should sort the table according to first table" do
|
417
525
|
@table.sort("Number")
|
418
|
-
@table.ListRows.Item(1).Range.Value.first.should == [1,"Werner",40,0.5, 80]
|
419
|
-
@table.ListRows.Item(2).Range.Value.first.should == [
|
420
|
-
@table.ListRows.Item(3).Range.Value.first.should == [
|
421
|
-
@table.ListRows.Item(4).Range.Value.first.should == [3, "
|
526
|
+
@table.ListRows.Item(1).Range.Value.first.should == [1, "Werner",40,0.5, 80]
|
527
|
+
@table.ListRows.Item(2).Range.Value.first.should == [1, "Napoli", 20.0, 0.4166666666666667, 70.0]
|
528
|
+
@table.ListRows.Item(3).Range.Value.first.should == [2, "Fred", nil, 0.5416666666666666, 40]
|
529
|
+
@table.ListRows.Item(4).Range.Value.first.should == [3, "John", 50.0, 0.5, 30]
|
530
|
+
@table.ListRows.Item(5).Range.Value.first.should == [3, "Angel", 100, 0.6666666666666666, 60]
|
531
|
+
@table.ListRows.Item(6).Range.Value.first.should == [3, "Eiffel", 50.0, 0.5, 30]
|
532
|
+
@table.ListRows.Item(7).Range.Value.first.should == [3, "Berta", nil, 0.5416666666666666, 40]
|
533
|
+
@table.ListRows.Item(8).Range.Value.first.should == [3, "Martha", nil, nil, nil]
|
534
|
+
@table.ListRows.Item(9).Range.Value.first.should == [3, "Paul", 40.0, 0.5, 80]
|
422
535
|
end
|
423
536
|
|
424
537
|
end
|