robust_excel_ole 1.26 → 1.27

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: a2553a7622f9092b5067ad3f7e945d57a1dbfa6e540716b326c6b684a351cf79
4
- data.tar.gz: e623c4a2f3e22ef1da88b6475d7f6dc277c9f3f4581db27427fd9ca6aa400f24
3
+ metadata.gz: bf42835b0febd0db61ca5f87c473f63256d97d2dbaaf05cbe8b97be01fc6f17e
4
+ data.tar.gz: 81c4e849c1aceca218207e04577e8857098c1c68482c209515a79e2ead44c5ed
5
5
  SHA512:
6
- metadata.gz: 9056cec7af1bf9c6c04ab2df83dd080bb63308f5c5a7d6af13286090d357441928d7dcb2dde2371940e36729fafb26460098d2063254f8809796a9dde87ddc85
7
- data.tar.gz: d036c741ef593695e0fecfd8f1e34b1db5bec0e7e2430b5a88f1e16a297a804b1a9d95c8bc847bc993f0a1ea4b666cd56db200cc9cdfec38078dab6c5b4ef59b
6
+ metadata.gz: 88fadf70ac1ec5fab7e133d21fe9a6e9f0ed5399fec3dd0d5198d9c639ebde470dde7f657778564c8a7b9a326fe6b0d177e3cfeca66c4f3642ca97fccfd9314e
7
+ data.tar.gz: 578aa3c80a722c10b2d4cdc390a45f1286775586fc58ac4c67dfe7dedb1da0939b4e79fea366bc6bf49034d9631f1b8cfaac3eb54c56b6dab3385f1811f86254
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.27] 2020-20-10
5
+
4
6
  ## [1.26] 2020-09-10
5
7
 
6
8
  ### Added
