robust_excel_ole 1.21 → 1.24
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 +9 -0
- data/README.rdoc +9 -135
- data/bin/jreo +11 -11
- data/bin/reo +3 -6
- data/docs/README_ranges.rdoc +26 -6
- data/docs/README_sheet.rdoc +1 -1
- data/jreo.bat +1 -1
- data/lib/reo_console.rb +79 -6
- data/lib/robust_excel_ole.rb +1 -1
- data/lib/robust_excel_ole/base.rbs +63 -0
- data/lib/robust_excel_ole/bookstore.rb +3 -3
- data/lib/robust_excel_ole/cell.rb +9 -5
- data/lib/robust_excel_ole/cell.rbs +25 -0
- data/lib/robust_excel_ole/excel.rb +1 -6
- data/lib/robust_excel_ole/general.rb +42 -25
- data/lib/robust_excel_ole/list_object.rb +16 -8
- data/lib/robust_excel_ole/range.rb +62 -98
- 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 +26 -7
- data/lib/robust_excel_ole/worksheet.rb +28 -16
- data/reo.bat +3 -0
- data/robust_excel_ole.gemspec +1 -0
- data/spec/general_spec.rb +10 -11
- data/spec/list_object_spec.rb +7 -2
- data/spec/range_spec.rb +8 -2
- data/spec/workbook_specs/workbook_misc_spec.rb +12 -2
- data/spec/worksheet_spec.rb +3 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7d0cb1b064c701e9a0cafbc632baceca0e69a4aeb47a6eba5ddcec109f27dee
|
4
|
+
data.tar.gz: f565901c9fa35233a7668958fd78ccf008e9ceb333e701e0662a850a9b5806e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69aebb4f2b71f46fbf58f3b9884a11347893b3335a32690b536c2174102fadf0971cb3074f8140feedaa8a4ef91683c79c67b77192c64b846bb310ba2bda20fa
|
7
|
+
data.tar.gz: 06bee2e7e0f277e2e647de1c4281a1961649b9d22128b76389873c03f86c7baf5f8c9681e030b735a29c2358b949bdc7ac54133e74b01adb6750e9368b2daffd
|
data/Changelog
CHANGED
data/README.rdoc
CHANGED
@@ -27,7 +27,6 @@ RobustExcelOle supports
|
|
27
27
|
- availability of all VBA methods
|
28
28
|
- availability of the Excel constants (in form if Ruby constants: Excel constant.capitalize)
|
29
29
|
- all standard Excel file formats (.xlsx, .xls, .xlsm)
|
30
|
-
- list objects
|
31
30
|
- reopening workbooks after closing them
|
32
31
|
- unobtrusively opening workbooks, i.e. opening and processing workbooks
|
33
32
|
while preserving their status, e.g. saved, readonly
|
@@ -65,7 +64,15 @@ If you want to start the console under jruby, and if you don't want to use a ver
|
|
65
64
|
|
66
65
|
jreo
|
67
66
|
|
68
|
-
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. The ruby shell 'pry' allows, among other useful things, to change the value of 'self' in the console: Let 'object' be an (almost) arbitrary object, e.g. a workbook, then you can put
|
68
|
+
|
69
|
+
object.pry
|
70
|
+
|
71
|
+
or
|
72
|
+
|
73
|
+
cd object
|
74
|
+
|
75
|
+
to assign self to this object. The original pry console is adapted to preserve local variables.
|
69
76
|
|
70
77
|
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.
|
71
78
|
|
@@ -318,139 +325,6 @@ and set another value to that range.
|
|
318
325
|
|
319
326
|
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]
|
320
327
|
|
321
|
-
=== List Objects
|
322
|
-
|
323
|
-
=== Creating List Objects
|
324
|
-
|
325
|
-
We can define a list object (or table) from scratch.
|
326
|
-
|
327
|
-
table = ListObject.new(worksheet, "table 1", [1,1], 3,["Person","AmountSales"])
|
328
|
-
|
329
|
-
This command creates a list object in worksheet named "table 1", with upper left corner at position [1,1] (first cell), with 3 rows and the columns "Person" and "Amoun%tSales".
|
330
|
-
|
331
|
-
Likewise we can get a RobustExcelOle list object with help of an existing WIN32OlE list object.
|
332
|
-
|
333
|
-
ole_listobject = worksheet.ListObjects.Item("Table 1")
|
334
|
-
table = ListObject.new(ole_listobject)
|
335
|
-
|
336
|
-
or
|
337
|
-
|
338
|
-
table = ole_listobject.to_reo
|
339
|
-
|
340
|
-
Now we have a RobustExcelOle ListObject that wraps a WIN32OLE ListObject. So we can send any WIN32OLE (VBA) method to it. See
|
341
|
-
https://docs.microsoft.com/en-us/office/vba/api/excel.listobject#methods.
|
342
|
-
|
343
|
-
A row in this table can be accessed with help of #[], e.g.
|
344
|
-
|
345
|
-
row1 = table[1]
|
346
|
-
|
347
|
-
=== Reading and setting values
|
348
|
-
|
349
|
-
Now we can set and get the value of a cell of the table with help of methods that are equal to or are underscored variants of the column names, e.g.
|
350
|
-
|
351
|
-
row1.AmountSales = 40
|
352
|
-
|
353
|
-
or
|
354
|
-
|
355
|
-
row1.amount_sales = 40
|
356
|
-
|
357
|
-
and
|
358
|
-
|
359
|
-
row1.AmountSales
|
360
|
-
# => 40
|
361
|
-
|
362
|
-
or
|
363
|
-
|
364
|
-
row1.amount_sales
|
365
|
-
# => 40
|
366
|
-
|
367
|
-
Special characters in the colare being ignored.
|
368
|
-
|
369
|
-
We can also read and set values in a whole row, e.g.
|
370
|
-
|
371
|
-
table.row_values(1)
|
372
|
-
# => ["John", 40]
|
373
|
-
|
374
|
-
or
|
375
|
-
|
376
|
-
table[1].values
|
377
|
-
# => ["John", 40]
|
378
|
-
|
379
|
-
and
|
380
|
-
|
381
|
-
table.set_row_values(1, ["Herbert", 80])
|
382
|
-
# => ["Herbert", 80]
|
383
|
-
|
384
|
-
or
|
385
|
-
|
386
|
-
table[1].set_values(["Herbert", 80])
|
387
|
-
|
388
|
-
If the number of given values is less than the number of cells in the row, only the first values are written. The remaining values keep their value.
|
389
|
-
|
390
|
-
Similarly, we can read and set the values in a whole column, e.g.
|
391
|
-
|
392
|
-
table.column_values("Person")
|
393
|
-
# => ["John", "Peter"]
|
394
|
-
|
395
|
-
and
|
396
|
-
|
397
|
-
table.set_column_values(1, ["Herbert","Paul"])
|
398
|
-
|
399
|
-
The column names we can get with help of
|
400
|
-
|
401
|
-
table.column_names
|
402
|
-
|
403
|
-
A column can be renamed.
|
404
|
-
|
405
|
-
table.rename_column("Person", "Enterprise")
|
406
|
-
|
407
|
-
or
|
408
|
-
|
409
|
-
table.rename_column(1, "Enterprise")
|
410
|
-
|
411
|
-
=== Adding and Deleting rows and columns
|
412
|
-
|
413
|
-
We can add rows and columns, supplying optionally their name, the position and contents.
|
414
|
-
|
415
|
-
table.add_column("column_name")
|
416
|
-
table.add_column("column_name", 3)
|
417
|
-
table.add_column("column_name", 3, ["John", "Paul"])
|
418
|
-
|
419
|
-
table.add_row(3)
|
420
|
-
table.add_row(3, ["John", 40, 2, 2004])
|
421
|
-
|
422
|
-
Deleting columns and rows is done by
|
423
|
-
|
424
|
-
table.delete_column("column_name")
|
425
|
-
table.delete_row(3)
|
426
|
-
|
427
|
-
We can delete only the contents of a column
|
428
|
-
|
429
|
-
table.delete_column_values("column_name")
|
430
|
-
|
431
|
-
Similarly can delete only the contents of a row.
|
432
|
-
|
433
|
-
table.delete_row_values(2)
|
434
|
-
|
435
|
-
or
|
436
|
-
|
437
|
-
table[2].delete_values
|
438
|
-
|
439
|
-
Finally we can delete empty rows and columns.
|
440
|
-
|
441
|
-
table.delete_empty_rows
|
442
|
-
table.delete_empty_columns
|
443
|
-
|
444
|
-
=== Finding values and sorting
|
445
|
-
|
446
|
-
You can find all cells containing a given value, e.g.
|
447
|
-
|
448
|
-
table.find_value(value)
|
449
|
-
#=> [#<Cell: (5,8)>#, #<Cell: (9,6)>#]
|
450
|
-
|
451
|
-
You can sort a table according to a given column and sort order, e.g.
|
452
|
-
|
453
|
-
table.sort("Person", :ascending)
|
454
328
|
|
455
329
|
=== More things
|
456
330
|
|
data/bin/jreo
CHANGED
@@ -2,23 +2,23 @@
|
|
2
2
|
# -*- jruby -*-
|
3
3
|
|
4
4
|
require 'pry'
|
5
|
-
require '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
|
-
puts 'REO console started'
|
11
|
-
puts
|
12
|
-
|
13
10
|
# some pry configuration
|
14
11
|
Pry.config.windows_console_warning = false
|
15
|
-
Pry.config.history.should_save = true
|
16
12
|
Pry.config.color = false
|
13
|
+
Pry.config.prompt_name = "REO "
|
14
|
+
|
15
|
+
#Pry.config.history_save = true
|
17
16
|
#Pry.editor = 'notepad' # 'subl', 'vi'
|
18
|
-
#Pry.config.prompt =
|
19
|
-
# [
|
20
|
-
# ->(_obj, _nest_level, _) { ">> " },
|
21
|
-
# ->(*) { " " }
|
22
|
-
# ]
|
23
17
|
|
24
|
-
|
18
|
+
hooks = Pry::Hooks.new
|
19
|
+
|
20
|
+
hooks.add_hook :when_started, :hook12 do
|
21
|
+
puts 'REO console started'
|
22
|
+
puts
|
23
|
+
end
|
24
|
+
Pry.start(nil, hooks: hooks)
|
data/bin/reo
CHANGED
@@ -9,14 +9,11 @@ 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/jreo.bat
CHANGED
data/lib/reo_console.rb
CHANGED
@@ -4,16 +4,89 @@ require '../robust_excel_ole/lib/robust_excel_ole'
|
|
4
4
|
include REO
|
5
5
|
include General
|
6
6
|
|
7
|
+
# pry mit behalten lokaler Variablen
|
8
|
+
|
9
|
+
class Object
|
10
|
+
|
11
|
+
def pry(object = nil, hash = {})
|
12
|
+
@local_vars ||= { }
|
13
|
+
if object.nil? || Hash === object # rubocop:disable Style/CaseEquality
|
14
|
+
Pry.start(self, object || {})
|
15
|
+
else
|
16
|
+
Pry.start(object, hash)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
class Pry
|
23
|
+
|
24
|
+
def self.set_local_vars local_vars
|
25
|
+
@local_vars = local_vars
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.get_local_vars
|
29
|
+
@local_vars
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.binding_for(target)
|
33
|
+
return target if Binding === target # rubocop:disable Style/CaseEquality
|
34
|
+
return TOPLEVEL_BINDING if Pry.main == target
|
35
|
+
__bnd = target.instance_eval{ target.__binding__ }
|
36
|
+
@local_vars.each{ |var,value| __bnd.local_variable_set(var, value) }
|
37
|
+
#target.__binding__
|
38
|
+
__bnd
|
39
|
+
end
|
40
|
+
|
41
|
+
class REPL
|
42
|
+
|
43
|
+
def repl
|
44
|
+
loop do
|
45
|
+
case val = read
|
46
|
+
when :control_c
|
47
|
+
output.puts ""
|
48
|
+
pry.reset_eval_string
|
49
|
+
when :no_more_input
|
50
|
+
output.puts "" if output.tty?
|
51
|
+
break
|
52
|
+
else
|
53
|
+
output.puts "" if val.nil? && output.tty?
|
54
|
+
# determine the local variables in the binding before evaluation
|
55
|
+
bnd = pry.binding_stack.first
|
56
|
+
exclude_vars = [:__, :_, :_dir, :_dir_, :_file, :_file_, :_in_, :_out_, :_ex, :_ex_, :pry_instance]
|
57
|
+
local_vars = Pry.get_local_vars
|
58
|
+
bnd.local_variables.each{ |var| local_vars[var] = bnd.local_variable_get(var) unless exclude_vars.include?(var) }
|
59
|
+
Pry.set_local_vars(local_vars)
|
60
|
+
return pry.exit_value unless pry.eval(val)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
7
68
|
# some pry configuration
|
8
69
|
Pry.config.windows_console_warning = false
|
9
|
-
#Pry.config.history_save = true
|
10
70
|
Pry.config.color = false
|
71
|
+
Pry.config.prompt_name = "REO "
|
72
|
+
|
73
|
+
#Pry.config.history_save = true
|
11
74
|
#Pry.editor = 'notepad' # 'subl', 'vi'
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
75
|
+
|
76
|
+
Pry.config.prompt = Pry::Prompt.new(
|
77
|
+
"REO",
|
78
|
+
"The RobustExcelOle Prompt. Besides the standard information it puts the current object",
|
79
|
+
[
|
80
|
+
proc { |target_self, nest_level, pry|
|
81
|
+
"[#{pry.input_ring.count}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self.inspect)})#{":#{nest_level}" unless nest_level.zero?}> "
|
82
|
+
},
|
83
|
+
|
84
|
+
proc { |target_self, nest_level, pry|
|
85
|
+
"[#{pry.input_ring.count}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self.inspect)})#{":#{nest_level}" unless nest_level.zero?}* "
|
86
|
+
}
|
87
|
+
]
|
88
|
+
)
|
89
|
+
|
17
90
|
|
18
91
|
hooks = Pry::Hooks.new
|
19
92
|
|
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
|