robust_excel_ole 1.32 → 1.33

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f56e6aaeeeec6c073cc4f871ea99185428523959c420e1165d199792979074c5
4
- data.tar.gz: 79dd7f6ea160e0045592a3dd8ae31a5b8a162c71b6986dcbcef157eba54c93b4
3
+ metadata.gz: c1c1d70d522034dc16bc609e2578e02b556396051ec7fdd14e2f11bd5aea85cd
4
+ data.tar.gz: e14ac932aae718dd25d3a3ddc9ab487d63dc934c6e1d136a1adb069b0c57c81e
5
5
  SHA512:
6
- metadata.gz: 894959ff3e8c48c8413bbb137013cf8ad7612bb991292f1461b1df9b3371d15c16132ecf0df0dbf78403171381064cfb43d9400604bc2155214f8aa2a514ea7c
7
- data.tar.gz: 508b37f27ef7c0e554b565f21263386e1b180cb5269f6a843b2da927eaa3f6eebe5a111a362d5dc96de4726a1c3648673b062b02589739eb7e5ff2a0bb7f59cc
6
+ metadata.gz: 77e8abbfee1226d86e58d75aa4e1625b3a7d385333974c4cb9e854527d1c6e2cfdcb827a55749343e34dfae0867bc843ac609ebb1541f71960dd08ffbdf7d1fd
7
+ data.tar.gz: f3b02fa7307c8d7031fdf65d246d3e22a800d39f476a24f227abba0dc2eb058b119dc29c249285392013a8d0de73735c176030d39fd8f97f7ea9150b7a8d0b61
data/Changelog CHANGED
@@ -1,6 +1,8 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.33] 2021-01-06
5
+
4
6
  ## [1.32] 2021-23-04
5
7
 
6
8
  ### Added
data/README.rdoc CHANGED
@@ -19,11 +19,6 @@ This returns the range of cell with address 1,1.
19
19
 
20
20
  With this new interface, we want to be compatible with the standard syntax of other known Excel libraries, e.g. +spreadsheet+ or +axlsx+.
21
21
 
22
- == Using own WIN32OLE objects
23
-
24
- If you use WIN32OLE objects and define your own methods, please use upper-case method names.
25
- The reason is that we extend the class WIN32OLE such that RobustExcelOle methods can be applied to WIN32OLE objects, such the RobustExcelOle objects and their wrapped WIN32OLE objects are interchangeable. We want to develop a refinement such that the name space is not being desturbed.
26
-
27
22
  = RobustExcelOle
28
23
 
29
24
  RobustExcelOle helps controlling Excel.
Binary file
@@ -10,26 +10,27 @@ module RobustExcelOle
10
10
  @col_letter = r1c1_letters[1..1]
11
11
  end
12
12
 
13
- # address formats that are valid:
13
+ # valid address formats are:
14
14
  # r1c1-format: e.g. "Z3S1", "Z3S1:Z5S2", "Z[3]S1", "Z3S[-1]:Z[5]S1", "Z[3]", "S[-2]"
15
15
  # infinite ranges are not possible, e.g. "Z3:Z5", "S2:S5", "Z2", "S3", "Z[2]"
16
- # integer_ranges-fromat: e.g. [3,1], [3,"A"], [3..5,1..2], [3..5, "A".."B"],
16
+ # integer_ranges-fromat: e.g. [3,1], [3,"A"], [3..5,1..2], [1..[2],[3]..8], [3..5, "A".."B"],
17
17
  # [3..4, nil], [nil, 2..4], [2,nil], [nil,4]
18
18
  # a1-format: e.g. "A3", "A3:B5", "A:B", "3:5", "A", "3"
19
+
20
+
19
21
  def as_r1c1(address)
20
22
  transform_address(address, :r1c1)
21
23
  end
22
24
 
25
+ # transformation from integer-range or r1c1.format to a1-format not implemented
23
26
  def as_a1(address)
24
27
  transform_address(address, :a1)
25
28
  end
26
29
 
27
- # valid address formats: e.g. [3,1], [3,"A"], [3..5,1..2], [3..5, "A".."B"],
28
- # [3..4, nil], [nil, 2..4], [2,nil], [nil,4]
29
30
  def as_integer_ranges(address)
30
31
  transform_address(address, :int_range)
31
32
  end
32
-
33
+
33
34
  private
34
35
 
35
36
  def transform_address(address, format)
@@ -278,30 +278,48 @@ module General
278
278
  [RobustExcelOle::ListRow , 'ListRow' , [:Creator, :no_method => :Row]]]
279
279
  end
280
280
 
