robust_excel_ole 1.18.8 → 1.19.4
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/.gitignore +1 -0
- data/Changelog +9 -1
- data/README.rdoc +51 -22
- data/bin/jreo +2 -72
- data/bin/reo +2 -59
- data/bin/reo.rb +21 -0
- data/docs/README_ranges.rdoc +1 -1
- data/docs/README_sheet.rdoc +2 -1
- data/lib/reo_console.rb +14 -56
- data/lib/robust_excel_ole.rb +1 -0
- data/lib/robust_excel_ole/excel.rb +0 -5
- data/lib/robust_excel_ole/general.rb +20 -1
- data/lib/robust_excel_ole/list_object.rb +129 -0
- data/lib/robust_excel_ole/version.rb +1 -1
- data/robust_excel_ole.gemspec +1 -0
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/general_spec.rb +12 -0
- data/spec/list_object_spec.rb +143 -0
- metadata +21 -4
- data/lib/jreo_console.rb +0 -67
- data/lib/rubygems_plugin.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95548d132f97e8ea26991a4ac303ed6ae8fa1b006cd155b6cce5500d3fde8c0d
|
4
|
+
data.tar.gz: 3549593f1108b8500c1cc7551befc352122ba034f9640e0acf14f26b77a429fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10dfed5039f7cca3bf98e67ffb384c2a715c6132befa66de5d5f34e9e70ce3f7bc19a43a1e349d3688c9898513d42ab77082d2c57a870ec0d2aebb4a1079d7cc
|
7
|
+
data.tar.gz: 05bc5ac08e0858142a9dcaf9aff3ebe4c52985c04a068e5e0e2b61ab4b02d1205e5f1616145f2d747d7cd76758b0ad92db2ee57a1bf9cf60ad478cfa23ecf4aa
|
data/.gitignore
CHANGED
data/Changelog
CHANGED
@@ -2,7 +2,15 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
4
|
|
5
|
-
## [1.
|
5
|
+
## [1.20] 2020-12-07
|
6
|
+
|
7
|
+
### Changed
|
8
|
+
- using pry in console
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- ListObject
|
12
|
+
|
13
|
+
## [1.19] 2020-10-6
|
6
14
|
|
7
15
|
### Added
|
8
16
|
- Workheet#values, each_rowvalue
|
data/README.rdoc
CHANGED
@@ -11,26 +11,30 @@ It supports handling workbooks across Excel instances by keeping track of workbo
|
|
11
11
|
|
12
12
|
Library references are supported.
|
13
13
|
|
14
|
-
RobustExcelOle works by sending VBA methods via
|
14
|
+
RobustExcelOle works by sending VBA methods via Win32OlE.
|
15
15
|
Therefore, it runs on Windows only.
|
16
16
|
|
17
|
-
==
|
17
|
+
== Features
|
18
|
+
|
19
|
+
RobustExcelOle supports
|
18
20
|
|
19
21
|
- opening and processing workbooks across various Excel instances
|
20
|
-
- reading
|
21
|
-
-
|
22
|
-
-
|
23
|
-
-
|
24
|
-
even with simultanously happening user interactions
|
22
|
+
- standard tasks like opening, reading, writing, saving, closing workbooks
|
23
|
+
- dealing with simultanously happening user interactions
|
24
|
+
- dealing with various cases of Excel and user behaviour
|
25
|
+
- managing conflicts when opening workbooks (e.g. blocking or unsaved workbooks)
|
25
26
|
- workarounds for Excel bugs and JRuby bugs
|
26
|
-
-
|
27
|
-
-
|
28
|
-
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
- availability of all VBA methods
|
28
|
+
- availability of the Excel constants (in form if Ruby constants: Excel constant.capitalize)
|
29
|
+
- all standard Excel file formats (.xlsx, .xls, .xlsm)
|
30
|
+
- list objects
|
31
|
+
- reopening workbooks after closing them
|
32
|
+
- unobtrusively opening workbooks, i.e. opening and processing workbooks
|
33
|
+
while preserving their status, e.g. saved, readonly
|
34
|
+
- reading and writing workbooks, worksheets, list objects, ranges, rows, columns, cells
|
35
|
+
- naming, adding, and copying ranges and worksheets
|
36
|
+
- references to other Excel libraries
|
37
|
+
- console for interactive mode
|
34
38
|
|
35
39
|
== Requirements
|
36
40
|
|
@@ -53,15 +57,13 @@ RobustExcelOle can be used either for scripts
|
|
53
57
|
require 'robust_excel_ole'
|
54
58
|
include RobustExcelOle
|
55
59
|
|
56
|
-
or as a console.
|
57
|
-
|
58
|
-
gem env
|
59
|
-
|
60
|
-
and go into the path of the gem 'robust_excel_ole'. There you start the console via the command
|
60
|
+
or as a console. You can start the console via the command
|
61
61
|
|
62
62
|
reo
|
63
63
|
|
64
|
-
If you don't want to use a version manager to switch between ruby and jruby,
|
64
|
+
If you want to start the console under jruby, and if you don't want to use a version manager to switch between ruby and jruby, then use the command
|
65
|
+
|
66
|
+
jreo
|
65
67
|
|
66
68
|
The call of the console will include RobustExcelOle for you.
|
67
69
|
|
@@ -316,10 +318,37 @@ and set another value to that range.
|
|
316
318
|
|
317
319
|
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]
|
318
320
|
|
321
|
+
=== Reading and writing list objects
|
322
|
+
|
323
|
+
We can define a list object (or table) from scratch.
|
324
|
+
|
325
|
+
table = ListObject.new(worksheet, "table 1", [1,1], 3,["Person","Amount"])
|
326
|
+
|
327
|
+
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 "Amount".
|
328
|
+
|
329
|
+
A row in this table can be accessed with help of [], e.g.
|
330
|
+
|
331
|
+
table[1]
|
332
|
+
|
333
|
+
Now we can set and get the value of a cell of the table, e.g.
|
334
|
+
|
335
|
+
table[1].person = "John"
|
336
|
+
table[1].person
|
337
|
+
# => "John"
|
338
|
+
|
339
|
+
Likewise we can get a table with help of an existing Win32OlE table.
|
340
|
+
|
341
|
+
ole_listobject = worksheet.ListObjects.Item("Table 1")
|
342
|
+
table = ListObject.new(ole_listobject)
|
343
|
+
|
344
|
+
r4 = t4[1]
|
345
|
+
r4.person
|
346
|
+
# =>
|
347
|
+
r.person = "John"
|
319
348
|
|
320
349
|
=== More things
|
321
350
|
|
322
|
-
You can convert some
|
351
|
+
You can convert some Win32Ole objects into a RobustExcelOle object.
|
323
352
|
|
324
353
|
range = sheet.Names.Item("firstcell").to_reo
|
325
354
|
|
data/bin/jreo
CHANGED
@@ -1,74 +1,4 @@
|
|
1
|
-
#!/usr/bin/env jruby
|
2
|
-
# -*- mode: jruby -*-
|
3
1
|
|
4
|
-
|
5
|
-
include REO
|
6
|
-
# include RobustExcelOle
|
7
|
-
include General
|
2
|
+
@echo off
|
8
3
|
|
9
|
-
|
10
|
-
require 'irb/completion'
|
11
|
-
require 'irb/ext/save-history'
|
12
|
-
#gem 'jruby-readline'
|
13
|
-
|
14
|
-
ARGV.concat ['--readline',
|
15
|
-
'--prompt-mode',
|
16
|
-
'simple']
|
17
|
-
# '-rjruby-readline']
|
18
|
-
|
19
|
-
#IRB.conf[:PROMPT_MODE] = :SIMPLE
|
20
|
-
#IRB.conf[:USE_READLINE] = true
|
21
|
-
#IRB.conf[:AUTO_INDENT] = true
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
# 250 entries in the list
|
27
|
-
IRB.conf[:SAVE_HISTORY] = 250
|
28
|
-
|
29
|
-
# Store results in home directory with specified file name
|
30
|
-
# IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-history"
|
31
|
-
#IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
|
32
|
-
|
33
|
-
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.reo-history"
|
34
|
-
|
35
|
-
# @private
|
36
|
-
module Readline
|
37
|
-
module Hist
|
38
|
-
LOG = IRB.conf[:HISTORY_FILE]
|
39
|
-
# LOG = "#{ENV['HOME']}/.irb-history"
|
40
|
-
|
41
|
-
def self.write_log(line)
|
42
|
-
File.open(LOG, 'ab') do |f|
|
43
|
-
f << "#{line}
|
44
|
-
"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.start_session_log
|
49
|
-
timestamp = proc { Time.now.strftime('%Y-%m-%d, %H:%M:%S') }
|
50
|
-
# @private
|
51
|
-
class <<timestamp
|
52
|
-
alias_method :to_s, :call
|
53
|
-
end
|
54
|
-
write_log("###### session start: #{timestamp}")
|
55
|
-
at_exit { write_log("###### session stop: #{timestamp}") }
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
alias old_readline readline
|
60
|
-
def readline(*args)
|
61
|
-
ln = old_readline(*args)
|
62
|
-
begin
|
63
|
-
Hist.write_log(ln)
|
64
|
-
rescue StandardError
|
65
|
-
end
|
66
|
-
ln
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
Readline::Hist.start_session_log
|
71
|
-
puts 'JREO console started'
|
72
|
-
|
73
|
-
|
74
|
-
IRB.start
|
4
|
+
jruby reo
|
data/bin/reo
CHANGED
@@ -1,61 +1,4 @@
|
|
1
|
-
#!/usr/bin/env jruby
|
2
|
-
# -*- mode: jruby -*-
|
3
1
|
|
4
|
-
|
5
|
-
include REO
|
6
|
-
# include RobustExcelOle
|
7
|
-
include General
|
2
|
+
@echo off
|
8
3
|
|
9
|
-
|
10
|
-
require 'irb/completion'
|
11
|
-
require 'irb/ext/save-history'
|
12
|
-
|
13
|
-
ARGV.concat ['--readline',
|
14
|
-
'--prompt-mode',
|
15
|
-
'simple']
|
16
|
-
|
17
|
-
# 250 entries in the list
|
18
|
-
IRB.conf[:SAVE_HISTORY] = 250
|
19
|
-
|
20
|
-
# Store results in home directory with specified file name
|
21
|
-
# IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-history"
|
22
|
-
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.reo-history"
|
23
|
-
|
24
|
-
# @private
|
25
|
-
module Readline
|
26
|
-
module Hist
|
27
|
-
LOG = IRB.conf[:HISTORY_FILE]
|
28
|
-
# LOG = "#{ENV['HOME']}/.irb-history"
|
29
|
-
|
30
|
-
def self.write_log(line)
|
31
|
-
File.open(LOG, 'ab') do |f|
|
32
|
-
f << "#{line}
|
33
|
-
"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.start_session_log
|
38
|
-
timestamp = proc { Time.now.strftime('%Y-%m-%d, %H:%M:%S') }
|
39
|
-
# @private
|
40
|
-
class <<timestamp
|
41
|
-
alias_method :to_s, :call
|
42
|
-
end
|
43
|
-
write_log("###### session start: #{timestamp}")
|
44
|
-
at_exit { write_log("###### session stop: #{timestamp}") }
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
alias old_readline readline
|
49
|
-
def readline(*args)
|
50
|
-
ln = old_readline(*args)
|
51
|
-
begin
|
52
|
-
Hist.write_log(ln)
|
53
|
-
rescue StandardError
|
54
|
-
end
|
55
|
-
ln
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
Readline::Hist.start_session_log
|
60
|
-
puts 'REO console started'
|
61
|
-
IRB.start
|
4
|
+
ruby reo
|
data/bin/reo.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'robust_excel_ole'
|
3
|
+
include REO
|
4
|
+
# include RobustExcelOle
|
5
|
+
include General
|
6
|
+
|
7
|
+
puts 'REO console started'
|
8
|
+
puts
|
9
|
+
|
10
|
+
|
11
|
+
# some pry configuration
|
12
|
+
Pry.config.windows_console_warning = false
|
13
|
+
Pry.config.history.should_save = true
|
14
|
+
#Pry.editor = 'notepad' # 'subl', 'vi'
|
15
|
+
#Pry.config.prompt =
|
16
|
+
# [
|
17
|
+
# ->(_obj, _nest_level, _) { ">> " },
|
18
|
+
# ->(*) { " " }
|
19
|
+
# ]
|
20
|
+
|
21
|
+
pry
|
data/docs/README_ranges.rdoc
CHANGED
data/docs/README_sheet.rdoc
CHANGED
@@ -124,7 +124,8 @@ Within a row or column range you can access a certain cell.
|
|
124
124
|
|
125
125
|
=== Deleting and inserting rows and columns
|
126
126
|
|
127
|
-
|
127
|
+
For the following standard tasks no RobustExcelOle commands are provided, but VBA methods can be used.
|
128
|
+
Here are some examples:
|
128
129
|
|
129
130
|
row1 = worksheet.row_range(1)
|
130
131
|
row1.Delete
|
data/lib/reo_console.rb
CHANGED
@@ -1,63 +1,21 @@
|
|
1
|
-
require '
|
1
|
+
require 'pry'
|
2
|
+
require 'robust_excel_ole'
|
2
3
|
include REO
|
3
4
|
# include RobustExcelOle
|
4
5
|
include General
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
require 'irb/ext/save-history'
|
9
|
-
|
10
|
-
ARGV.concat ['--readline',
|
11
|
-
'--prompt-mode',
|
12
|
-
'simple']
|
13
|
-
|
14
|
-
# 250 entries in the list
|
15
|
-
IRB.conf[:SAVE_HISTORY] = 250
|
16
|
-
|
17
|
-
# Store results in home directory with specified file name
|
18
|
-
# IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-history"
|
19
|
-
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.reo-history"
|
20
|
-
|
21
|
-
IRB.conf[:PROMPT_MODE] = 'ert' #:SIMPLE
|
22
|
-
#IRB.conf[:USE_READLINE] = true
|
23
|
-
#IRB.conf[:AUTO_INDENT] = true
|
24
|
-
|
25
|
-
# @private
|
26
|
-
module Readline
|
27
|
-
module Hist
|
28
|
-
LOG = IRB.conf[:HISTORY_FILE]
|
29
|
-
# LOG = "#{ENV['HOME']}/.irb-history"
|
30
|
-
|
31
|
-
def self.write_log(line)
|
32
|
-
File.open(LOG, 'ab') do |f|
|
33
|
-
f << "#{line}
|
34
|
-
"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.start_session_log
|
39
|
-
timestamp = proc { Time.now.strftime('%Y-%m-%d, %H:%M:%S') }
|
40
|
-
# @private
|
41
|
-
class <<timestamp
|
42
|
-
alias_method :to_s, :call
|
43
|
-
end
|
44
|
-
write_log("###### session start: #{timestamp}")
|
45
|
-
at_exit { write_log("###### session stop: #{timestamp}") }
|
46
|
-
end
|
47
|
-
end
|
7
|
+
puts 'REO console started'
|
8
|
+
puts
|
48
9
|
|
49
|
-
alias old_readline readline
|
50
|
-
def readline(*args)
|
51
|
-
ln = old_readline(*args)
|
52
|
-
begin
|
53
|
-
Hist.write_log(ln)
|
54
|
-
rescue StandardError
|
55
|
-
end
|
56
|
-
ln
|
57
|
-
end
|
58
|
-
end
|
59
10
|
|
60
|
-
|
61
|
-
|
62
|
-
|
11
|
+
# some pry configuration
|
12
|
+
Pry.config.windows_console_warning = false
|
13
|
+
Pry.config.history.should_save = true
|
14
|
+
#Pry.editor = 'notepad' # 'subl', 'vi'
|
15
|
+
#Pry.config.prompt =
|
16
|
+
# [
|
17
|
+
# ->(_obj, _nest_level, _) { ">> " },
|
18
|
+
# ->(*) { " " }
|
19
|
+
# ]
|
63
20
|
|
21
|
+
pry
|
data/lib/robust_excel_ole.rb
CHANGED
@@ -14,6 +14,7 @@ require File.join(File.dirname(__FILE__), 'robust_excel_ole/workbook')
|
|
14
14
|
require File.join(File.dirname(__FILE__), 'robust_excel_ole/worksheet')
|
15
15
|
require File.join(File.dirname(__FILE__), 'robust_excel_ole/cell')
|
16
16
|
require File.join(File.dirname(__FILE__), 'robust_excel_ole/range')
|
17
|
+
require File.join(File.dirname(__FILE__), 'robust_excel_ole/list_object')
|
17
18
|
require File.join(File.dirname(__FILE__), 'robust_excel_ole/cygwin') if RUBY_PLATFORM =~ /cygwin/
|
18
19
|
require File.join(File.dirname(__FILE__), 'robust_excel_ole/version')
|
19
20
|
|
@@ -95,10 +95,18 @@ end
|
|
95
95
|
|
96
96
|
# @private
|
97
97
|
class WIN32OLE
|
98
|
+
|
99
|
+
include Enumerable
|
98
100
|
|
99
101
|
# type-lifting WIN32OLE objects to RobustExcelOle objects
|
100
102
|
def to_reo
|
101
|
-
class2method = [
|
103
|
+
class2method = [
|
104
|
+
{Excel => :Hwnd},
|
105
|
+
{Workbook => :FullName},
|
106
|
+
{Worksheet => :Copy},
|
107
|
+
{RobustExcelOle::Range => :Row},
|
108
|
+
{ListObject => :ListRows}
|
109
|
+
]
|
102
110
|
class2method.each do |element|
|
103
111
|
classname = element.first.first
|
104
112
|
method = element.first.last
|
@@ -115,6 +123,17 @@ class WIN32OLE
|
|
115
123
|
end
|
116
124
|
raise TypeREOError, "given object cannot be type-lifted to a RobustExcelOle object"
|
117
125
|
end
|
126
|
+
|
127
|
+
alias method_missing_before_implicit_typelift method_missing
|
128
|
+
def xx_method_missing(name, *args, &blk)
|
129
|
+
begin
|
130
|
+
reo_obj = self.to_reo
|
131
|
+
rescue
|
132
|
+
puts "$!.message: #{$!.message}"
|
133
|
+
method_missing_before_implicit_typelift(name, *args, &blk)
|
134
|
+
end
|
135
|
+
reo_obj.send(name, *args, &blk)
|
136
|
+
end
|
118
137
|
end
|
119
138
|
|
120
139
|
# @private
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module RobustExcelOle
|
4
|
+
|
5
|
+
class ListRow
|
6
|
+
end
|
7
|
+
|
8
|
+
# This class essentially wraps a Win32Ole ListObject.
|
9
|
+
# You can apply all VBA methods (starting with a capital letter)
|
10
|
+
# that you would apply for a ListObject.
|
11
|
+
# See https://docs.microsoft.com/en-us/office/vba/api/excel.listobject#methods
|
12
|
+
|
13
|
+
class ListObject < VbaObjects
|
14
|
+
|
15
|
+
attr_reader :ole_table
|
16
|
+
|
17
|
+
# constructs a list object (or table).
|
18
|
+
# @param [Variable] worksheet_or_ole_listobject a worksheet or a Win32Ole list object
|
19
|
+
# @param [Variable] table_name_or_number a table name or table number
|
20
|
+
# @param [Array] position a position of the upper left corner
|
21
|
+
# @param [Integer] rows_count number of rows
|
22
|
+
# @param [Variable] columns_count_or_names number of columns or array of column names
|
23
|
+
# @return [ListObject] a ListObject object
|
24
|
+
def initialize(worksheet_or_ole_listobject,
|
25
|
+
table_name_or_number = "",
|
26
|
+
position = [1,1],
|
27
|
+
rows_count = 1,
|
28
|
+
columns_count_or_names = 1)
|
29
|
+
|
30
|
+
if (worksheet_or_ole_listobject.ListRows rescue nil)
|
31
|
+
@ole_table = worksheet_or_ole_listobject
|
32
|
+
else
|
33
|
+
@worksheet = worksheet_or_ole_listobject.to_reo
|
34
|
+
@ole_table = @worksheet.ListObjects.Item(table_name_or_number) rescue nil
|
35
|
+
end
|
36
|
+
unless @ole_table
|
37
|
+
columns_count =
|
38
|
+
columns_count_or_names.is_a?(Integer) ? columns_count_or_names : columns_count_or_names.length
|
39
|
+
column_names = columns_count_or_names.respond_to?(:first) ? columns_count_or_names : []
|
40
|
+
begin
|
41
|
+
listobjects = @worksheet.ListObjects
|
42
|
+
@ole_table = listobjects.Add(XlSrcRange,
|
43
|
+
@worksheet.range([position[0]..position[0]+rows_count-1,
|
44
|
+
position[1]..position[1]+columns_count-1]).ole_range,
|
45
|
+
XlYes)
|
46
|
+
@ole_table.Name = table_name_or_number
|
47
|
+
@ole_table.HeaderRowRange.Value = [column_names] unless column_names.empty?
|
48
|
+
rescue WIN32OLERuntimeError => msg # , Java::OrgRacobCom::ComFailException => msg
|
49
|
+
raise TableError, "error #{$!.message}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
ole_table = @ole_table
|
54
|
+
@row_class = Class.new(ListRow) do
|
55
|
+
|
56
|
+
@@ole_table = ole_table
|
57
|
+
|
58
|
+
def initialize(row_number)
|
59
|
+
@ole_listrow = @@ole_table.ListRows.Item(row_number)
|
60
|
+
end
|
61
|
+
|
62
|
+
def method_missing(name, *args)
|
63
|
+
name_before_last_equal = name.to_s.split('=').first
|
64
|
+
column_names = @@ole_table.HeaderRowRange.Value.first
|
65
|
+
method_names = column_names.map{|c| c.underscore.gsub(/[^[\w\d]]/, '_')}
|
66
|
+
column_name = column_names[method_names.index(name_before_last_equal)]
|
67
|
+
if column_name
|
68
|
+
ole_cell = @@ole_table.Application.Intersect(
|
69
|
+
@ole_listrow.Range, @@ole_table.ListColumns(column_name).Range)
|
70
|
+
define_getting_setting_method(ole_cell,name.to_s)
|
71
|
+
self.send(name, *args)
|
72
|
+
else
|
73
|
+
super
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def define_getting_setting_method(ole_cell,name_str)
|
78
|
+
if name_str[-1] != '='
|
79
|
+
self.class.define_method(name_str) do
|
80
|
+
ole_cell.Value
|
81
|
+
end
|
82
|
+
else
|
83
|
+
self.class.define_method(name_str) do |value|
|
84
|
+
ole_cell.Value = value
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# accesses a table row object
|
91
|
+
# @param [Integer] a row number (>= 1)
|
92
|
+
# @return [ListRow] a object of dynamically constructed class with superclass ListRow
|
93
|
+
def [] row_number
|
94
|
+
@row_class.new(row_number)
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def method_missing(name, *args)
|
102
|
+
if name.to_s[0,1] =~ /[A-Z]/
|
103
|
+
if ::ERRORMESSAGE_JRUBY_BUG
|
104
|
+
begin
|
105
|
+
@ole_table.send(name, *args)
|
106
|
+
rescue Java::OrgRacobCom::ComFailException
|
107
|
+
raise VBAMethodMissingError, "unknown VBA property or method #{name.inspect}"
|
108
|
+
end
|
109
|
+
else
|
110
|
+
begin
|
111
|
+
@ole_table.send(name, *args)
|
112
|
+
rescue NoMethodError
|
113
|
+
raise VBAMethodMissingError, "unknown VBA property or method #{name.inspect}"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
else
|
117
|
+
super
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# @private
|
123
|
+
class TableError < WorksheetREOError
|
124
|
+
end
|
125
|
+
|
126
|
+
Table = ListObject
|
127
|
+
TableRow = ListRow
|
128
|
+
|
129
|
+
end
|
data/robust_excel_ole.gemspec
CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
34
34
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
35
35
|
s.require_paths = ["lib"]
|
36
|
+
s.add_runtime_dependency "pry", '>= 0.12.1'
|
36
37
|
s.add_development_dependency "rspec", '>= 2.6.0'
|
37
38
|
s.required_ruby_version = '>= 2.1'
|
38
39
|
end
|
Binary file
|
data/spec/general_spec.rb
CHANGED
@@ -20,6 +20,7 @@ module RobustExcelOle
|
|
20
20
|
|
21
21
|
before do
|
22
22
|
@dir = create_tmpdir
|
23
|
+
@listobject_file = @dir + '/workbook_listobjects.xlsx'
|
23
24
|
@simple_file = @dir + '/workbook.xls'
|
24
25
|
@simple_save_file = @dir + '/workbook_save.xls'
|
25
26
|
@different_file = @dir + '/different_workbook.xls'
|
@@ -39,6 +40,17 @@ module RobustExcelOle
|
|
39
40
|
|
40
41
|
before do
|
41
42
|
@book1 = Workbook.open(@simple_file)
|
43
|
+
@book2 = Workbook.open(@listobject_file)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should type-lift an ListObject" do
|
47
|
+
worksheet = @book2.sheet(3)
|
48
|
+
ole_table = worksheet.ListObjects.Item(1)
|
49
|
+
table = Table.new(ole_table)
|
50
|
+
table.Name.should == "table3"
|
51
|
+
table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Date"]
|
52
|
+
table.ListRows.Count.should == 6
|
53
|
+
worksheet[3,4].Value.should == "Number"
|
42
54
|
end
|
43
55
|
|
44
56
|
it "should type-lift an Excel" do
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), './spec_helper')
|
4
|
+
|
5
|
+
$VERBOSE = nil
|
6
|
+
|
7
|
+
include RobustExcelOle
|
8
|
+
include General
|
9
|
+
|
10
|
+
describe ListObject do
|
11
|
+
|
12
|
+
before(:all) do
|
13
|
+
excel = Excel.new(:reuse => true)
|
14
|
+
open_books = excel == nil ? 0 : excel.Workbooks.Count
|
15
|
+
puts "*** open books *** : #{open_books}" if open_books > 0
|
16
|
+
Excel.kill_all
|
17
|
+
end
|
18
|
+
|
19
|
+
before do
|
20
|
+
@dir = create_tmpdir
|
21
|
+
@listobject_file = @dir + '/workbook_listobjects.xlsx'
|
22
|
+
@book = Workbook.open(@listobject_file, :visible => true)
|
23
|
+
@sheet = @book.sheet(3)
|
24
|
+
end
|
25
|
+
|
26
|
+
after do
|
27
|
+
@book.close(:if_unsaved => :forget)
|
28
|
+
Excel.kill_all
|
29
|
+
rm_tmp(@dir)
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "creating" do
|
33
|
+
|
34
|
+
context "with standard" do
|
35
|
+
|
36
|
+
it "should simply create a new table" do
|
37
|
+
table = Table.new(@sheet, "table_name", [1,1], 3, ["Person","Amount"])
|
38
|
+
table.Name.should == "table_name"
|
39
|
+
table.HeaderRowRange.Value.first.should == ["Person","Amount"]
|
40
|
+
table.ListRows.Count.should == 3
|
41
|
+
@sheet[1,1].Value.should == "Person"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should type-lift a Win32ole list object into a RobustExcelOle list object" do
|
45
|
+
ole_table = @sheet.ListObjects.Item(1)
|
46
|
+
table = Table.new(ole_table)
|
47
|
+
table.Name.should == "table3"
|
48
|
+
table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Date"]
|
49
|
+
table.ListRows.Count.should == 6
|
50
|
+
@sheet[3,4].Value.should == "Number"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should type-lift a Win32ole list object into a RobustExcelOle list object with table name" do
|
54
|
+
ole_table = @sheet.ListObjects.Item(1)
|
55
|
+
table = Table.new(@sheet, "table3")
|
56
|
+
table.Name.should == "table3"
|
57
|
+
table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Date"]
|
58
|
+
table.ListRows.Count.should == 6
|
59
|
+
@sheet[3,4].Value.should == "Number"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should type-lift a Win32ole list object into a RobustExcelOle list object with item number" do
|
63
|
+
ole_table = @sheet.ListObjects.Item(1)
|
64
|
+
table = Table.new(@sheet, 1)
|
65
|
+
table.Name.should == "table3"
|
66
|
+
table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Date"]
|
67
|
+
table.ListRows.Count.should == 6
|
68
|
+
@sheet[3,4].Value.should == "Number"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should simply create a new table from a ole-worksheet" do
|
72
|
+
table = Table.new(@sheet.ole_worksheet, "table_name", [1,1], 3, ["Person","Amount"])
|
73
|
+
table.Name.should == "table_name"
|
74
|
+
table.HeaderRowRange.Value.first.should == ["Person","Amount"]
|
75
|
+
table.ListRows.Count.should == 3
|
76
|
+
@sheet[1,1].Value.should == "Person"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should type-lift a Win32ole list object into a RobustExcelOle list object with table name" do
|
80
|
+
ole_table = @sheet.ListObjects.Item(1)
|
81
|
+
table = Table.new(@sheet.ole_worksheet, "table3")
|
82
|
+
table.Name.should == "table3"
|
83
|
+
table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Date"]
|
84
|
+
table.ListRows.Count.should == 6
|
85
|
+
@sheet[3,4].Value.should == "Number"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should type-lift a Win32ole list object into a RobustExcelOle list object with item number" do
|
89
|
+
ole_table = @sheet.ListObjects.Item(1)
|
90
|
+
table = Table.new(@sheet.ole_worksheet, 1)
|
91
|
+
table.Name.should == "table3"
|
92
|
+
table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Date"]
|
93
|
+
table.ListRows.Count.should == 6
|
94
|
+
@sheet[3,4].Value.should == "Number"
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "getting and setting values" do
|
102
|
+
|
103
|
+
context "with new table" do
|
104
|
+
|
105
|
+
before do
|
106
|
+
@table = Table.new(@sheet, "table_name", [1,1], 3, ["Person","Amount"])
|
107
|
+
@table_row1 = @table[1]
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should set and read values" do
|
111
|
+
@table_row1.person.should be nil
|
112
|
+
@table_row1.person = "John"
|
113
|
+
@table_row1.person.should == "John"
|
114
|
+
@sheet[2,1].Value.should == "John"
|
115
|
+
@table_row1.amount.should be nil
|
116
|
+
@table_row1.amount = 42
|
117
|
+
@table_row1.amount.should == 42
|
118
|
+
@sheet[2,2].Value.should == 42
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "with type-lifted ole list object" do
|
123
|
+
|
124
|
+
before do
|
125
|
+
ole_table = @sheet.ListObjects.Item(1)
|
126
|
+
@table = Table.new(ole_table)
|
127
|
+
@table_row1 = @table[1]
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should set and read values" do
|
131
|
+
@table_row1.number.should == 3
|
132
|
+
@table_row1.number = 1
|
133
|
+
@table_row1.number.should == 1
|
134
|
+
@sheet[4,4].Value.should == 1
|
135
|
+
@table_row1.person.should == "Herbert"
|
136
|
+
@table_row1.person = "John"
|
137
|
+
@table_row1.person.should == "John"
|
138
|
+
@sheet[4,5].Value.should == "John"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
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.19.4
|
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-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.12.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.12.1
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rspec
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -36,6 +50,7 @@ email:
|
|
36
50
|
executables:
|
37
51
|
- jreo
|
38
52
|
- reo
|
53
|
+
- reo.rb
|
39
54
|
extensions: []
|
40
55
|
extra_rdoc_files:
|
41
56
|
- README.rdoc
|
@@ -66,6 +81,7 @@ files:
|
|
66
81
|
- benchmarking/spreadsheet_example.rb
|
67
82
|
- bin/jreo
|
68
83
|
- bin/reo
|
84
|
+
- bin/reo.rb
|
69
85
|
- docs/README_excel.rdoc
|
70
86
|
- docs/README_open.rdoc
|
71
87
|
- docs/README_ranges.rdoc
|
@@ -99,7 +115,6 @@ files:
|
|
99
115
|
- examples/open_save_close/example_simple.rb
|
100
116
|
- examples/open_save_close/example_unobtrusively.rb
|
101
117
|
- jreo.bat
|
102
|
-
- lib/jreo_console.rb
|
103
118
|
- lib/reo_console.rb
|
104
119
|
- lib/robust_excel_ole.rb
|
105
120
|
- lib/robust_excel_ole/address_tool.rb
|
@@ -109,6 +124,7 @@ files:
|
|
109
124
|
- lib/robust_excel_ole/cygwin.rb
|
110
125
|
- lib/robust_excel_ole/excel.rb
|
111
126
|
- lib/robust_excel_ole/general.rb
|
127
|
+
- lib/robust_excel_ole/list_object.rb
|
112
128
|
- lib/robust_excel_ole/range.rb
|
113
129
|
- lib/robust_excel_ole/range_owners.rb
|
114
130
|
- lib/robust_excel_ole/robustexcelole.sublime-project
|
@@ -117,7 +133,6 @@ files:
|
|
117
133
|
- lib/robust_excel_ole/version.rb
|
118
134
|
- lib/robust_excel_ole/workbook.rb
|
119
135
|
- lib/robust_excel_ole/worksheet.rb
|
120
|
-
- lib/rubygems_plugin.rb
|
121
136
|
- lib/spec_helper.rb
|
122
137
|
- reo.bat
|
123
138
|
- robust_excel_ole.gemspec
|
@@ -141,10 +156,12 @@ files:
|
|
141
156
|
- spec/data/workbook_connected.xlsm
|
142
157
|
- spec/data/workbook_linked.xlsm
|
143
158
|
- spec/data/workbook_linked_sub.xlsm
|
159
|
+
- spec/data/workbook_listobjects.xlsx
|
144
160
|
- spec/excel_spec.rb
|
145
161
|
- spec/general_spec.rb
|
146
162
|
- spec/helpers/create_temporary_dir.rb
|
147
163
|
- spec/helpers/key_sender.rb
|
164
|
+
- spec/list_object_spec.rb
|
148
165
|
- spec/range_spec.rb
|
149
166
|
- spec/spec_helper.rb
|
150
167
|
- spec/workbook_spec.rb
|
data/lib/jreo_console.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
# require '../robust_excel_ole/lib/robust_excel_ole'
|
2
|
-
include REO
|
3
|
-
# include RobustExcelOle
|
4
|
-
include General
|
5
|
-
|
6
|
-
require 'irb/completion'
|
7
|
-
require 'irb/ext/save-history'
|
8
|
-
gem 'jruby-readline'
|
9
|
-
|
10
|
-
ARGV.concat ['--readline',
|
11
|
-
'--prompt-mode',
|
12
|
-
'simple',
|
13
|
-
'-rjruby-readline']
|
14
|
-
|
15
|
-
#IRB.conf[:PROMPT_MODE] = :SIMPLE
|
16
|
-
#IRB.conf[:USE_READLINE] = true
|
17
|
-
#IRB.conf[:AUTO_INDENT] = true
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
# 250 entries in the list
|
23
|
-
IRB.conf[:SAVE_HISTORY] = 250
|
24
|
-
|
25
|
-
# Store results in home directory with specified file name
|
26
|
-
# IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-history"
|
27
|
-
#IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
|
28
|
-
|
29
|
-
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.reo-history"
|
30
|
-
|
31
|
-
# @private
|
32
|
-
module Readline
|
33
|
-
module Hist
|
34
|
-
LOG = IRB.conf[:HISTORY_FILE]
|
35
|
-
# LOG = "#{ENV['HOME']}/.irb-history"
|
36
|
-
|
37
|
-
def self.write_log(line)
|
38
|
-
File.open(LOG, 'ab') do |f|
|
39
|
-
f << "#{line}
|
40
|
-
"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.start_session_log
|
45
|
-
timestamp = proc { Time.now.strftime('%Y-%m-%d, %H:%M:%S') }
|
46
|
-
# @private
|
47
|
-
class <<timestamp
|
48
|
-
alias_method :to_s, :call
|
49
|
-
end
|
50
|
-
write_log("###### session start: #{timestamp}")
|
51
|
-
at_exit { write_log("###### session stop: #{timestamp}") }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
alias old_readline readline
|
56
|
-
def readline(*args)
|
57
|
-
ln = old_readline(*args)
|
58
|
-
begin
|
59
|
-
Hist.write_log(ln)
|
60
|
-
rescue StandardError
|
61
|
-
end
|
62
|
-
ln
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
Readline::Hist.start_session_log
|
67
|
-
puts 'JREO console started'
|
data/lib/rubygems_plugin.rb
DELETED