robust_excel_ole 1.27 → 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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog +36 -2
  3. data/README.rdoc +121 -19
  4. data/___dummy_workbook.xls +0 -0
  5. data/benchmarking/creek_example.rb +1 -1
  6. data/benchmarking/reo_example.rb +1 -1
  7. data/benchmarking/reo_example1.rb +1 -1
  8. data/benchmarking/reo_example2.rb +1 -1
  9. data/benchmarking/roo_example.rb +1 -1
  10. data/benchmarking/simple_xlsx_reader_example.rb +1 -1
  11. data/benchmarking/spreadsheet_example.rb +1 -1
  12. data/bin/jreo +19 -0
  13. data/bin/reo +19 -0
  14. data/docs/README_excel.rdoc +16 -24
  15. data/docs/README_listobjects.rdoc +176 -0
  16. data/docs/README_open.rdoc +20 -16
  17. data/docs/README_ranges.rdoc +72 -55
  18. data/docs/README_save_close.rdoc +3 -3
  19. data/docs/README_sheet.rdoc +19 -20
  20. data/examples/example_ruby_library.rb +2 -2
  21. data/examples/introductory_examples/example_open.rb +11 -0
  22. data/examples/introductory_examples/example_range.rb +2 -2
  23. data/examples/modifying_sheets/example_access_sheets_and_cells.rb +6 -6
  24. data/examples/modifying_sheets/example_add_names.rb +1 -1
  25. data/examples/modifying_sheets/example_concating.rb +1 -1
  26. data/examples/modifying_sheets/example_copying.rb +2 -2
  27. data/examples/modifying_sheets/example_listobjects.rb +86 -0
  28. data/examples/modifying_sheets/example_naming.rb +1 -1
  29. data/examples/modifying_sheets/example_ranges.rb +1 -1
  30. data/examples/open_save_close/example_control_to_excel.rb +1 -1
  31. data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +1 -1
  32. data/examples/open_save_close/example_if_obstructed_save.rb +3 -3
  33. data/examples/open_save_close/example_if_unsaved_accept.rb +1 -1
  34. data/examples/open_save_close/example_if_unsaved_forget.rb +3 -3
  35. data/examples/open_save_close/example_if_unsaved_forget_more.rb +4 -4
  36. data/examples/open_save_close/example_read_only.rb +1 -1
  37. data/examples/open_save_close/example_simple.rb +1 -1
  38. data/examples/open_save_close/example_unobtrusively.rb +3 -3
  39. data/lib/robust_excel_ole.rb +19 -16
  40. data/lib/robust_excel_ole/address_tool.rb +54 -44
  41. data/lib/robust_excel_ole/base.rb +9 -6
  42. data/lib/robust_excel_ole/bookstore.rb +3 -17
  43. data/lib/robust_excel_ole/cell.rb +17 -22
  44. data/lib/robust_excel_ole/cygwin.rb +2 -0
  45. data/lib/robust_excel_ole/excel.rb +136 -201
  46. data/lib/robust_excel_ole/general.rb +249 -238
  47. data/lib/robust_excel_ole/list_object.rb +186 -210
  48. data/lib/robust_excel_ole/list_row.rb +155 -0
  49. data/lib/robust_excel_ole/range.rb +130 -94
  50. data/lib/robust_excel_ole/range_owners.rb +54 -135
  51. data/lib/robust_excel_ole/version.rb +1 -1
  52. data/lib/robust_excel_ole/workbook.rb +230 -196
  53. data/lib/robust_excel_ole/worksheet.rb +254 -133
  54. data/lib/spec_helper.rb +1 -1
  55. data/robust_excel_ole.gemspec +4 -3
  56. data/spec/address_tool_spec.rb +2 -2
  57. data/spec/base_spec.rb +19 -17
  58. data/spec/bookstore_spec.rb +3 -4
  59. data/spec/cell_spec.rb +10 -10
  60. data/spec/cygwin_spec.rb +1 -1
  61. data/spec/data/more_data/workbook.xls +0 -0
  62. data/spec/excel_spec.rb +133 -86
  63. data/spec/general_spec.rb +79 -18
  64. data/spec/list_object_spec.rb +259 -81
  65. data/spec/list_row_spec.rb +218 -0
  66. data/spec/range_spec.rb +75 -41
  67. data/spec/spec_helper.rb +16 -2
  68. data/spec/workbook_spec.rb +87 -46
  69. data/spec/workbook_specs/workbook_all_spec.rb +9 -28
  70. data/spec/workbook_specs/workbook_close_spec.rb +1 -1
  71. data/spec/workbook_specs/workbook_misc_spec.rb +52 -45
  72. data/spec/workbook_specs/workbook_open_spec.rb +103 -50
  73. data/spec/workbook_specs/workbook_save_spec.rb +22 -23
  74. data/spec/workbook_specs/workbook_sheet_spec.rb +4 -4
  75. data/spec/workbook_specs/workbook_subclass_spec.rb +1 -1
  76. data/spec/workbook_specs/workbook_unobtr_spec.rb +553 -395
  77. data/spec/worksheet_spec.rb +544 -308
  78. metadata +38 -3
  79. data/lib/reo_console.rb +0 -42