@@ -320,7 +320,11 @@ For more details about reading and writing contents of cells and ranges see {REA
320
320
 
321
321
  === More features
322
322
 
323
- The ruby shell 'pry' allows, among other useful things, to change the value of 'self' in the console. For example,
323
+ 1. The method +General.change_current_binding+ allows to change the value of self within the current binding, while preserving the local variables, without starting another repl. Assume, +object+ shall be the self, then you would put
324
+
325
+ General.change_current_binding(object)
326
+
327
+ Without this method, the ruby shell 'pry' allows to change the value of 'self' in the console as well, e.g.
324
328
 
325
329
  object.pry
326
330
 
@@ -328,13 +332,14 @@ or
328
332
 
329
333
  cd object
330
334
 
331
- will set +object+ to self. However, this command also starts another pry repl (with another binding). Moreover, local variables in the previous binding are forgotten.
335
+ However, this command also starts another pry repl (with another binding). Moreover, local variables in the previous binding are forgotten.
336
+
332
337
 
333
- The method +General.change_current_binding+ allows to change the value of self within the current binding, while preserving the local variables, without starting another repl.
338
+ 2. The method +General.update_to_reo+ extends the class Win32Ole such that RobustExcelOle methods can be applied to Win32Ole objects. As mentioned above, the RobustExcelOle objects are wrapper of corresponding WIN32OLE objects. With help of +update_to_reo+ the RobustExcelOle objects and their wrapped Win32Ole objects are interchangeable. One example would be
334
339
 
335
- General.change_current_binding
340
+ range.ole_range.copy([4,3])
336
341
 
337
- You can convert some Win32Ole objects into a RobustExcelOle object.
342
+ Likewise it is possible to convert ("type-lift") Win32Ole objects into the corresponding RobustExcelOle object, using General.to_reo.
338
343
 
339
344
  range = sheet.Names.Item("firstcell").to_reo
340
345
 
data/bin/jreo CHANGED
@@ -2,7 +2,7 @@
2
2
  # -*- jruby -*-
3
3
 
4
4
  require 'pry'
5
- require '../robust_excel_ole/lib/robust_excel_ole'
5
+ require_relative '../lib/robust_excel_ole'
6
6
 
7
7
  include REO
8
8
  include General
data/bin/reo CHANGED
@@ -2,7 +2,7 @@
2
2
  # -*- ruby -*-
3
3
 
4
4
  require 'pry'
5
- require '../robust_excel_ole/lib/robust_excel_ole'
5
+ require_relative '../lib/robust_excel_ole'
6
6
 
7
7
  include REO
8
8
  include General
@@ -4,35 +4,6 @@ require '../robust_excel_ole/lib/robust_excel_ole'
4
4
  include REO
5
5
  include General
6
6
 
7
- # change the current binding such that self is the current object in the pry-instance,
8
- # preserve the local variables
9
-
10
- class Pry
11
-
12
- class << self
13
- attr_accessor :pry_instance
14
- end
15
-
16
- def self.change_current_binding(current_object)
17
- pry_instance = self.pry_instance
18
- old_binding = pry_instance.binding_stack.pop
19
- pry_instance.push_binding(current_object.__binding__)
20
- exclude_vars = [:__, :_, :_dir, :_dir_, :_file, :_file_, :_in_, :_out_, :_ex, :_ex_, :pry_instance]
21
- old_binding.local_variables.each do |var|
22
- pry_instance.add_sticky_local(var) {old_binding.local_variable_get(var)} unless exclude_vars.include?(var)
23
- end
24
- self.pry_instance = pry_instance
25
- nil
26
- end
27
-
28
- def push_initial_binding(target = nil)
29
- # memorize the current pry instance
30
- self.class.pry_instance = self
31
- push_binding(target || Pry.toplevel_binding)
32
- end
33
-
34
- end
35
-
36
7
  # some pry configuration
37
8
  Pry.config.windows_console_warning = false
38
9
  Pry.config.color = false
@@ -65,4 +36,7 @@ hooks.add_hook :when_started, :hook12 do
65
36
  puts 'REO console started'
66
37
  puts
67
38
  end
39
+
40
+ General.uplift_to_reo
41
+
68
42
  Pry.start(nil, hooks: hooks)
@@ -370,7 +370,7 @@ module RobustExcelOle
370
370
  number = 0
371
371
  WIN32OLE.connect('winmgmts:\\\\.').InstancesOf('win32_process').each do |p|
372
372
  begin
373
- if p.name == 'EXCEL.EXE'
373
+ if p.Name == 'EXCEL.EXE'
374
374
  Process.kill('KILL', p.processid)
375
375
  number += 1
376
376
  end
@@ -384,7 +384,7 @@ module RobustExcelOle
384
384
 
385
385
  def self.excels_number
386
386
  processes = WIN32OLE.connect('winmgmts:\\\\.').InstancesOf('win32_process')
387
- processes.select { |p| p.name == 'EXCEL.EXE' }.size
387
+ processes.select { |p| p.Name == 'EXCEL.EXE' }.size
388
388
  end
389
389
 
390
390
  def self.known_excels_number
@@ -417,7 +417,7 @@ module RobustExcelOle
417
417
  result.Visible # send any method, just to see if it responds
418
418
  rescue
419
419
  trace 'dead excel ' + (begin
420
- "Window-handle = #{result.HWnd}"
420
+ "Window-handle = #{result.Hwnd}"
421
421
  rescue
422
422
  'without window handle'
423
423
  end)
@@ -471,13 +471,13 @@ module RobustExcelOle
471
471
  pid2excel[pid] = excel
472
472
  end
473
473
  processes = WIN32OLE.connect('winmgmts:\\\\.').InstancesOf('win32_process')
474
- processes.select { |p| Excel.new(pid2excel[p.processid]) if p.name == 'EXCEL.EXE' && pid2excel.include?(p.processid) }
474
+ processes.select { |p| Excel.new(pid2excel[p.ProcessId]) if p.Name == 'EXCEL.EXE' && pid2excel.include?(p.ProcessId) }
475
475
  result = []
476
476
  processes.each do |p|
477
- next unless p.name == 'EXCEL.EXE'
477
+ next unless p.Name == 'EXCEL.EXE'
478
478
 
479
- if pid2excel.include?(p.processid)
480
- excel = pid2excel[p.processid]
479
+ if pid2excel.include?(p.ProcessId)
480
+ excel = pid2excel[p.ProcessId]
481
481
  result << excel
482
482
  end
483
483
  # how to connect to an (interactively opened) Excel instance and get a WIN32OLE object?
@@ -3,14 +3,14 @@
3
3
  module General
4
4
 
5
5
  IS_JRUBY_PLATFORM = (RUBY_PLATFORM =~ /java/)
6
- ::EXPANDPATH_JRUBY_BUG = IS_JRUBY_PLATFORM && true
7
- ::CONNECT_JRUBY_BUG = IS_JRUBY_PLATFORM && true
8
- ::COPYSHEETS_JRUBY_BUG = IS_JRUBY_PLATFORM && true
9
- ::ERRORMESSAGE_JRUBY_BUG = IS_JRUBY_PLATFORM && true
10
- ::CONNECT_EXCEL_JRUBY_BUG = IS_JRUBY_PLATFORM && true
11
- ::RANGES_JRUBY_BUG = IS_JRUBY_PLATFORM && true
12
-
13
- @private
6
+ ::EXPANDPATH_JRUBY_BUG = IS_JRUBY_PLATFORM && true
7
+ ::CONNECT_JRUBY_BUG = IS_JRUBY_PLATFORM && true
8
+ ::COPYSHEETS_JRUBY_BUG = IS_JRUBY_PLATFORM && true
9
+ ::ERRORMESSAGE_JRUBY_BUG = IS_JRUBY_PLATFORM && true
10
+ ::CONNECT_EXCEL_JRUBY_BUG = IS_JRUBY_PLATFORM && true
11
+ ::RANGES_JRUBY_BUG = IS_JRUBY_PLATFORM && true
12
+
13
+ # @private
14
14
  NetworkDrive = Struct.new(:drive_letter, :network_name) do
15
15
 
16
16
  def self.get_all(drives)
@@ -24,7 +24,7 @@ module General
24
24
 
25
25
  end
26
26
 
27
- @private
27
+ # @private
28
28
  def hostnameshare2networkpath(filename)
29
29
  return filename unless filename[0,2] == "//"
30
30
  network = WIN32OLE.new('WScript.Network')
@@ -68,8 +68,95 @@ module General
68
68
  Pry.change_current_binding(current_object)
69
69
  end
70
70
 
71
- module_function :absolute_path, :canonize, :normalize, :change_current_binding
71
+ def class2method
72
+ [{Excel => :Hwnd},
73
+ {Workbook => :FullName},
74
+ {Worksheet => :UsedRange},
75
+ {RobustExcelOle::Range => :Row},
76
+ {ListObject => :ListRows}]
77
+ end
78
+
79
+
80
+ # enable RobustExcelOle methods to Win32Ole objects
81
+ def uplift_to_reo
82
+ exclude_list = [:each, :inspect]
83
+ class2method.each do |element|
84
+ classname = element.first.first
85
+ method = element.first.last
86
+ classname.instance_methods(false).each do |inst_method|
87
+ if !exclude_list.include?(inst_method)
88
+ WIN32OLE.send(:define_method, inst_method) do |*args, &blk|
89
+ self.to_reo.send(inst_method, *args, &blk)
90
+ end
91
+ end
92
+ end
93
+ end
94
+ nil
95
+ end
96
+
97
+ module_function :absolute_path, :canonize, :normalize, :change_current_binding, :class2method, :uplift_to_reo
98
+
99
+ end
100
+
101
+ # @private
102
+ class Pry
103
+
104
+ # change the current binding such that self is the current object in the pry-instance,
105
+ # preserve the local variables
106
+
107
+ class << self
108
+ attr_accessor :pry_instance
109
+ end
110
+
111
+ def self.change_current_binding(current_object)
112
+ pry_instance = self.pry_instance
113
+ old_binding = pry_instance.binding_stack.pop
114
+ pry_instance.push_binding(current_object.__binding__)
115
+ exclude_vars = [:__, :_, :_dir, :_dir_, :_file, :_file_, :_in_, :_out_, :_ex, :_ex_, :pry_instance]
116
+ old_binding.local_variables.each do |var|
117
+ pry_instance.add_sticky_local(var) {old_binding.local_variable_get(var)} unless exclude_vars.include?(var)
118
+ end
119
+ self.pry_instance = pry_instance
120
+ nil
121
+ end
122
+
123
+ def push_initial_binding(target = nil)
124
+ # memorize the current pry instance
125
+ self.class.pry_instance = self
126
+ push_binding(target || Pry.toplevel_binding)
127
+ end
72
128
 
129
+ class REPL
130
+
131
+ def read
132
+ @indent.reset if pry.eval_string.empty?
133
+ current_prompt = pry.select_prompt
134
+ indentation = pry.config.auto_indent ? @indent.current_prefix : ''
135
+ val = read_line("#{current_prompt}#{indentation}")
136
+ # Return nil for EOF, :no_more_input for error, or :control_c for <Ctrl-C>
137
+ return val unless val.is_a?(String)
138
+ if pry.config.auto_indent
139
+ original_val = "#{indentation}#{val}"
140
+ indented_val = @indent.indent(val)
141
+
142
+ if output.tty? &&
143
+ pry.config.correct_indent &&
144
+ Pry::Helpers::BaseHelpers.use_ansi_codes?
145
+ # avoid repeating read line
146
+
147
+ #output.print @indent.correct_indentation(
148
+ # current_prompt,
149
+ # indented_val,
150
+ # calculate_overhang(current_prompt, original_val, indented_val)
151
+ #)
152
+ output.flush
153
+ end
154
+ else
155
+ indented_val = val
156
+ end
157
+ indented_val
158
+ end
159
+ end
73
160
  end
74
161
 
75
162
  # @private
@@ -122,14 +209,7 @@ class WIN32OLE
122
209
 
123
210
  # type-lifting WIN32OLE objects to RobustExcelOle objects
124
211
  def to_reo
125
- class2method = [
126
- {Excel => :Hwnd},
127
- {Workbook => :FullName},
128
- {Worksheet => :UsedRange},
129
- {RobustExcelOle::Range => :Row},
130
- {ListObject => :ListRows}
131
- ]
132
- class2method.each do |element|
212
+ General.class2method.each do |element|
133
213
  classname = element.first.first
134
214
  method = element.first.last
135
215
  begin
@@ -1,3 +1,3 @@
1
1
  module RobustExcelOle
2
- VERSION = "1.26"
2
+ VERSION = "1.27"
3
3
  end
@@ -96,6 +96,34 @@ module RobustExcelOle
96
96
 
97
97
  end
98
98
 
99
+ describe "General.uplift_to_reo" do
100
+
101
+ before do
102
+ @book1 = Workbook.open(@simple_file, :visible => true)
103
+ end
104
+
105
+ it "should apply reo-methods to win32ole objects" do
106
+ General.uplift_to_reo
107
+ ole_book1 = @book1.ole_workbook
108
+ sheet1 = ole_book1.sheet(1)
109
+ sheet1.should be_a Worksheet
110
+ sheet1.name.should == "Sheet1"
111
+ ole_sheet1 = sheet1.ole_worksheet
112
+ range1 = ole_sheet1.range([1..2,3..4])
113
+ range1.should be_a RobustExcelOle::Range
114
+ range1.value.should == [["sheet1",nil],["foobaaa",nil]]
115
+ ole_range1 = range1.ole_range
116
+ ole_range1.copy([6,6])
117
+ range2 = sheet1.range([6..7,6..7])
118
+ range2.value.should == [["sheet1",nil],["foobaaa",nil]]
119
+ excel1 = @book1.excel
120
+ ole_excel1 = excel1.ole_excel
121
+ ole_excel1.close(:if_unsaved => :forget)
122
+ Excel.kill_all
123
+ end
124
+
125
+ end
126
+
99
127
  describe "methods, own_methods, respond_to?" do
100
128
 
101
129
  before do
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.26'
4
+ version: '1.27'
5
5
  platform: ruby
6
6
  authors:
7
7
  - traths
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-09 00:00:00.000000000 Z
11
+ date: 2020-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -126,7 +126,6 @@ files:
126
126
  - examples/open_save_close/example_reuse.rb
127
127
  - examples/open_save_close/example_simple.rb
128
128
  - examples/open_save_close/example_unobtrusively.rb
129
- - jreo.bat
130
129
  - lib/reo_console.rb
131
130
  - lib/robust_excel_ole.rb
132
131
  - lib/robust_excel_ole/address_tool.rb
@@ -149,7 +148,6 @@ files:
149
148
  - lib/robust_excel_ole/workbook.rb
150
149
  - lib/robust_excel_ole/worksheet.rb
151
150
  - lib/spec_helper.rb
152
- - reo.bat
153
151
  - robust_excel_ole.gemspec
154
152
  - spec/address_tool_spec.rb
155
153
  - spec/base_spec.rb
data/jreo.bat DELETED
@@ -1,3 +0,0 @@
1
- @echo off
2
-
3
- jruby lib/reo_console.rb
data/reo.bat DELETED
@@ -1,3 +0,0 @@
1
- @echo off
2
-
3
- ruby lib/reo_console.rb