robust_excel_ole 1.22.2 → 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 +4 -4
- data/Changelog +16 -0
- data/README.rdoc +22 -3
- data/bin/jreo +4 -7
- data/bin/reo +4 -7
- data/docs/README_ranges.rdoc +26 -6
- data/docs/README_sheet.rdoc +1 -1
- data/lib/reo_console.rb +24 -6
- data/lib/robust_excel_ole.rb +1 -1
- data/lib/robust_excel_ole/base.rbs +63 -0
- data/lib/robust_excel_ole/cell.rb +5 -2
- data/lib/robust_excel_ole/cell.rbs +25 -0
- data/lib/robust_excel_ole/excel.rb +9 -14
- data/lib/robust_excel_ole/general.rb +125 -21
- data/lib/robust_excel_ole/list_object.rb +16 -8
- data/lib/robust_excel_ole/range.rb +32 -8
- data/lib/robust_excel_ole/range_owners.rb +4 -30
- data/lib/robust_excel_ole/vba_objects.rbs +23 -0
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +18 -0
- data/lib/robust_excel_ole/worksheet.rb +27 -15
- data/robust_excel_ole.gemspec +1 -0
- data/spec/general_spec.rb +28 -0
- data/spec/list_object_spec.rb +7 -2
- data/spec/range_spec.rb +8 -2
- data/spec/workbook_specs/workbook_misc_spec.rb +10 -0
- data/spec/worksheet_spec.rb +3 -0
- metadata +19 -4
- data/jreo.bat +0 -3
- data/reo.bat +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf42835b0febd0db61ca5f87c473f63256d97d2dbaaf05cbe8b97be01fc6f17e
|
4
|
+
data.tar.gz: 81c4e849c1aceca218207e04577e8857098c1c68482c209515a79e2ead44c5ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88fadf70ac1ec5fab7e133d21fe9a6e9f0ed5399fec3dd0d5198d9c639ebde470dde7f657778564c8a7b9a326fe6b0d177e3cfeca66c4f3642ca97fccfd9314e
|
7
|
+
data.tar.gz: 578aa3c80a722c10b2d4cdc390a45f1286775586fc58ac4c67dfe7dedb1da0939b4e79fea366bc6bf49034d9631f1b8cfaac3eb54c56b6dab3385f1811f86254
|
data/Changelog
CHANGED
@@ -1,8 +1,24 @@
|
|
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
|
+
|
6
|
+
## [1.26] 2020-09-10
|
7
|
+
|
8
|
+
### Added
|
9
|
+
- General#change_current_binding
|
10
|
+
|
11
|
+
## [1.25] 2020-10-09]
|
12
|
+
|
13
|
+
## [1.24] 2020-25-09
|
14
|
+
|
15
|
+
## [1.23] 2020-02-09
|
16
|
+
|
4
17
|
## [1.22] 2020-10-08
|
5
18
|
|
19
|
+
### Added
|
20
|
+
- Range#set_value
|
21
|
+
|
6
22
|
## [1.21] 2020-05-08
|
7
23
|
|
8
24
|
### Added
|
data/README.rdoc
CHANGED
@@ -64,7 +64,7 @@ If you want to start the console under jruby, and if you don't want to use a ver
|
|
64
64
|
|
65
65
|
jreo
|
66
66
|
|
67
|
-
The call of the console will include RobustExcelOle for you.
|
67
|
+
The call of the console will include RobustExcelOle for you. The consoles require the ruby gem 'pry' and 'pry-bond' to enable the ruby shell 'pry' with filename and string completion.
|
68
68
|
|
69
69
|
The following examples can be used for both scripts and console. If you have started the console in the gem path, you can just put these examples.
|
70
70
|
|
@@ -318,9 +318,28 @@ and set another value to that range.
|
|
318
318
|
For more details about reading and writing contents of cells and ranges see {README_ranges}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_ranges.rdoc]
|
319
319
|
|
320
320
|
|
321
|
-
=== More
|
321
|
+
=== More features
|
322
322
|
|
323
|
-
|
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.
|
328
|
+
|
329
|
+
object.pry
|
330
|
+
|
331
|
+
or
|
332
|
+
|
333
|
+
cd object
|
334
|
+
|
335
|
+
However, this command also starts another pry repl (with another binding). Moreover, local variables in the previous binding are forgotten.
|
336
|
+
|
337
|
+
|
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
|
339
|
+
|
340
|
+
range.ole_range.copy([4,3])
|
341
|
+
|
342
|
+
Likewise it is possible to convert ("type-lift") Win32Ole objects into the corresponding RobustExcelOle object, using General.to_reo.
|
324
343
|
|
325
344
|
range = sheet.Names.Item("firstcell").to_reo
|
326
345
|
|
data/bin/jreo
CHANGED
@@ -2,21 +2,18 @@
|
|
2
2
|
# -*- jruby -*-
|
3
3
|
|
4
4
|
require 'pry'
|
5
|
-
|
5
|
+
require_relative '../lib/robust_excel_ole'
|
6
6
|
|
7
7
|
include REO
|
8
8
|
include General
|
9
9
|
|
10
10
|
# some pry configuration
|
11
11
|
Pry.config.windows_console_warning = false
|
12
|
-
#Pry.config.history_save = true
|
13
12
|
Pry.config.color = false
|
13
|
+
Pry.config.prompt_name = "REO "
|
14
|
+
|
15
|
+
#Pry.config.history_save = true
|
14
16
|
#Pry.editor = 'notepad' # 'subl', 'vi'
|
15
|
-
#Pry.config.prompt =
|
16
|
-
#[
|
17
|
-
#->(_obj, _nest_level, _) { ">> " },
|
18
|
-
#->(*) { " " }
|
19
|
-
#]
|
20
17
|
|
21
18
|
hooks = Pry::Hooks.new
|
22
19
|
|
data/bin/reo
CHANGED
@@ -2,21 +2,18 @@
|
|
2
2
|
# -*- ruby -*-
|
3
3
|
|
4
4
|
require 'pry'
|
5
|
-
|
5
|
+
require_relative '../lib/robust_excel_ole'
|
6
6
|
|
7
7
|
include REO
|
8
8
|
include General
|
9
9
|
|
10
10
|
# some pry configuration
|
11
11
|
Pry.config.windows_console_warning = false
|
12
|
-
#Pry.config.history_save = true
|
13
12
|
Pry.config.color = false
|
13
|
+
Pry.config.prompt_name = "REO "
|
14
|
+
|
15
|
+
#Pry.config.history_save = true
|
14
16
|
#Pry.editor = 'notepad' # 'subl', 'vi'
|
15
|
-
#Pry.config.prompt =
|
16
|
-
#[
|
17
|
-
#->(_obj, _nest_level, _) { ">> " },
|
18
|
-
#->(*) { " " }
|
19
|
-
#]
|
20
17
|
|
21
18
|
hooks = Pry::Hooks.new
|
22
19
|
|
data/docs/README_ranges.rdoc
CHANGED
@@ -42,14 +42,18 @@ or
|
|
42
42
|
|
43
43
|
range = worksheet.range(["A1:D3"])
|
44
44
|
|
45
|
-
You can
|
45
|
+
You can also access a range from a workbook by providing the worksheet
|
46
|
+
|
47
|
+
range = workbook(workbook.sheet(1), [1..3,1..4])
|
48
|
+
|
49
|
+
Now you can read the values by
|
46
50
|
|
47
51
|
range.Value
|
48
52
|
=> [["foo", "workbook", "sheet1", nil], ["foo", nil, "foobaaa", nil], ["matz", "is", "nice", nil]]
|
49
53
|
|
50
54
|
or
|
51
55
|
|
52
|
-
range.v
|
56
|
+
range.value or range.v
|
53
57
|
=> [["foo", "workbook", "sheet1", nil], ["foo", nil, "foobaaa", nil], ["matz", "is", "nice", nil]]
|
54
58
|
|
55
59
|
or as flat array
|
@@ -63,8 +67,20 @@ You can set values with help of range#Value or range#v, e.g.
|
|
63
67
|
|
64
68
|
or
|
65
69
|
|
70
|
+
range.value = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
|
71
|
+
|
72
|
+
or
|
73
|
+
|
66
74
|
range.v = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
|
67
75
|
|
76
|
+
or
|
77
|
+
|
78
|
+
range.set_value([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
|
79
|
+
|
80
|
+
You can color the range when setting the contents of a range.
|
81
|
+
|
82
|
+
range.set_value([[1,2,3,4],[5,6,7,8],[9,10,11,12]], :color => 42)
|
83
|
+
|
68
84
|
Now we copy the range. With help of VBA methods you would do
|
69
85
|
|
70
86
|
range.Copy(:destination => sheet.range([4,5]).ole_range)
|
@@ -194,6 +210,10 @@ or
|
|
194
210
|
|
195
211
|
range = worksheet.range([[1]..3,2..[4]])
|
196
212
|
|
213
|
+
You can access a range also from a workbook by providing the respective worksheet
|
214
|
+
|
215
|
+
range = workbook(worksheet, [[1..3],2..[4]])
|
216
|
+
|
197
217
|
You get the values of the range as flat array with help of
|
198
218
|
|
199
219
|
range.values
|
@@ -202,6 +222,10 @@ You can access a range via its defined name with
|
|
202
222
|
|
203
223
|
range = worksheet.range("name")
|
204
224
|
|
225
|
+
or
|
226
|
+
|
227
|
+
range = workbook(worksheet, "name")
|
228
|
+
|
205
229
|
=== Copying a range
|
206
230
|
|
207
231
|
Let's assume, you have a source range
|
@@ -310,10 +334,6 @@ You can color the range when setting the contents of a range.
|
|
310
334
|
|
311
335
|
workbook.set_namevalue_glob("name", "new_value", :color => 4)
|
312
336
|
|
313
|
-
The method []= sets the contents of a range and colors the range via some default color.
|
314
|
-
|
315
|
-
workbook["name"] = "new_value"
|
316
|
-
|
317
337
|
Similarly, the contents of a named range can be read and modified in a worksheet
|
318
338
|
|
319
339
|
worksheet = workbook.sheet(1)
|
data/docs/README_sheet.rdoc
CHANGED
@@ -97,7 +97,7 @@ The method Worksheet#values yields all cell values of the used range of the work
|
|
97
97
|
worksheet.values
|
98
98
|
=> [["foo", "workbook", "sheet1"], ["foo", nil, "foobaaa"], ["matz", "is", "nice"]]
|
99
99
|
|
100
|
-
The method Worksheet#each_rowvalue
|
100
|
+
The method Worksheet#each_rowvalue enables to access the values of each row.
|
101
101
|
|
102
102
|
worksheet.each_rowvalue do |row_values|
|
103
103
|
# do something with the row_values
|
data/lib/reo_console.rb
CHANGED
@@ -6,14 +6,29 @@ include General
|
|
6
6
|
|
7
7
|
# some pry configuration
|
8
8
|
Pry.config.windows_console_warning = false
|
9
|
-
#Pry.config.history_save = true
|
10
9
|
Pry.config.color = false
|
10
|
+
Pry.config.prompt_name = "REO "
|
11
|
+
|
12
|
+
#Pry.config.history_save = true
|
11
13
|
#Pry.editor = 'notepad' # 'subl', 'vi'
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
|
15
|
+
prompt_proc1 = proc { |target_self, nest_level, pry|
|
16
|
+
"[#{pry.input_ring.count}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self.inspect)})#{":#{nest_level}" unless nest_level.zero?}> "
|
17
|
+
}
|
18
|
+
|
19
|
+
prompt_proc2 = proc { |target_self, nest_level, pry|
|
20
|
+
"[#{pry.input_ring.count}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self.inspect)})#{":#{nest_level}" unless nest_level.zero?}* "
|
21
|
+
}
|
22
|
+
|
23
|
+
Pry.config.prompt = if RUBY_PLATFORM =~ /java/
|
24
|
+
[prompt_proc1, prompt_proc2]
|
25
|
+
else
|
26
|
+
Pry::Prompt.new(
|
27
|
+
"REO",
|
28
|
+
"The RobustExcelOle Prompt. Besides the standard information it puts the current object",
|
29
|
+
[prompt_proc1, prompt_proc2]
|
30
|
+
)
|
31
|
+
end
|
17
32
|
|
18
33
|
hooks = Pry::Hooks.new
|
19
34
|
|
@@ -21,4 +36,7 @@ hooks.add_hook :when_started, :hook12 do
|
|
21
36
|
puts 'REO console started'
|
22
37
|
puts
|
23
38
|
end
|
39
|
+
|
40
|
+
General.uplift_to_reo
|
41
|
+
|
24
42
|
Pry.start(nil, hooks: hooks)
|
data/lib/robust_excel_ole.rb
CHANGED
@@ -18,5 +18,5 @@ require File.join(File.dirname(__FILE__), 'robust_excel_ole/list_object')
|
|
18
18
|
require File.join(File.dirname(__FILE__), 'robust_excel_ole/cygwin') if RUBY_PLATFORM =~ /cygwin/
|
19
19
|
require File.join(File.dirname(__FILE__), 'robust_excel_ole/version')
|
20
20
|
|
21
|
-
include RobustExcelOle
|
21
|
+
#include RobustExcelOle
|
22
22
|
include General
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
LOG_TO_STDOUT: Boolean = false
|
4
|
+
REO_LOG_DIR: String
|
5
|
+
REO_LOG_FILE: String
|
6
|
+
|
7
|
+
class String
|
8
|
+
|
9
|
+
def end_with? : (suffixes: Array[String]) -> String
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
module RobustExcelOle
|
14
|
+
|
15
|
+
class VBAMethodMissingError < RuntimeError
|
16
|
+
end
|
17
|
+
|
18
|
+
class REOError < RuntimeError
|
19
|
+
end
|
20
|
+
|
21
|
+
class ExcelREOError < REOError
|
22
|
+
end
|
23
|
+
|
24
|
+
class WorkbookREOError < REOError
|
25
|
+
end
|
26
|
+
|
27
|
+
class WorksheetREOError < REOError
|
28
|
+
end
|
29
|
+
|
30
|
+
class FileREOError < REOError
|
31
|
+
end
|
32
|
+
|
33
|
+
class NamesREOError < REOError
|
34
|
+
end
|
35
|
+
|
36
|
+
class MiscREOError < REOError
|
37
|
+
end
|
38
|
+
|
39
|
+
class TypeREOError < REOError
|
40
|
+
end
|
41
|
+
|
42
|
+
# @private
|
43
|
+
class UnexpectedREOError < REOError
|
44
|
+
end
|
45
|
+
|
46
|
+
# @private
|
47
|
+
class NotImplementedREOError < REOError
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
class Base
|
52
|
+
|
53
|
+
def own_methods -> Array[Symbol]
|
54
|
+
|
55
|
+
def self.tr1: (_text1: String) -> void
|
56
|
+
|
57
|
+
def self.trace: (text: String) -> void
|
58
|
+
|
59
|
+
def self.puts_hash: (hash: Hash) -> void
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -12,14 +12,17 @@ module RobustExcelOle
|
|
12
12
|
ole_cell
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def value
|
16
16
|
self.Value
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def value=(value)
|
20
20
|
self.Value = value
|
21
21
|
end
|
22
22
|
|
23
|
+
alias_method :v, :value
|
24
|
+
alias_method :v=, :value=
|
25
|
+
|
23
26
|
# @private
|
24
27
|
def ole_cell
|
25
28
|
@ole_range = @ole_range.MergeArea.Item(1,1) if @ole_range.MergeCells
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module RobustExcelOle
|
4
|
+
|
5
|
+
class Cell < Range
|
6
|
+
|
7
|
+
def initialize: (win32_cell: WIN32OLE, worksheet: Worksheet) -> void
|
8
|
+
|
9
|
+
def value -> String
|
10
|
+
|
11
|
+
def value= (value: Variant) -> Variant
|
12
|
+
|
13
|
+
def v -> String
|
14
|
+
|
15
|
+
def v= (value: Variant) -> Variant
|
16
|
+
|
17
|
+
def ole_cell -> WIN32OLE | void
|
18
|
+
|
19
|
+
def to_s -> String
|
20
|
+
|
21
|
+
def inspect -> String
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -76,7 +76,7 @@ module RobustExcelOle
|
|
76
76
|
end
|
77
77
|
connected = (not ole_xl.nil?) && win32ole_excel.nil?
|
78
78
|
ole_xl ||= WIN32OLE.new('Excel.Application')
|
79
|
-
hwnd = ole_xl.
|
79
|
+
hwnd = ole_xl.Hwnd
|
80
80
|
stored = hwnd2excel(hwnd)
|
81
81
|
if stored && stored.alive?
|
82
82
|
result = stored
|
@@ -297,7 +297,7 @@ module RobustExcelOle
|
|
297
297
|
finishing_living_excel = alive?
|
298
298
|
if finishing_living_excel
|
299
299
|
hwnd = (begin
|
300
|
-
@ole_excel.
|
300
|
+
@ole_excel.Hwnd
|
301
301
|
rescue
|
302
302
|
nil
|
303
303
|
end)
|
@@ -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.
|
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.
|
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.
|
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.
|
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.
|
477
|
+
next unless p.Name == 'EXCEL.EXE'
|
478
478
|
|
479
|
-
if pid2excel.include?(p.
|
480
|
-
excel = pid2excel[p.
|
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?
|
@@ -640,13 +640,8 @@ module RobustExcelOle
|
|
640
640
|
# set options in this Excel instance
|
641
641
|
def for_this_instance(options)
|
642
642
|
set_options(options)
|
643
|
-
#self.class.new(@ole_excel, options)
|
644
643
|
end
|
645
644
|
|
646
|
-
#def set_options(options)
|
647
|
-
# for_this_instance(options)
|
648
|
-
#end
|
649
|
-
|
650
645
|
def set_options(options)
|
651
646
|
@properties ||= { }
|
652
647
|
PROPERTIES.each do |property|
|
@@ -3,14 +3,14 @@
|
|
3
3
|
module General
|
4
4
|
|
5
5
|
IS_JRUBY_PLATFORM = (RUBY_PLATFORM =~ /java/)
|
6
|
-
::EXPANDPATH_JRUBY_BUG
|
7
|
-
::CONNECT_JRUBY_BUG
|
8
|
-
::COPYSHEETS_JRUBY_BUG
|
9
|
-
::ERRORMESSAGE_JRUBY_BUG
|
10
|
-
::CONNECT_EXCEL_JRUBY_BUG
|
11
|
-
::RANGES_JRUBY_BUG
|
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')
|
@@ -44,7 +44,7 @@ module General
|
|
44
44
|
file[0,2] = './' if ::EXPANDPATH_JRUBY_BUG && file =~ /[A-Z]:[^\/]/
|
45
45
|
file = File.expand_path(file)
|
46
46
|
file = RobustExcelOle::Cygwin.cygpath('-w', file) if RUBY_PLATFORM =~ /cygwin/
|
47
|
-
WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName(file)
|
47
|
+
WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName(file) #.tr('/','\\')
|
48
48
|
end
|
49
49
|
|
50
50
|
# @private
|
@@ -64,8 +64,99 @@ module General
|
|
64
64
|
path
|
65
65
|
end
|
66
66
|
|
67
|
-
|
67
|
+
def change_current_binding(current_object)
|
68
|
+
Pry.change_current_binding(current_object)
|
69
|
+
end
|
70
|
+
|
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
|
68
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
|
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
|
69
160
|
end
|
70
161
|
|
71
162
|
# @private
|
@@ -118,14 +209,7 @@ class WIN32OLE
|
|
118
209
|
|
119
210
|
# type-lifting WIN32OLE objects to RobustExcelOle objects
|
120
211
|
def to_reo
|
121
|
-
class2method
|
122
|
-
{Excel => :Hwnd},
|
123
|
-
{Workbook => :FullName},
|
124
|
-
{Worksheet => :UsedRange},
|
125
|
-
{RobustExcelOle::Range => :Row},
|
126
|
-
{ListObject => :ListRows}
|
127
|
-
]
|
128
|
-
class2method.each do |element|
|
212
|
+
General.class2method.each do |element|
|
129
213
|
classname = element.first.first
|
130
214
|
method = element.first.last
|
131
215
|
begin
|
@@ -142,16 +226,37 @@ class WIN32OLE
|
|
142
226
|
raise TypeREOError, "given object cannot be type-lifted to a RobustExcelOle object"
|
143
227
|
end
|
144
228
|
|
229
|
+
=begin
|
230
|
+
def to_reo
|
231
|
+
case ole_type.name
|
232
|
+
when 'Range' then RobustExcelOle::Range.new(self)
|
233
|
+
when '_Worksheet' then RobustExcelOle::Worksheet.new(self)
|
234
|
+
when '_Workbook' then RobustExcelOle::Workbook.new(self)
|
235
|
+
when '_Application' then RobustExcelOle::Excel.new(self)
|
236
|
+
else
|
237
|
+
self
|
238
|
+
end
|
239
|
+
end
|
240
|
+
=end
|
241
|
+
|
242
|
+
=begin
|
145
243
|
alias method_missing_before_implicit_typelift method_missing
|
146
|
-
|
244
|
+
|
245
|
+
def method_missing(name, *args, &blk)
|
246
|
+
puts "method_missing:"
|
247
|
+
puts "name: #{name.inspect}"
|
248
|
+
#raise NoMethodError if name.to_s == "Hwnd" or name.to_s == "FullName" or name.to_s == "UsedRange" or name.to_s == "Row" or name.to_s == "ListRows"
|
147
249
|
begin
|
148
250
|
reo_obj = self.to_reo
|
251
|
+
puts "reo_obj: #{reo_obj.inspect}"
|
149
252
|
rescue
|
150
253
|
puts "$!.message: #{$!.message}"
|
151
254
|
method_missing_before_implicit_typelift(name, *args, &blk)
|
152
255
|
end
|
153
256
|
reo_obj.send(name, *args, &blk)
|
154
257
|
end
|
258
|
+
=end
|
259
|
+
|
155
260
|
end
|
156
261
|
|
157
262
|
# @private
|
@@ -276,7 +381,6 @@ module MethodHelpers
|
|
276
381
|
super
|
277
382
|
end
|
278
383
|
end
|
279
|
-
|
280
384
|
end
|
281
385
|
|
282
386
|
REO = RobustExcelOle
|
@@ -17,23 +17,30 @@ module RobustExcelOle
|
|
17
17
|
alias ole_object ole_table
|
18
18
|
|
19
19
|
# constructs a list object (or table).
|
20
|
-
# @param [Variable]
|
20
|
+
# @param [Variable] worksheet_or_listobject a worksheet or a list object
|
21
21
|
# @param [Variable] table_name_or_number a table name or table number
|
22
22
|
# @param [Array] position a position of the upper left corner
|
23
23
|
# @param [Integer] rows_count number of rows
|
24
24
|
# @param [Variable] columns_count_or_names number of columns or array of column names
|
25
25
|
# @return [ListObject] a ListObject object
|
26
|
-
def initialize(
|
27
|
-
table_name_or_number = "",
|
26
|
+
def initialize(worksheet_or_listobject,
|
27
|
+
table_name_or_number = "_table_name",
|
28
28
|
position = [1,1],
|
29
29
|
rows_count = 1,
|
30
30
|
columns_count_or_names = 1)
|
31
|
-
|
32
|
-
if
|
33
|
-
|
31
|
+
|
32
|
+
# ole_table is being assigned to the first parameter, if this parameter is a ListObject
|
33
|
+
# otherwise the first parameter could be a worksheet, and get the ole_table via the ListObject name or number
|
34
|
+
@ole_table = if worksheet_or_listobject.respond_to?(:ListRows)
|
35
|
+
worksheet_or_listobject.ole_table
|
34
36
|
else
|
35
|
-
|
36
|
-
|
37
|
+
begin
|
38
|
+
worksheet_or_listobject.send(:ListRows)
|
39
|
+
worksheet_or_listobject
|
40
|
+
rescue
|
41
|
+
@worksheet = worksheet_or_listobject.to_reo
|
42
|
+
@worksheet.ListObjects.Item(table_name_or_number) rescue nil
|
43
|
+
end
|
37
44
|
end
|
38
45
|
unless @ole_table
|
39
46
|
columns_count =
|
@@ -52,6 +59,7 @@ module RobustExcelOle
|
|
52
59
|
end
|
53
60
|
end
|
54
61
|
|
62
|
+
|
55
63
|
ole_table = @ole_table
|
56
64
|
@row_class = Class.new(ListRow) do
|
57
65
|
|
@@ -5,7 +5,7 @@ module RobustExcelOle
|
|
5
5
|
# This class essentially wraps a Win32Ole Range object.
|
6
6
|
# You can apply all VBA methods (starting with a capital letter)
|
7
7
|
# that you would apply for a Range object.
|
8
|
-
# See https://docs.microsoft.com/en-us/office/vba/api/excel.
|
8
|
+
# See https://docs.microsoft.com/en-us/office/vba/api/excel.range#methods
|
9
9
|
|
10
10
|
class Range < VbaObjects
|
11
11
|
|
@@ -70,7 +70,9 @@ module RobustExcelOle
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
|
73
|
+
# returns flat array of the values of a given range
|
74
|
+
# @returns [Array] values of the range (as a nested array)
|
75
|
+
def value
|
74
76
|
begin
|
75
77
|
if !::RANGES_JRUBY_BUG
|
76
78
|
self.Value
|
@@ -89,7 +91,9 @@ module RobustExcelOle
|
|
89
91
|
|
90
92
|
end
|
91
93
|
|
92
|
-
|
94
|
+
# sets the values if the range
|
95
|
+
# @param [Variant] value
|
96
|
+
def value=(value)
|
93
97
|
begin
|
94
98
|
if !::RANGES_JRUBY_BUG
|
95
99
|
ole_range.Value = value
|
@@ -102,12 +106,33 @@ module RobustExcelOle
|
|
102
106
|
end
|
103
107
|
value
|
104
108
|
rescue WIN32OLERuntimeError, Java::OrgRacobCom::ComFailException => msg
|
105
|
-
raise RangeNotEvaluatable, "cannot assign value to range #{
|
109
|
+
raise RangeNotEvaluatable, "cannot assign value to range #{self.inspect}"
|
106
110
|
end
|
107
111
|
end
|
108
112
|
|
109
|
-
alias_method :
|
110
|
-
alias_method :
|
113
|
+
alias_method :v, :value
|
114
|
+
alias_method :v=, :value=
|
115
|
+
|
116
|
+
# sets the values if the range with a given color
|
117
|
+
# @param [Variant] value
|
118
|
+
# @option opts [Symbol] :color the color of the cell when set
|
119
|
+
def set_value(value, opts = { })
|
120
|
+
begin
|
121
|
+
if !::RANGES_JRUBY_BUG
|
122
|
+
ole_range.Value = value
|
123
|
+
else
|
124
|
+
rows.each_with_index do |r,i|
|
125
|
+
columns.each_with_index do |c,j|
|
126
|
+
ole_range.Cells(i+1,j+1).Value = (value.respond_to?(:first) ? value[i][j] : value)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
ole_range.Interior.ColorIndex = opts[:color] unless opts[:color].nil?
|
131
|
+
value
|
132
|
+
rescue WIN32OLERuntimeError, Java::OrgRacobCom::ComFailException => msg
|
133
|
+
raise RangeNotEvaluatable, "cannot assign value to range #{self.inspect}"
|
134
|
+
end
|
135
|
+
end
|
111
136
|
|
112
137
|
# copies a range
|
113
138
|
# @params [Address or Address-Array] address or upper left position of the destination range
|
@@ -189,12 +214,11 @@ module RobustExcelOle
|
|
189
214
|
# @private
|
190
215
|
def to_s
|
191
216
|
"#<REO::Range: " + "#{@ole_range.Address('External' => true).gsub(/\$/,'')} " + ">"
|
192
|
-
# "#<REO::Range: " + "#{@ole_range.Address.gsub(/\$/,'')} " + "#{worksheet.Name} " + ">"
|
193
217
|
end
|
194
218
|
|
195
219
|
# @private
|
196
220
|
def inspect
|
197
|
-
to_s
|
221
|
+
to_s
|
198
222
|
end
|
199
223
|
|
200
224
|
# @private
|
@@ -62,7 +62,7 @@ module RobustExcelOle
|
|
62
62
|
# sets the contents of a range
|
63
63
|
# @param [String] name the name of a range
|
64
64
|
# @param [Variant] value the contents of the range
|
65
|
-
# @option opts [Symbol] :color the color of the
|
65
|
+
# @option opts [Symbol] :color the color of the range when set
|
66
66
|
def set_namevalue_glob(name, value, opts = { })
|
67
67
|
begin
|
68
68
|
name_obj = begin
|
@@ -177,36 +177,10 @@ module RobustExcelOle
|
|
177
177
|
end
|
178
178
|
|
179
179
|
# creates a range from a given defined name or address
|
180
|
-
#
|
181
|
-
# @params [Variant] range name or address
|
180
|
+
# @params [Variant] defined name or address, and optional a worksheet
|
182
181
|
# @return [Range] a range
|
183
|
-
def range(
|
184
|
-
|
185
|
-
worksheet = self if self.is_a?(Worksheet)
|
186
|
-
if address2 == :__not_provided
|
187
|
-
range = if name_or_address.is_a?(String)
|
188
|
-
begin
|
189
|
-
RobustExcelOle::Range.new(name_object(name_or_address).RefersToRange, worksheet)
|
190
|
-
rescue NameNotFound
|
191
|
-
nil
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
if self.is_a?(Worksheet) && (range.nil? || (address2 != :__not_provided))
|
196
|
-
address = name_or_address
|
197
|
-
address = [name_or_address,address2] unless address2 == :__not_provided
|
198
|
-
self.Names.Add('__dummy001',nil,true,nil,nil,nil,nil,nil,nil,'=' + address_tool.as_r1c1(address))
|
199
|
-
range = RobustExcelOle::Range.new(name_object('__dummy001').RefersToRange, worksheet)
|
200
|
-
self.Names.Item('__dummy001').Delete
|
201
|
-
workbook = self.is_a?(Workbook) ? self : self.workbook
|
202
|
-
workbook.save
|
203
|
-
range
|
204
|
-
end
|
205
|
-
rescue WIN32OLERuntimeError, Java::OrgRacobCom::ComFailException
|
206
|
-
address2_string = address2.nil? ? "" : ", #{address2.inspect}"
|
207
|
-
raise RangeNotCreated, "cannot create range (#{name_or_address.inspect}#{address2_string})"
|
208
|
-
end
|
209
|
-
range
|
182
|
+
def range(*args)
|
183
|
+
raise RangeNotCreated, "not yet implemented"
|
210
184
|
end
|
211
185
|
|
212
186
|
def name2range(name) # :deprecated: #
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
module RobustExcelOle
|
5
|
+
|
6
|
+
class VbaObjects < Base
|
7
|
+
|
8
|
+
def to_reo -> VbaObjects
|
9
|
+
|
10
|
+
def address_tool -> AddressTool
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
class RangeNotEvaluatable < MiscREOError
|
15
|
+
end
|
16
|
+
|
17
|
+
class OptionInvalid < MiscREOError
|
18
|
+
end
|
19
|
+
|
20
|
+
class ObjectNotAlive < MiscREOError
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -882,6 +882,24 @@ module RobustExcelOle
|
|
882
882
|
worksheet_class.new(@ole_workbook.Worksheets.Item(1))
|
883
883
|
end
|
884
884
|
|
885
|
+
# creates a range from a given defined name or from a given worksheet and address
|
886
|
+
# @params [Variant] defined name or a worksheet
|
887
|
+
# @params [Address] address
|
888
|
+
# @return [Range] a range
|
889
|
+
def range(name_or_worksheet, name_or_address = :__not_provided, address2 = :__not_provided)
|
890
|
+
if name_or_worksheet.respond_to?(:gsub)
|
891
|
+
name = name_or_worksheet
|
892
|
+
RobustExcelOle::Range.new(name_object(name).RefersToRange)
|
893
|
+
else
|
894
|
+
begin
|
895
|
+
worksheet = name_or_worksheet.to_reo
|
896
|
+
worksheet.range(name_or_address, address2)
|
897
|
+
rescue
|
898
|
+
raise RangeNotCreated, "argument error: a defined name or a worksheet and an address must be provided"
|
899
|
+
end
|
900
|
+
end
|
901
|
+
end
|
902
|
+
|
885
903
|
# returns the value of a range
|
886
904
|
# @param [String] name the name of a range
|
887
905
|
# @returns [Variant] the value of the range
|
@@ -64,7 +64,7 @@ module RobustExcelOle
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
# a cell given the defined name or row and column
|
67
|
+
# returns a cell given the defined name or row and column
|
68
68
|
# @params row, column, or name
|
69
69
|
# @returns cell, if row and column are given
|
70
70
|
def [] p1, p2 = :__not_provided
|
@@ -118,19 +118,6 @@ module RobustExcelOle
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
-
=begin
|
122
|
-
def cellval(x,y)
|
123
|
-
xy = "#{x}_#{y}"
|
124
|
-
@cells = { }
|
125
|
-
begin
|
126
|
-
@cells[xy] ||= RobustExcelOle::Cell.new(@ole_worksheet.Cells.Item(x, y), @worksheet)
|
127
|
-
@cells[xy].Value
|
128
|
-
rescue
|
129
|
-
raise RangeNotEvaluatable, "cannot read cell (#{p1.inspect},#{p2.inspect})"
|
130
|
-
end
|
131
|
-
end
|
132
|
-
=end
|
133
|
-
|
134
121
|
# sets the value of a cell, if row, column and color of the cell are given
|
135
122
|
# @params [Integer] x,y row and column
|
136
123
|
# @option opts [Symbol] :color the color of the cell when set
|
@@ -226,6 +213,31 @@ module RobustExcelOle
|
|
226
213
|
self.Name == other_worksheet.Name
|
227
214
|
end
|
228
215
|
|
216
|
+
# creates a range from a given defined name or address
|
217
|
+
# @params [Variant] defined name or address
|
218
|
+
# @return [Range] a range
|
219
|
+
def range(name_or_address, address2 = :__not_provided)
|
220
|
+
if name_or_address.respond_to?(:gsub) && address2 == :__not_provided
|
221
|
+
name = name_or_address
|
222
|
+
range = RobustExcelOle::Range.new(name_object(name).RefersToRange, self) rescue nil
|
223
|
+
end
|
224
|
+
unless range
|
225
|
+
address = name_or_address
|
226
|
+
address = [name_or_address,address2] unless address2 == :__not_provided
|
227
|
+
workbook.retain_saved do
|
228
|
+
begin
|
229
|
+
self.Names.Add('__dummy001',nil,true,nil,nil,nil,nil,nil,nil,'=' + address_tool.as_r1c1(address))
|
230
|
+
range = RobustExcelOle::Range.new(name_object('__dummy001').RefersToRange, self)
|
231
|
+
self.Names.Item('__dummy001').Delete
|
232
|
+
rescue
|
233
|
+
address2_string = address2.nil? ? "" : ", #{address2.inspect}"
|
234
|
+
raise RangeNotCreated, "cannot create range (#{name_or_address.inspect}#{address2_string})"
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
range
|
239
|
+
end
|
240
|
+
|
229
241
|
# @private
|
230
242
|
# returns true, if the worksheet object responds to VBA methods, false otherwise
|
231
243
|
def alive?
|
@@ -258,7 +270,7 @@ module RobustExcelOle
|
|
258
270
|
|
259
271
|
# @private
|
260
272
|
def inspect
|
261
|
-
|
273
|
+
to_s
|
262
274
|
end
|
263
275
|
|
264
276
|
include MethodHelpers
|
data/robust_excel_ole.gemspec
CHANGED
@@ -34,6 +34,7 @@ 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_runtime_dependency "pry", '>= 0.12.1'
|
37
|
+
s.add_runtime_dependency "pry-bond", '>=0.0.1'
|
37
38
|
s.add_development_dependency "rspec", '>= 2.6.0'
|
38
39
|
s.required_ruby_version = '>= 2.1'
|
39
40
|
end
|
data/spec/general_spec.rb
CHANGED
@@ -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
|
data/spec/list_object_spec.rb
CHANGED
@@ -41,6 +41,13 @@ describe ListObject do
|
|
41
41
|
@sheet[1,1].Value.should == "Person"
|
42
42
|
end
|
43
43
|
|
44
|
+
it "should do the idempotence" do
|
45
|
+
ole_table = @sheet.ListObjects.Item(1)
|
46
|
+
table = Table.new(ole_table)
|
47
|
+
table2 = Table.new(table)
|
48
|
+
table2.ole_table.should be_a WIN32OLE
|
49
|
+
end
|
50
|
+
|
44
51
|
it "should type-lift a Win32ole list object into a RobustExcelOle list object" do
|
45
52
|
ole_table = @sheet.ListObjects.Item(1)
|
46
53
|
table = Table.new(ole_table)
|
@@ -330,8 +337,6 @@ describe ListObject do
|
|
330
337
|
cells[0].Column.should == 8
|
331
338
|
cells[1].Row.should == 9
|
332
339
|
cells[1].Column.should == 6
|
333
|
-
puts "cells[0]: #{[cells[0]]}"
|
334
|
-
p "cells[0]: #{[cells[0]]}"
|
335
340
|
end
|
336
341
|
|
337
342
|
end
|
data/spec/range_spec.rb
CHANGED
@@ -177,9 +177,9 @@ describe RobustExcelOle::Range do
|
|
177
177
|
end
|
178
178
|
end
|
179
179
|
|
180
|
-
describe "#
|
180
|
+
describe "#value" do
|
181
181
|
|
182
|
-
context "
|
182
|
+
context "value, value=" do
|
183
183
|
|
184
184
|
before do
|
185
185
|
@sheet1 = @book.sheet(1)
|
@@ -207,6 +207,12 @@ describe RobustExcelOle::Range do
|
|
207
207
|
@sheet1.range([1..2,3..5]).v = [[1,2,3],[4,5,6]]
|
208
208
|
@sheet1.range([1..2,3..5]).v.should == [[1,2,3],[4,5,6]]
|
209
209
|
end
|
210
|
+
|
211
|
+
it "should color the range" do
|
212
|
+
@sheet1.range([1..2,3..5]).set_value([[1,2,3],[4,5,6]],:color => 42)
|
213
|
+
@sheet1.range([1..2,3..5]).Interior.ColorIndex.should == 42
|
214
|
+
end
|
215
|
+
|
210
216
|
end
|
211
217
|
end
|
212
218
|
|
@@ -1096,6 +1096,16 @@ describe Workbook do
|
|
1096
1096
|
range.Address.should == "$A$1:$D$3"
|
1097
1097
|
end
|
1098
1098
|
|
1099
|
+
it "should raise error when given integer range" do
|
1100
|
+
expect{
|
1101
|
+
@book1.range([1..2,3..4])
|
1102
|
+
}.to raise_error(RangeNotCreated, /argument/)
|
1103
|
+
end
|
1104
|
+
|
1105
|
+
it "should accept an integer range when given a worksheet" do
|
1106
|
+
@book1.range(@book1.sheet(1),[4..5,1..2]).Address.should == "$A$4:$B$5"
|
1107
|
+
end
|
1108
|
+
|
1099
1109
|
end
|
1100
1110
|
|
1101
1111
|
context "adding and deleting the name of a range" do
|
data/spec/worksheet_spec.rb
CHANGED
@@ -19,6 +19,7 @@ describe Worksheet do
|
|
19
19
|
before do
|
20
20
|
@dir = create_tmpdir
|
21
21
|
@simple_file = @dir + '/workbook.xls'
|
22
|
+
@another_workbook = @dir + '/another_workbook.xls'
|
22
23
|
@protected_file = @dir + '/protected_sheet.xls'
|
23
24
|
@blank_file = @dir + '/book_with_blank.xls'
|
24
25
|
@merge_file = @dir + '/merge_cells.xls'
|
@@ -207,11 +208,13 @@ describe Worksheet do
|
|
207
208
|
describe "range" do
|
208
209
|
|
209
210
|
it "should a range with relative r1c1-reference" do
|
211
|
+
@sheet.range([1,1]).Select
|
210
212
|
@sheet.range(["Z1S[3]:Z[2]S8"]).Address.should == "$D$1:$H$3"
|
211
213
|
@sheet.range(["Z1S3:Z2S8"]).Address.should == "$C$1:$H$2"
|
212
214
|
end
|
213
215
|
|
214
216
|
it "should a range with relative integer-range-reference" do
|
217
|
+
@sheet.range([1,1]).Select
|
215
218
|
@sheet.range([1..[2],[3]..8]).Address.should == "$D$1:$H$3"
|
216
219
|
end
|
217
220
|
|
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.
|
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-
|
11
|
+
date: 2020-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.12.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry-bond
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.1
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,13 +126,14 @@ files:
|
|
112
126
|
- examples/open_save_close/example_reuse.rb
|
113
127
|
- examples/open_save_close/example_simple.rb
|
114
128
|
- examples/open_save_close/example_unobtrusively.rb
|
115
|
-
- jreo.bat
|
116
129
|
- lib/reo_console.rb
|
117
130
|
- lib/robust_excel_ole.rb
|
118
131
|
- lib/robust_excel_ole/address_tool.rb
|
119
132
|
- lib/robust_excel_ole/base.rb
|
133
|
+
- lib/robust_excel_ole/base.rbs
|
120
134
|
- lib/robust_excel_ole/bookstore.rb
|
121
135
|
- lib/robust_excel_ole/cell.rb
|
136
|
+
- lib/robust_excel_ole/cell.rbs
|
122
137
|
- lib/robust_excel_ole/cygwin.rb
|
123
138
|
- lib/robust_excel_ole/excel.rb
|
124
139
|
- lib/robust_excel_ole/general.rb
|
@@ -128,11 +143,11 @@ files:
|
|
128
143
|
- lib/robust_excel_ole/robustexcelole.sublime-project
|
129
144
|
- lib/robust_excel_ole/robustexcelole.sublime-workspace
|
130
145
|
- lib/robust_excel_ole/vba_objects.rb
|
146
|
+
- lib/robust_excel_ole/vba_objects.rbs
|
131
147
|
- lib/robust_excel_ole/version.rb
|
132
148
|
- lib/robust_excel_ole/workbook.rb
|
133
149
|
- lib/robust_excel_ole/worksheet.rb
|
134
150
|
- lib/spec_helper.rb
|
135
|
-
- reo.bat
|
136
151
|
- robust_excel_ole.gemspec
|
137
152
|
- spec/address_tool_spec.rb
|
138
153
|
- spec/base_spec.rb
|
data/jreo.bat
DELETED
data/reo.bat
DELETED