robust_excel_ole 1.17 → 1.18

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c268eff75271d48aae54af54c03c138e8a965a6c6965b6fc9b5fd330a346888d
4
- data.tar.gz: '0921d96d9d20546523acb5ea5e419d8e2351307c23d25abe8b8d96010364b643'
3
+ metadata.gz: 7f98eac7f4995b60c16017d6be170e0621eaf77b708c4f796b4bde1b0bdb17fc
4
+ data.tar.gz: bdad471c90fbda86803c03860077e29d2eba3583ec94173d782f8f80b1eb3480
5
5
  SHA512:
6
- metadata.gz: c98669d651a2ff192bab0767ea16085a08cab8e0c656c3123b684080b96b62899967f3c4998637002dddf72eb1dbbd635f2ef102153d53842977adeba11d32c6
7
- data.tar.gz: 1ac22fd73f4dae16142c1dc1d81bd9d9f8eeb5fbf95f85b4bcf26d99293b474c544aae863af4d40cc64052535ab40541956b69db8301274aade5afcacea37534
6
+ metadata.gz: a8a472ec475629d7f9cb2d6886ed009a23e1a5598ba79152accca7f21dde87b05ff46f4a6f776acc6b75ea21538249df31e94145883946d379e0b71dcdcae05f
7
+ data.tar.gz: 90aa4909eaec50fc74b57c75ad5112ba4216e49177263532dbf703ad4d3694b5a64f7f4c69613dac528fc9cf7874dae98d39900bef5aa62eee3bfb0a860bc215
data/Changelog CHANGED
@@ -1,6 +1,24 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.18] 2020-30-4
5
+
6
+ ### Added
7
+ - Workbook#worksheets, worksheets_count
8
+ - Worksheet#each_value
9
+ - Range#value, value=
10
+
11
+ ### Changed
12
+ - Range#initialize: optional paramter worksheet
13
+
14
+ ## [1.17]
15
+
16
+ ### Added
17
+ - Excel#active_workbook
18
+
19
+ ### Changed
20
+ - Excel#namevalue, set_namevalue, namevalue_glob, set_namevalue_glob are being removed
21
+
4
22
  ## [1.16]
5
23
 
6
24
  ### Added
@@ -14,6 +14,23 @@ Library references are supported.
14
14
  RobustExcelOle works by sending VBA methods via Win32OLE.
15
15
  Therefore, it runs on Windows only.
16
16
 
17
+ == Feature list
18
+
19
+ - opening and processing workbooks across various Excel instances
20
+ - reading and writing workbooks (cells and ranges)
21
+ - reopening and unobtrusively opening workbooks
22
+ - convenient methods for standard tasks (like opening, reading, writing, closing, saving workbooks, naming, adding, and copying ranges and worksheets)
23
+ - dealing with various cases of Excel and user behaviour, e.g. managing conflicts when opening workbooks (e.g. blocking or unsaved workbooks),
24
+ even with simultanously happening user interactions
25
+ - workarounds for Excel bugs and JRuby bugs
26
+ - various workbook formats, e.g. .xlsx, .xls, .xlsm are supported
27
+ - library references are supported
28
+ - console for convenient usage
29
+
30
+ == What's new?
31
+
32
+ - removing methods to operate on ranges directly from an Excel instance. However, you can use the method Excel.active_workbook to do so.
33
+ See ChangeLogs.
17
34
 
18
35
  == Requirements
19
36
 
@@ -124,6 +124,12 @@ or, with a block,
124
124
 
125
125
  excel.each_workbook(:visible => true) {|w| puts w}
126
126
 
127
+ === Accessing the active workbook
128
+
129
+ You can operate on the active workbook with help of the method Workbook#active_workbook, e.g.
130
+
131
+ workbook = excel.active_workbook
132
+
127
133
  === Bringing an Excel instance to the foreground
128
134
 
129
135
  excel1.focus
@@ -394,6 +394,12 @@ The methods Worksheet#each, Worksheet#each_row and Worksheet#each_column enable
394
394
  # do something with column
395
395
  end
396
396
 
397
+ The method Worksheet#each_value accesses the values of each row.
398
+
399
+ worksheet.each_value do |row_values|
400
+ # do something with the row_values
401
+ end
402
+
397
403
  You access a range of a row by giving the number of the row, and optionally, the range of the cell numbers.
