robust_excel_ole 1.22.1 → 1.26

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: 263dffb48164d10b6d26fea5ff0b6ba8dc989f625e0ce082f61d953880ac4016
4
- data.tar.gz: 85ea44b392bd2a1c183b757d8c17ffc5a24dcc2688097f4e66701c770cc4f962
3
+ metadata.gz: a2553a7622f9092b5067ad3f7e945d57a1dbfa6e540716b326c6b684a351cf79
4
+ data.tar.gz: e623c4a2f3e22ef1da88b6475d7f6dc277c9f3f4581db27427fd9ca6aa400f24
5
5
  SHA512:
6
- metadata.gz: aabd79f1f908e32cf2849fdbe2ae50c6f9e3212eae5fa524b3e8609c2db35baeeba6d3922b85d6bac1919fab0fc58dcd45b97a69519f9c48f42b97e4aa11b99a
7
- data.tar.gz: 134cdfab22b7a12c65bd4d27b7969ca5000a9742bfd64728562d1027eee8a3a70af1d5e779c760c7a1310d108707e6d7135e8e8da0e8cc3adac33bad4a52d62d
6
+ metadata.gz: 9056cec7af1bf9c6c04ab2df83dd080bb63308f5c5a7d6af13286090d357441928d7dcb2dde2371940e36729fafb26460098d2063254f8809796a9dde87ddc85
7
+ data.tar.gz: d036c741ef593695e0fecfd8f1e34b1db5bec0e7e2430b5a88f1e16a297a804b1a9d95c8bc847bc993f0a1ea4b666cd56db200cc9cdfec38078dab6c5b4ef59b
data/Changelog CHANGED
@@ -1,8 +1,22 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.26] 2020-09-10
5
+
6
+ ### Added
7
+ - General#change_current_binding
8
+
9
+ ## [1.25] 2020-10-09]
10
+
11
+ ## [1.24] 2020-25-09
12
+
13
+ ## [1.23] 2020-02-09
14
+
4
15
  ## [1.22] 2020-10-08
5
16
 
17
+ ### Added
18
+ - Range#set_value
19
+
6
20
  ## [1.21] 2020-05-08
7
21
 
8
22
  ### Added
@@ -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,7 +318,21 @@ 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 things
321
+ === More features
322
+
323
+ The ruby shell 'pry' allows, among other useful things, to change the value of 'self' in the console. For example,
324
+
325
+ object.pry
326
+
327
+ or
328
+
329
+ cd object
330
+
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.
332
+
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.
334
+
335
+ General.change_current_binding
322
336
 
323
337
  You can convert some Win32Ole objects into a RobustExcelOle object.
324
338
 
data/bin/jreo CHANGED
@@ -2,21 +2,18 @@
2
2
  # -*- jruby -*-
3
3
 
4
4
  require 'pry'
5
- require '../lib/robust_excel_ole'
5
+ require '../robust_excel_ole/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
- require '../lib/robust_excel_ole'
5
+ require '../robust_excel_ole/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
 
@@ -42,14 +42,18 @@ or
42
42
 
43
43
  range = worksheet.range(["A1:D3"])
44
44
 
45
- You can read the values by
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)
@@ -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 provides enable to access the values of each row.
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
@@ -4,16 +4,60 @@ 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
+
7
36
  # some pry configuration
8
37
  Pry.config.windows_console_warning = false
9
- #Pry.config.history_save = true
10
38
  Pry.config.color = false
39
+ Pry.config.prompt_name = "REO "
40
+
41
+ #Pry.config.history_save = true
11
42
  #Pry.editor = 'notepad' # 'subl', 'vi'
12
- #Pry.config.prompt =
13
- #[
14
- #->(_obj, _nest_level, _) { ">> " },
15
- #->(*) { " " }
16
- #]
43
+
44
+ prompt_proc1 = proc { |target_self, nest_level, pry|
45
+ "[#{pry.input_ring.count}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self.inspect)})#{":#{nest_level}" unless nest_level.zero?}> "
46
+ }
47
+
48
+ prompt_proc2 = proc { |target_self, nest_level, pry|
49
+ "[#{pry.input_ring.count}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self.inspect)})#{":#{nest_level}" unless nest_level.zero?}* "
50
+ }
51
+
52
+ Pry.config.prompt = if RUBY_PLATFORM =~ /java/
53
+ [prompt_proc1, prompt_proc2]
54
+ else
55
+ Pry::Prompt.new(
56
+ "REO",
57
+ "The RobustExcelOle Prompt. Besides the standard information it puts the current object",
58
+ [prompt_proc1, prompt_proc2]
59
+ )
60
+ end
17
61
 
18
62
  hooks = Pry::Hooks.new
19
63
 
@@ -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 v
15
+ def value
16
16
  self.Value
17
17
  end
18
18
 
19
- def v=(value)
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.HWnd
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.HWnd
300
+ @ole_excel.Hwnd
301
301
  rescue
302
302
  nil
303
303
  end)
@@ -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|
@@ -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).tr('/','\\')
47
+ WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName(file) #.tr('/','\\')
48
48
  end