281
+ WIN32OLE_INSTANCE_METHODS = [
282
+ :ole_methods, :ole_free, :ole_get_methods, :ole_put_methods, :ole_func_methods, :ole_method, :ole_method_help,
283
+ :ole_activex_initialize, :ole_type, :ole_obj_help, :ole_typelib, :ole_query_interface, :ole_respond_to?,
284
+ :invoke, :_invoke, :_getproperty, :_setproperty, :setproperty, :[], :[]=, :methods, :method_missing, :each
285
+ ]
286
+
281
287
  # @private
282
288
  # enable RobustExcelOle methods to Win32Ole objects
283
289
  def init_reo_for_win32ole
290
+ method_occurrences = {}
284
291
  main_classes_ole_types_and_recognising_methods.each do |classname, _ole_type, _recognising_method|
285
- meths = (classname.instance_methods(false) - WIN32OLE.instance_methods(false) - Object.methods - Enumerable.instance_methods(false) - [:Calculation=])
292
+ meths = (classname.instance_methods(false) - WIN32OLE_INSTANCE_METHODS - Object.methods - Enumerable.instance_methods(false) - [:Calculation=])
286
293
  meths.each do |inst_method|
287
- if classname.method_defined?(inst_method)
288
- WIN32OLE.send(:define_method, inst_method) do |*args, &blk|
289
- begin
290
- obj = to_reo
291
- rescue
292
- return self.send(inst_method.capitalize, *args, &blk)
293
- end
294
- obj.send(inst_method, *args, &blk)
294
+ method_occurrences[inst_method] = method_occurrences[inst_method] ? :several_classes : classname
295
+ end
296
+ end
297
+ method_occurrences.each do |inst_method, class_name|
298
+ if WIN32OLE.method_defined?(inst_method)
299
+ aliased_method = "#{inst_method}_after_reo".to_s.to_sym
300
+ WIN32OLE.send(:alias_method, aliased_method, inst_method)
301
+ else
302
+ aliased_method = nil
303
+ end
304
+ if aliased_method || class_name == :several_classes
305
+ WIN32OLE.send(:define_method, inst_method) do |*args, &blk|
306
+ begin
307
+ obj = to_reo
308
+ rescue
309
+ sending_method = aliased_method ? aliased_method : inst_method.capitalize
310
+ return self.send(sending_method, *args, &blk)
295
311
  end
296
- else
297
- WIN32OLE.send(:define_method, inst_method) do |*args, &blk|
298
- begin
299
- obj = classname.constantize.new(self)
300
- rescue
301
- return self.send(inst_method.capitalize, *args, &blk)
302
- end
303
- obj.send(inst_method, *args, &blk)
312
+ obj.send(inst_method, *args, &blk)
313
+ end
314
+ else
315
+ WIN32OLE.send(:define_method, inst_method) do |*args, &blk|
316
+ begin
317
+ obj = class_name.new(self)
318
+ rescue
319
+ sending_method = aliased_method ? aliased_method : inst_method.capitalize
320
+ return self.send(sending_method, *args, &blk)
304
321
  end
322
+ obj.send(inst_method, *args, &blk)
305
323
  end
306
324
  end
307
325
  end
@@ -349,8 +349,8 @@ module RobustExcelOle
349
349
 
350
350
  def == other_table
351
351
  other_table.is_a?(ListObject) &&
352
- self.HeaderRowRange.Value == other_table.HeaderRowRange.Value &&
353
- self.DataBodyRange.Value == other_table.DataBodyRange.Value
352
+ self.Range.Address == other_table.Range.Address &&
353
+ self.Parent.to_reo == other_table.Parent.to_reo
354
354
  end
355
355
 
356
356
 
@@ -11,10 +11,15 @@ module RobustExcelOle
11
11
  alias ole_object ole_tablerow
12
12
 
13
13
  def initialize(rownumber_or_oletablerow)
14
- @ole_tablerow = if !rownumber_or_oletablerow.respond_to?(:succ)
15
- rownumber_or_oletablerow
14
+ @ole_tablerow = if rownumber_or_oletablerow.is_a?(ListRow)
15
+ rownumber_or_oletablerow.ole_tablerow
16
16
  else
17
- ole_table.ListRows.Item(rownumber_or_oletablerow)
17
+ begin
18
+ rownumber_or_oletablerow.Parent.send(:ListRows)
19
+ rownumber_or_oletablerow
20
+ rescue
21
+ ole_table.ListRows.Item(rownumber_or_oletablerow)
22
+ end
18
23
  end
19
24
  end
20
25
 
@@ -19,7 +19,12 @@ module RobustExcelOle
19
19
  using ToReoRefinement