398
404
 
399
405
  worksheet.row_range(1) # => first row
@@ -0,0 +1,27 @@
1
+ #require 'robust_excel_ole'
2
+
3
+ #workbook = Workbook.open './sample_excel_files/xlsx_500_rows.xlsx'
4
+
5
+ require_relative '../lib/robust_excel_ole'
6
+
7
+ include RobustExcelOle
8
+
9
+ workbook = Workbook.open './../spec/data/workbook.xls'
10
+
11
+ puts "Found #{workbook.worksheets_count} worksheets"
12
+
13
+ workbook.each do |worksheet|
14
+ puts "Reading: #{worksheet.name}"
15
+ num_rows = 0
16
+
17
+ worksheet.each do |row|
18
+ row_cells = row.map{ |cell| cell.value }
19
+ num_rows += 1
20
+
21
+ # uncomment to print out row values
22
+ # puts row_cells.join " "
23
+ end
24
+ puts "Read #{num_rows} rows"
25
+ end
26
+
27
+ puts 'Done'
@@ -0,0 +1,7 @@
1
+ dummy_make_content = "make:\n" \
2
+ "\t:\n" \
3
+ "install:\n" \
4
+ "\t:\n" \
5
+ "clean:\n" \
6
+ "\t:\n"
7
+ File.write('Makefile', dummy_make_content)
@@ -12,8 +12,8 @@ require File.join(File.dirname(__FILE__), 'robust_excel_ole/excel')
12
12
  require File.join(File.dirname(__FILE__), 'robust_excel_ole/bookstore')
13
13
  require File.join(File.dirname(__FILE__), 'robust_excel_ole/workbook')
14
14
  require File.join(File.dirname(__FILE__), 'robust_excel_ole/worksheet')
15
- require File.join(File.dirname(__FILE__), 'robust_excel_ole/range')
16
15
  require File.join(File.dirname(__FILE__), 'robust_excel_ole/cell')
16
+ require File.join(File.dirname(__FILE__), 'robust_excel_ole/range')
17
17
  require File.join(File.dirname(__FILE__), 'robust_excel_ole/cygwin') if RUBY_PLATFORM =~ /cygwin/
18
18
  require File.join(File.dirname(__FILE__), 'robust_excel_ole/version')
19
19
 
@@ -1,13 +1,15 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
+ require File.join(File.dirname(__FILE__), './range')
4
+
3
5
  module RobustExcelOle
4
6
 
5
7
  class Cell < Range
6
- attr_reader :ole_cell
8
+ #attr_reader :ole_cell
7
9
 
8
- def initialize(win32_cell)
9
- @ole_cell = win32_cell.MergeCells ? win32_cell.MergeArea.Item(1,1) : win32_cell
10
+ def initialize(win32_cell, worksheet)
10
11
  super
12
+ ole_cell
11
13
  end
12
14
 
13
15
  def v
@@ -18,6 +20,10 @@ module RobustExcelOle
18
20
  self.Value = value
19
21
  end
20
22
 
23
+ def ole_cell
24
+ @ole_range = @ole_range.MergeArea.Item(1,1) if @ole_range.MergeCells
25
+ end
26
+
21
27
  private
22
28
 
23
29
  # @private
@@ -25,13 +31,15 @@ module RobustExcelOle
25
31
  if name.to_s[0,1] =~ /[A-Z]/
26
32
  if ::ERRORMESSAGE_JRUBY_BUG
27
33
  begin
28
- @ole_cell.send(name, *args)
34
+ #@ole_cell.send(name, *args)
35
+ @ole_range.send(name, *args)
29
36
  rescue Java::OrgRacobCom::ComFailException
30
37
  raise VBAMethodMissingError, "unknown VBA property or method #{name.inspect}"
31
38
  end
32
39
  else
33
40
  begin
34
- @ole_cell.send(name, *args)
41
+ #@ole_cell.send(name, *args)
42
+ @ole_range.send(name, *args)
35
43
  rescue NoMethodError
36
44
  raise VBAMethodMissingError, "unknown VBA property or method #{name.inspect}"
37
45
  end
@@ -3,8 +3,6 @@
3
3
  require 'weakref'
4
4
  require 'Win32API'
5
5
 
