robust_excel_ole 1.17 → 1.18.4

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.
@@ -71,7 +71,7 @@ module RobustExcelOle
71
71
  xy = "#{x}_#{y}"
72
72
  @cells = { }
73
73
  begin
74
- @cells[xy] = RobustExcelOle::Cell.new(@ole_worksheet.Cells.Item(x, y))
74
+ @cells[xy] = RobustExcelOle::Cell.new(@ole_worksheet.Cells.Item(x, y), @worksheet)
75
75
  rescue
76
76
  raise RangeNotEvaluatable, "cannot read cell (#{x.inspect},#{y.inspect})"
77
77
  end
@@ -108,16 +108,26 @@ module RobustExcelOle
108
108
  # value of a cell, if row and column are given
109
109
  # @params row and column
110
110
  # @returns value of the cell
111
+ def cellval(x,y)
112
+ begin
113
+ @ole_worksheet.Cells.Item(x, y).Value
114
+ rescue
115
+ raise RangeNotEvaluatable, "cannot read cell (#{x.inspect},#{y.inspect})"
116
+ end
117
+ end
118
+
119
+ =begin
111
120
  def cellval(x,y)
112
121
  xy = "#{x}_#{y}"
113
122
  @cells = { }
114
123
  begin
115
- @cells[xy] = RobustExcelOle::Cell.new(@ole_worksheet.Cells.Item(x, y))
124
+ @cells[xy] ||= RobustExcelOle::Cell.new(@ole_worksheet.Cells.Item(x, y), @worksheet)
116
125
  @cells[xy].Value
117
126
  rescue
118
127
  raise RangeNotEvaluatable, "cannot read cell (#{p1.inspect},#{p2.inspect})"
119
128
  end
120
129
  end
130
+ =end
121
131
 
122
132
  # sets the value of a cell, if row, column and color of the cell are given
123
133
  # @params [Integer] x,y row and column
@@ -130,6 +140,10 @@ module RobustExcelOle
130
140
  raise RangeNotEvaluatable, "cannot assign value #{value.inspect} to cell (#{y.inspect},#{x.inspect})"
131
141
  end
132
142
 
143
+ def values
144
+ @ole_worksheet.UsedRange.Value
145
+ end
146
+
133
147
  def each
134
148
  each_row do |row_range|
135
149
  row_range.each do |cell|
@@ -148,17 +162,35 @@ module RobustExcelOle
148
162
  end
149
163
  end
150
164
 
165
+ def each_rowvalue
166
+ @ole_worksheet.UsedRange.Value.each do |row_values|
167
+ yield row_values
168
+ end
169
+ end
170
+
171
+ def each_value # :deprecated: #
172
+ each_rowvalue
173
+ end
174
+
175
+ def each_rowvalue_with_index(offset = 0)
176
+ i = offset
177
+ @ole_worksheet.UsedRange.Value.each do |row_values|
178
+ yield row_values, i
179
+ i += 1
180
+ end
181
+ end
182
+
151
183
  def each_row(offset = 0)
152
184
  offset += 1
153
185
  1.upto(@end_row) do |row|
154
186
  next if row < offset
155
- yield RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(row, 1), @ole_worksheet.Cells(row, @end_column)))
187
+ yield RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(row, 1), @ole_worksheet.Cells(row, @end_column)), self)
156
188
  end
157
189
  end
158
190
 
159
191
  def each_row_with_index(offset = 0)
160
192
  each_row(offset) do |row_range|
161
- yield RobustExcelOle::Range.new(row_range), (row_range.Row - 1 - offset)
193
+ yield RobustExcelOle::Range.new(row_range, self), (row_range.Row - 1 - offset)
162
194
  end
163
195
  end
164
196
 
@@ -166,24 +198,24 @@ module RobustExcelOle
166
198
  offset += 1
167
199
  1.upto(@end_column) do |column|
168
200
  next if column < offset
169
- yield RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(1, column), @ole_worksheet.Cells(@end_row, column)))
201
+ yield RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(1, column), @ole_worksheet.Cells(@end_row, column)), self)
170
202
  end
171
203
  end
172
204
 
173
205
  def each_column_with_index(offset = 0)
174
206
  each_column(offset) do |column_range|
175
- yield RobustExcelOle::Range.new(column_range), (column_range.Column - 1 - offset)
207
+ yield RobustExcelOle::Range.new(column_range, self), (column_range.Column - 1 - offset)
176
208
  end
177
209
  end
178
210
 
179
211
  def row_range(row, integer_range = nil)
180
212
  integer_range ||= 1..@end_column
181
- RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(row, integer_range.min), @ole_worksheet.Cells(row, integer_range.max)))
213
+ RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(row, integer_range.min), @ole_worksheet.Cells(row, integer_range.max)), self)
182
214
  end
