robust_excel_ole 1.7 → 1.8
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/.yardopts +2 -1
- data/lib/reo_console.rb +5 -3
- data/lib/robust_excel_ole/bookstore.rb +10 -6
- data/lib/robust_excel_ole/cell.rb +2 -1
- data/lib/robust_excel_ole/cygwin.rb +2 -1
- data/lib/robust_excel_ole/excel.rb +33 -20
- data/lib/robust_excel_ole/general.rb +17 -8
- data/lib/robust_excel_ole/range.rb +7 -31
- data/lib/robust_excel_ole/reo_common.rb +56 -28
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +34 -16
- data/lib/robust_excel_ole/worksheet.rb +11 -6
- data/lib/spec_helper.rb +9 -4
- data/spec/bookstore_spec.rb +2 -1
- data/spec/excel_spec.rb +4 -2
- data/spec/helpers/key_sender.rb +2 -1
- data/spec/spec_helper.rb +5 -3
- data/spec/workbook_spec.rb +6 -3
- data/spec/workbook_specs/workbook_subclass_spec.rb +4 -4
- data/spec/workbook_specs/workbook_unobtr_spec.rb +2 -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: 2bdbfacd559753a2e1126c1ff1a28520a6c6cd57
|
4
|
+
data.tar.gz: a5cdf8708f6862cda1630fc9152f65a498e446b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 830ff59640559e837e7d15daf2ee5ec18c734aaebaba3a56189ea837f755deb8d4e7f7bf06aa01365ea59f633837ef4faa27bf1951a6af0f7ba834c083fd0e79
|
7
|
+
data.tar.gz: 4aea6e53ba40c1c14a26ce2bef43591e0a39194d65a1b90b4acc6623206bfad9796b8a69351d35aa7f99bca2201f8b23eac55a951f0d23b42a34f9f93fd91b03
|
data/.yardopts
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
--legacy
|
1
|
+
--legacy
|
2
|
+
--no-private
|
data/lib/reo_console.rb
CHANGED
@@ -17,8 +17,9 @@ 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
|
-
|
21
|
-
|
20
|
+
# @private
|
21
|
+
module Readline
|
22
|
+
module Hist
|
22
23
|
LOG = IRB.conf[:HISTORY_FILE]
|
23
24
|
# LOG = "#{ENV['HOME']}/.irb-history"
|
24
25
|
|
@@ -31,7 +32,8 @@ module Readline # :nodoc:
|
|
31
32
|
|
32
33
|
def self.start_session_log
|
33
34
|
timestamp = proc { Time.now.strftime('%Y-%m-%d, %H:%M:%S') }
|
34
|
-
|
35
|
+
# @private
|
36
|
+
class <<timestamp
|
35
37
|
alias_method :to_s, :call
|
36
38
|
end
|
37
39
|
write_log("###### session start: #{timestamp}")
|
@@ -73,7 +73,8 @@ module RobustExcelOle
|
|
73
73
|
end
|
74
74
|
|
75
75
|
# creates and returns a separate Excel instance with Visible and DisplayAlerts equal false
|
76
|
-
|
76
|
+
# @private
|
77
|
+
def hidden_excel
|
77
78
|
unless @hidden_excel_instance && @hidden_excel_instance.weakref_alive? && @hidden_excel_instance.__getobj__.alive?
|
78
79
|
@hidden_excel_instance = WeakRef.new(Excel.create)
|
79
80
|
end
|
@@ -95,16 +96,18 @@ module RobustExcelOle
|
|
95
96
|
result
|
96
97
|
end
|
97
98
|
|
98
|
-
|
99
|
+
private
|
99
100
|
|
100
|
-
|
101
|
+
# @private
|
102
|
+
def try_hidden_excel
|
101
103
|
@hidden_excel_instance.__getobj__ if @hidden_excel_instance && @hidden_excel_instance.weakref_alive? && @hidden_excel_instance.__getobj__.alive?
|
102
104
|
end
|
103
105
|
|
104
|
-
|
106
|
+
public
|
105
107
|
|
106
108
|
# prints the book store
|
107
|
-
|
109
|
+
# @private
|
110
|
+
def print
|
108
111
|
# trace "@filename2books:"
|
109
112
|
if @filename2books
|
110
113
|
@filename2books.each do |_filename,books|
|
@@ -126,7 +129,8 @@ module RobustExcelOle
|
|
126
129
|
end
|
127
130
|
end
|
128
131
|
|
129
|
-
|
132
|
+
# @private
|
133
|
+
class BookstoreError < WIN32OLERuntimeError
|
130
134
|
end
|
131
135
|
|
132
136
|
end
|
@@ -11,7 +11,8 @@ module RobustExcelOle
|
|
11
11
|
@conv_to_win32_path =
|
12
12
|
Win32API.new('cygwin1.dll', 'cygwin_conv_to_win32_path', 'PP', 'I')
|
13
13
|
|
14
|
-
|
14
|
+
# @private
|
15
|
+
def cygpath(options, path)
|
15
16
|
absolute = shortname = false
|
16
17
|
func = nil
|
17
18
|
options.delete(" \t-").chars do |opt|
|
@@ -140,7 +140,8 @@ 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
|
-
|
143
|
+
# @private
|
144
|
+
def self.current_excel
|
144
145
|
result = begin
|
145
146
|
WIN32OLE.connect('Excel.Application')
|
146
147
|
rescue
|
@@ -352,7 +353,8 @@ module RobustExcelOle
|
|
352
353
|
end
|
353
354
|
|
354
355
|
# frees all OLE objects in the object space
|
355
|
-
|
356
|
+
# @private
|
357
|
+
def self.free_all_ole_objects
|
356
358
|
anz_objekte = 0
|
357
359
|
ObjectSpace.each_object(WIN32OLE) do |o|
|
358
360
|
anz_objekte += 1
|
@@ -430,11 +432,13 @@ module RobustExcelOle
|
|
430
432
|
result
|
431
433
|
end
|
432
434
|
|
433
|
-
|
435
|
+
# @private
|
436
|
+
def excel
|
434
437
|
self
|
435
438
|
end
|
436
439
|
|
437
|
-
|
440
|
+
# @private
|
441
|
+
def self.hwnd2excel(hwnd)
|
438
442
|
excel_weakref = @@hwnd2excel[hwnd]
|
439
443
|
if excel_weakref
|
440
444
|
if excel_weakref.weakref_alive?
|
@@ -451,13 +455,15 @@ module RobustExcelOle
|
|
451
455
|
end
|
452
456
|
end
|
453
457
|
|
454
|
-
|
458
|
+
# @private
|
459
|
+
def hwnd
|
455
460
|
self.Hwnd
|
456
461
|
rescue
|
457
462
|
nil
|
458
463
|
end
|
459
464
|
|
460
|
-
|
465
|
+
# @private
|
466
|
+
def self.print_hwnd2excel
|
461
467
|
@@hwnd2excel.each do |hwnd,wr_excel|
|
462
468
|
excel_string = (wr_excel.weakref_alive? ? wr_excel.__getobj__.to_s : 'weakref not alive')
|
463
469
|
printf("hwnd: %8i => excel: %s\n", hwnd, excel_string)
|
@@ -480,7 +486,8 @@ module RobustExcelOle
|
|
480
486
|
end
|
481
487
|
|
482
488
|
# returns unsaved workbooks in known (not opened by user) Excel instances
|
483
|
-
|
489
|
+
# @private
|
490
|
+
def self.unsaved_known_workbooks
|
484
491
|
result = []
|
485
492
|
@@hwnd2excel.each do |_hwnd,wr_excel|
|
486
493
|
excel = wr_excel.__getobj__ if wr_excel.weakref_alive?
|
@@ -489,12 +496,14 @@ module RobustExcelOle
|
|
489
496
|
result
|
490
497
|
end
|
491
498
|
|
492
|
-
|
499
|
+
# @private
|
500
|
+
def print_workbooks
|
493
501
|
self.Workbooks.each { |w| trace "#{w.Name} #{w}" }
|
494
502
|
end
|
495
503
|
|
496
504
|
# generates, saves, and closes empty workbook
|
497
|
-
|
505
|
+
# @private
|
506
|
+
def generate_workbook file_name
|
498
507
|
raise FileNameNotGiven, 'filename is nil' if file_name.nil?
|
499
508
|
|
500
509
|
self.Workbooks.Add
|
@@ -547,20 +556,19 @@ module RobustExcelOle
|
|
547
556
|
# retains the saved-status of the workbooks when set to manual
|
548
557
|
def calculation= calculation_mode
|
549
558
|
return if calculation_mode.nil?
|
550
|
-
|
551
559
|
@calculation = calculation_mode
|
552
560
|
calc_mode_changable = @ole_excel.Workbooks.Count > 0 && @ole_excel.Calculation.is_a?(Integer)
|
553
561
|
if calc_mode_changable
|
554
|
-
if calculation_mode == :manual
|
562
|
+
#if calculation_mode == :manual
|
555
563
|
saved = []
|
556
564
|
(1..@ole_excel.Workbooks.Count).each { |i| saved << @ole_excel.Workbooks(i).Saved }
|
557
|
-
end
|
565
|
+
#end
|
558
566
|
@ole_excel.CalculateBeforeSave = false
|
559
567
|
@ole_excel.Calculation =
|
560
568
|
calculation_mode == :automatic ? XlCalculationAutomatic : XlCalculationManual
|
561
|
-
if calculation_mode == :manual
|
569
|
+
#if calculation_mode == :manual
|
562
570
|
(1..@ole_excel.Workbooks.Count).each { |i| @ole_excel.Workbooks(i).Saved = true if saved[i - 1] }
|
563
|
-
end
|
571
|
+
#end
|
564
572
|
end
|
565
573
|
end
|
566
574
|
|
@@ -636,15 +644,18 @@ module RobustExcelOle
|
|
636
644
|
set_namevalue_glob(name,value, :color => 42) # 42 - aqua-marin, 7-green
|
637
645
|
end
|
638
646
|
|
639
|
-
|
647
|
+
# @private
|
648
|
+
def to_s
|
640
649
|
'#<Excel: ' + hwnd.to_s + ('not alive' unless alive?).to_s + '>'
|
641
650
|
end
|
642
651
|
|
643
|
-
|
652
|
+
# @private
|
653
|
+
def inspect
|
644
654
|
to_s
|
645
655
|
end
|
646
656
|
|
647
|
-
|
657
|
+
# @private
|
658
|
+
def self.workbook_class
|
648
659
|
@workbook_class ||= begin
|
649
660
|
module_name = parent_name
|
650
661
|
"#{module_name}::Workbook".constantize
|
@@ -653,15 +664,17 @@ module RobustExcelOle
|
|
653
664
|
end
|
654
665
|
end
|
655
666
|
|
656
|
-
|
667
|
+
# @private
|
668
|
+
def workbook_class
|
657
669
|
self.class.workbook_class
|
658
670
|
end
|
659
671
|
|
660
672
|
include MethodHelpers
|
661
673
|
|
662
|
-
|
674
|
+
private
|
663
675
|
|
664
|
-
|
676
|
+
# @private
|
677
|
+
def method_missing(name, *args)
|
665
678
|
if name.to_s[0,1] =~ /[A-Z]/
|
666
679
|
begin
|
667
680
|
raise ObjectNotAlive, 'method missing: Excel not alive' unless alive?
|
@@ -2,19 +2,22 @@
|
|
2
2
|
|
3
3
|
module General
|
4
4
|
|
5
|
-
|
5
|
+
# @private
|
6
|
+
def absolute_path(file)
|
6
7
|
file = File.expand_path(file)
|
7
8
|
file = RobustExcelOle::Cygwin.cygpath('-w', file) if RUBY_PLATFORM =~ /cygwin/
|
8
9
|
WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName(file)
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
|
+
# @private
|
13
|
+
def canonize(filename)
|
12
14
|
raise TypeREOError, "No string given to canonize, but #{filename.inspect}" unless filename.is_a?(String)
|
13
15
|
|
14
16
|
normalize(filename).downcase
|
15
17
|
end
|
16
18
|
|
17
|
-
|
19
|
+
# @private
|
20
|
+
def normalize(path)
|
18
21
|
path = path.gsub('/./', '/') + '/'
|
19
22
|
path = path.gsub(/[\/\\]+/, '/')
|
20
23
|
nil while path.gsub!(/(\/|^)(?!\.\.?)([^\/]+)\/\.\.\//, '\1')
|
@@ -24,11 +27,13 @@ module General
|
|
24
27
|
|
25
28
|
module_function :absolute_path, :canonize, :normalize
|
26
29
|
|
27
|
-
|
30
|
+
# @private
|
31
|
+
class VBAMethodMissingError < RuntimeError
|
28
32
|
end
|
29
33
|
|
30
34
|
end
|
31
35
|
|
36
|
+
# @private
|
32
37
|
class WIN32OLE
|
33
38
|
# promoting WIN32OLE objects to RobustExcelOle objects
|
34
39
|
def to_reo
|
@@ -43,7 +48,8 @@ class WIN32OLE
|
|
43
48
|
end
|
44
49
|
end
|
45
50
|
|
46
|
-
|
51
|
+
# @private
|
52
|
+
class ::String
|
47
53
|
def / path_part
|
48
54
|
if empty?
|
49
55
|
path_part
|
@@ -106,7 +112,8 @@ class ::String # :nodoc:
|
|
106
112
|
end
|
107
113
|
|
108
114
|
# taken from http://api.rubyonrails.org/v2.3.8/classes/ActiveSupport/CoreExtensions/Module.html#M000806
|
109
|
-
|
115
|
+
# @private
|
116
|
+
class Module
|
110
117
|
def parent_name
|
111
118
|
unless defined? @parent_name
|
112
119
|
@parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil
|
@@ -121,7 +128,8 @@ end
|
|
121
128
|
|
122
129
|
module MethodHelpers
|
123
130
|
|
124
|
-
|
131
|
+
# @private
|
132
|
+
def respond_to?(meth_name, include_private = false)
|
125
133
|
if alive?
|
126
134
|
methods.include?(meth_name.to_s)
|
127
135
|
else
|
@@ -129,7 +137,8 @@ module MethodHelpers
|
|
129
137
|
end
|
130
138
|
end
|
131
139
|
|
132
|
-
|
140
|
+
# @private
|
141
|
+
def methods
|
133
142
|
if alive?
|
134
143
|
(super.map { |m| m.to_s } + ole_object.ole_methods.map { |m| m.to_s }).uniq.select { |m| m =~ /^(?!\_)/ }.sort
|
135
144
|
else
|
@@ -165,34 +165,8 @@ module RobustExcelOle
|
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
|
-
|
169
|
-
|
170
|
-
# @params [Address] address of the destination range
|
171
|
-
# @options [Worksheet] the worksheet in which to copy
|
172
|
-
def copy(address, sheet = :__not_provided, third_argument_deprecated = :__not_provided)
|
173
|
-
if third_argument_deprecated != :__not_provided
|
174
|
-
address = [address,sheet]
|
175
|
-
sheet = third_argument_deprecated
|
176
|
-
end
|
177
|
-
address = Address.new(address)
|
178
|
-
sheet = @worksheet if sheet == :__not_provided
|
179
|
-
destination_range = sheet.range([address.rows.min..address.rows.max,
|
180
|
-
address.columns.min..address.columns.max]).ole_range
|
181
|
-
if sheet.workbook.excel == @worksheet.workbook.excel
|
182
|
-
begin
|
183
|
-
self.Copy(:destination => destination_range)
|
184
|
-
rescue WIN32OLERuntimeError
|
185
|
-
raise RangeNotCopied, 'cannot copy range'
|
186
|
-
end
|
187
|
-
else
|
188
|
-
#self.Select
|
189
|
-
self.Copy
|
190
|
-
sheet.Paste(:destination => destination_range)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
=end
|
194
|
-
|
195
|
-
def self.worksheet_class # :nodoc:
|
168
|
+
# @private
|
169
|
+
def self.worksheet_class
|
196
170
|
@worksheet_class ||= begin
|
197
171
|
module_name = parent_name
|
198
172
|
"#{module_name}::Worksheet".constantize
|
@@ -201,13 +175,15 @@ module RobustExcelOle
|
|
201
175
|
end
|
202
176
|
end
|
203
177
|
|
204
|
-
|
178
|
+
# @private
|
179
|
+
def worksheet_class
|
205
180
|
self.class.worksheet_class
|
206
181
|
end
|
207
182
|
|
208
|
-
|
183
|
+
private
|
209
184
|
|
210
|
-
|
185
|
+
# @private
|
186
|
+
def method_missing(name, *args)
|
211
187
|
#if name.to_s[0,1] =~ /[A-Z]/
|
212
188
|
begin
|
213
189
|
@ole_range.send(name, *args)
|
@@ -8,88 +8,116 @@ File.delete REO_LOG_FILE rescue nil
|
|
8
8
|
|
9
9
|
module RobustExcelOle
|
10
10
|
|
11
|
-
|
11
|
+
# @private
|
12
|
+
class REOError < RuntimeError
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
+
# @private
|
16
|
+
class ExcelREOError < REOError
|
15
17
|
end
|
16
18
|
|
17
|
-
|
19
|
+
# @private
|
20
|
+
class WorkbookREOError < REOError
|
18
21
|
end
|
19
22
|
|
20
|
-
|
23
|
+
# @private
|
24
|
+
class SheetREOError < REOError
|
21
25
|
end
|
22
26
|
|
23
|
-
|
27
|
+
# @private
|
28
|
+
class FileREOError < REOError
|
24
29
|
end
|
25
30
|
|
26
|
-
|
31
|
+
# @private
|
32
|
+
class NamesREOError < REOError
|
27
33
|
end
|
28
34
|
|
29
|
-
|
35
|
+
# @private
|
36
|
+
class MiscREOError < REOError
|
30
37
|
end
|
31
38
|
|
32
|
-
|
39
|
+
# @private
|
40
|
+
class ExcelDamaged < ExcelREOError
|
33
41
|
end
|
34
42
|
|
35
|
-
|
43
|
+
# @private
|
44
|
+
class UnsavedWorkbooks < ExcelREOError
|
36
45
|
end
|
37
46
|
|
38
|
-
|
47
|
+
# @private
|
48
|
+
class WorkbookBlocked < WorkbookREOError
|
39
49
|
end
|
40
50
|
|
41
|
-
|
51
|
+
# @private
|
52
|
+
class WorkbookNotSaved < WorkbookREOError
|
42
53
|
end
|
43
54
|
|
44
|
-
|
55
|
+
# @private
|
56
|
+
class WorkbookReadOnly < WorkbookREOError
|
45
57
|
end
|
46
58
|
|
47
|
-
|
59
|
+
# @private
|
60
|
+
class WorkbookBeingUsed < WorkbookREOError
|
48
61
|
end
|
49
62
|
|
50
|
-
|
63
|
+
# @private
|
64
|
+
class FileNotFound < FileREOError
|
51
65
|
end
|
52
66
|
|
53
|
-
|
67
|
+
# @private
|
68
|
+
class FileNameNotGiven < FileREOError
|
54
69
|
end
|
55
70
|
|
56
|
-
|
71
|
+
# @private
|
72
|
+
class FileAlreadyExists < FileREOError
|
57
73
|
end
|
58
74
|
|
59
|
-
|
75
|
+
# @private
|
76
|
+
class NameNotFound < NamesREOError
|
60
77
|
end
|
61
78
|
|
62
|
-
|
79
|
+
# @private
|
80
|
+
class NameAlreadyExists < NamesREOError
|
63
81
|
end
|
64
82
|
|
65
|
-
|
83
|
+
# @private
|
84
|
+
class RangeNotEvaluatable < MiscREOError
|
66
85
|
end
|
67
86
|
|
68
|
-
|
87
|
+
# @private
|
88
|
+
class RangeNotCreated < MiscREOError
|
69
89
|
end
|
70
90
|
|
71
|
-
|
91
|
+
# @private
|
92
|
+
class RangeNotCopied < MiscREOError
|
72
93
|
end
|
73
94
|
|
74
|
-
|
95
|
+
# @private
|
96
|
+
class OptionInvalid < MiscREOError
|
75
97
|
end
|
76
98
|
|
77
|
-
|
99
|
+
# @private
|
100
|
+
class ObjectNotAlive < MiscREOError
|
78
101
|
end
|
79
102
|
|
80
|
-
|
103
|
+
# @private
|
104
|
+
class TypeREOError < REOError
|
81
105
|
end
|
82
106
|
|
83
|
-
|
107
|
+
# @private
|
108
|
+
class TimeOut < REOError
|
84
109
|
end
|
85
110
|
|
86
|
-
|
111
|
+
# @private
|
112
|
+
class AddressInvalid < REOError
|
87
113
|
end
|
88
114
|
|
89
|
-
|
115
|
+
# @private
|
116
|
+
class UnexpectedREOError < REOError
|
90
117
|
end
|
91
118
|
|
92
|
-
|
119
|
+
# @private
|
120
|
+
class NotImplementedREOError < REOError
|
93
121
|
end
|
94
122
|
|
95
123
|
class REOCommon
|
@@ -216,7 +216,8 @@ 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
|
-
|
219
|
+
# @private
|
220
|
+
def self.excel_of(object)
|
220
221
|
if object.is_a? WIN32OLE
|
221
222
|
case object.ole_obj_help.name
|
222
223
|
when /Workbook/i
|
@@ -237,7 +238,8 @@ module RobustExcelOle
|
|
237
238
|
|
238
239
|
public
|
239
240
|
|
240
|
-
|
241
|
+
# @private
|
242
|
+
def ensure_excel(options)
|
241
243
|
if excel && @excel.alive?
|
242
244
|
@excel.created = false
|
243
245
|
return
|
@@ -249,7 +251,8 @@ module RobustExcelOle
|
|
249
251
|
@excel
|
250
252
|
end
|
251
253
|
|
252
|
-
|
254
|
+
# @private
|
255
|
+
def ensure_workbook(file, options)
|
253
256
|
file = @stored_filename ? @stored_filename : file
|
254
257
|
raise(FileNameNotGiven, 'filename is nil') if file.nil?
|
255
258
|
raise(FileNotFound, "file #{General.absolute_path(file).inspect} is a directory") if File.directory?(file)
|
@@ -322,7 +325,8 @@ module RobustExcelOle
|
|
322
325
|
|
323
326
|
private
|
324
327
|
|
325
|
-
|
328
|
+
# @private
|
329
|
+
def open_or_create_workbook(file, options)
|
326
330
|
if !@ole_workbook || (options[:if_unsaved] == :alert) || options[:if_obstructed]
|
327
331
|
begin
|
328
332
|
filename = General.absolute_path(file)
|
@@ -637,11 +641,13 @@ module RobustExcelOle
|
|
637
641
|
|
638
642
|
private
|
639
643
|
|
644
|
+
# @private
|
640
645
|
def discoloring
|
641
646
|
@modified_cells.each { |cell| cell.Interior.ColorIndex = XlNone }
|
642
647
|
end
|
643
648
|
|
644
|
-
|
649
|
+
# @private
|
650
|
+
def save_as_workbook(file, options)
|
645
651
|
dirname, basename = File.split(file)
|
646
652
|
file_format =
|
647
653
|
case File.extname(basename)
|
@@ -826,11 +832,13 @@ module RobustExcelOle
|
|
826
832
|
@ole_workbook.Fullname.tr('\\','/') rescue nil
|
827
833
|
end
|
828
834
|
|
829
|
-
|
835
|
+
# @private
|
836
|
+
def writable
|
830
837
|
!@ole_workbook.ReadOnly if @ole_workbook
|
831
838
|
end
|
832
839
|
|
833
|
-
|
840
|
+
# @private
|
841
|
+
def saved
|
834
842
|
@ole_workbook.Saved if @ole_workbook
|
835
843
|
end
|
836
844
|
|
@@ -838,6 +846,7 @@ module RobustExcelOle
|
|
838
846
|
@excel.calculation if @ole_workbook
|
839
847
|
end
|
840
848
|
|
849
|
+
# @private
|
841
850
|
def check_compatibility
|
842
851
|
@ole_workbook.CheckCompatibility if @ole_workbook
|
843
852
|
end
|
@@ -878,23 +887,28 @@ module RobustExcelOle
|
|
878
887
|
bookstore.books
|
879
888
|
end
|
880
889
|
|
881
|
-
|
890
|
+
# @private
|
891
|
+
def self.bookstore
|
882
892
|
@@bookstore ||= Bookstore.new
|
883
893
|
end
|
884
894
|
|
885
|
-
|
895
|
+
# @private
|
896
|
+
def bookstore
|
886
897
|
self.class.bookstore
|
887
898
|
end
|
888
899
|
|
889
|
-
|
900
|
+
# @private
|
901
|
+
def to_s
|
890
902
|
self.filename.to_s
|
891
903
|
end
|
892
904
|
|
893
|
-
|
905
|
+
# @private
|
906
|
+
def inspect
|
894
907
|
'#<Workbook: ' + ('not alive ' unless alive?).to_s + (File.basename(self.filename) if alive?).to_s + " #{@ole_workbook} #{@excel}" + '>'
|
895
908
|
end
|
896
909
|
|
897
|
-
|
910
|
+
# @private
|
911
|
+
def self.excel_class
|
898
912
|
@excel_class ||= begin
|
899
913
|
module_name = self.parent_name
|
900
914
|
"#{module_name}::Excel".constantize
|
@@ -904,7 +918,8 @@ module RobustExcelOle
|
|
904
918
|
end
|
905
919
|
end
|
906
920
|
|
907
|
-
|
921
|
+
# @private
|
922
|
+
def self.worksheet_class
|
908
923
|
@worksheet_class ||= begin
|
909
924
|
module_name = self.parent_name
|
910
925
|
"#{module_name}::Worksheet".constantize
|
@@ -913,11 +928,13 @@ module RobustExcelOle
|
|
913
928
|
end
|
914
929
|
end
|
915
930
|
|
916
|
-
|
931
|
+
# @private
|
932
|
+
def excel_class
|
917
933
|
self.class.excel_class
|
918
934
|
end
|
919
935
|
|
920
|
-
|
936
|
+
# @private
|
937
|
+
def worksheet_class
|
921
938
|
self.class.worksheet_class
|
922
939
|
end
|
923
940
|
|
@@ -925,7 +942,8 @@ module RobustExcelOle
|
|
925
942
|
|
926
943
|
private
|
927
944
|
|
928
|
-
|
945
|
+
# @private
|
946
|
+
def method_missing(name, *args)
|
929
947
|
if name.to_s[0,1] =~ /[A-Z]/
|
930
948
|
begin
|
931
949
|
raise ObjectNotAlive, 'method missing: workbook not alive' unless alive?
|
@@ -173,7 +173,8 @@ module RobustExcelOle
|
|
173
173
|
RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(integer_range.min, col), @ole_worksheet.Cells(integer_range.max, col)))
|
174
174
|
end
|
175
175
|
|
176
|
-
|
176
|
+
# @private
|
177
|
+
def self.workbook_class
|
177
178
|
@workbook_class ||= begin
|
178
179
|
module_name = self.parent_name
|
179
180
|
"#{module_name}::Workbook".constantize
|
@@ -182,21 +183,25 @@ module RobustExcelOle
|
|
182
183
|
end
|
183
184
|
end
|
184
185
|
|
185
|
-
|
186
|
+
# @private
|
187
|
+
def workbook_class
|
186
188
|
self.class.workbook_class
|
187
189
|
end
|
188
190
|
|
189
|
-
|
191
|
+
# @private
|
192
|
+
def to_s
|
190
193
|
'#<Worksheet: ' + ('not alive ' unless @workbook.alive?).to_s + name.to_s + " #{File.basename(@workbook.stored_filename)} >"
|
191
194
|
end
|
192
195
|
|
193
|
-
|
196
|
+
# @private
|
197
|
+
def inspect
|
194
198
|
self.to_s
|
195
199
|
end
|
196
200
|
|
197
|
-
|
201
|
+
private
|
198
202
|
|
199
|
-
|
203
|
+
# @private
|
204
|
+
def method_missing(name, *args)
|
200
205
|
if name.to_s[0,1] =~ /[A-Z]/
|
201
206
|
begin
|
202
207
|
@ole_worksheet.send(name, *args)
|
data/lib/spec_helper.rb
CHANGED
@@ -4,20 +4,25 @@ require 'tmpdir'
|
|
4
4
|
require 'fileutils'
|
5
5
|
require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
# @private
|
8
|
+
module RobustExcelOle::SpecHelpers
|
9
|
+
|
10
|
+
# @private
|
11
|
+
def create_tmpdir
|
9
12
|
tmpdir = Dir.mktmpdir
|
10
13
|
FileUtils.cp_r(File.join(File.dirname(__FILE__), 'data'), tmpdir)
|
11
14
|
tmpdir + '/data'
|
12
15
|
end
|
13
16
|
|
14
|
-
|
17
|
+
# @private
|
18
|
+
def rm_tmp(tmpdir)
|
15
19
|
FileUtils.remove_entry_secure(File.dirname(tmpdir))
|
16
20
|
end
|
17
21
|
|
18
22
|
# This method is almost copy of wycats's implementation.
|
19
23
|
# http://pochi.hatenablog.jp/entries/2010/03/24
|
20
|
-
|
24
|
+
# @private
|
25
|
+
def capture(stream)
|
21
26
|
begin
|
22
27
|
stream = stream.to_s
|
23
28
|
eval "$#{stream} = StringIO.new"
|
data/spec/bookstore_spec.rb
CHANGED
data/spec/excel_spec.rb
CHANGED
@@ -437,7 +437,8 @@ module RobustExcelOle
|
|
437
437
|
end
|
438
438
|
|
439
439
|
context "close excel instances" do
|
440
|
-
|
440
|
+
# @private
|
441
|
+
def direct_excel_creation_helper
|
441
442
|
expect { WIN32OLE.connect("Excel.Application") }.to raise_error
|
442
443
|
sleep 0.1
|
443
444
|
ole_excel1 = WIN32OLE.new("Excel.Application")
|
@@ -1984,5 +1985,6 @@ module RobustExcelOle
|
|
1984
1985
|
end
|
1985
1986
|
end
|
1986
1987
|
|
1987
|
-
|
1988
|
+
# @private
|
1989
|
+
class TestError < RuntimeError
|
1988
1990
|
end
|
data/spec/helpers/key_sender.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -4,20 +4,22 @@ require 'tmpdir'
|
|
4
4
|
require "fileutils"
|
5
5
|
require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
|
6
6
|
|
7
|
+
# @private
|
7
8
|
module RobustExcelOle::SpecHelpers
|
8
|
-
|
9
|
+
|
10
|
+
def create_tmpdir
|
9
11
|
tmpdir = Dir.mktmpdir
|
10
12
|
FileUtils.cp_r(File.join(File.dirname(__FILE__), 'data'), tmpdir)
|
11
13
|
tmpdir + '/data'
|
12
14
|
end
|
13
15
|
|
14
|
-
def rm_tmp(tmpdir)
|
16
|
+
def rm_tmp(tmpdir)
|
15
17
|
FileUtils.rm_f(File.dirname(tmpdir))
|
16
18
|
end
|
17
19
|
|
18
20
|
# This method is almost copy of wycats's implementation.
|
19
21
|
# http://pochi.hatenablog.jp/entries/2010/03/24
|
20
|
-
def capture(stream)
|
22
|
+
def capture(stream)
|
21
23
|
begin
|
22
24
|
stream = stream.to_s
|
23
25
|
eval "$#{stream} = StringIO.new"
|
data/spec/workbook_spec.rb
CHANGED
@@ -639,7 +639,8 @@ describe Workbook do
|
|
639
639
|
|
640
640
|
describe "unobtrusively" do
|
641
641
|
|
642
|
-
|
642
|
+
# @private
|
643
|
+
def unobtrusively_ok?
|
643
644
|
Workbook.unobtrusively(@simple_file) do |book|
|
644
645
|
book.should be_a Workbook
|
645
646
|
sheet = book.sheet(1)
|
@@ -854,7 +855,8 @@ describe Workbook do
|
|
854
855
|
|
855
856
|
context "with a virgin Workbook class" do
|
856
857
|
before do
|
857
|
-
|
858
|
+
# @private
|
859
|
+
class Workbook
|
858
860
|
@@bookstore = nil
|
859
861
|
end
|
860
862
|
end
|
@@ -865,7 +867,8 @@ describe Workbook do
|
|
865
867
|
|
866
868
|
context "with a book never opened before" do
|
867
869
|
before do
|
868
|
-
|
870
|
+
# @private
|
871
|
+
class Workbook
|
869
872
|
@@bookstore = nil
|
870
873
|
end
|
871
874
|
other_book = Workbook.open(@different_file)
|
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
require File.join(File.dirname(__FILE__), './../spec_helper')
|
4
4
|
|
5
|
-
|
6
|
-
module My
|
7
|
-
class Excel < RobustExcelOle::Excel
|
5
|
+
# @private
|
6
|
+
module My
|
7
|
+
class Excel < RobustExcelOle::Excel
|
8
8
|
end
|
9
9
|
|
10
|
-
class Workbook < RobustExcelOle::Workbook
|
10
|
+
class Workbook < RobustExcelOle::Workbook
|
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.8'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- traths
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|