6
-
7
-
8
6
  def ka
9
7
  Excel.kill_all
10
8
  end
@@ -709,8 +707,7 @@ module RobustExcelOle
709
707
  # @private
710
708
  # returns active workbook
711
709
  def workbook
712
- return @workbook unless @workbook.nil?
713
- @workbook = workbook_class.new(@ole_excel.ActiveWorkbook)
710
+ @workbook ||= workbook_class.new(@ole_excel.ActiveWorkbook) if @ole_excel.Workbooks.Count > 0
714
711
  end
715
712
 
716
713
  alias_method :active_workbook, :workbook
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+
2
3
  module RobustExcelOle
3
4
 
4
5
  # This class essentially wraps a Win32Ole Range object.
@@ -11,17 +12,33 @@ module RobustExcelOle
11
12
  attr_reader :ole_range
12
13
  attr_reader :worksheet
13
14
 
14
- def initialize(win32_range)
15
+ def initialize(win32_range, worksheet = nil)
15
16
  @ole_range = win32_range
16
- @worksheet = worksheet_class.new(self.Parent)
17
+ @worksheet = worksheet ? worksheet : worksheet_class.new(self.Parent)
18
+ #@worksheet = worksheet_class.new(self.Parent)
17
19
  end
18
20
 
19
21
  def each
20
- @ole_range.each do |row_or_column|
21
- yield RobustExcelOle::Cell.new(row_or_column)
22
+ @ole_range.each_with_index do |ole_cell, index|
23
+ yield cell(index){ole_cell}
22
24
  end
23
25
  end
24
26
 
27
+ def [] index
28
+ cell(index) {
29
+ @ole_range.Cells.Item(index + 1)
30
+ }
31
+ end
32
+
33
+ private
34
+
35
+ def cell(index)
36
+ @cells ||= []
37
+ @cells[index + 1] ||= RobustExcelOle::Cell.new(yield,@worksheet)
38
+ end
39
+
40
+ public
41
+
25
42
  # returns flat array of the values of a given range
26
43
  # @params [Range] a range
27
44
  # @returns [Array] the values
@@ -82,10 +99,8 @@ module RobustExcelOle
82
99
  end
83
100
  end
84
101
 
85
- def [] index
86
- @cells = []
87
- @cells[index + 1] = RobustExcelOle::Cell.new(@ole_range.Cells.Item(index + 1))
88
- end
102
+ alias_method :value, :v
103
+ alias_method :value=, :v=
89
104
 
90
105
  # copies a range
91
106
  # @params [Address or Address-Array] address or upper left position of the destination range
@@ -22,12 +22,13 @@ module RobustExcelOle
22
22
  raise
23
23
  end
24
24
  ole_range = name_obj.RefersToRange
25
+ worksheet = self if self.is_a?(Worksheet)
25
26
  value = begin
26
27
  #name_obj.RefersToRange.Value
27
28
  if !::RANGES_JRUBY_BUG
28
29
  ole_range.Value
29
30
  else
30
- values = RobustExcelOle::Range.new(ole_range).v
31
+ values = RobustExcelOle::Range.new(ole_range, worksheet).v
31
32
  (values.size==1 && values.first.size==1) ? values.first.first : values
32
33
  end
33
34
  rescue WIN32OLERuntimeError, Java::OrgRacobCom::ComFailException
@@ -42,7 +43,7 @@ module RobustExcelOle
42
43
  if !::RANGES_JRUBY_BUG
43
44
  ole_range.Value
44
45
  else
45
- values = RobustExcelOle::Range.new(ole_range).v
46
+ values = RobustExcelOle::Range.new(ole_range, worksheet).v
46
47
  (values.size==1 && values.first.size==1) ? values.first.first : values
47
48
  end
48
49
  rescue WIN32OLERuntimeError, Java::OrgRacobCom::ComFailException
@@ -105,11 +106,12 @@ module RobustExcelOle
105
106
  raise NameNotFound, "name #{name.inspect} not in #{self.inspect}"
106
107
  end
107
108
  begin
109
+ worksheet = self if self.is_a?(Worksheet)
108
110
  #value = ole_range.Value
109
111
  value = if !::RANGES_JRUBY_BUG
110
112
  ole_range.Value
111
113
  else