183
215
 
184
216
  def col_range(col, integer_range = nil)
185
217
  integer_range ||= 1..@end_row
186
- RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(integer_range.min, col), @ole_worksheet.Cells(integer_range.max, col)))
218
+ RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(integer_range.min, col), @ole_worksheet.Cells(integer_range.max, col)), self)
187
219
  end
188
220
 
189
221
  def == other_worksheet
@@ -0,0 +1,3 @@
1
+ Gem.post_install do
2
+ puts "post_install called for gem"
3
+ end
@@ -34,5 +34,5 @@ Gem::Specification.new do |s|
34
34
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
35
35
  s.require_paths = ["lib"]
36
36
  s.add_development_dependency "rspec", '>= 2.6.0'
37
- s.required_ruby_version = '>= 1.8.6'
37
+ s.required_ruby_version = '>= 2.1'
38
38
  end
@@ -35,6 +35,22 @@ module RobustExcelOle
35
35
  rm_tmp(@dir)
36
36
  end
37
37
 
38
+ context "active_workbook" do
39
+
40
+ before do
41
+ @excel = Excel.create
42
+ end
43
+
44
+ it "should access the active workbook" do
45
+ @excel.active_workbook.should be nil
46
+ workbook = Workbook.open(@simple_file1)
47
+ active_workbook = @excel.active_workbook
48
+ active_workbook.Fullname.should == workbook.Fullname
49
+ active_workbook.should == workbook
50
+ end
51
+
52
+ end
53
+
38
54
  context "with connect and preserving options" do
39
55
 
40
56
  before do
@@ -67,7 +67,6 @@ module RobustExcelOle
67
67
 
68
68
  it "should type-lift a cell" do
69
69
  cell = @book1.sheet(1).range([1,1]).ole_range.to_reo
70
- #cell = @book1.sheet(1)[1,1].ole_cell.to_reo
71
70
  cell.should be_kind_of Cell
72
71
  cell.Value.should == "foo"
73
72
  end
@@ -18,20 +18,74 @@ describe RobustExcelOle::Range do
18
18
  @book = Workbook.open(@dir + '/workbook.xls', :force_excel => :new)
19
19
  @sheet = @book.sheet(2)
20
20
  @range = RobustExcelOle::Range.new(@sheet.ole_worksheet.UsedRange.Rows(1))
21
+ @range2 = @sheet.range([1..2,1..3])
21
22
  end
22
23
 
23
24
  after do
24
- @book.close
25
+ @book.close(:if_unsaved => :forget)
25
26
  Excel.kill_all
26
27
  rm_tmp(@dir)
27
28
  end
28
29
 
30
+ describe "#[]" do
31
+
32
+ it "should yield a cell" do
33
+ @range[0].should be_kind_of RobustExcelOle::Cell
34
+ end
35
+
36
+ it "should yield the value of the first cell" do
37
+ @range2[0].Value.should == 'simple'
38
+ end
39
+
40
+ it "should cash the cells in the range" do
41
+ cell = @range2[0]
42
+ cell.v.should == 'simple'
43
+ @range2.Cells.Item(1).Value = 'foo'
44
+ cell.v.should == 'foo'
45
+ end
46
+ end
47
+
29
48
  describe "#each" do
49
+
30
50
  it "items is RobustExcelOle::Cell" do
31
- @range.each do |cell|
51
+ @range2.each do |cell|
32
52
  cell.should be_kind_of RobustExcelOle::Cell
33
53
  end
34
54
  end
55
+
56
+ it "should work with [] doing cashing synchonized, from #[] to #each" do
57
+ i = 0
58
+ @range2.each do |cell|
59
+ cell.v.should == 'simple' if i == 0
60
+ cell.v.should == 'file' if i == 1
61
+ cell.v.should == 'sheet2' if i == 2
62
+ i += 1
63
+ end
64
+ @range2[0].Value = 'foo'
65
+ @range2[1].Value = 'bar'
66
+ @range2[2].Value = 'simple'
67
+ i = 0
68
+ @range2.each do |cell|
69
+ cell.v.should == 'foo' if i == 0
70
+ cell.v.should == 'bar' if i == 1
71
+ cell.v.should == 'simple' if i == 2
72
+ i += 1
73
+ end
74
+ end
75
+
76
+ it "should work with [] doing cashing synchonized, from #each to #[]" do
77
+ @range2[0].Value.should == 'simple'
78
+ @range2[1].Value.should == 'file'
79
+ @range2[2].Value.should == 'sheet2'
80
+ i = 0
81
+ @range2.each do |cell|
82
+ cell.Value = 'foo' if i == 0
83
+ cell.Value = 'bar' if i == 1
84
+ cell.Value = 'simple' if i == 2
85
+ i += 1
86
+ end
87
+ end
88
+
35
89
  end
