robust_excel_ole 0.3.9 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +17 -0
- data/README.rdoc +1 -1
- data/README_detail.rdoc +4 -2
- data/lib/robust_excel_ole.rb +0 -1
- data/lib/robust_excel_ole/book.rb +13 -11
- data/lib/robust_excel_ole/bookstore.rb +0 -2
- data/lib/robust_excel_ole/excel.rb +0 -2
- data/lib/robust_excel_ole/general.rb +27 -3
- data/lib/robust_excel_ole/sheet.rb +0 -2
- data/lib/robust_excel_ole/version.rb +1 -1
- data/spec/book_specs/book_unobtr_spec.rb +32 -0
- metadata +4 -6
- data/lib/robust_excel_ole/utilities.rb +0 -28
data/Changelog
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.4] - 2016-03-16
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- options visible, displayalerts in unobtrusively, for_reading, for_writing
|
8
|
+
|
9
|
+
## [0.3.8] - 2016-02-12
|
10
|
+
|
11
|
+
### Added
|
12
|
+
- mark down comments
|
13
|
+
- trace
|
14
|
+
- Excel, Book: respond_to?, methods, special_methods, special_methods
|
15
|
+
|
16
|
+
## [0.3.9] - 2016-03-03
|
17
|
+
|
18
|
+
### Added
|
19
|
+
- methods, respond_to?, own_methods in new module General
|
20
|
+
- yardopts option --legacy for ruby 1.8.6. such that class Book is included in the documentation
|
4
21
|
|
5
22
|
## [0.3.8] - 2016-02-12
|
6
23
|
|
data/README.rdoc
CHANGED
@@ -125,7 +125,7 @@ The method +unobtrusively+ enables the user to read or modify a workbook, no mat
|
|
125
125
|
|
126
126
|
Some options determine the Excel instance in which a closed workbook is opened. The options +:reuse (default) indicates that the closed workbook is opened in the Excel instance where the workbooks is opened, if such an Excel instance exists, otherwise that another Excel instance is reused. The option +:hidden+ provokes that the closed workbook is opened in a separate Excel instance that is not visible and has no DisplayAlerts. Any following closed workbook would be opened in this Excel instance as well when using this option. Moreover, an Excel instance can be given directly where to open the closed workbook.
|
127
127
|
|
128
|
-
Further options are +:read_only+, +:readonly_excel+, and +:keep_open. The option +:readonly_excel+ chooses whether a book that is opened in read only mode. If the workbook is opened as read only, then the option +:readonly_excel+ determines whether to close the workbook and open it as writable in the Excel instance where it was open so far, or to open it as writable in another running Excel instance, if such an instance exists, or to open it in a new Excel instance.
|
128
|
+
Further options are +:read_only+, +:readonly_excel+, and +:keep_open. The option +:readonly_excel+ chooses whether a book that is opened in read only mode. If the workbook is opened as read only, then the option +:readonly_excel+ determines whether to close the workbook and open it as writable in the Excel instance where it was open so far, or to open it as writable in another running Excel instance, if such an instance exists, or to open it in a new Excel instance. Moreover, there are the options +:visible+ and +:displayalerts+.
|
129
129
|
|
130
130
|
Book.unobtrusively('workbook.xls', :reuse, :read_only => false, :keep_open => false) do |book|
|
131
131
|
# some modification
|
data/README_detail.rdoc
CHANGED
@@ -179,8 +179,8 @@ One option chooses the Excel instance in which a closed workbook is opened. The
|
|
179
179
|
|
180
180
|
Options are the following:
|
181
181
|
|
182
|
-
|
183
|
-
|
182
|
+
+:reuse+:: (default) : open a closed workbook in the Excel instance of the workbook, if it exists, otherwise reuse another Excel
|
183
|
+
+:hidden+:: : open a closed workbook in one separate Excel instance that is not visible and has no displayalerts
|
184
184
|
<excel-instance> : open a closed workbooks in the given Excel instance
|
185
185
|
|
186
186
|
+:read_only+:: Open the workbook unobtrusively for reading only (default: false)
|
@@ -189,6 +189,8 @@ Options are the following:
|
|
189
189
|
false (default) open it as writable in another running excel instance, if it exists,
|
190
190
|
otherwise open in a new excel instance
|
191
191
|
+:keep_open+:: let the workbook open after unobtrusively opening (default: false)
|
192
|
+
+:visible+:: change the Excel into visible or invisible
|
193
|
+
+:displayalerts+:: change the Excel into enable or disable displayalerts
|
192
194
|
|
193
195
|
Book.unobtrusively('workbook.xls') do |book|
|
194
196
|
# some modification
|
data/lib/robust_excel_ole.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require "win32ole"
|
2
2
|
require File.join(File.dirname(__FILE__), 'robust_excel_ole/general')
|
3
|
-
require File.join(File.dirname(__FILE__), 'robust_excel_ole/utilities')
|
4
3
|
require File.join(File.dirname(__FILE__), 'robust_excel_ole/excel')
|
5
4
|
require File.join(File.dirname(__FILE__), 'robust_excel_ole/bookstore')
|
6
5
|
require File.join(File.dirname(__FILE__), 'robust_excel_ole/book')
|
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'weakref'
|
4
4
|
|
5
|
-
include Utilities
|
6
|
-
|
7
5
|
module RobustExcelOle
|
8
6
|
|
9
7
|
class Book
|
@@ -12,6 +10,7 @@ module RobustExcelOle
|
|
12
10
|
attr_accessor :ole_workbook
|
13
11
|
attr_accessor :stored_filename
|
14
12
|
attr_accessor :options
|
13
|
+
attr_accessor :can_be_closed
|
15
14
|
|
16
15
|
alias ole_object ole_workbook
|
17
16
|
|
@@ -196,12 +195,7 @@ module RobustExcelOle
|
|
196
195
|
@excel = self.class.excel_of(options[:excel])
|
197
196
|
end
|
198
197
|
end
|
199
|
-
|
200
|
-
# keep the old values for :visible and :displayalerts, set them only if the parameters are given
|
201
|
-
if (not excel_options)
|
202
|
-
@excel.displayalerts = options[:displayalerts] unless options[:displayalerts].nil?
|
203
|
-
@excel.visible = options[:visible] unless options[:visible].nil?
|
204
|
-
end
|
198
|
+
apply_options(options) unless excel_options
|
205
199
|
end
|
206
200
|
|
207
201
|
def ensure_workbook(file, options) # :nodoc: #
|
@@ -305,6 +299,7 @@ module RobustExcelOle
|
|
305
299
|
workbooks.Add if @excel.Version == "12.0" && count == 0
|
306
300
|
workbooks.Open(filename,{ 'ReadOnly' => options[:read_only] })
|
307
301
|
workbooks.Item(1).Close if @excel.Version == "12.0" && count == 0
|
302
|
+
@can_be_closed = false
|
308
303
|
rescue WIN32OLERuntimeError => msg
|
309
304
|
trace "WIN32OLERuntimeError: #{msg.message}"
|
310
305
|
if msg.message =~ /800A03EC/
|
@@ -395,6 +390,8 @@ module RobustExcelOle
|
|
395
390
|
# @option opts [Boolean] :read_only whether the file is opened for read-only
|
396
391
|
# @option opts [Boolean] :readonly_excel behaviour when workbook is opened read-only and shall be modified
|
397
392
|
# @option opts [Boolean] :keep_open whether the workbook shall be kept open after unobtrusively opening
|
393
|
+
# @option opts [Boolean] :displayalerts true, or false (default)
|
394
|
+
# @option opts [Boolean] :visible true, or false (default)
|
398
395
|
# options:
|
399
396
|
# :if_closed : if the workbook is closed, then open it in
|
400
397
|
# :reuse -> the Excel instance of the workbook, if it exists,
|
@@ -406,7 +403,8 @@ module RobustExcelOle
|
|
406
403
|
# true: closes it and open it as writable in the Excel instance where it was open so far
|
407
404
|
# false (default) opens it as writable in another running excel instance, if it exists,
|
408
405
|
# otherwise open in a new Excel instance.
|
409
|
-
#
|
406
|
+
# :displayalerts enables DisplayAlerts in Excel
|
407
|
+
# :visible makes visible in Excel
|
410
408
|
# @return [Book] a workbook
|
411
409
|
def self.unobtrusively(file, if_closed = nil, opts = { }, &block)
|
412
410
|
if if_closed.is_a? Hash
|
@@ -417,7 +415,7 @@ module RobustExcelOle
|
|
417
415
|
options = {
|
418
416
|
:read_only => false,
|
419
417
|
:readonly_excel => false,
|
420
|
-
:keep_open => false
|
418
|
+
:keep_open => false
|
421
419
|
}.merge(opts)
|
422
420
|
book = bookstore.fetch(file, :prefer_writable => (not options[:read_only]))
|
423
421
|
was_not_alive_or_nil = book.nil? || (not book.alive?)
|
@@ -450,6 +448,8 @@ module RobustExcelOle
|
|
450
448
|
open(file, :force_excel => :new, :read_only => options[:read_only])
|
451
449
|
end
|
452
450
|
end
|
451
|
+
book.excel.displayalerts = options[:displayalerts] unless options[:displayalerts].nil?
|
452
|
+
book.excel.visible = options[:visible] unless options[:visible].nil?
|
453
453
|
yield book
|
454
454
|
ensure
|
455
455
|
book.save if (was_not_alive_or_nil || was_saved || ((not options[:read_only]) && (not was_writable))) && (not options[:read_only]) && book && (not book.saved)
|
@@ -457,6 +457,7 @@ module RobustExcelOle
|
|
457
457
|
if (not was_not_alive_or_nil) && (not options[:read_only]) && (not was_writable) && options[:readonly_excel]
|
458
458
|
open(file, :force_excel => book.excel, :if_obstructed => :new_excel, :read_only => true)
|
459
459
|
end
|
460
|
+
@can_be_closed = true if options[:keep_open] && book
|
460
461
|
book.close if (was_not_alive_or_nil && (not now_alive) && (not options[:keep_open]) && book)
|
461
462
|
end
|
462
463
|
end
|
@@ -807,8 +808,9 @@ module RobustExcelOle
|
|
807
808
|
def self.excel_class # :nodoc: #
|
808
809
|
@excel_class ||= begin
|
809
810
|
module_name = self.parent_name
|
810
|
-
"#{module_name}::Excel".
|
811
|
+
"#{module_name}::Excel".constantize
|
811
812
|
rescue NameError => e
|
813
|
+
#trace "excel_class: NameError: #{e}"
|
812
814
|
Excel
|
813
815
|
end
|
814
816
|
end
|
@@ -1,3 +1,9 @@
|
|
1
|
+
LOG_TO_STDOUT = true unless Object.const_defined?(:LOG_TO_STDOUT)
|
2
|
+
REO_LOG_DIR = "" unless Object.const_defined?(:REO_LOG_DIR)
|
3
|
+
REO_LOG_FILE = "reo.log" unless Object.const_defined?(:REO_LOG_FILE)
|
4
|
+
|
5
|
+
File.delete REO_LOG_FILE rescue nil
|
6
|
+
|
1
7
|
include Enumerable
|
2
8
|
|
3
9
|
module General
|
@@ -76,7 +82,25 @@ module General
|
|
76
82
|
path
|
77
83
|
end
|
78
84
|
|
79
|
-
|
85
|
+
def trace(text)
|
86
|
+
if LOG_TO_STDOUT
|
87
|
+
puts text
|
88
|
+
else
|
89
|
+
if REO_LOG_DIR.empty?
|
90
|
+
homes = ["HOME", "HOMEPATH"]
|
91
|
+
home = homes.find {|h| ENV[h] != nil}
|
92
|
+
reo_log_dir = ENV[home]
|
93
|
+
else
|
94
|
+
reo_log_dir = REO_LOG_DIR
|
95
|
+
end
|
96
|
+
File.open(reo_log_dir + "/" + REO_LOG_FILE,"a") do | file |
|
97
|
+
file.puts text
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
module_function :absolute_path, :canonize, :normalize, :rot, :trace
|
80
104
|
|
81
105
|
class VBAMethodMissingError < RuntimeError # :nodoc: #
|
82
106
|
end
|
@@ -172,8 +196,6 @@ class Module # :nodoc: #
|
|
172
196
|
end
|
173
197
|
end
|
174
198
|
|
175
|
-
REO = General
|
176
|
-
|
177
199
|
module MethodHelpers
|
178
200
|
|
179
201
|
def respond_to?(meth_name, include_private = false) # :nodoc: #
|
@@ -186,3 +208,5 @@ module MethodHelpers
|
|
186
208
|
end
|
187
209
|
|
188
210
|
end
|
211
|
+
|
212
|
+
REO = General
|
@@ -124,6 +124,25 @@ describe Book do
|
|
124
124
|
}.to raise_error(ExcelError, "receiver instance is neither an Excel nor a Book")
|
125
125
|
end
|
126
126
|
|
127
|
+
it "should be visible and displayalerts" do
|
128
|
+
Book.unobtrusively(@simple_file, :visible => true, :displayalerts => true) do |book|
|
129
|
+
book.should be_a Book
|
130
|
+
book.should be_alive
|
131
|
+
book.excel.visible.should be_true
|
132
|
+
book.excel.displayalerts.should be_true
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should be visible" do
|
137
|
+
excel = Excel.new(:reuse => false, :displayalerts => true)
|
138
|
+
Book.unobtrusively(@simple_file, :visible => true) do |book|
|
139
|
+
book.should be_a Book
|
140
|
+
book.should be_alive
|
141
|
+
book.excel.visible.should be_true
|
142
|
+
book.excel.displayalerts.should be_true
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
127
146
|
end
|
128
147
|
|
129
148
|
context "with an open book" do
|
@@ -273,6 +292,19 @@ describe Book do
|
|
273
292
|
sheet[1,1].value.should_not == old_cell_value
|
274
293
|
end
|
275
294
|
|
295
|
+
it "should set can_be_closed" do
|
296
|
+
Excel.close_all
|
297
|
+
Book.unobtrusively(@simple_file, :keep_open => true) do |book|
|
298
|
+
book.should be_a Book
|
299
|
+
book.should be_alive
|
300
|
+
book.can_be_closed.should be_false
|
301
|
+
@book2 = book
|
302
|
+
end
|
303
|
+
@book2.should be_alive
|
304
|
+
book = Book.open(@simple_file)
|
305
|
+
book.can_be_closed.should be_true
|
306
|
+
end
|
307
|
+
|
276
308
|
# book shall be reanimated even with :hidden
|
277
309
|
it "should use the excel of the book and keep open the book" do
|
278
310
|
excel = Excel.new(:reuse => false)
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robust_excel_ole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.3.9
|
8
|
+
- 4
|
9
|
+
version: "0.4"
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- traths
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2016-03-
|
17
|
+
date: 2016-03-16 00:00:00 +01:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -89,7 +88,6 @@ files:
|
|
89
88
|
- lib/robust_excel_ole/robustexcelole.sublime-project
|
90
89
|
- lib/robust_excel_ole/robustexcelole.sublime-workspace
|
91
90
|
- lib/robust_excel_ole/sheet.rb
|
92
|
-
- lib/robust_excel_ole/utilities.rb
|
93
91
|
- lib/robust_excel_ole/version.rb
|
94
92
|
- lib/spec_helper.rb
|
95
93
|
- reo.bat
|
@@ -1,28 +0,0 @@
|
|
1
|
-
LOG_TO_STDOUT = true unless Object.const_defined?(:LOG_TO_STDOUT)
|
2
|
-
REO_LOG_DIR = "" unless Object.const_defined?(:REO_LOG_DIR)
|
3
|
-
REO_LOG_FILE = "reo.log" unless Object.const_defined?(:REO_LOG_FILE)
|
4
|
-
|
5
|
-
File.delete REO_LOG_FILE rescue nil
|
6
|
-
|
7
|
-
module Utilities # :nodoc: #
|
8
|
-
|
9
|
-
def trace(text)
|
10
|
-
if LOG_TO_STDOUT
|
11
|
-
puts text
|
12
|
-
else
|
13
|
-
if REO_LOG_DIR.empty?
|
14
|
-
homes = ["HOME", "HOMEPATH"]
|
15
|
-
home = homes.find {|h| ENV[h] != nil}
|
16
|
-
reo_log_dir = ENV[home]
|
17
|
-
else
|
18
|
-
reo_log_dir = REO_LOG_DIR
|
19
|
-
end
|
20
|
-
File.open(reo_log_dir + "/" + REO_LOG_FILE,"a") do | file |
|
21
|
-
file.puts text
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
module_function :trace
|
27
|
-
|
28
|
-
end
|