112
- values = RobustExcelOle::Range.new(ole_range).v
114
+ values = RobustExcelOle::Range.new(ole_range, worksheet).v
113
115
  (values.size==1 && values.first.size==1) ? values.first.first : values
114
116
  end
115
117
  rescue WIN32OLERuntimeError, Java::OrgRacobCom::ComFailException
@@ -180,10 +182,11 @@ module RobustExcelOle
180
182
  # @return [Range] a range
181
183
  def range(name_or_address, address2 = :__not_provided)
182
184
  begin
185
+ worksheet = self if self.is_a?(Worksheet)
183
186
  if address2 == :__not_provided
184
187
  range = if name_or_address.is_a?(String)
185
188
  begin
186
- RobustExcelOle::Range.new(name_object(name_or_address).RefersToRange)
189
+ RobustExcelOle::Range.new(name_object(name_or_address).RefersToRange, worksheet)
187
190
  rescue NameNotFound
188
191
  nil
189
192
  end
@@ -193,7 +196,7 @@ module RobustExcelOle
193
196
  address = name_or_address
194
197
  address = [name_or_address,address2] unless address2 == :__not_provided
195
198
  self.Names.Add('__dummy001',nil,true,nil,nil,nil,nil,nil,nil,'=' + address_tool.as_r1c1(address))
196
- range = RobustExcelOle::Range.new(name_object('__dummy001').RefersToRange)
199
+ range = RobustExcelOle::Range.new(name_object('__dummy001').RefersToRange, worksheet)
197
200
  self.Names.Item('__dummy001').Delete
198
201
  workbook = self.is_a?(Workbook) ? self : self.workbook
199
202
  workbook.save
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module RobustExcelOle
4
+
5
+ class VbaObjects < Base
6
+
7
+ def to_reo
8
+ self
9
+ end
10
+
11
+ # @private
12
+ def address_tool
13
+ excel.address_tool
14
+ end
15
+
16
+ end
17
+
18
+ # @private
19
+ class RangeNotEvaluatable < MiscREOError
20
+ end
21
+
22
+ # @private
23
+ class OptionInvalid < MiscREOError
24
+ end
25
+
26
+ # @private
27
+ class ObjectNotAlive < MiscREOError
28
+ end
29
+
30
+ end
@@ -1,3 +1,3 @@
1
1
  module RobustExcelOle
2
- VERSION = "1.17"
2
+ VERSION = "1.18"
3
3
  end
@@ -783,12 +783,22 @@ module RobustExcelOle
783
783
  raise NameNotFound, "could not return a sheet with name #{name.inspect}"
784
784
  end
785
785
 
786
+ def worksheets_count
787
+ @ole_workbook.Worksheets.Count
788
+ end
789
+
786
790
  def each
787
791
  @ole_workbook.Worksheets.each do |sheet|
788
792
  yield worksheet_class.new(sheet)
789
793
  end
790
794
  end
791
795
 
796
+ def worksheets
797
+ result = []
798
+ each { |worksheet| result << worksheet }
799
+ result
800
+ end
801
+
792
802
  def each_with_index(offset = 0)
793
803
  i = offset
794
804
  @ole_workbook.Worksheets.each do |sheet|
@@ -813,24 +823,18 @@ module RobustExcelOle
813
823
  new_sheet_name = opts.delete(:as)
814
824
  last_sheet_local = last_sheet
815
825
  after_or_before, base_sheet = opts.to_a.first || [:after, last_sheet_local]
826
+ base_sheet_ole = base_sheet.ole_worksheet
816
827
  begin
817
828
  if !::COPYSHEETS_JRUBY_BUG
818
- #if sheet
819
- # sheet.Copy({ after_or_before.to_s => base_sheet.ole_worksheet })
820
- #else
821
- # ole_workbook.Worksheets.Add({ after_or_before.to_s => base_sheet.ole_worksheet })
822
- #end
823
- add_or_copy_sheet_simple(sheet, { after_or_before.to_s => base_sheet.ole_worksheet })
829
+ add_or_copy_sheet_simple(sheet, { after_or_before.to_s => base_sheet_ole })
824
830
  else
825
831
  if after_or_before == :before
826
- #add_or_copy_sheet_simple(sheet,base_sheet)
827
- add_or_copy_sheet_simple(sheet, base_sheet.ole_worksheet)
832
+ add_or_copy_sheet_simple(sheet, base_sheet_ole)
828
833
  else