36
90
 
37
91
  describe "#values" do
@@ -295,6 +295,48 @@ describe Worksheet do
295
295
 
296
296
  end
297
297
 
298
+ describe "#values" do
299
+
300
+ it "should yield cell values of the used range" do
301
+ @sheet.values.should == [["foo", "workbook", "sheet1"], ["foo", nil, "foobaaa"], ["matz", "is", "nice"]]
302
+ end
303
+
304
+ end
305
+
306
+ describe "#each_rowvalue" do
307
+
308
+ it "should yield arrays" do
309
+ @sheet.each_rowvalue do |row_value|
310
+ row_value.should be_kind_of Array
311
+ end
312
+ end
313
+
314
+ it "should read the rows" do
315
+ i = 0
316
+ @sheet.each_rowvalue do |row_values|
317
+ case i
318
+ when 0
319
+ row_values.should == ['foo', 'workbook', 'sheet1']
320
+ when 1
321
+ row_values.should == ['foo', nil, 'foobaaa']
322
+ end
323
+ i += 1
324
+ end
325
+ end
326
+
327
+ it "should read the rows with index" do
328
+ @sheet.each_rowvalue_with_index do |row_values, i|
329
+ case i
330
+ when 0
331
+ row_values.should == ['foo', 'workbook', 'sheet1']
332
+ when 1
333
+ row_values.should == ['foo', nil, 'foobaaa']
334
+ end
335
+ end
336
+ end
337
+
338
+ end
339
+
298
340
  describe "#each_row" do
299
341
  it "items should RobustExcelOle::Range" do
300
342
  @sheet.each_row do |rows|
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.17'
4
+ version: 1.18.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - traths
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-13 00:00:00.000000000 Z
11
+ date: 2020-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -33,7 +33,9 @@ description: "RobustExcelOle helps controlling Excel. \n This
33
33
  are supported.\n It runs on Windows and uses the win32ole library."
34
34
  email:
35
35
  - Thomas.Raths@gmx.net
36
- executables: []
36
+ executables:
37
+ - jreo
38
+ - reo
37
39
  extensions: []
38
40
  extra_rdoc_files:
39
41
  - README.rdoc
@@ -50,11 +52,26 @@ files:
50
52
  - Rakefile
51
53
  - TodoList.md
52
54
  - ___dummy_workbook.xls
55
+ - benchmarking/Gemfile
56
+ - benchmarking/README.md
57
+ - benchmarking/creek_example.rb
58
+ - benchmarking/generating_excel_files.rb
59
+ - benchmarking/reo_example.rb
60
+ - benchmarking/reo_example1.rb
61
+ - benchmarking/reo_example2.rb
62
+ - benchmarking/roo_example.rb
63
+ - benchmarking/ruby_xl_example.rb
64
+ - benchmarking/sample_excel_files/xlsx_500_rows.xlsx
65
+ - benchmarking/simple_xlsx_reader_example.rb
66
+ - benchmarking/spreadsheet_example.rb
67
+ - bin/jreo
68
+ - bin/reo
53
69
  - docs/README_excel.rdoc
54
70
  - docs/README_open.rdoc
55
71
  - docs/README_ranges.rdoc
56
72
  - docs/README_save_close.rdoc
57
73
  - docs/README_sheet.rdoc
74
+ - examples/example_ruby_library.rb
58
75
  - examples/introductory_examples/example_introductory.rb
59
76
  - examples/introductory_examples/example_open.rb
60
77
  - examples/introductory_examples/example_range.rb
@@ -96,9 +113,11 @@ files:
96
113
  - lib/robust_excel_ole/range_owners.rb
97
114
  - lib/robust_excel_ole/robustexcelole.sublime-project
98
115
  - lib/robust_excel_ole/robustexcelole.sublime-workspace
116
+ - lib/robust_excel_ole/vba_objects.rb
99
117
  - lib/robust_excel_ole/version.rb
100
118
  - lib/robust_excel_ole/workbook.rb
101
119
  - lib/robust_excel_ole/worksheet.rb
120
+ - lib/rubygems_plugin.rb
102
121
  - lib/spec_helper.rb
103
122
  - reo.bat
104
123
  - robust_excel_ole.gemspec
@@ -155,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
174
  requirements:
156
175
  - - ">="
157
176
  - !ruby/object:Gem::Version
158
- version: 1.8.6
177
+ version: '2.1'
159
178
  required_rubygems_version: !ruby/object:Gem::Requirement
160
179
  requirements:
161
180
  - - ">="