robust_excel_ole 1.20 → 1.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +1 -1
- data/README.rdoc +21 -7
- data/bin/reo +13 -10
- data/lib/reo_console.rb +12 -9
- data/lib/robust_excel_ole/bookstore.rb +1 -0
- data/lib/robust_excel_ole/cell.rb +1 -1
- data/lib/robust_excel_ole/general.rb +26 -43
- data/lib/robust_excel_ole/list_object.rb +38 -13
- data/lib/robust_excel_ole/range.rb +65 -45
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +1 -1
- data/lib/robust_excel_ole/worksheet.rb +14 -0
- data/spec/list_object_spec.rb +13 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7598173082d025a168f3c4e8021eb41c97fb1af36943e35cf2a812fcc0f39672
|
4
|
+
data.tar.gz: 2e1e0585da1b1369d323b218b0817f23679b71f99f637a269a6abf14673df615
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09581d754af617dcbe58149087d78c0281e7aa1e6d5feb27f4b58a0b08a0cc5967d15398d85952174143a2e867133b2d1dbf352fd0656bc7488183c7edca94ab'
|
7
|
+
data.tar.gz: bc6c1bed4f9b3370a376b875fa5a4f64b690ef6df6da70efde30a5caa49447b32b28ba09864adcb4c0ca9ea861ddeb28b5af851e30db826e749c6c97cc0153de
|
data/Changelog
CHANGED
data/README.rdoc
CHANGED
@@ -320,13 +320,13 @@ For more details about reading and writing contents of cells and ranges see {REA
|
|
320
320
|
|
321
321
|
=== List Objects
|
322
322
|
|
323
|
-
=== Creating
|
323
|
+
=== Creating List Objects
|
324
324
|
|
325
325
|
We can define a list object (or table) from scratch.
|
326
326
|
|
327
|
-
table = ListObject.new(worksheet, "table 1", [1,1], 3,["Person","
|
327
|
+
table = ListObject.new(worksheet, "table 1", [1,1], 3,["Person","AmountSales"])
|
328
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 "
|
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
330
|
|
331
331
|
Likewise we can get a RobustExcelOle list object with help of an existing WIN32OlE list object.
|
332
332
|
|
@@ -346,11 +346,25 @@ A row in this table can be accessed with help of #[], e.g.
|
|
346
346
|
|
347
347
|
=== Reading and setting values
|
348
348
|
|
349
|
-
Now we can set and get the value of a cell of the table with help of methods that are underscored
|
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
350
|
|
351
|
-
row1.
|
352
|
-
|
353
|
-
|
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.
|
354
368
|
|
355
369
|
We can also read and set values in a whole row, e.g.
|
356
370
|
|
data/bin/reo
CHANGED
@@ -2,23 +2,26 @@
|
|
2
2
|
# -*- ruby -*-
|
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.
|
12
|
+
#Pry.config.history_save = true
|
16
13
|
Pry.config.color = false
|
17
14
|
#Pry.editor = 'notepad' # 'subl', 'vi'
|
18
15
|
#Pry.config.prompt =
|
19
|
-
#
|
20
|
-
|
21
|
-
|
22
|
-
#
|
16
|
+
#[
|
17
|
+
#->(_obj, _nest_level, _) { ">> " },
|
18
|
+
#->(*) { " " }
|
19
|
+
#]
|
23
20
|
|
24
|
-
|
21
|
+
hooks = Pry::Hooks.new
|
22
|
+
|
23
|
+
hooks.add_hook :when_started, :hook12 do
|
24
|
+
puts 'REO console started'
|
25
|
+
puts
|
26
|
+
end
|
27
|
+
Pry.start(nil, hooks: hooks)
|
data/lib/reo_console.rb
CHANGED
@@ -4,18 +4,21 @@ require '../robust_excel_ole/lib/robust_excel_ole'
|
|
4
4
|
include REO
|
5
5
|
include General
|
6
6
|
|
7
|
-
puts 'REO console started'
|
8
|
-
puts
|
9
|
-
|
10
7
|
# some pry configuration
|
11
8
|
Pry.config.windows_console_warning = false
|
12
|
-
Pry.config.
|
9
|
+
#Pry.config.history_save = true
|
13
10
|
Pry.config.color = false
|
14
11
|
#Pry.editor = 'notepad' # 'subl', 'vi'
|
15
12
|
#Pry.config.prompt =
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
#
|
13
|
+
#[
|
14
|
+
#->(_obj, _nest_level, _) { ">> " },
|
15
|
+
#->(*) { " " }
|
16
|
+
#]
|
20
17
|
|
21
|
-
|
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)
|
@@ -38,49 +38,7 @@ module General
|
|
38
38
|
def self.normalize_drive_letter(drive)
|
39
39
|
drive.upcase.end_with?(':') ? drive : "#{drive}:"
|
40
40
|
end
|
41
|
-
|
42
41
|
|
43
|
-
=begin
|
44
|
-
NetworkDrive = Struct.new(:drive_letter, :network_name)
|
45
|
-
|
46
|
-
@private
|
47
|
-
def network2hostnamesharepath(filename)
|
48
|
-
puts "network2hostnamesharepath:"
|
49
|
-
puts "filename: #{filename}"
|
50
|
-
network = WIN32OLE.new('WScript.Network')
|
51
|
-
drives = network.enumnetworkdrives
|
52
|
-
puts "drives: #{drives.inspect}"
|
53
|
-
drive_letter, filename_after_drive_letter = filename.split(':')
|
54
|
-
puts "drive_letter: #{drive_letter.inspect}"
|
55
|
-
puts "filename_after_drive_letter: #{filename_after_drive_letter.inspect}"
|
56
|
-
drive_letter = normalize_drive_letter(drive_letter)
|
57
|
-
puts "drive_letter: #{drive_letter.inspect}"
|
58
|
-
network_drives = get_network_drives
|
59
|
-
puts "network_drives: #{network_drives.inspect}"
|
60
|
-
network_drive = network_drives.find{ |d| d.drive_letter == drive_letter }
|
61
|
-
puts "network_drive: #{network_drive.inspect}"
|
62
|
-
return filename unless network_drive
|
63
|
-
#return (File.exists?(filename) ? filename : nil) unless network_drive
|
64
|
-
return network_drive.network_name + filename_after_drive_letter
|
65
|
-
end
|
66
|
-
|
67
|
-
def get_network_drives
|
68
|
-
network = WIN32OLE.new('WScript.Network')
|
69
|
-
drives = network.enumnetworkdrives
|
70
|
-
ndrives = []
|
71
|
-
count = drives.Count
|
72
|
-
(0..(count - 1)).step(2) do |i|
|
73
|
-
ndrives << NetworkDrive.new( drives.Item(i), drives.Item(i + 1))
|
74
|
-
end
|
75
|
-
ndrives
|
76
|
-
end
|
77
|
-
|
78
|
-
def normalize_drive_letter(drive)
|
79
|
-
drive.upcase.end_with?(':') ? drive : "#{drive}:"
|
80
|
-
end
|
81
|
-
|
82
|
-
=end
|
83
|
-
|
84
42
|
# @private
|
85
43
|
def absolute_path(file)
|
86
44
|
file[0,2] = './' if ::EXPANDPATH_JRUBY_BUG && file =~ /[A-Z]:[^\/]/
|
@@ -163,7 +121,7 @@ class WIN32OLE
|
|
163
121
|
class2method = [
|
164
122
|
{Excel => :Hwnd},
|
165
123
|
{Workbook => :FullName},
|
166
|
-
{Worksheet => :
|
124
|
+
{Worksheet => :UsedRange},
|
167
125
|
{RobustExcelOle::Range => :Row},
|
168
126
|
{ListObject => :ListRows}
|
169
127
|
]
|
@@ -224,6 +182,31 @@ class ::String
|
|
224
182
|
word
|
225
183
|
end
|
226
184
|
|
185
|
+
def delete_multiple_underscores
|
186
|
+
word = self
|
187
|
+
while word.index('__') do
|
188
|
+
word.gsub!('__','_')
|
189
|
+
end
|
190
|
+
word
|
191
|
+
end
|
192
|
+
|
193
|
+
def replace_umlauts
|
194
|
+
word = self
|
195
|
+
word.gsub!('ä','ae')
|
196
|
+
word.gsub!('Ä','Ae')
|
197
|
+
word.gsub!('ö','oe')
|
198
|
+
word.gsub!('Ö','Oe')
|
199
|
+
word.gsub!('ü','ue')
|
200
|
+
word.gsub!('Ü','Ue')
|
201
|
+
#word.gsub!(/\x84/,'ae')
|
202
|
+
#word.gsub!(/\x8E/,'Ae')
|
203
|
+
#word.gsub!(/\x94/,'oe')
|
204
|
+
#word.gsub!(/\x99/,'Oe')
|
205
|
+
#word.gsub!(/\x81/,'ue')
|
206
|
+
#word.gsub!(/\x9A/,'Ue')
|
207
|
+
word
|
208
|
+
end
|
209
|
+
|
227
210
|
# taken from http://apidock.com/rails/ActiveSupport/Inflector/constantize
|
228
211
|
# File activesupport/lib/active_support/inflector/methods.rb, line 226
|
229
212
|
def constantize # (camel_cased_word)
|
@@ -14,6 +14,8 @@ module RobustExcelOle
|
|
14
14
|
|
15
15
|
attr_reader :ole_table
|
16
16
|
|
17
|
+
alias ole_object ole_table
|
18
|
+
|
17
19
|
# constructs a list object (or table).
|
18
20
|
# @param [Variable] worksheet_or_ole_listobject a worksheet or a Win32Ole list object
|
19
21
|
# @param [Variable] table_name_or_number a table name or table number
|
@@ -115,31 +117,42 @@ module RobustExcelOle
|
|
115
117
|
raise TableError, "could not delete values"
|
116
118
|
end
|
117
119
|
end
|
118
|
-
|
120
|
+
|
119
121
|
def method_missing(name, *args)
|
120
|
-
|
122
|
+
name_str = name.to_s
|
123
|
+
core_name = name_str[-1]!='=' ? name_str : name_str[0..-2]
|
121
124
|
column_names = @@ole_table.HeaderRowRange.Value.first
|
122
|
-
|
123
|
-
|
125
|
+
column_name = column_names.find do |c|
|
126
|
+
c == core_name ||
|
127
|
+
c.gsub(/\W/,'') == core_name ||
|
128
|
+
c.replace_umlauts == core_name ||
|
129
|
+
c.gsub(/\W/,'').replace_umlauts == core_name ||
|
130
|
+
c.gsub(/\W/,'').replace_umlauts.underscore.gsub(/[^[\w\d]]/, '_').delete_multiple_underscores == core_name
|
131
|
+
end
|
124
132
|
if column_name
|
125
|
-
|
126
|
-
|
127
|
-
define_getting_setting_method(ole_cell,name.to_s)
|
128
|
-
self.send(name, *args)
|
133
|
+
method_name = core_name.gsub(/\W/,'') + (name_str[-1]!='=' ? "" : "=")
|
134
|
+
define_and_call_method(column_name,method_name,*args)
|
129
135
|
else
|
130
|
-
super
|
136
|
+
super(name, *args)
|
131
137
|
end
|
132
138
|
end
|
133
139
|
|
134
140
|
private
|
135
141
|
|
136
|
-
def
|
137
|
-
|
138
|
-
|
142
|
+
def define_and_call_method(column_name,method_name,*args)
|
143
|
+
ole_cell = @@ole_table.Application.Intersect(
|
144
|
+
@ole_listrow.Range, @@ole_table.ListColumns.Item(column_name).Range)
|
145
|
+
define_getting_setting_method(ole_cell,method_name)
|
146
|
+
self.send(method_name, *args)
|
147
|
+
end
|
148
|
+
|
149
|
+
def define_getting_setting_method(ole_cell,name)
|
150
|
+
if name[-1] != '='
|
151
|
+
self.class.define_method(name) do
|
139
152
|
ole_cell.Value
|
140
153
|
end
|
141
154
|
else
|
142
|
-
self.class.define_method(
|
155
|
+
self.class.define_method(name) do |value|
|
143
156
|
ole_cell.Value = value
|
144
157
|
end
|
145
158
|
end
|
@@ -349,6 +362,16 @@ module RobustExcelOle
|
|
349
362
|
@ole_table.Sort.Apply
|
350
363
|
end
|
351
364
|
|
365
|
+
# @private
|
366
|
+
# returns true, if the list object responds to VBA methods, false otherwise
|
367
|
+
def alive?
|
368
|
+
@ole_table.ListRows
|
369
|
+
true
|
370
|
+
rescue
|
371
|
+
# trace $!.message
|
372
|
+
false
|
373
|
+
end
|
374
|
+
|
352
375
|
# @private
|
353
376
|
def to_s
|
354
377
|
@ole_table.Name.to_s
|
@@ -361,6 +384,8 @@ module RobustExcelOle
|
|
361
384
|
" #{@ole_table.Parent.Name}" + " #{@ole_table.Parent.Parent.Name}" + ">"
|
362
385
|
end
|
363
386
|
|
387
|
+
include MethodHelpers
|
388
|
+
|
364
389
|
private
|
365
390
|
|
366
391
|
def method_missing(name, *args)
|
@@ -8,14 +8,20 @@ module RobustExcelOle
|
|
8
8
|
# See https://docs.microsoft.com/en-us/office/vba/api/excel.worksheet#methods
|
9
9
|
|
10
10
|
class Range < VbaObjects
|
11
|
+
|
11
12
|
include Enumerable
|
13
|
+
|
12
14
|
attr_reader :ole_range
|
13
15
|
attr_reader :worksheet
|
14
16
|
|
17
|
+
alias ole_object ole_range
|
18
|
+
|
19
|
+
|
15
20
|
def initialize(win32_range, worksheet = nil)
|
16
21
|
@ole_range = win32_range
|
17
|
-
@worksheet = worksheet ? worksheet : worksheet_class.new(self.Parent)
|
18
|
-
|
22
|
+
@worksheet = worksheet ? worksheet.to_reo : worksheet_class.new(self.Parent)
|
23
|
+
address_r1c1 = @ole_range.AddressLocal(true,true,XlR1C1)
|
24
|
+
@rows, @columns = address_tool.as_integer_ranges(address_r1c1)
|
19
25
|
end
|
20
26
|
|
21
27
|
def each
|
@@ -64,12 +70,10 @@ module RobustExcelOle
|
|
64
70
|
if !::RANGES_JRUBY_BUG
|
65
71
|
self.Value
|
66
72
|
else
|
67
|
-
address_r1c1 = self.AddressLocal(true,true,XlR1C1)
|
68
|
-
row, col = address_tool.as_integer_ranges(address_r1c1)
|
69
73
|
values = []
|
70
|
-
|
74
|
+
@rows.each do |r|
|
71
75
|
values_col = []
|
72
|
-
|
76
|
+
@columns.each{ |c| values_col << worksheet.Cells(r,c).Value}
|
73
77
|
values << values_col
|
74
78
|
end
|
75
79
|
values
|
@@ -85,10 +89,8 @@ module RobustExcelOle
|
|
85
89
|
if !::RANGES_JRUBY_BUG
|
86
90
|
ole_range.Value = value
|
87
91
|
else
|
88
|
-
|
89
|
-
|
90
|
-
row.each_with_index do |r,i|
|
91
|
-
col.each_with_index do |c,j|
|
92
|
+
@rows.each_with_index do |r,i|
|
93
|
+
@columns.each_with_index do |c,j|
|
92
94
|
ole_range.Cells(i+1,j+1).Value = (value.respond_to?(:first) ? value[i][j] : value)
|
93
95
|
end
|
94
96
|
end
|
@@ -107,55 +109,52 @@ module RobustExcelOle
|
|
107
109
|
# @options [Worksheet] the destination worksheet
|
108
110
|
# @options [Hash] options: :transpose, :values_only
|
109
111
|
def copy(dest_address1, sheet_or_dest_address2 = :__not_provided, options_or_sheet = :__not_provided, not_provided_or_options = :__not_provided)
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
dest_address1
|
114
|
-
end
|
115
|
-
dest_sheet = if sheet_or_dest_address2.is_a?(Worksheet)
|
116
|
-
sheet_or_dest_address2
|
117
|
-
else
|
118
|
-
if options_or_sheet.is_a?(Worksheet)
|
119
|
-
options_or_sheet
|
112
|
+
begin
|
113
|
+
dest_address = if sheet_or_dest_address2.is_a?(Object::Range) or sheet_or_dest_address2.is_a?(Integer)
|
114
|
+
[dest_address1,sheet_or_dest_address2]
|
120
115
|
else
|
121
|
-
|
116
|
+
dest_address1
|
122
117
|
end
|
123
|
-
|
124
|
-
|
125
|
-
options_or_sheet
|
126
|
-
else
|
127
|
-
if not_provided_or_options.is_a?(Hash)
|
128
|
-
not_provided_or_options
|
118
|
+
dest_sheet = if sheet_or_dest_address2.is_a?(Worksheet) or sheet_or_dest_address2.is_a?(WIN32OLE)
|
119
|
+
sheet_or_dest_address2.to_reo
|
129
120
|
else
|
130
|
-
|
121
|
+
if options_or_sheet.is_a?(Worksheet) or options_or_sheet.is_a?(WIN32OLE)
|
122
|
+
options_or_sheet.to_reo
|
123
|
+
else
|
124
|
+
@worksheet
|
125
|
+
end
|
131
126
|
end
|
132
|
-
|
133
|
-
|
134
|
-
dest_address_is_position = (rows.min == rows.max && columns.min == columns.max)
|
135
|
-
dest_range_address = if (not dest_address_is_position)
|
136
|
-
[rows.min..rows.max,columns.min..columns.max]
|
127
|
+
options = if options_or_sheet.is_a?(Hash)
|
128
|
+
options_or_sheet
|
137
129
|
else
|
138
|
-
if (
|
139
|
-
|
140
|
-
columns.min..columns.min+self.Columns.Count-1]
|
130
|
+
if not_provided_or_options.is_a?(Hash)
|
131
|
+
not_provided_or_options
|
141
132
|
else
|
142
|
-
|
143
|
-
columns.min..columns.min+self.Rows.Count-1]
|
133
|
+
{ }
|
144
134
|
end
|
145
135
|
end
|
146
|
-
|
147
|
-
|
136
|
+
rows, columns = address_tool.as_integer_ranges(dest_address)
|
137
|
+
dest_address_is_position = (rows.min == rows.max && columns.min == columns.max)
|
138
|
+
dest_range_address = if (not dest_address_is_position)
|
139
|
+
[rows.min..rows.max,columns.min..columns.max]
|
140
|
+
else
|
141
|
+
if (not options[:transpose])
|
142
|
+
[rows.min..rows.min+self.Rows.Count-1,
|
143
|
+
columns.min..columns.min+self.Columns.Count-1]
|
144
|
+
else
|
145
|
+
[rows.min..rows.min+self.Columns.Count-1,
|
146
|
+
columns.min..columns.min+self.Rows.Count-1]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
dest_range = dest_sheet.range(dest_range_address)
|
148
150
|
if options[:values_only]
|
149
|
-
# dest_range.Value = options[:transpose] ? self.Value.transpose : self.Value
|
150
151
|
dest_range.v = options[:transpose] ? self.v.transpose : self.v
|
151
152
|
else
|
152
153
|
if dest_range.worksheet.workbook.excel == @worksheet.workbook.excel
|
153
154
|
if options[:transpose]
|
154
155
|
self.Copy
|
155
|
-
#dest_range.PasteSpecial('transpose' => true)
|
156
156
|
dest_range.PasteSpecial(XlPasteAll,XlPasteSpecialOperationNone,false,true)
|
157
157
|
else
|
158
|
-
#self.Copy('destination' => dest_range.ole_range)
|
159
158
|
self.Copy(dest_range.ole_range)
|
160
159
|
end
|
161
160
|
else
|
@@ -166,7 +165,6 @@ module RobustExcelOle
|
|
166
165
|
@worksheet.workbook.excel.with_displayalerts(false) {added_sheet.Delete}
|
167
166
|
else
|
168
167
|
self.Copy
|
169
|
-
#dest_sheet.Paste('destination' => dest_range.ole_range)
|
170
168
|
dest_sheet.Paste(dest_range.ole_range)
|
171
169
|
end
|
172
170
|
end
|
@@ -184,7 +182,7 @@ module RobustExcelOle
|
|
184
182
|
def copy_special(dest_address, dest_sheet = :__not_provided, options = { })
|
185
183
|
rows, columns = address_tool.as_integer_ranges(dest_address)
|
186
184
|
dest_sheet = @worksheet if dest_sheet == :__not_provided
|
187
|
-
dest_address_is_position = (rows.min == rows.max && columns.min == columns.max)
|
185
|
+
dest_address_is_position = (rows.min == rows.max && @columns.min == @columns.max)
|
188
186
|
dest_range_address = if (not dest_address_is_position)
|
189
187
|
[rows.min..rows.max,columns.min..columns.max]
|
190
188
|
else
|
@@ -239,6 +237,26 @@ module RobustExcelOle
|
|
239
237
|
@worksheet.workbook.excel
|
240
238
|
end
|
241
239
|
|
240
|
+
# @private
|
241
|
+
# returns true, if the Range object responds to VBA methods, false otherwise
|
242
|
+
def alive?
|
243
|
+
@ole_range.Row
|
244
|
+
true
|
245
|
+
rescue
|
246
|
+
# trace $!.message
|
247
|
+
false
|
248
|
+
end
|
249
|
+
|
250
|
+
# @private
|
251
|
+
def to_s
|
252
|
+
"#<REO::Range: " + "[#{@rows},#{@columns}] " + "#{worksheet.Name} " + ">"
|
253
|
+
end
|
254
|
+
|
255
|
+
# @private
|
256
|
+
def inspect
|
257
|
+
self.to_s
|
258
|
+
end
|
259
|
+
|
242
260
|
# @private
|
243
261
|
def self.worksheet_class
|
244
262
|
@worksheet_class ||= begin
|
@@ -254,6 +272,8 @@ module RobustExcelOle
|
|
254
272
|
self.class.worksheet_class
|
255
273
|
end
|
256
274
|
|
275
|
+
include MethodHelpers
|
276
|
+
|
257
277
|
private
|
258
278
|
|
259
279
|
def method_missing(name, *args)
|
@@ -1004,7 +1004,7 @@ module RobustExcelOle
|
|
1004
1004
|
|
1005
1005
|
# @private
|
1006
1006
|
def inspect
|
1007
|
-
'#<Workbook: ' + ('not alive ' unless alive?).to_s + (File.basename(self.filename) if alive?).to_s + " #{@
|
1007
|
+
'#<Workbook: ' + ('not alive ' unless alive?).to_s + (File.basename(self.filename) if alive?).to_s + " #{@excel}" + '>'
|
1008
1008
|
end
|
1009
1009
|
|
1010
1010
|
# @private
|
@@ -14,6 +14,8 @@ module RobustExcelOle
|
|
14
14
|
attr_reader :ole_worksheet
|
15
15
|
attr_reader :workbook
|
16
16
|
|
17
|
+
alias ole_object ole_worksheet
|
18
|
+
|
17
19
|
def initialize(win32_worksheet)
|
18
20
|
@ole_worksheet = win32_worksheet
|
19
21
|
if @ole_worksheet.ProtectContents
|
@@ -224,6 +226,16 @@ module RobustExcelOle
|
|
224
226
|
self.Name == other_worksheet.Name
|
225
227
|
end
|
226
228
|
|
229
|
+
# @private
|
230
|
+
# returns true, if the worksheet object responds to VBA methods, false otherwise
|
231
|
+
def alive?
|
232
|
+
@ole_worksheet.UsedRange
|
233
|
+
true
|
234
|
+
rescue
|
235
|
+
# trace $!.message
|
236
|
+
false
|
237
|
+
end
|
238
|
+
|
227
239
|
# @private
|
228
240
|
def self.workbook_class
|
229
241
|
@workbook_class ||= begin
|
@@ -249,6 +261,8 @@ module RobustExcelOle
|
|
249
261
|
self.to_s
|
250
262
|
end
|
251
263
|
|
264
|
+
include MethodHelpers
|
265
|
+
|
252
266
|
private
|
253
267
|
|
254
268
|
def method_missing(name, *args)
|
data/spec/list_object_spec.rb
CHANGED
@@ -103,19 +103,25 @@ describe ListObject do
|
|
103
103
|
context "with new table" do
|
104
104
|
|
105
105
|
before do
|
106
|
-
@table = Table.new(@sheet, "table_name", [1,1], 3, ["Person","
|
106
|
+
@table = Table.new(@sheet, "table_name", [1,1], 3, ["Person","Amo%untSales"])
|
107
107
|
@table_row1 = @table[1]
|
108
108
|
end
|
109
109
|
|
110
|
-
it "should
|
110
|
+
it "should read and set values via alternative column names" do
|
111
111
|
@table_row1.person.should be nil
|
112
112
|
@table_row1.person = "John"
|
113
113
|
@table_row1.person.should == "John"
|
114
114
|
@sheet[2,1].Value.should == "John"
|
115
|
-
@table_row1.
|
116
|
-
@table_row1.
|
117
|
-
@table_row1.
|
115
|
+
@table_row1.amount_sales.should be nil
|
116
|
+
@table_row1.amount_sales = 42
|
117
|
+
@table_row1.amount_sales.should == 42
|
118
118
|
@sheet[2,2].Value.should == 42
|
119
|
+
@table_row1.Person = "Herbert"
|
120
|
+
@table_row1.Person.should == "Herbert"
|
121
|
+
@sheet[2,1].Value.should == "Herbert"
|
122
|
+
@table_row1.AmountSales = 80
|
123
|
+
@table_row1.AmountSales.should == 80
|
124
|
+
@sheet[2,2].Value.should == 80
|
119
125
|
end
|
120
126
|
|
121
127
|
end
|
@@ -324,6 +330,8 @@ describe ListObject do
|
|
324
330
|
cells[0].Column.should == 8
|
325
331
|
cells[1].Row.should == 9
|
326
332
|
cells[1].Column.should == 6
|
333
|
+
puts "cells[0]: #{[cells[0]]}"
|
334
|
+
p "cells[0]: #{[cells[0]]}"
|
327
335
|
end
|
328
336
|
|
329
337
|
end
|
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.21'
|
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-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|