829
834
  if base_sheet.name != last_sheet_local.name
830
835
  add_or_copy_sheet_simple(sheet, base_sheet.Next)
831
836
  else
832
- #add_or_copy_sheet_simple(sheet,base_sheet)
833
- add_or_copy_sheet_simple(sheet, base_sheet.ole_worksheet)
837
+ add_or_copy_sheet_simple(sheet, base_sheet_ole)
834
838
  base_sheet.Move(ole_workbook.Worksheets.Item(ole_workbook.Worksheets.Count-1))
835
839
  ole_workbook.Worksheets.Item(ole_workbook.Worksheets.Count).Activate
836
840
  end
@@ -846,19 +850,11 @@ module RobustExcelOle
846
850
 
847
851
  private
848
852
 
849
- #def add_or_copy_sheet_simple(sheet, base_sheet)
850
- # if sheet
851
- # sheet.Copy(base_sheet.ole_worksheet)
852
- # else
853
- # ole_workbook.Worksheets.Add(base_sheet.ole_worksheet)
854
- # end
855
- #end
856
-
857
- def add_or_copy_sheet_simple(sheet, base_ole_worksheet)
853
+ def add_or_copy_sheet_simple(sheet, base_sheet_ole_or_hash)
858
854
  if sheet
859
- sheet.Copy(base_ole_worksheet)
855
+ sheet.Copy(base_sheet_ole_or_hash)
860
856
  else
861
- ole_workbook.Worksheets.Add(base_ole_worksheet)
857
+ ole_workbook.Worksheets.Add(base_sheet_ole_or_hash)
862
858
  end
863
859
  end
864
860
 
@@ -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,27 @@ 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
+ xy = "#{x}_#{y}"
113
+ begin
114
+ @ole_worksheet.Cells.Item(x, y).Value
115
+ rescue
116
+ raise RangeNotEvaluatable, "cannot read cell (#{p1.inspect},#{p2.inspect})"
117
+ end
118
+ end
119
+
120
+ =begin
111
121
  def cellval(x,y)
112
122
  xy = "#{x}_#{y}"
113
123
  @cells = { }
114
124
  begin
115
- @cells[xy] = RobustExcelOle::Cell.new(@ole_worksheet.Cells.Item(x, y))
125
+ @cells[xy] = RobustExcelOle::Cell.new(@ole_worksheet.Cells.Item(x, y), @worksheet)
116
126
  @cells[xy].Value
117
127
  rescue
118
128
  raise RangeNotEvaluatable, "cannot read cell (#{p1.inspect},#{p2.inspect})"
119
129
  end
120
130
  end
131
+ =end
121
132
 
122
133
  # sets the value of a cell, if row, column and color of the cell are given
123
134
  # @params [Integer] x,y row and column
@@ -148,17 +159,31 @@ module RobustExcelOle
148
159
  end
149
160
  end
150
161
 
162
+ def each_value
163
+ @ole_worksheet.UsedRange.Value.each do |row_values|
164
+ yield row_values
165
+ end
166
+ end
167
+
168
+ def each_value_with_index(offset = 0)
169
+ i = offset
170
+ @ole_worksheet.UsedRange.Value.each do |row_values|
171
+ yield row_values, i
172
+ i += 1
173
+ end
174
+ end
175
+
151
176
  def each_row(offset = 0)
152
177
  offset += 1
153
178
  1.upto(@end_row) do |row|
154
179
  next if row < offset
155
- yield RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(row, 1), @ole_worksheet.Cells(row, @end_column)))
180
+ yield RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(row, 1), @ole_worksheet.Cells(row, @end_column)), self)
156
181
  end
157
182
  end
158
183
 
159
184
  def each_row_with_index(offset = 0)
160
185
  each_row(offset) do |row_range|
161
- yield RobustExcelOle::Range.new(row_range), (row_range.Row - 1 - offset)
186
+ yield RobustExcelOle::Range.new(row_range, self), (row_range.Row - 1 - offset)
162
187
  end
163
188
  end
164
189
 
@@ -166,24 +191,24 @@ module RobustExcelOle
166
191
  offset += 1
167
192
  1.upto(@end_column) do |column|
168
193
  next if column < offset