data/spec/general_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require File.join(File.dirname(__FILE__), './spec_helper')
3
+ require_relative 'spec_helper'
4
4
 
5
5
  $VERBOSE = nil
6
6
 
@@ -9,6 +9,10 @@ include RobustExcelOle
9
9
 
10
10
  module RobustExcelOle
11
11
 
12
+ using StringRefinement
13
+ using ToReoRefinement
14
+ using FindAllIndicesRefinement
15
+
12
16
  describe General do
13
17
 
14
18
  before(:all) do
@@ -31,6 +35,8 @@ module RobustExcelOle
31
35
  @simple_file_xlsx = @dir + '/workbook.xlsx'
32
36
  @network_path = "N:/data/workbook.xls"
33
37
  @hostname_share_path = "//DESKTOP-A3C5CJ6/spec/data/workbook.xls"
38
+ @network_path_downcase = "n:/data/workbook.xls"
39
+ @hostname_share_path_downcase = "//desktop-a3c5cj6/spec/data/workbook.xls"
34
40
  @simple_file_extern = "D:/data/workbook.xls"
35
41
  @hostname_share_path = "//DESKTOP-A3C5CJ6/spec/data/workbook.xls"
36
42
  end
@@ -40,6 +46,33 @@ module RobustExcelOle
40
46
  rm_tmp(@dir)
41
47
  end
42
48
 
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]
60
+ end
61
+
62
+ end
63
+
64
+ describe "relace_umlauts, underscore" do
65
+
66
+ it "should replace umlauts" do
67
+ "BeforeÄÖÜäöüß²³After".replace_umlauts.should == "BeforeAeOeUeaeoeuess23After"
68
+ end
69
+
70
+ it "should underscore" do
71
+ "BeforeAfter".underscore.should == "before_after"
72
+ end
73
+
74
+ end
75
+
43
76
  describe "to_reo" do
44
77
 
45
78
  before do
@@ -47,14 +80,25 @@ module RobustExcelOle
47
80
  @book2 = Workbook.open(@listobject_file)
48
81
  end
49
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
+
50
94
  it "should type-lift an ListObject" do
51
95
  worksheet = @book2.sheet(3)
52
96
  ole_table = worksheet.ListObjects.Item(1)
53
97
  table = Table.new(ole_table)
54
98
  table.Name.should == "table3"
55
99
  table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
56
- table.ListRows.Count.should == 6
57
- worksheet[3,4].Value.should == "Number"
100
+ table.ListRows.Count.should == 13
101
+ worksheet[3,4].should == "Number"
58
102
  end
59
103
 
60
104
  it "should type-lift an Excel" do
@@ -92,18 +136,34 @@ module RobustExcelOle
92
136
  @book1.sheet(1).to_reo.should == @book1.sheet(1)
93
137
  @book1.excel.to_reo.should == @book1.excel
94
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)
95
148
  end
96
149
 
97
150
  end