49
49
 
50
50
  # @private
@@ -64,7 +64,11 @@ module General
64
64
  path
65
65
  end
66
66
 
67
- module_function :absolute_path, :canonize, :normalize
67
+ def change_current_binding(current_object)
68
+ Pry.change_current_binding(current_object)
69
+ end
70
+
71
+ module_function :absolute_path, :canonize, :normalize, :change_current_binding
68
72
 
69
73
  end
70
74
 
@@ -142,16 +146,37 @@ class WIN32OLE
142
146
  raise TypeREOError, "given object cannot be type-lifted to a RobustExcelOle object"
143
147
  end
144
148
 
149
+ =begin
150
+ def to_reo
151
+ case ole_type.name
152
+ when 'Range' then RobustExcelOle::Range.new(self)
153
+ when '_Worksheet' then RobustExcelOle::Worksheet.new(self)
154
+ when '_Workbook' then RobustExcelOle::Workbook.new(self)
155
+ when '_Application' then RobustExcelOle::Excel.new(self)
156
+ else
157
+ self
158
+ end
159
+ end
160
+ =end
161
+
162
+ =begin
145
163
  alias method_missing_before_implicit_typelift method_missing
146
- def xx_method_missing(name, *args, &blk)
164
+
165
+ def method_missing(name, *args, &blk)
166
+ puts "method_missing:"
167
+ puts "name: #{name.inspect}"
168
+ #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
169
  begin
148
170
  reo_obj = self.to_reo
171
+ puts "reo_obj: #{reo_obj.inspect}"
149
172
  rescue
150
173
  puts "$!.message: #{$!.message}"
151
174
  method_missing_before_implicit_typelift(name, *args, &blk)
152
175
  end
153
176
  reo_obj.send(name, *args, &blk)
154
177
  end
178
+ =end
179
+
155
180
  end
156
181
 
157
182
  # @private
@@ -276,7 +301,6 @@ module MethodHelpers
276
301
  super
277
302
  end
278
303
  end
279
-
280
304
  end
281
305
 
282
306
  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] worksheet_or_ole_listobject a worksheet or a Win32Ole list object
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(worksheet_or_ole_listobject,
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 (worksheet_or_ole_listobject.ListRows rescue nil)
33
- @ole_table = worksheet_or_ole_listobject
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
- @worksheet = worksheet_or_ole_listobject.to_reo
36
- @ole_table = @worksheet.ListObjects.Item(table_name_or_number) rescue nil
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.worksheet#methods
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
- def v
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
- def v=(value)
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 #{address_r1c1.inspect}"
109
+ raise RangeNotEvaluatable, "cannot assign value to range #{self.inspect}"
106
110
  end
107
111
  end
108
112
 
109
- alias_method :value, :v
110
- alias_method :value=, :v=
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 # [0..-2] + "#{worksheet.workbook.Name} " + ">"
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 cell when set
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
- # range(address) does work for Worksheet objects only
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(name_or_address, address2 = :__not_provided)
184
- begin
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
@@ -1,3 +1,3 @@
1
1
  module RobustExcelOle
2
- VERSION = "1.22.1"
2
+ VERSION = "1.26"
3
3
  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
- self.to_s[0..-2] + "#{workbook.Name} " + ">"
273
+ to_s
262
274
  end
263
275
 
264
276
  include MethodHelpers
@@ -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
@@ -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
@@ -177,9 +177,9 @@ describe RobustExcelOle::Range do
177
177
  end
178
178
  end
179
179
 
180
- describe "#v" do
180
+ describe "#value" do
181
181
 
182
- context "v, v=" do
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
@@ -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.22.1
4
+ version: '1.26'
5
5
  platform: ruby
6
6
  authors:
7
7
  - traths
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-10 00:00:00.000000000 Z
11
+ date: 2020-10-09 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
@@ -117,8 +131,10 @@ files:
117
131
  - lib/robust_excel_ole.rb
118
132
  - lib/robust_excel_ole/address_tool.rb
119
133
  - lib/robust_excel_ole/base.rb
134
+ - lib/robust_excel_ole/base.rbs
120
135
  - lib/robust_excel_ole/bookstore.rb
121
136
  - lib/robust_excel_ole/cell.rb
137
+ - lib/robust_excel_ole/cell.rbs
122
138
  - lib/robust_excel_ole/cygwin.rb
123
139
  - lib/robust_excel_ole/excel.rb
124
140
  - lib/robust_excel_ole/general.rb
@@ -128,6 +144,7 @@ files:
128
144
  - lib/robust_excel_ole/robustexcelole.sublime-project
129
145
  - lib/robust_excel_ole/robustexcelole.sublime-workspace
130
146
  - lib/robust_excel_ole/vba_objects.rb
147
+ - lib/robust_excel_ole/vba_objects.rbs
131
148
  - lib/robust_excel_ole/version.rb
132
149
  - lib/robust_excel_ole/workbook.rb
133
150
  - lib/robust_excel_ole/worksheet.rb