169
- yield RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(1, column), @ole_worksheet.Cells(@end_row, column)))
194
+ yield RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(1, column), @ole_worksheet.Cells(@end_row, column)), self)
170
195
  end
171
196
  end
172
197
 
173
198
  def each_column_with_index(offset = 0)
174
199
  each_column(offset) do |column_range|
175
- yield RobustExcelOle::Range.new(column_range), (column_range.Column - 1 - offset)
200
+ yield RobustExcelOle::Range.new(column_range, self), (column_range.Column - 1 - offset)
176
201
  end
177
202
  end
178
203
 
179
204
  def row_range(row, integer_range = nil)
180
205
  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)))
206
+ RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(row, integer_range.min), @ole_worksheet.Cells(row, integer_range.max)), self)
182
207
  end
183
208
 
184
209
  def col_range(col, integer_range = nil)
185
210
  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)))
211
+ RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(integer_range.min, col), @ole_worksheet.Cells(integer_range.max, col)), self)
187
212
  end
188
213
 
189
214
  def == other_worksheet
@@ -35,4 +35,5 @@ Gem::Specification.new do |s|
35
35
  s.require_paths = ["lib"]
36
36
  s.add_development_dependency "rspec", '>= 2.6.0'
37
37
  s.required_ruby_version = '>= 1.8.6'
38
+ s.extensions << 'extconf.rb'
38
39
  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,40 @@ describe Worksheet do
295
295
 
296
296
  end
297
297
 
298
+ describe "#each_value" do
299
+
300
+ it "should yield arrays" do
301
+ @sheet.each_value do |row_value|
302
+ row_value.should be_kind_of Array
303
+ end
304
+ end
305
+
306
+ it "should read the rows" do
307
+ i = 0
308
+ @sheet.each_value do |row_values|
309
+ case i
310
+ when 0
311
+ row_values.should == ['foo', 'workbook', 'sheet1']
312
+ when 1
313
+ row_values.should == ['foo', nil, 'foobaaa']
314
+ end
315
+ i += 1
316
+ end
317
+ end
318
+
319
+ it "should read the rows with index" do
320
+ @sheet.each_value_with_index do |row_values, i|
321
+ case i
322
+ when 0
323
+ row_values.should == ['foo', 'workbook', 'sheet1']
324
+ when 1
325
+ row_values.should == ['foo', nil, 'foobaaa']
326
+ end
327
+ end
328
+ end
329
+
330
+ end
331
+
298
332
  describe "#each_row" do
299
333
  it "items should RobustExcelOle::Range" do
300
334
  @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'
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-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -34,7 +34,8 @@ description: "RobustExcelOle helps controlling Excel. \n This
34
34
  email:
35
35
  - Thomas.Raths@gmx.net
36
36
  executables: []
37
- extensions: []
37
+ extensions:
38
+ - extconf.rb
38
39
  extra_rdoc_files:
39
40
  - README.rdoc
40
41
  - LICENSE
@@ -55,6 +56,7 @@ files:
55
56
  - docs/README_ranges.rdoc
56
57
  - docs/README_save_close.rdoc
57
58
  - docs/README_sheet.rdoc
59
+ - examples/example_ruby_library.rb
58
60
  - examples/introductory_examples/example_introductory.rb
59
61
  - examples/introductory_examples/example_open.rb
60
62
  - examples/introductory_examples/example_range.rb
@@ -81,6 +83,7 @@ files:
81
83
  - examples/open_save_close/example_reuse.rb
82
84
  - examples/open_save_close/example_simple.rb
83
85
  - examples/open_save_close/example_unobtrusively.rb
86
+ - extconf.rb
84
87
  - jreo.bat
85
88
  - lib/jreo_console.rb
86
89
  - lib/reo_console.rb
@@ -96,6 +99,7 @@ files:
96
99
  - lib/robust_excel_ole/range_owners.rb
97
100
  - lib/robust_excel_ole/robustexcelole.sublime-project
98
101
  - lib/robust_excel_ole/robustexcelole.sublime-workspace
102
+ - lib/robust_excel_ole/vba_objects.rb
99
103
  - lib/robust_excel_ole/version.rb
100
104
  - lib/robust_excel_ole/workbook.rb
101
105
  - lib/robust_excel_ole/worksheet.rb