98
151
 
99
- describe "General.uplift_to_reo" do
152
+ describe "General.init_reo_for_win32ole" do
100
153
 
101
154
  before do
102
155
  @book1 = Workbook.open(@simple_file, :visible => true)
103
156
  end
104
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
+
105
166
  it "should apply reo-methods to win32ole objects" do
106
- General.uplift_to_reo
107
167
  ole_book1 = @book1.ole_workbook
108
168
  sheet1 = ole_book1.sheet(1)
109
169
  sheet1.should be_a Worksheet
@@ -249,13 +309,6 @@ module RobustExcelOle
249
309
  canonize("this../.i.s/.../..the/..../pa.th/").should == "this../.i.s/.../..the/..../pa.th"
250
310
  end
251
311
 
252
- =begin
253
- it "should downcase" do
254
- canonize("/This/IS/tHe/path").should == "/this/is/the/path"
255
- canonize("///THIS/.///./////iS//the/../PatH/////").should == "/this/is/path"
256
- end
257
- =end
258
-
259
312
  it "should raise an error for no strings" do
260
313
  expect{
261
314
  canonize(1)
@@ -267,6 +320,8 @@ module RobustExcelOle
267
320
  General.canonize(@network_path).should == @network_path
268
321
  General.canonize(@simple_file).should == @simple_file
269
322
  General.canonize(@simple_file_extern).should == @simple_file_extern
323
+ General.canonize(@hostname_share_path_downcase).should == @network_path
324
+ General.canonize(@network_path_downcase).should == @network_path_downcase
270
325
  end
271
326
 
272
327
  end
@@ -277,12 +332,18 @@ module RobustExcelOle
277
332
  it "should create a path" do
278
333
  path1 = "this" / "is" / "a" / "path"
279
334
  path1.should == "this/is/a/path"
280
- path2 = "this" / "is" / "a" / "path" /
281
- #path2.should == "this/is/a/path/"
282
- path3 = "this" /
283
- #path3.should == "this/"
284
- path4 = "this" / nil
285
- path4.should == "this"
335
+ path2 = "this" / nil
336
+ path2.should == "this"
337
+ path3 = "N:/E2" / "C:/gim/E2/workbook.xls"
338
+ path3.should == "C:/gim/E2/workbook.xls"
339
+ path4 = "N:/E2/" / "/gim/E2/workbook.xls"
340
+ path4.should == "/gim/E2/workbook.xls"
341
+ path5 = "N:/E2/" / "gim/E2/workbook.xls"
342
+ path5.should == "N:/E2/gim/E2/workbook.xls"
343
+ path6 = "N:/E2" / "spec/data/workbook.xls"
344
+ path6.should == "N:/E2/spec/data/workbook.xls"
345
+ path7 = "N:/E2" / "c:/gim/E2/workbook.xls"
346
+ path7.should == "c:/gim/E2/workbook.xls"
286
347
  end
287
348
  end
288
349
 
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require File.join(File.dirname(__FILE__), './spec_helper')
3
+ require_relative 'spec_helper'
4
4
 
5
5
  $VERBOSE = nil
6
6
 
@@ -10,7 +10,7 @@ include General
10
10
  describe ListObject do
11
11
 
12
12
  before(:all) do
13
- excel = Excel.new(:reuse => true)
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, :visible => true)
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(:if_unsaved => :forget)
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].Value.should == "Person"
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 == 6
57
- @sheet[3,4].Value.should == "Number"
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 == 6
66
- @sheet[3,4].Value.should == "Number"
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 == 6
75
- @sheet[3,4].Value.should == "Number"
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].Value.should == "Person"
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 == 6
92
- @sheet[3,4].Value.should == "Number"
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,60 +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 == 6
101
- @sheet[3,4].Value.should == "Number"
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 "getting and setting values" do
131
+ describe "each" do
109
132
 
110
- context "with new table" do
133
+ before do
134
+ @table1 = @sheet.table(1)
135
+ end
111
136
 
