robust_excel_ole 1.6 → 1.7
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/docs/README_excel.rdoc +4 -0
- data/docs/README_open.rdoc +3 -0
- data/docs/README_ranges.rdoc +5 -0
- data/docs/README_save_close.rdoc +4 -0
- data/docs/README_sheet.rdoc +3 -0
- data/lib/reo_console.rb +3 -3
- data/lib/robust_excel_ole/bookstore.rb +4 -4
- data/lib/robust_excel_ole/cell.rb +1 -1
- data/lib/robust_excel_ole/cygwin.rb +1 -1
- data/lib/robust_excel_ole/excel.rb +15 -65
- data/lib/robust_excel_ole/general.rb +8 -8
- data/lib/robust_excel_ole/range.rb +3 -3
- data/lib/robust_excel_ole/reo_common.rb +28 -28
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +16 -16
- data/lib/robust_excel_ole/worksheet.rb +7 -5
- data/lib/spec_helper.rb +4 -4
- data/spec/bookstore_spec.rb +1 -1
- data/spec/excel_spec.rb +3 -3
- data/spec/helpers/key_sender.rb +1 -1
- data/spec/spec_helper.rb +3 -3
- data/spec/workbook_spec.rb +3 -3
- data/spec/workbook_specs/workbook_subclass_spec.rb +3 -3
- data/spec/workbook_specs/workbook_unobtr_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 395fcac0e9c786c579758cb0b93c02d2e1ae0226
|
4
|
+
data.tar.gz: e1d901e048a027c84fd75a8154c413340db3a61b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8c91c3d9e2e2074abfa6dd56841aac9cc76f12a20943bd202e9ee584753e659d1402cc08ea4b30999be162680a710d82cdc838c4dfeb4046e7ead79955a91d6
|
7
|
+
data.tar.gz: 5af76ba942addc3b31eba65c78fd8db1a75722f805490af36ba7f86b843048c68c703db6f289dce40820ab185a094606be8c107c2ec8d7848faa25da83b11ead
|
data/docs/README_excel.rdoc
CHANGED
@@ -146,3 +146,7 @@ This method has the option +:if_unsaved+ as described above. For example, if you
|
|
146
146
|
Excel.kill_all
|
147
147
|
|
148
148
|
This method kills all Excel instances no matter whether they contain unsaved workbooks.
|
149
|
+
|
150
|
+
== Code
|
151
|
+
|
152
|
+
excel.rb[https://github.com/Thomas008/robust_excel_ole/blob/master/lib/robust_excel_ole/excel.rb]
|
data/docs/README_open.rdoc
CHANGED
data/docs/README_ranges.rdoc
CHANGED
@@ -336,3 +336,8 @@ Within a row or column range you can access a certain cell.
|
|
336
336
|
row_range[1] # => first cell in row_range
|
337
337
|
column_range[2] # => second cell in column_range
|
338
338
|
|
339
|
+
== Code
|
340
|
+
|
341
|
+
range.rb[https://github.com/Thomas008/robust_excel_ole/blob/master/lib/robust_excel_ole/range.rb]
|
342
|
+
|
343
|
+
worksheet.rb[https://github.com/Thomas008/robust_excel_ole/blob/master/lib/robust_excel_ole/worksheet.rb]
|
data/docs/README_save_close.rdoc
CHANGED
@@ -75,3 +75,7 @@ The workbook can be saved under a new file name, if it is open.
|
|
75
75
|
Finally the workbook can be closed with a given filename.
|
76
76
|
|
77
77
|
Workbook.close('spec/data/workbook.xls')
|
78
|
+
|
79
|
+
== Code
|
80
|
+
|
81
|
+
workbook.rb[https://github.com/Thomas008/robust_excel_ole/blob/master/lib/robust_excel_ole/workbook.rb]
|
data/docs/README_sheet.rdoc
CHANGED
@@ -73,3 +73,6 @@ If you want to copy a worksheet, if a sheet is given, and add an empty worksheet
|
|
73
73
|
|
74
74
|
book.add_or_copy_sheet(sheet, :as => 'new_name', :after => another_sheet)
|
75
75
|
|
76
|
+
== Code
|
77
|
+
|
78
|
+
worksheet.rb[https://github.com/Thomas008/robust_excel_ole/blob/master/lib/robust_excel_ole/worksheet.rb]
|
data/lib/reo_console.rb
CHANGED
@@ -17,8 +17,8 @@ IRB.conf[:SAVE_HISTORY] = 250
|
|
17
17
|
# IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-history"
|
18
18
|
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.reo-history"
|
19
19
|
|
20
|
-
module Readline # :nodoc:
|
21
|
-
module Hist # :nodoc:
|
20
|
+
module Readline # :nodoc:
|
21
|
+
module Hist # :nodoc:
|
22
22
|
LOG = IRB.conf[:HISTORY_FILE]
|
23
23
|
# LOG = "#{ENV['HOME']}/.irb-history"
|
24
24
|
|
@@ -31,7 +31,7 @@ module Readline # :nodoc: #
|
|
31
31
|
|
32
32
|
def self.start_session_log
|
33
33
|
timestamp = proc { Time.now.strftime('%Y-%m-%d, %H:%M:%S') }
|
34
|
-
class <<timestamp # :nodoc:
|
34
|
+
class <<timestamp # :nodoc:
|
35
35
|
alias_method :to_s, :call
|
36
36
|
end
|
37
37
|
write_log("###### session start: #{timestamp}")
|
@@ -73,7 +73,7 @@ module RobustExcelOle
|
|
73
73
|
end
|
74
74
|
|
75
75
|
# creates and returns a separate Excel instance with Visible and DisplayAlerts equal false
|
76
|
-
def hidden_excel # :nodoc:
|
76
|
+
def hidden_excel # :nodoc:
|
77
77
|
unless @hidden_excel_instance && @hidden_excel_instance.weakref_alive? && @hidden_excel_instance.__getobj__.alive?
|
78
78
|
@hidden_excel_instance = WeakRef.new(Excel.create)
|
79
79
|
end
|
@@ -97,14 +97,14 @@ module RobustExcelOle
|
|
97
97
|
|
98
98
|
private
|
99
99
|
|
100
|
-
def try_hidden_excel # :nodoc:
|
100
|
+
def try_hidden_excel # :nodoc:
|
101
101
|
@hidden_excel_instance.__getobj__ if @hidden_excel_instance && @hidden_excel_instance.weakref_alive? && @hidden_excel_instance.__getobj__.alive?
|
102
102
|
end
|
103
103
|
|
104
104
|
public
|
105
105
|
|
106
106
|
# prints the book store
|
107
|
-
def print # :nodoc:
|
107
|
+
def print # :nodoc:
|
108
108
|
# trace "@filename2books:"
|
109
109
|
if @filename2books
|
110
110
|
@filename2books.each do |_filename,books|
|
@@ -126,7 +126,7 @@ module RobustExcelOle
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
-
class BookstoreError < WIN32OLERuntimeError
|
129
|
+
class BookstoreError < WIN32OLERuntimeError # :nodoc:
|
130
130
|
end
|
131
131
|
|
132
132
|
end
|
@@ -11,7 +11,7 @@ module RobustExcelOle
|
|
11
11
|
@conv_to_win32_path =
|
12
12
|
Win32API.new('cygwin1.dll', 'cygwin_conv_to_win32_path', 'PP', 'I')
|
13
13
|
|
14
|
-
def cygpath(options, path) # :nodoc:
|
14
|
+
def cygpath(options, path) # :nodoc:
|
15
15
|
absolute = shortname = false
|
16
16
|
func = nil
|
17
17
|
options.delete(" \t-").chars do |opt|
|
@@ -140,7 +140,7 @@ module RobustExcelOle
|
|
140
140
|
# returns a Win32OLE object that represents a Excel instance to which Excel connects
|
141
141
|
# connects to the first opened Excel instance
|
142
142
|
# if this Excel instance is being closed, then Excel creates a new Excel instance
|
143
|
-
def self.current_excel # :nodoc:
|
143
|
+
def self.current_excel # :nodoc:
|
144
144
|
result = begin
|
145
145
|
WIN32OLE.connect('Excel.Application')
|
146
146
|
rescue
|
@@ -296,57 +296,7 @@ module RobustExcelOle
|
|
296
296
|
|
297
297
|
[finished_number, error_number]
|
298
298
|
end
|
299
|
-
=begin
|
300
|
-
def self.close_all(options = { :if_unsaved => :raise }, &blk)
|
301
|
-
options[:if_unsaved] = blk if blk
|
302
|
-
finished_number = error_number = overall_number = 0
|
303
|
-
first_error = nil
|
304
|
-
finishing_action = proc do |excel|
|
305
|
-
if excel
|
306
|
-
begin
|
307
|
-
overall_number += 1
|
308
|
-
finished_number += excel.close(:if_unsaved => options[:if_unsaved])
|
309
|
-
rescue
|
310
|
-
first_error = $ERROR_INFO
|
311
|
-
# trace "error when finishing #{$!}"
|
312
|
-
error_number += 1
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
# known Excel-instances
|
318
|
-
@@hwnd2excel.each do |hwnd, wr_excel|
|
319
|
-
if wr_excel.weakref_alive?
|
320
|
-
excel = wr_excel.__getobj__
|
321
|
-
if excel.alive?
|
322
|
-
excel.displayalerts = false
|
323
|
-
finishing_action.call(excel)
|
324
|
-
end
|
325
|
-
else
|
326
|
-
@@hwnd2excel.delete(hwnd)
|
327
|
-
end
|
328
|
-
end
|
329
299
|
|
330
|
-
# unknown Excel-instances
|
331
|
-
old_error_number = error_number
|
332
|
-
9.times do |_index|
|
333
|
-
sleep 0.1
|
334
|
-
excel = begin
|
335
|
-
new(WIN32OLE.connect('Excel.Application'))
|
336
|
-
rescue
|
337
|
-
nil
|
338
|
-
end
|
339
|
-
finishing_action.call(excel) if excel
|
340
|
-
free_all_ole_objects unless (error_number > 0) && (options[:if_unsaved] == :raise)
|
341
|
-
break unless excel
|
342
|
-
break if error_number > old_error_number # + 3
|
343
|
-
end
|
344
|
-
|
345
|
-
raise first_error if ((options[:if_unsaved] == :raise) && first_error) || (first_error.class == OptionInvalid)
|
346
|
-
|
347
|
-
[finished_number, error_number]
|
348
|
-
end
|
349
|
-
=end
|
350
300
|
# closes the Excel
|
351
301
|
# @param [Hash] options the options
|
352
302
|
# @option options [Symbol] :if_unsaved :raise, :save, :forget, :alert
|
@@ -355,7 +305,7 @@ module RobustExcelOle
|
|
355
305
|
# :raise (default) -> raises an exception
|
356
306
|
# :save -> saves the workbooks before closing
|
357
307
|
# :forget -> closes the Excel instance without saving the workbooks
|
358
|
-
# :alert -> Excel takes over
|
308
|
+
# :alert -> Excel takes over
|
359
309
|
def close(options = { :if_unsaved => :raise })
|
360
310
|
finishing_living_excel = alive?
|
361
311
|
if finishing_living_excel
|
@@ -402,7 +352,7 @@ module RobustExcelOle
|
|
402
352
|
end
|
403
353
|
|
404
354
|
# frees all OLE objects in the object space
|
405
|
-
def self.free_all_ole_objects # :nodoc:
|
355
|
+
def self.free_all_ole_objects # :nodoc:
|
406
356
|
anz_objekte = 0
|
407
357
|
ObjectSpace.each_object(WIN32OLE) do |o|
|
408
358
|
anz_objekte += 1
|
@@ -480,11 +430,11 @@ module RobustExcelOle
|
|
480
430
|
result
|
481
431
|
end
|
482
432
|
|
483
|
-
def excel # :nodoc:
|
433
|
+
def excel # :nodoc:
|
484
434
|
self
|
485
435
|
end
|
486
436
|
|
487
|
-
def self.hwnd2excel(hwnd) # :nodoc:
|
437
|
+
def self.hwnd2excel(hwnd) # :nodoc:
|
488
438
|
excel_weakref = @@hwnd2excel[hwnd]
|
489
439
|
if excel_weakref
|
490
440
|
if excel_weakref.weakref_alive?
|
@@ -501,13 +451,13 @@ module RobustExcelOle
|
|
501
451
|
end
|
502
452
|
end
|
503
453
|
|
504
|
-
def hwnd # :nodoc:
|
454
|
+
def hwnd # :nodoc:
|
505
455
|
self.Hwnd
|
506
456
|
rescue
|
507
457
|
nil
|
508
458
|
end
|
509
459
|
|
510
|
-
def self.print_hwnd2excel # :nodoc:
|
460
|
+
def self.print_hwnd2excel # :nodoc:
|
511
461
|
@@hwnd2excel.each do |hwnd,wr_excel|
|
512
462
|
excel_string = (wr_excel.weakref_alive? ? wr_excel.__getobj__.to_s : 'weakref not alive')
|
513
463
|
printf("hwnd: %8i => excel: %s\n", hwnd, excel_string)
|
@@ -530,7 +480,7 @@ module RobustExcelOle
|
|
530
480
|
end
|
531
481
|
|
532
482
|
# returns unsaved workbooks in known (not opened by user) Excel instances
|
533
|
-
def self.unsaved_known_workbooks # :nodoc:
|
483
|
+
def self.unsaved_known_workbooks # :nodoc:
|
534
484
|
result = []
|
535
485
|
@@hwnd2excel.each do |_hwnd,wr_excel|
|
536
486
|
excel = wr_excel.__getobj__ if wr_excel.weakref_alive?
|
@@ -539,12 +489,12 @@ module RobustExcelOle
|
|
539
489
|
result
|
540
490
|
end
|
541
491
|
|
542
|
-
def print_workbooks # :nodoc:
|
492
|
+
def print_workbooks # :nodoc:
|
543
493
|
self.Workbooks.each { |w| trace "#{w.Name} #{w}" }
|
544
494
|
end
|
545
495
|
|
546
496
|
# generates, saves, and closes empty workbook
|
547
|
-
def generate_workbook file_name # :nodoc:
|
497
|
+
def generate_workbook file_name # :nodoc:
|
548
498
|
raise FileNameNotGiven, 'filename is nil' if file_name.nil?
|
549
499
|
|
550
500
|
self.Workbooks.Add
|
@@ -686,15 +636,15 @@ module RobustExcelOle
|
|
686
636
|
set_namevalue_glob(name,value, :color => 42) # 42 - aqua-marin, 7-green
|
687
637
|
end
|
688
638
|
|
689
|
-
def to_s # :nodoc:
|
639
|
+
def to_s # :nodoc:
|
690
640
|
'#<Excel: ' + hwnd.to_s + ('not alive' unless alive?).to_s + '>'
|
691
641
|
end
|
692
642
|
|
693
|
-
def inspect # :nodoc:
|
643
|
+
def inspect # :nodoc:
|
694
644
|
to_s
|
695
645
|
end
|
696
646
|
|
697
|
-
def self.workbook_class # :nodoc:
|
647
|
+
def self.workbook_class # :nodoc:
|
698
648
|
@workbook_class ||= begin
|
699
649
|
module_name = parent_name
|
700
650
|
"#{module_name}::Workbook".constantize
|
@@ -703,7 +653,7 @@ module RobustExcelOle
|
|
703
653
|
end
|
704
654
|
end
|
705
655
|
|
706
|
-
def workbook_class # :nodoc:
|
656
|
+
def workbook_class # :nodoc:
|
707
657
|
self.class.workbook_class
|
708
658
|
end
|
709
659
|
|
@@ -711,7 +661,7 @@ module RobustExcelOle
|
|
711
661
|
|
712
662
|
private
|
713
663
|
|
714
|
-
def method_missing(name, *args) # :nodoc:
|
664
|
+
def method_missing(name, *args) # :nodoc:
|
715
665
|
if name.to_s[0,1] =~ /[A-Z]/
|
716
666
|
begin
|
717
667
|
raise ObjectNotAlive, 'method missing: Excel not alive' unless alive?
|
@@ -2,19 +2,19 @@
|
|
2
2
|
|
3
3
|
module General
|
4
4
|
|
5
|
-
def absolute_path(file) # :nodoc:
|
5
|
+
def absolute_path(file) # :nodoc:
|
6
6
|
file = File.expand_path(file)
|
7
7
|
file = RobustExcelOle::Cygwin.cygpath('-w', file) if RUBY_PLATFORM =~ /cygwin/
|
8
8
|
WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName(file)
|
9
9
|
end
|
10
10
|
|
11
|
-
def canonize(filename) # :nodoc:
|
11
|
+
def canonize(filename) # :nodoc:
|
12
12
|
raise TypeREOError, "No string given to canonize, but #{filename.inspect}" unless filename.is_a?(String)
|
13
13
|
|
14
14
|
normalize(filename).downcase
|
15
15
|
end
|
16
16
|
|
17
|
-
def normalize(path) # :nodoc:
|
17
|
+
def normalize(path) # :nodoc:
|
18
18
|
path = path.gsub('/./', '/') + '/'
|
19
19
|
path = path.gsub(/[\/\\]+/, '/')
|
20
20
|
nil while path.gsub!(/(\/|^)(?!\.\.?)([^\/]+)\/\.\.\//, '\1')
|
@@ -24,7 +24,7 @@ module General
|
|
24
24
|
|
25
25
|
module_function :absolute_path, :canonize, :normalize
|
26
26
|
|
27
|
-
class VBAMethodMissingError < RuntimeError # :nodoc:
|
27
|
+
class VBAMethodMissingError < RuntimeError # :nodoc:
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
@@ -43,7 +43,7 @@ class WIN32OLE
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
class ::String # :nodoc:
|
46
|
+
class ::String # :nodoc:
|
47
47
|
def / path_part
|
48
48
|
if empty?
|
49
49
|
path_part
|
@@ -106,7 +106,7 @@ class ::String # :nodoc: #
|
|
106
106
|
end
|
107
107
|
|
108
108
|
# taken from http://api.rubyonrails.org/v2.3.8/classes/ActiveSupport/CoreExtensions/Module.html#M000806
|
109
|
-
class Module # :nodoc:
|
109
|
+
class Module # :nodoc:
|
110
110
|
def parent_name
|
111
111
|
unless defined? @parent_name
|
112
112
|
@parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil
|
@@ -121,7 +121,7 @@ end
|
|
121
121
|
|
122
122
|
module MethodHelpers
|
123
123
|
|
124
|
-
def respond_to?(meth_name, include_private = false) # :nodoc:
|
124
|
+
def respond_to?(meth_name, include_private = false) # :nodoc:
|
125
125
|
if alive?
|
126
126
|
methods.include?(meth_name.to_s)
|
127
127
|
else
|
@@ -129,7 +129,7 @@ module MethodHelpers
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
-
def methods # :nodoc:
|
132
|
+
def methods # :nodoc:
|
133
133
|
if alive?
|
134
134
|
(super.map { |m| m.to_s } + ole_object.ole_methods.map { |m| m.to_s }).uniq.select { |m| m =~ /^(?!\_)/ }.sort
|
135
135
|
else
|
@@ -192,7 +192,7 @@ module RobustExcelOle
|
|
192
192
|
end
|
193
193
|
=end
|
194
194
|
|
195
|
-
def self.worksheet_class
|
195
|
+
def self.worksheet_class # :nodoc:
|
196
196
|
@worksheet_class ||= begin
|
197
197
|
module_name = parent_name
|
198
198
|
"#{module_name}::Worksheet".constantize
|
@@ -201,13 +201,13 @@ module RobustExcelOle
|
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
204
|
-
def worksheet_class # :nodoc:
|
204
|
+
def worksheet_class # :nodoc:
|
205
205
|
self.class.worksheet_class
|
206
206
|
end
|
207
207
|
|
208
208
|
private
|
209
209
|
|
210
|
-
def method_missing(name, *args) # :nodoc:
|
210
|
+
def method_missing(name, *args) # :nodoc:
|
211
211
|
#if name.to_s[0,1] =~ /[A-Z]/
|
212
212
|
begin
|
213
213
|
@ole_range.send(name, *args)
|
@@ -8,88 +8,88 @@ File.delete REO_LOG_FILE rescue nil
|
|
8
8
|
|
9
9
|
module RobustExcelOle
|
10
10
|
|
11
|
-
class REOError < RuntimeError # :nodoc:
|
11
|
+
class REOError < RuntimeError # :nodoc:
|
12
12
|
end
|
13
13
|
|
14
|
-
class ExcelREOError < REOError # :nodoc:
|
14
|
+
class ExcelREOError < REOError # :nodoc:
|
15
15
|
end
|
16
16
|
|
17
|
-
class WorkbookREOError < REOError # :nodoc:
|
17
|
+
class WorkbookREOError < REOError # :nodoc:
|
18
18
|
end
|
19
19
|
|
20
|
-
class SheetREOError < REOError # :nodoc:
|
20
|
+
class SheetREOError < REOError # :nodoc:
|
21
21
|
end
|
22
22
|
|
23
|
-
class FileREOError < REOError # :nodoc:
|
23
|
+
class FileREOError < REOError # :nodoc:
|
24
24
|
end
|
25
25
|
|
26
|
-
class NamesREOError < REOError # :nodoc:
|
26
|
+
class NamesREOError < REOError # :nodoc:
|
27
27
|
end
|
28
28
|
|
29
|
-
class MiscREOError < REOError # :nodoc:
|
29
|
+
class MiscREOError < REOError # :nodoc:
|
30
30
|
end
|
31
31
|
|
32
|
-
class ExcelDamaged < ExcelREOError # :nodoc:
|
32
|
+
class ExcelDamaged < ExcelREOError # :nodoc:
|
33
33
|
end
|
34
34
|
|
35
|
-
class UnsavedWorkbooks < ExcelREOError # :nodoc:
|
35
|
+
class UnsavedWorkbooks < ExcelREOError # :nodoc:
|
36
36
|
end
|
37
37
|
|
38
|
-
class WorkbookBlocked < WorkbookREOError # :nodoc:
|
38
|
+
class WorkbookBlocked < WorkbookREOError # :nodoc:
|
39
39
|
end
|
40
40
|
|
41
|
-
class WorkbookNotSaved < WorkbookREOError # :nodoc:
|
41
|
+
class WorkbookNotSaved < WorkbookREOError # :nodoc:
|
42
42
|
end
|
43
43
|
|
44
|
-
class WorkbookReadOnly < WorkbookREOError # :nodoc:
|
44
|
+
class WorkbookReadOnly < WorkbookREOError # :nodoc:
|
45
45
|
end
|
46
46
|
|
47
|
-
class WorkbookBeingUsed < WorkbookREOError # :nodoc:
|
47
|
+
class WorkbookBeingUsed < WorkbookREOError # :nodoc:
|
48
48
|
end
|
49
49
|
|
50
|
-
class FileNotFound < FileREOError # :nodoc:
|
50
|
+
class FileNotFound < FileREOError # :nodoc:
|
51
51
|
end
|
52
52
|
|
53
|
-
class FileNameNotGiven < FileREOError # :nodoc:
|
53
|
+
class FileNameNotGiven < FileREOError # :nodoc:
|
54
54
|
end
|
55
55
|
|
56
|
-
class FileAlreadyExists < FileREOError # :nodoc:
|
56
|
+
class FileAlreadyExists < FileREOError # :nodoc:
|
57
57
|
end
|
58
58
|
|
59
|
-
class NameNotFound < NamesREOError # :nodoc:
|
59
|
+
class NameNotFound < NamesREOError # :nodoc:
|
60
60
|
end
|
61
61
|
|
62
|
-
class NameAlreadyExists < NamesREOError # :nodoc:
|
62
|
+
class NameAlreadyExists < NamesREOError # :nodoc:
|
63
63
|
end
|
64
64
|
|
65
|
-
class RangeNotEvaluatable < MiscREOError # :nodoc:
|
65
|
+
class RangeNotEvaluatable < MiscREOError # :nodoc:
|
66
66
|
end
|
67
67
|
|
68
|
-
class RangeNotCreated < MiscREOError # :nodoc:
|
68
|
+
class RangeNotCreated < MiscREOError # :nodoc:
|
69
69
|
end
|
70
70
|
|
71
|
-
class RangeNotCopied < MiscREOError # :nodoc:
|
71
|
+
class RangeNotCopied < MiscREOError # :nodoc:
|
72
72
|
end
|
73
73
|
|
74
|
-
class OptionInvalid < MiscREOError # :nodoc:
|
74
|
+
class OptionInvalid < MiscREOError # :nodoc:
|
75
75
|
end
|
76
76
|
|
77
|
-
class ObjectNotAlive < MiscREOError # :nodoc:
|
77
|
+
class ObjectNotAlive < MiscREOError # :nodoc:
|
78
78
|
end
|
79
79
|
|
80
|
-
class TypeREOError < REOError # :nodoc:
|
80
|
+
class TypeREOError < REOError # :nodoc:
|
81
81
|
end
|
82
82
|
|
83
|
-
class TimeOut < REOError # :nodoc:
|
83
|
+
class TimeOut < REOError # :nodoc:
|
84
84
|
end
|
85
85
|
|
86
|
-
class AddressInvalid < REOError # :nodoc:
|
86
|
+
class AddressInvalid < REOError # :nodoc:
|
87
87
|
end
|
88
88
|
|
89
|
-
class UnexpectedREOError < REOError # :nodoc:
|
89
|
+
class UnexpectedREOError < REOError # :nodoc:
|
90
90
|
end
|
91
91
|
|
92
|
-
class NotImplementedREOError < REOError # :nodoc:
|
92
|
+
class NotImplementedREOError < REOError # :nodoc:
|
93
93
|
end
|
94
94
|
|
95
95
|
class REOCommon
|
@@ -216,7 +216,7 @@ module RobustExcelOle
|
|
216
216
|
end
|
217
217
|
|
218
218
|
# returns an Excel object when given Excel, Workbook or Win32ole object representing a Workbook or an Excel
|
219
|
-
def self.excel_of(object) # :nodoc:
|
219
|
+
def self.excel_of(object) # :nodoc:
|
220
220
|
if object.is_a? WIN32OLE
|
221
221
|
case object.ole_obj_help.name
|
222
222
|
when /Workbook/i
|
@@ -237,7 +237,7 @@ module RobustExcelOle
|
|
237
237
|
|
238
238
|
public
|
239
239
|
|
240
|
-
def ensure_excel(options) # :nodoc:
|
240
|
+
def ensure_excel(options) # :nodoc:
|
241
241
|
if excel && @excel.alive?
|
242
242
|
@excel.created = false
|
243
243
|
return
|
@@ -249,7 +249,7 @@ module RobustExcelOle
|
|
249
249
|
@excel
|
250
250
|
end
|
251
251
|
|
252
|
-
def ensure_workbook(file, options) # :nodoc:
|
252
|
+
def ensure_workbook(file, options) # :nodoc:
|
253
253
|
file = @stored_filename ? @stored_filename : file
|
254
254
|
raise(FileNameNotGiven, 'filename is nil') if file.nil?
|
255
255
|
raise(FileNotFound, "file #{General.absolute_path(file).inspect} is a directory") if File.directory?(file)
|
@@ -322,7 +322,7 @@ module RobustExcelOle
|
|
322
322
|
|
323
323
|
private
|
324
324
|
|
325
|
-
def open_or_create_workbook(file, options) # :nodoc:
|
325
|
+
def open_or_create_workbook(file, options) # :nodoc:
|
326
326
|
if !@ole_workbook || (options[:if_unsaved] == :alert) || options[:if_obstructed]
|
327
327
|
begin
|
328
328
|
filename = General.absolute_path(file)
|
@@ -641,7 +641,7 @@ module RobustExcelOle
|
|
641
641
|
@modified_cells.each { |cell| cell.Interior.ColorIndex = XlNone }
|
642
642
|
end
|
643
643
|
|
644
|
-
def save_as_workbook(file, options) # :nodoc:
|
644
|
+
def save_as_workbook(file, options) # :nodoc:
|
645
645
|
dirname, basename = File.split(file)
|
646
646
|
file_format =
|
647
647
|
case File.extname(basename)
|
@@ -826,11 +826,11 @@ module RobustExcelOle
|
|
826
826
|
@ole_workbook.Fullname.tr('\\','/') rescue nil
|
827
827
|
end
|
828
828
|
|
829
|
-
def writable # :nodoc:
|
829
|
+
def writable # :nodoc:
|
830
830
|
!@ole_workbook.ReadOnly if @ole_workbook
|
831
831
|
end
|
832
832
|
|
833
|
-
def saved # :nodoc:
|
833
|
+
def saved # :nodoc:
|
834
834
|
@ole_workbook.Saved if @ole_workbook
|
835
835
|
end
|
836
836
|
|
@@ -878,23 +878,23 @@ module RobustExcelOle
|
|
878
878
|
bookstore.books
|
879
879
|
end
|
880
880
|
|
881
|
-
def self.bookstore # :nodoc:
|
881
|
+
def self.bookstore # :nodoc:
|
882
882
|
@@bookstore ||= Bookstore.new
|
883
883
|
end
|
884
884
|
|
885
|
-
def bookstore # :nodoc:
|
885
|
+
def bookstore # :nodoc:
|
886
886
|
self.class.bookstore
|
887
887
|
end
|
888
888
|
|
889
|
-
def to_s # :nodoc:
|
889
|
+
def to_s # :nodoc:
|
890
890
|
self.filename.to_s
|
891
891
|
end
|
892
892
|
|
893
|
-
def inspect # :nodoc:
|
893
|
+
def inspect # :nodoc:
|
894
894
|
'#<Workbook: ' + ('not alive ' unless alive?).to_s + (File.basename(self.filename) if alive?).to_s + " #{@ole_workbook} #{@excel}" + '>'
|
895
895
|
end
|
896
896
|
|
897
|
-
def self.excel_class # :nodoc:
|
897
|
+
def self.excel_class # :nodoc:
|
898
898
|
@excel_class ||= begin
|
899
899
|
module_name = self.parent_name
|
900
900
|
"#{module_name}::Excel".constantize
|
@@ -904,7 +904,7 @@ module RobustExcelOle
|
|
904
904
|
end
|
905
905
|
end
|
906
906
|
|
907
|
-
def self.worksheet_class # :nodoc:
|
907
|
+
def self.worksheet_class # :nodoc:
|
908
908
|
@worksheet_class ||= begin
|
909
909
|
module_name = self.parent_name
|
910
910
|
"#{module_name}::Worksheet".constantize
|
@@ -913,11 +913,11 @@ module RobustExcelOle
|
|
913
913
|
end
|
914
914
|
end
|
915
915
|
|
916
|
-
def excel_class # :nodoc:
|
916
|
+
def excel_class # :nodoc:
|
917
917
|
self.class.excel_class
|
918
918
|
end
|
919
919
|
|
920
|
-
def worksheet_class # :nodoc:
|
920
|
+
def worksheet_class # :nodoc:
|
921
921
|
self.class.worksheet_class
|
922
922
|
end
|
923
923
|
|
@@ -925,7 +925,7 @@ module RobustExcelOle
|
|
925
925
|
|
926
926
|
private
|
927
927
|
|
928
|
-
def method_missing(name, *args) # :nodoc:
|
928
|
+
def method_missing(name, *args) # :nodoc:
|
929
929
|
if name.to_s[0,1] =~ /[A-Z]/
|
930
930
|
begin
|
931
931
|
raise ObjectNotAlive, 'method missing: workbook not alive' unless alive?
|
@@ -7,6 +7,8 @@ module RobustExcelOle
|
|
7
7
|
# that you would apply for a Worksheet object.
|
8
8
|
# see https://docs.microsoft.com/en-us/office/vba/api/excel.worksheet#methods
|
9
9
|
|
10
|
+
|
11
|
+
# worksheet: see https://github.com/Thomas008/robust_excel_ole/blob/master/lib/robust_excel_ole/worksheet.rb
|
10
12
|
class Worksheet < RangeOwners
|
11
13
|
|
12
14
|
attr_reader :ole_worksheet
|
@@ -171,7 +173,7 @@ module RobustExcelOle
|
|
171
173
|
RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(integer_range.min, col), @ole_worksheet.Cells(integer_range.max, col)))
|
172
174
|
end
|
173
175
|
|
174
|
-
def self.workbook_class # :nodoc:
|
176
|
+
def self.workbook_class # :nodoc:
|
175
177
|
@workbook_class ||= begin
|
176
178
|
module_name = self.parent_name
|
177
179
|
"#{module_name}::Workbook".constantize
|
@@ -180,21 +182,21 @@ module RobustExcelOle
|
|
180
182
|
end
|
181
183
|
end
|
182
184
|
|
183
|
-
def workbook_class # :nodoc:
|
185
|
+
def workbook_class # :nodoc:
|
184
186
|
self.class.workbook_class
|
185
187
|
end
|
186
188
|
|
187
|
-
def to_s # :nodoc:
|
189
|
+
def to_s # :nodoc:
|
188
190
|
'#<Worksheet: ' + ('not alive ' unless @workbook.alive?).to_s + name.to_s + " #{File.basename(@workbook.stored_filename)} >"
|
189
191
|
end
|
190
192
|
|
191
|
-
def inspect # :nodoc:
|
193
|
+
def inspect # :nodoc:
|
192
194
|
self.to_s
|
193
195
|
end
|
194
196
|
|
195
197
|
private
|
196
198
|
|
197
|
-
def method_missing(name, *args) # :nodoc:
|
199
|
+
def method_missing(name, *args) # :nodoc:
|
198
200
|
if name.to_s[0,1] =~ /[A-Z]/
|
199
201
|
begin
|
200
202
|
@ole_worksheet.send(name, *args)
|
data/lib/spec_helper.rb
CHANGED
@@ -4,20 +4,20 @@ require 'tmpdir'
|
|
4
4
|
require 'fileutils'
|
5
5
|
require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
|
6
6
|
|
7
|
-
module RobustExcelOle::SpecHelpers # :nodoc:
|
8
|
-
def create_tmpdir # :nodoc:
|
7
|
+
module RobustExcelOle::SpecHelpers # :nodoc:
|
8
|
+
def create_tmpdir # :nodoc:
|
9
9
|
tmpdir = Dir.mktmpdir
|
10
10
|
FileUtils.cp_r(File.join(File.dirname(__FILE__), 'data'), tmpdir)
|
11
11
|
tmpdir + '/data'
|
12
12
|
end
|
13
13
|
|
14
|
-
def rm_tmp(tmpdir) # :nodoc:
|
14
|
+
def rm_tmp(tmpdir) # :nodoc:
|
15
15
|
FileUtils.remove_entry_secure(File.dirname(tmpdir))
|
16
16
|
end
|
17
17
|
|
18
18
|
# This method is almost copy of wycats's implementation.
|
19
19
|
# http://pochi.hatenablog.jp/entries/2010/03/24
|
20
|
-
def capture(stream) # :nodoc:
|
20
|
+
def capture(stream) # :nodoc:
|
21
21
|
begin
|
22
22
|
stream = stream.to_s
|
23
23
|
eval "$#{stream} = StringIO.new"
|
data/spec/bookstore_spec.rb
CHANGED
data/spec/excel_spec.rb
CHANGED
@@ -144,7 +144,7 @@ module RobustExcelOle
|
|
144
144
|
|
145
145
|
context "excel creation" do
|
146
146
|
|
147
|
-
def creation_ok? # :nodoc:
|
147
|
+
def creation_ok? # :nodoc:
|
148
148
|
@excel.alive?
|
149
149
|
@excel.Screenupdating.should be true
|
150
150
|
@excel.Visible.should be false
|
@@ -437,7 +437,7 @@ module RobustExcelOle
|
|
437
437
|
end
|
438
438
|
|
439
439
|
context "close excel instances" do
|
440
|
-
def direct_excel_creation_helper # :nodoc:
|
440
|
+
def direct_excel_creation_helper # :nodoc:
|
441
441
|
expect { WIN32OLE.connect("Excel.Application") }.to raise_error
|
442
442
|
sleep 0.1
|
443
443
|
ole_excel1 = WIN32OLE.new("Excel.Application")
|
@@ -1984,5 +1984,5 @@ module RobustExcelOle
|
|
1984
1984
|
end
|
1985
1985
|
end
|
1986
1986
|
|
1987
|
-
class TestError < RuntimeError # :nodoc:
|
1987
|
+
class TestError < RuntimeError # :nodoc:
|
1988
1988
|
end
|
data/spec/helpers/key_sender.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -5,19 +5,19 @@ require "fileutils"
|
|
5
5
|
require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
|
6
6
|
|
7
7
|
module RobustExcelOle::SpecHelpers
|
8
|
-
def create_tmpdir # :nodoc:
|
8
|
+
def create_tmpdir # :nodoc:
|
9
9
|
tmpdir = Dir.mktmpdir
|
10
10
|
FileUtils.cp_r(File.join(File.dirname(__FILE__), 'data'), tmpdir)
|
11
11
|
tmpdir + '/data'
|
12
12
|
end
|
13
13
|
|
14
|
-
def rm_tmp(tmpdir) # :nodoc:
|
14
|
+
def rm_tmp(tmpdir) # :nodoc:
|
15
15
|
FileUtils.rm_f(File.dirname(tmpdir))
|
16
16
|
end
|
17
17
|
|
18
18
|
# This method is almost copy of wycats's implementation.
|
19
19
|
# http://pochi.hatenablog.jp/entries/2010/03/24
|
20
|
-
def capture(stream) # :nodoc:
|
20
|
+
def capture(stream) # :nodoc:
|
21
21
|
begin
|
22
22
|
stream = stream.to_s
|
23
23
|
eval "$#{stream} = StringIO.new"
|
data/spec/workbook_spec.rb
CHANGED
@@ -639,7 +639,7 @@ describe Workbook do
|
|
639
639
|
|
640
640
|
describe "unobtrusively" do
|
641
641
|
|
642
|
-
def unobtrusively_ok? # :nodoc:
|
642
|
+
def unobtrusively_ok? # :nodoc:
|
643
643
|
Workbook.unobtrusively(@simple_file) do |book|
|
644
644
|
book.should be_a Workbook
|
645
645
|
sheet = book.sheet(1)
|
@@ -854,7 +854,7 @@ describe Workbook do
|
|
854
854
|
|
855
855
|
context "with a virgin Workbook class" do
|
856
856
|
before do
|
857
|
-
class Workbook # :nodoc:
|
857
|
+
class Workbook # :nodoc:
|
858
858
|
@@bookstore = nil
|
859
859
|
end
|
860
860
|
end
|
@@ -865,7 +865,7 @@ describe Workbook do
|
|
865
865
|
|
866
866
|
context "with a book never opened before" do
|
867
867
|
before do
|
868
|
-
class Workbook # :nodoc:
|
868
|
+
class Workbook # :nodoc:
|
869
869
|
@@bookstore = nil
|
870
870
|
end
|
871
871
|
other_book = Workbook.open(@different_file)
|
@@ -3,11 +3,11 @@
|
|
3
3
|
require File.join(File.dirname(__FILE__), './../spec_helper')
|
4
4
|
|
5
5
|
|
6
|
-
module My # :nodoc:
|
7
|
-
class Excel < RobustExcelOle::Excel # :nodoc:
|
6
|
+
module My # :nodoc:
|
7
|
+
class Excel < RobustExcelOle::Excel # :nodoc:
|
8
8
|
end
|
9
9
|
|
10
|
-
class Workbook < RobustExcelOle::Workbook # :nodoc:
|
10
|
+
class Workbook < RobustExcelOle::Workbook # :nodoc:
|
11
11
|
end
|
12
12
|
|
13
13
|
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.7'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- traths
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|