20
20
 
21
21
  def initialize(win32_range, worksheet = nil)
22
- @ole_range = win32_range
22
+ @ole_range = begin
23
+ win32_range.send(:Areas)
24
+ win32_range
25
+ rescue
26
+ raise TypeREOError, "given win32ole object is not a range"
27
+ end
23
28
  @worksheet = (worksheet ? worksheet : self.Parent).to_reo
24
29
  end
25
30
 
@@ -1,3 +1,3 @@
1
1
  module RobustExcelOle
2
- VERSION = "1.32"
2
+ VERSION = "1.33"
3
3
  end
@@ -93,7 +93,12 @@ module RobustExcelOle
93
93
  when NilClass
94
94
  raise FileNameNotGiven, "filename is nil"
95
95
  when WIN32OLE
96
- file = file_or_workbook.Fullname.tr('\\','/')
96
+ begin
97
+ file_or_workbook.send(:LinkSources)
98
+ file = file_or_workbook.Fullname.tr('\\','/')
99
+ rescue
100
+ raise TypeREOError, "given win32ol object is not a workbook"
101
+ end
97
102
  when Workbook
98
103
  file = file_or_workbook.Fullname.tr('\\','/')
99
104
  when String
@@ -104,9 +104,17 @@ module RobustExcelOle
104
104
  address = normalize_address(name_or_address, address2)
105
105
  workbook.retain_saved do
106
106
  begin
107
- self.Names.Add('__dummy001',nil,true,nil,nil,nil,nil,nil,nil,'=' + address_tool.as_r1c1(address))
108
- range = get_name_object('__dummy001').RefersToRange
109
- self.Names.Item('__dummy001').Delete
107
+ a1_address = address_tool.as_a1(address) rescue nil
108
+ if a1_address
109
+ range = self.Range(a1_address)
110
+ else
111
+ begin
112
+ self.Names.Add('__dummy_name_object_001__',nil,true,nil,nil,nil,nil,nil,nil,'=' + address_tool.as_r1c1(address))
113
+ range = get_name_object('__dummy_name_object_001__').RefersToRange
114
+ ensure
115
+ self.Names.Item('__dummy_name_object_001__').Delete
116
+ end
117
+ end
110
118
  rescue
111
119
  address2_string = (address2.nil? || address2 == :__not_provided) ? "" : ", #{address2.inspect}"
112
120
  raise RangeNotCreated, "cannot find name or address #{name_or_address.inspect}#{address2_string})"
@@ -115,7 +123,7 @@ module RobustExcelOle
115
123
  end
116
124
  range.to_reo
117
125
  end
118
-
126
+
119
127
  private
120
128
 
121
129
  def normalize_address(address, address2)
@@ -55,11 +55,16 @@ describe Bookstore do
55
55
  @simple_file_other_path = @dir + '/more_data/workbook.xls'
56
56
  @simple_file1 = @simple_file
57
57
  @different_file1 = @different_file
58
-
59
58
  @file_path = "spec/data/workbook.xls"
60
59
  @absolute_file_path = "C:/gim/ats/aSrc/gems/robust_excel_ole/spec/data/workbook.xls"
61
60
  @network_path = "N:/data/workbook.xls"
62
- @hostname_share_path = "DESKTOP-A3C5CJ6/spec/data/workbook.xls"
61
+ network = WIN32OLE.new('WScript.Network')
62
+ computer_name = network.ComputerName
63
+ #@hostname_share_path = "DESKTOP-A3C5CJ6/spec/data/workbook.xls"
64
+ @hostname_share_path = "//#{computer_name}/#{absolute_path('spec/data/workbook.xls').tr('\\','/').gsub('C:','c$')}"
65
+ @network_path_not_existing = "M:/data/workbook.xls"
66
+ @hostname_not_existing_share_path = "//DESKTOP_not_existing/spec/data/workbook.xls"
67
+ @hostname_share_not_existing_path = "//#{computer_name}/c$/gim/ats/aSrc/gems/robust_excel_ole/spec_not_existing/data/workbook.xls"
63
68
  end
64
69
 
65
70
  after do
@@ -135,16 +140,6 @@ describe Bookstore do
135
140
 
136
141
  describe "fetch" do
137
142
 