112
- before do
113
- @table = Table.new(@sheet, "table_name", [1,1], 3, ["Person","Amo%untSales"])
114
- @table_row1 = @table[1]
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
115
142
  end
143
+ end
144
+
145
+ end
146
+
147
+ describe "benchmarking for accessing a listrow" do
116
148
 
117
- it "should read and set values via alternative column names" do
118
- @table_row1.person.should be nil
119
- @table_row1.person = "John"
120
- @table_row1.person.should == "John"
121
- @sheet[2,1].Value.should == "John"
122
- @table_row1.amount_sales.should be nil
123
- @table_row1.amount_sales = 42
124
- @table_row1.amount_sales.should == 42
125
- @sheet[2,2].Value.should == 42
126
- @table_row1.Person = "Herbert"
127
- @table_row1.Person.should == "Herbert"
128
- @sheet[2,1].Value.should == "Herbert"
129
- @table_row1.AmountSales = 80
130
- @table_row1.AmountSales.should == 80
131
- @sheet[2,2].Value.should == 80
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"]
132
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
164
+
165
+ end
133
166
 
167
+ describe "accessing a listrow" do
168
+
169
+ before do
170
+ @table1 = @sheet.table(1)
134
171
  end
135
172
 
136
- context "with type-lifted ole list object" do
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
137
178
 
138
- before do
139
- ole_table = @sheet.ListObjects.Item(1)
140
- @table = Table.new(ole_table)
141
- @table_row1 = @table[1]
142
- end
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
143
184
 
144
- it "should set and read values" do
145
- @table_row1.number.should == 3
146
- @table_row1.number = 1
147
- @table_row1.number.should == 1
148
- @sheet[4,4].Value.should == 1
149
- @table_row1.person.should == "John"
150
- @table_row1.person = "Herbert"
151
- @table_row1.person.should == "Herbert"
152
- @sheet[4,5].Value.should == "Herbert"
153
- end
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
154
268
  end
155
269
 
156
270
  end
@@ -163,17 +277,17 @@ describe ListObject do
163
277
  end
164
278
 
165
279
  it "should read contents of a column" do
166
- @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"]
167
281
  expect{
168
282
  @table.column_values("P")
169
283
  }.to raise_error(TableError)
170
284
  end
171
285
 
172
286
  it "should set contents of a column" do
173
- @table.set_column_values("Person",["H",nil,nil,nil,"G","W"])
174
- @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]]
175
289
  @table.set_column_values("Person",["T","Z"])
176
- @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]]
177
291
  expect{
178
292
  @table.set_column_values("P",["H",nil,nil,nil,"G","W"])
179
293
  }.to raise_error(TableError)
@@ -183,7 +297,7 @@ describe ListObject do
183
297
  @table.row_values(1).should == [3.0, "John", 50.0, 0.5, 30]
184
298
  @table[1].values.should == [3.0, "John", 50.0, 0.5, 30]
185
299
  expect{
186
- @table.row_values(9)
300
+ @table.row_values(14)
187
301
  }.to raise_error(TableError)
188
302
  end
189
303
 
@@ -196,10 +310,21 @@ describe ListObject do
196
310
  @table[1].set_values([4, "John"])
197
311
  @table.ListRows.Item(1).Range.Value.first.should == [4, "John", 20.0, 0.1, 40]
198
312
  expect{
199
- @table.set_row_values(9, [5, "George", 30.0, 0.2, 50])
313
+ @table.set_row_values(14, [5, "George", 30.0, 0.2, 50])
200
314
  }.to raise_error(TableError)
201
315
  end
202
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
+
203
328
  end
204
329
 
205
330
  describe "renaming, adding and deleting columns and rows" do
@@ -232,9 +357,15 @@ describe ListObject do
232
357
  end
233
358
 
234
359
  it "should add a column with contents" do
235
- @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"])
236
361
  column_names = @table.HeaderRowRange.Value.first.should == ["Number","Person","column_name","Amount","Time","Price"]
237
- @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"]]
238
369
  end
239
370
 
240
371
  it "should delete a column" do
@@ -258,7 +389,7 @@ describe ListObject do
258
389
  listrows.Item(2).Range.Value.first.should == [nil,nil,nil,nil,nil]
259
390
  listrows.Item(3).Range.Value.first.should == [2.0, "Fred", nil, 0.5416666666666666, 40]
260
391
  expect{
261
- @table.add_row(9)
392
+ @table.add_row(16)
262
393
  }.to raise_error(TableError)
263
394
  end
264
395
 
@@ -270,24 +401,29 @@ describe ListObject do
270
401
  listrows.Item(3).Range.Value.first.should == [2.0, "Fred", nil, 0.5416666666666666, 40]
271
402
  end
272
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
+
273
409
  it "should delete a row" do
274
410
  @table.delete_row(4)
275
411
  listrows = @table.ListRows
276
412
  listrows.Item(5).Range.Value.first.should == [1,"Werner",40,0.5, 80]
277
413
  listrows.Item(4).Range.Value.first.should == [nil,nil,nil,nil,nil]
278
414
  expect{
279
- @table.delete_row(8)
415
+ @table.delete_row(15)
280
416
  }.to raise_error(TableError)
281
417
  end
282
418
 
283
419
  it "should delete the contents of a column" do
284
- @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]]
285
421
  @table.delete_column_values(3)
286
422
  @table.HeaderRowRange.Value.first.should == ["Number","Person", "Amount", "Time","Price"]
287
- @table.ListColumns.Item(3).Range.Value.should == [["Amount"],[nil],[nil],[nil],[nil],[nil],[nil]]
288
- @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]]
289
425
  @table.delete_column_values("Number")
290
- @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]]
291
427
  expect{
292
428
  @table.delete_column_values("N")
293
429
  }.to raise_error(TableError)
@@ -301,13 +437,13 @@ describe ListObject do
301
437
  @table[1].delete_values
302
438
  @table.ListRows.Item(1).Range.Value.first.should == [nil,nil,nil,nil,nil]
303
439
  expect{
304
- @table.delete_row_values(9)
440
+ @table.delete_row_values(14)
305
441
  }.to raise_error(TableError)
306
442
  end
307
443
 
308
444
  it "should delete empty rows" do
309
445
  @table.delete_empty_rows
310
- @table.ListRows.Count.should == 4
446
+ @table.ListRows.Count.should == 9
311
447
  @table.ListRows.Item(1).Range.Value.first.should == [3.0, "John", 50.0, 0.5, 30]
312
448
  @table.ListRows.Item(2).Range.Value.first.should == [2.0, "Fred", nil, 0.5416666666666666, 40]
313
449
  @table.ListRows.Item(3).Range.Value.first.should == [3, "Angel", 100, 0.6666666666666666, 60]
@@ -326,21 +462,58 @@ describe ListObject do
326
462
 
327
463
  describe "find all cells of a given value" do
328
464
 
329
- before do
330
- ole_table = @sheet.ListObjects.Item(1)
331
- @table = Table.new(ole_table)
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
+
332
480
  end
333
481
 
334
- it "should find all cells" do
335
- cells = @table.find_cells(40)
336
- cells[0].Row.should == 5
337
- cells[0].Column.should == 8
338
- cells[1].Row.should == 9
339
- cells[1].Column.should == 6
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
+
340
501
  end
341
502
 
342
503
  end
343
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
+
344
517
  describe "sort the table" do
345
518
 
346
519
  before do
@@ -350,10 +523,15 @@ describe ListObject do
350
523
 
351
524
  it "should sort the table according to first table" do
352
525
  @table.sort("Number")
353
- @table.ListRows.Item(1).Range.Value.first.should == [1,"Werner",40,0.5, 80]
354
- @table.ListRows.Item(2).Range.Value.first.should == [2, "Fred", nil, 0.5416666666666666, 40]
355
- @table.ListRows.Item(3).Range.Value.first.should == [3, "John", 50.0, 0.5, 30]
356
- @table.ListRows.Item(4).Range.Value.first.should == [3, "Angel", 100, 0.6666666666666666, 60]
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]
357
535
  end
358
536
 
359
537
  end