138
- before do
139
- @file_path = "spec/data/workbook.xls"
140
- @absolute_file_path = "C:/gim/ats/aSrc/gems/robust_excel_ole/spec/data/workbook.xls"
141
- @network_path = "N:/data/workbook.xls"
142
- @hostname_share_path = "//DESKTOP-A3C5CJ6/spec/data/workbook.xls"
143
- @network_path_not_existing = "M:/data/workbook.xls"
144
- @hostname_not_existing_share_path = "//DESKTOP_not_existing/spec/data/workbook.xls"
145
- @hostname_share_not_existing_path = "//DESKTOP-A3C5CJ6/spec_not_existing/data/workbook.xls"
146
- end
147
-
148
143
  context "with stored network and hostname share path" do
149
144
 
150
145
  it "should fetch to a given network path file the stored hostname_share_path file" do
data/spec/excel_spec.rb CHANGED
@@ -1925,7 +1925,7 @@ module RobustExcelOle
1925
1925
  excel_instances.first.should == excel
1926
1926
  excel_instances.to_a.should == [excel]
1927
1927
  res = []
1928
- excel_instances.each.with_index{|e,i| res << [e,i]}
1928
+ excel_instances.each_with_index{|e,i| res << [e,i]}
1929
1929
  res.should == [[excel,0]]
1930
1930
  end
1931
1931
 
@@ -1937,7 +1937,7 @@ module RobustExcelOle
1937
1937
  excel_instances.first.should == excel1
1938
1938
  excel_instances.to_a.should == [excel1, excel2]
1939
1939
  res = []
1940
- excel_instances.each.with_index{|e,i| res << [e,i]}
1940
+ excel_instances.each_with_index{|e,i| res << [e,i]}
1941
1941
  res.should == [[excel1,0],[excel2,1]]
1942
1942
  end
1943
1943
 
data/spec/general_spec.rb CHANGED
@@ -1,5 +1,15 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
+ require 'win32ole'
4
+
5
+ class WIN32OLE
6
+ def save
7
+ "save"
8
+ end
9
+ end
10
+
11
+ NETWORK = WIN32OLE.new('WScript.Network')
12
+
3
13
  require_relative 'spec_helper'
4
14
 
5
15
  $VERBOSE = nil
@@ -34,11 +44,12 @@ module RobustExcelOle
34
44
  @simple_file_xlsm = @dir + '/workbook.xls'
35
45
  @simple_file_xlsx = @dir + '/workbook.xlsx'
36
46
  @network_path = "N:/data/workbook.xls"
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"
47
+ computer_name = NETWORK.ComputerName
48
+ #@hostname_share_path = "//#{computer_name}/spec/data/workbook.xls"
49
+ @hostname_share_path = "//#{computer_name}/#{absolute_path('spec/data/workbook.xls').tr('\\','/').gsub('C:','c$')}"
50
+ @network_path_downcase = @network_path.downcase
51
+ @hostname_share_path_downcase = @hostname_share_path.downcase
40
52
  @simple_file_extern = "D:/data/workbook.xls"
41
- @hostname_share_path = "//DESKTOP-A3C5CJ6/spec/data/workbook.xls"
42
53
  end
43
54
 
44
55
  after do
@@ -46,6 +57,66 @@ module RobustExcelOle
46
57
  rm_tmp(@dir)
47
58
  end
48
59
 
60
+ describe "General.init_reo_for_win32ole" do
61
+
62
+ before do
63
+ @book1 = Workbook.open(@simple_file, :visible => true)
64
+ end
65
+
66
+ it "should preserve the instance method of a win32ole object via calling an aliased method" do
67
+ NETWORK.save.should == "save"
68
+ end
69
+
70
+ it "should preserve the instance methods of a win32ole object " do
71
+ RobustExcelOle::Excel.define_method(:ComputerName){ "computer" }
72
+ network = WIN32OLE.new('WScript.Network')
73
+ computername = network.ComputerName
74
+ General.init_reo_for_win32ole
75
+ network.ComputerName.should == computername
76
+ end
77
+
78
+ #it "should preserve the lower-case instance methods of a win32ole object " do
79
+ # RobustExcelOle::Excel.define_method(:computername){ "computer" }
80
+ # network = WIN32OLE.new('WScript.Network')
81
+ # computername = network.computername
82
+ # General.init_reo_for_win32ole
83
+ # network.computername.should == computername
84
+ #end
85
+
86
+ it "should call a capitalized method for an instance method occurring in one classes" do
87
+ expect{
88
+ NETWORK.delete_empty_columns
89
+ }.to raise_error(NoMethodError, /Delete_empty_columns/)
90
+ end
91
+
92
+
93
+ it "should call a capitalized method for an instance method occurring in several classes" do
94
+ expect{
95
+ NETWORK.focus
96
+ }.to raise_error(NoMethodError, /Focus/)
97
+ end
98
+
99
+ it "should apply reo-methods to win32ole objects" do
100
+ ole_book1 = @book1.ole_workbook
101
+ sheet1 = ole_book1.sheet(1)
102
+ sheet1.should be_a Worksheet
103
+ sheet1.name.should == "Sheet1"
104
+ ole_sheet1 = sheet1.ole_worksheet
105
+ range1 = ole_sheet1.range([1..2,3..4])
106
+ range1.should be_a RobustExcelOle::Range
107
+ range1.value.should == [["sheet1"],["foobaaa"]]
108
+ ole_range1 = range1.ole_range
109
+ ole_range1.copy([6,6])
110
+ range2 = sheet1.range([6..7,6..7])
111
+ range2.value.should == [["sheet1"],["foobaaa"]]
112
+ excel1 = @book1.excel
113
+ ole_excel1 = excel1.ole_excel
114
+ ole_excel1.close(:if_unsaved => :forget)
115
+ Excel.kill_all
116
+ end
117
+
118
+ end
119
+
49
120
  describe "find_all_indices" do
50
121
 
51
122
  it "should find all occurrences" do
@@ -149,41 +220,6 @@ module RobustExcelOle
149
220
 
150
221
  end
151
222
 
152
- describe "General.init_reo_for_win32ole" do
153
-
154
- before do
155
- @book1 = Workbook.open(@simple_file, :visible => true)
156
- end
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
-
166
- it "should apply reo-methods to win32ole objects" do
167
- ole_book1 = @book1.ole_workbook
168
- sheet1 = ole_book1.sheet(1)
169
- sheet1.should be_a Worksheet
170
- sheet1.name.should == "Sheet1"
171
- ole_sheet1 = sheet1.ole_worksheet
172
- range1 = ole_sheet1.range([1..2,3..4])
173
- range1.should be_a RobustExcelOle::Range
174
- range1.value.should == [["sheet1",nil],["foobaaa",nil]]
175
- ole_range1 = range1.ole_range
176
- ole_range1.copy([6,6])
177
- range2 = sheet1.range([6..7,6..7])
178
- range2.value.should == [["sheet1",nil],["foobaaa",nil]]
179
- excel1 = @book1.excel
180
- ole_excel1 = excel1.ole_excel
181
- ole_excel1.close(:if_unsaved => :forget)
182
- Excel.kill_all
183
- end
184
-
185
- end
186
-
187
223
  describe "methods, own_methods, respond_to?" do
188
224
 
189
225
  before do
@@ -49,8 +49,10 @@ describe ListRow do
49
49
 
50
50
  it "should promote a win32ole tablerow" do
51
51
  table1 = @sheet.table(1)
52
- ole_tablerow = table1[2].ole_tablerow
53
- ListRow.new(ole_tablerow).values.should == [2.0, "Fred", nil, 0.5416666666666666, 40]
52
+ tablerow1 = table1[2]
53
+ ole_tablerow1 = tablerow1.ole_tablerow
54
+ ListRow.new(ole_tablerow1).values.should == [2.0, "Fred", nil, 0.5416666666666666, 40]
55
+ ListRow.new(tablerow1).values.should == [2.0, "Fred", nil, 0.5416666666666666, 40]
54
56
  end
55
57
  end
56
58
 
@@ -9,6 +9,5 @@ require_relative 'workbook_close_spec'
9
9
  require_relative 'workbook_save_spec'
10
10
  require_relative 'workbook_misc_spec'
11
11
  require_relative 'workbook_sheet_spec'
12
- require_relative 'workbook
13
- _unobtr_spec'
12
+ require_relative 'workbook_unobtr_spec'
14
13
  require_relative 'workbook_subclass_spec'
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.32'
4
+ version: '1.33'
5
5
  platform: ruby
6
6
  authors:
7
7
  - traths
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-23 00:00:00.000000000 Z
11
+ date: 2021-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: win32api
@@ -227,7 +227,7 @@ homepage: https://github.com/Thomas008/robust_excel_ole
227
227
  licenses:
228
228
  - MIT
229
229
  metadata: {}
230
- post_install_message:
230
+ post_install_message:
231
231
  rdoc_options:
232
232
  - "--main"
233
233
  - README.rdoc
@@ -246,9 +246,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  - !ruby/object:Gem::Version
247
247
  version: '0'
248
248
  requirements: []
249
- rubyforge_project: robust_excel_ole
250
- rubygems_version: 2.7.6
251
- signing_key:
249
+ rubygems_version: 3.1.6
250
+ signing_key:
252
251
  specification_version: 4
253
252
  summary: RobustExcelOle automates processing Excel workbooks in Windows by using the
254
253
  win32ole library.