robust_excel_ole 1.11 → 1.12
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/Changelog +11 -0
- data/README.rdoc +20 -8
- data/docs/README_open.rdoc +1 -0
- data/docs/README_ranges.rdoc +5 -11
- data/examples/{introducing_examples/example_introducing.rb → introductory_examples/example_introductory.rb} +10 -2
- data/examples/{introducing_examples → introductory_examples}/example_open.rb +18 -17
- data/examples/{introducing_examples → introductory_examples}/example_range.rb +29 -16
- data/examples/modifying_sheets/example_access_sheets_and_cells.rb +8 -7
- data/examples/modifying_sheets/example_add_names.rb +4 -8
- data/examples/modifying_sheets/example_adding_sheets.rb +7 -6
- data/examples/modifying_sheets/example_concating.rb +2 -2
- data/examples/modifying_sheets/example_copying.rb +3 -3
- data/examples/modifying_sheets/example_expanding.rb +2 -2
- data/examples/modifying_sheets/example_naming.rb +2 -2
- data/examples/modifying_sheets/example_ranges.rb +4 -4
- data/examples/modifying_sheets/example_saving.rb +3 -3
- data/examples/open_save_close/example_control_to_excel.rb +10 -11
- data/examples/open_save_close/example_default_excel.rb +13 -14
- data/examples/open_save_close/example_force_excel.rb +9 -10
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +7 -7
- data/examples/open_save_close/example_if_obstructed_forget.rb +5 -5
- data/examples/open_save_close/example_if_obstructed_save.rb +7 -7
- data/examples/open_save_close/example_if_unsaved_accept.rb +13 -13
- data/examples/open_save_close/example_if_unsaved_forget.rb +9 -10
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +9 -10
- data/examples/open_save_close/example_read_only.rb +6 -6
- data/examples/open_save_close/example_rename_cells.rb +4 -5
- data/examples/open_save_close/example_reuse.rb +6 -6
- data/examples/open_save_close/example_simple.rb +5 -5
- data/examples/open_save_close/example_unobtrusively.rb +4 -4
- data/lib/robust_excel_ole/address.rb +0 -4
- data/lib/robust_excel_ole/bookstore.rb +4 -28
- data/lib/robust_excel_ole/excel.rb +17 -22
- data/lib/robust_excel_ole/general.rb +11 -18
- data/lib/robust_excel_ole/range_owners.rb +17 -27
- data/lib/robust_excel_ole/reo_common.rb +7 -3
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +178 -180
- data/lib/robust_excel_ole/worksheet.rb +7 -4
- data/robust_excel_ole.gemspec +6 -4
- data/spec/bookstore_spec.rb +38 -34
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/excel_spec.rb +89 -44
- data/spec/general_spec.rb +1 -0
- data/spec/range_spec.rb +7 -4
- data/spec/workbook_specs/workbook_close_spec.rb +2 -1
- data/spec/workbook_specs/workbook_misc_spec.rb +34 -18
- data/spec/workbook_specs/workbook_open_spec.rb +112 -71
- data/spec/workbook_specs/workbook_save_spec.rb +173 -5
- data/spec/workbook_specs/workbook_sheet_spec.rb +6 -42
- data/spec/workbook_specs/workbook_unobtr_spec.rb +9 -246
- data/spec/worksheet_spec.rb +21 -5
- metadata +12 -11
@@ -1,8 +1,8 @@
|
|
1
1
|
# example_ifunsaved_forget_more.rb:
|
2
2
|
# open with :if_unsaved => :forget, :new_excel, close with :if_unsaved => :save
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
require_relative '../../lib/robust_excel_ole'
|
5
|
+
require_relative '../../spec/helpers/create_temporary_dir'
|
6
6
|
require "fileutils"
|
7
7
|
|
8
8
|
include RobustExcelOle
|
@@ -11,26 +11,25 @@ Excel.kill_all
|
|
11
11
|
begin
|
12
12
|
dir = create_tmpdir
|
13
13
|
file_name = dir + 'workbook.xls'
|
14
|
-
book = Workbook.open(file_name)
|
15
|
-
|
16
|
-
sheet = book.sheet(1) # access a sheet
|
14
|
+
book = Workbook.open(file_name, :visible => true) # open a workbook
|
15
|
+
sheet = book.sheet(1) # access a worksheet
|
17
16
|
first_cell = sheet[1,1].Value
|
18
17
|
sheet[1,1] = first_cell == "simple" ? "complex" : "simple" # change a cell
|
19
18
|
sleep 1
|
20
|
-
new_book = Workbook.open(file_name, :if_unsaved => :new_excel, :visible => true) # open another
|
19
|
+
new_book = Workbook.open(file_name, :if_unsaved => :new_excel, :visible => true) # open another workbook with the same file name in a new Excel
|
21
20
|
sheet_new_book = new_book.sheet(1)
|
22
|
-
if (not book.alive?) && new_book.alive? && sheet_new_book[1,1].Value == first_cell then # check whether the unsaved
|
21
|
+
if (not book.alive?) && new_book.alive? && sheet_new_book[1,1].Value == first_cell then # check whether the unsaved workbook
|
23
22
|
puts "open with :if_unsaved => :forget : the unsaved book is closed and not saved." # is closed and was not saved
|
24
23
|
end
|
25
24
|
sleep 1
|
26
25
|
sheet_new_book[1,1] = sheet_new_book[1,1].Value == "simple" ? "complex" : "simple" # change a cell
|
27
|
-
# open another
|
26
|
+
# open another workbook in the running Excel application, and make Excel visible, closing the unsaved workbook
|
28
27
|
another_book = Workbook.open(file_name, :if_unsaved => :forget, :visible => true)
|
29
28
|
sleep 1
|
30
29
|
sheet_another_book = another_book.sheet(1)
|
31
30
|
sheet_another_book[1,1] = sheet_another_book[1,1].Value == "simple" ? "complex" : "simple" # change a cell
|
32
|
-
another_book.close(:if_unsaved => :forget ) # close the last
|
33
|
-
book.close(:if_unsaved => :save) # close the first
|
31
|
+
another_book.close(:if_unsaved => :forget ) # close the last workbook without saving it.
|
32
|
+
book.close(:if_unsaved => :save) # close the first workbook and save it before
|
34
33
|
ensure
|
35
34
|
Excel.kill_all # close all workbooks, quit Excel application
|
36
35
|
rm_tmp(dir)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# example_read_only: open with read_only mode. save, close
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require_relative '../../lib/robust_excel_ole'
|
4
|
+
require_relative '../../spec/helpers/create_temporary_dir'
|
5
5
|
require "fileutils"
|
6
6
|
|
7
7
|
include RobustExcelOle
|
@@ -11,17 +11,17 @@ begin
|
|
11
11
|
dir = create_tmpdir
|
12
12
|
file_name = dir + 'workbook.xls'
|
13
13
|
other_file_name = dir + 'different_workbook.xls'
|
14
|
-
book = Workbook.open(file_name, :read_only => true, :visible => true) # open a
|
15
|
-
sheet = book.sheet(1) # access a
|
14
|
+
book = Workbook.open(file_name, :read_only => true, :visible => true) # open a workbook with read_only and make Excel visible
|
15
|
+
sheet = book.sheet(1) # access a worksheet
|
16
16
|
sleep 1
|
17
17
|
sheet[1,1] = sheet[1,1].Value == "simple" ? "complex" : "simple" # change a cell
|
18
18
|
sleep 1
|
19
19
|
begin
|
20
20
|
book.save # simple save.
|
21
|
-
rescue WorkbookReadOnly => msg # raises an exception because
|
21
|
+
rescue WorkbookReadOnly => msg # raises an exception because workbook is opened in read_only mode
|
22
22
|
puts "error: save_as: #{msg.message}"
|
23
23
|
end
|
24
|
-
book.close # close the
|
24
|
+
book.close # close the workbook without saving it
|
25
25
|
ensure
|
26
26
|
Excel.kill_all # close workbooks, quit Excel application
|
27
27
|
rm_tmp(dir)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# example_simple.rb:
|
2
2
|
# open a book, simple save, save_as, close
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
require_relative '../../lib/robust_excel_ole'
|
5
|
+
require_relative '../../spec/helpers/create_temporary_dir'
|
6
6
|
require "fileutils"
|
7
7
|
|
8
8
|
include RobustExcelOle
|
@@ -11,8 +11,7 @@ Excel.kill_all
|
|
11
11
|
begin
|
12
12
|
dir = create_tmpdir
|
13
13
|
file_name = dir + 'workbook.xls'
|
14
|
-
book = Workbook.open(file_name)
|
15
|
-
book.excel.visible = true # make current Excel visible
|
14
|
+
book = Workbook.open(file_name, :visible => true) # open a workbook. default: :read_only => false
|
16
15
|
sheet = book.sheet(1)
|
17
16
|
workbook = book.ole_workbook
|
18
17
|
fullname = workbook.Fullname
|
@@ -48,7 +47,7 @@ begin
|
|
48
47
|
sleep 2
|
49
48
|
new_name_object.Delete
|
50
49
|
sleep 2
|
51
|
-
book.close(:if_unsaved => :forget) # close the
|
50
|
+
book.close(:if_unsaved => :forget) # close the workbook
|
52
51
|
|
53
52
|
ensure
|
54
53
|
Excel.kill_all # close workbooks, quit Excel application
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# example_reuse.rb: open a book in a new Excel and a running Excel instance. make visible
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require_relative '../../lib/robust_excel_ole'
|
4
|
+
require_relative '../../spec/helpers/create_temporary_dir'
|
5
5
|
require "fileutils"
|
6
6
|
|
7
7
|
include RobustExcelOle
|
@@ -13,16 +13,16 @@ begin
|
|
13
13
|
file_name2 = dir + 'different_workbook.xls'
|
14
14
|
file_name3 = dir + 'different_workbook.xls'
|
15
15
|
file_name4 = dir + 'book_with_blank.xls'
|
16
|
-
book1 = Workbook.open(file_name1) # open a
|
16
|
+
book1 = Workbook.open(file_name1) # open a workbook in a new Excel instance since no Excel is open
|
17
17
|
book1.excel.visible = true # make current Excel visible
|
18
18
|
sleep 2
|
19
19
|
book2 = Workbook.open(file_name2) # open a new book in the same Excel instance
|
20
20
|
sleep 2
|
21
|
-
book3 = Workbook.open(file_name3, :force_excel => :new, :visible => true) # open another
|
21
|
+
book3 = Workbook.open(file_name3, :force_excel => :new, :visible => true) # open another workbook in a new Excel instance,
|
22
22
|
sleep 2 # make Excel visible
|
23
|
-
book4 = Workbook.open(file_name4, :visible => true) # open
|
23
|
+
book4 = Workbook.open(file_name4, :visible => true) # open another workbook, and use a running Excel application
|
24
24
|
sleep 2 # (Excel chooses the first Excel application)
|
25
|
-
book1.close # close the
|
25
|
+
book1.close # close the workbooks
|
26
26
|
book2.close
|
27
27
|
book3.close
|
28
28
|
book4.close
|
@@ -5,8 +5,8 @@ LOG_TO_STDOUT = false
|
|
5
5
|
REO_LOG_FILE = "reo2.log"
|
6
6
|
REO_LOG_DIR = "C:/"
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
require_relative '../../lib/robust_excel_ole'
|
9
|
+
require_relative '../../spec/helpers/create_temporary_dir'
|
10
10
|
require "fileutils"
|
11
11
|
|
12
12
|
include RobustExcelOle
|
@@ -16,9 +16,9 @@ begin
|
|
16
16
|
dir = create_tmpdir
|
17
17
|
file_name = dir + 'workbook.xls'
|
18
18
|
other_file_name = dir + 'different_workbook.xls'
|
19
|
-
book = Workbook.open(file_name)
|
19
|
+
book = Workbook.open(file_name, :visible => true) # open a workbook. default: :read_only => false
|
20
20
|
book.excel.visible = true # make current Excel visible
|
21
|
-
sheet = book.sheet(1)
|
21
|
+
sheet = book.sheet(1) # access a worksheet
|
22
22
|
sleep 1
|
23
23
|
sheet[1,1] = sheet[1,1].Value == "simple" ? "complex" : "simple" # change a cell
|
24
24
|
sleep 1
|
@@ -30,7 +30,7 @@ begin
|
|
30
30
|
end
|
31
31
|
book.save_as(other_file_name, :if_exists => :overwrite) # save_as with :if_exists => :overwrite
|
32
32
|
puts "save_as: saved successfully with option :if_exists => :overwrite"
|
33
|
-
book.close # close the
|
33
|
+
book.close # close the workbook
|
34
34
|
ensure
|
35
35
|
Excel.kill_all # close workbooks, quit Excel application
|
36
36
|
#rm_tmp(dir)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# example_unobtrusively.rb:
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require_relative '../../lib/robust_excel_ole'
|
4
|
+
require_relative '../../spec/helpers/create_temporary_dir'
|
5
5
|
require "fileutils"
|
6
6
|
|
7
7
|
include RobustExcelOle
|
@@ -10,7 +10,7 @@ Excel.kill_all
|
|
10
10
|
begin
|
11
11
|
dir = create_tmpdir
|
12
12
|
simple_file = dir + 'workbook.xls'
|
13
|
-
book = Workbook.open(simple_file, :visible => true) # open a
|
13
|
+
book = Workbook.open(simple_file, :visible => true) # open a workbook, make Excel visible
|
14
14
|
old_sheet = book.sheet(1)
|
15
15
|
p "1st cell: #{old_sheet[1,1].Value}"
|
16
16
|
sleep 2
|
@@ -21,7 +21,7 @@ begin
|
|
21
21
|
new_sheet = book.sheet(1)
|
22
22
|
p "1st cell: #{new_sheet[1,1].Value}"
|
23
23
|
p "book saved" if book.Saved
|
24
|
-
book.close # close the
|
24
|
+
book.close # close the workbook
|
25
25
|
ensure
|
26
26
|
Excel.kill_all # close all workbooks, quit Excel application
|
27
27
|
rm_tmp(dir)
|
@@ -67,15 +67,15 @@ module RobustExcelOle
|
|
67
67
|
result
|
68
68
|
end
|
69
69
|
|
70
|
+
# @private
|
70
71
|
def consider_networkpaths(filename)
|
71
72
|
network = WIN32OLE.new('WScript.Network')
|
72
73
|
drives = network.enumnetworkdrives
|
73
74
|
drive_letter, filename_after_drive_letter = filename.split(':')
|
75
|
+
found_filename = nil
|
74
76
|
# if filename starts with a drive letter not c and this drive exists,
|
75
77
|
# then if there is the corresponding host_share_path in the bookstore,
|
76
|
-
# then take the corresponding workbooks
|
77
|
-
# otherwise (there is an usual file path) find in the bookstore the workbooks of which filenames
|
78
|
-
# ends with the latter part of the given filename (after the drive letter)
|
78
|
+
# then take the corresponding workbooks
|
79
79
|
if drive_letter != 'c' && drive_letter != filename
|
80
80
|
for i in 0 .. drives.Count-1
|
81
81
|
next if i % 2 == 1
|
@@ -83,8 +83,7 @@ module RobustExcelOle
|
|
83
83
|
hostname_share = drives.Item(i+1).gsub('\\','/').gsub('//','').downcase
|
84
84
|
break
|
85
85
|
end
|
86
|
-
end
|
87
|
-
found_filename = nil
|
86
|
+
end
|
88
87
|
@filename2books.each do |stored_filename,_|
|
89
88
|
if hostname_share && stored_filename
|
90
89
|
if stored_filename[0] == '/'
|
@@ -95,8 +94,6 @@ module RobustExcelOle
|
|
95
94
|
found_filename = stored_filename
|
96
95
|
break
|
97
96
|
end
|
98
|
-
elsif found_filename.nil? && stored_filename.end_with?(filename_after_drive_letter)
|
99
|
-
found_filename = stored_filename
|
100
97
|
end
|
101
98
|
end
|
102
99
|
end
|
@@ -104,8 +101,6 @@ module RobustExcelOle
|
|
104
101
|
# if filename starts with a host name and share, and this is an existing host name share path,
|
105
102
|
# then if there are workbooks with the corresponding drive letter,
|
106
103
|
# then take these workbooks,
|
107
|
-
# otherwise (there is an usual file path) find in the bookstore the workbooks of which filenames
|
108
|
-
# ends with the latter part of the given filename (after the drive letter)
|
109
104
|
index_hostname = filename[1,filename.length].index('/')+2
|
110
105
|
index_hostname_share = filename[index_hostname,filename.length].index('/')
|
111
106
|
hostname_share_in_filename = filename[1,index_hostname+index_hostname_share-1]
|
@@ -126,29 +121,10 @@ module RobustExcelOle
|
|
126
121
|
if drive_letter && stored_filename.start_with?(drive_letter.downcase) && stored_filename.end_with?(filename_after_hostname_share)
|
127
122
|
found_filename = stored_filename
|
128
123
|
break
|
129
|
-
elsif found_filename.nil? && stored_filename.end_with?(filename_after_hostname_share)
|
130
|
-
found_filename = stored_filename
|
131
124
|
end
|
132
125
|
end
|
133
126
|
end
|
134
127
|
end
|
135
|
-
else
|
136
|
-
# if filename is an usual file path,
|
137
|
-
# then find in the bookstore a workbook of which filename starts with
|
138
|
-
# a drive letter or a host name
|
139
|
-
@filename2books.each do |stored_filename,_|
|
140
|
-
drive_letter, _ = stored_filename.split(':')
|
141
|
-
stored_filename_end = if drive_letter != stored_filename && drive_letter != 'c'
|
142
|
-
stored_filename[stored_filename.index(':')+1,stored_filename.length]
|
143
|
-
elsif stored_filename[0] == '/'
|
144
|
-
index_after_hostname = stored_filename[1,stored_filename.length].index('/')
|
145
|
-
stored_filename[index_after_hostname+1, stored_filename.length]
|
146
|
-
end
|
147
|
-
if stored_filename_end && filename.end_with?(stored_filename_end)
|
148
|
-
found_filename = stored_filename
|
149
|
-
break
|
150
|
-
end
|
151
|
-
end
|
152
128
|
end
|
153
129
|
@filename2books[found_filename]
|
154
130
|
end
|
@@ -16,7 +16,7 @@ module RobustExcelOle
|
|
16
16
|
|
17
17
|
class Excel < RangeOwners
|
18
18
|
attr_accessor :ole_excel
|
19
|
-
attr_accessor :created
|
19
|
+
#attr_accessor :created
|
20
20
|
attr_accessor :workbook
|
21
21
|
|
22
22
|
# setter methods are implemented below
|
@@ -78,13 +78,13 @@ module RobustExcelOle
|
|
78
78
|
#ole_xl = current_excel if options[:reuse] == true
|
79
79
|
if options[:reuse] == true && ole_xl.nil?
|
80
80
|
ole_xl = if RUBY_PLATFORM =~ /java/
|
81
|
-
excel_instance = known_excel_instance
|
81
|
+
excel_instance = known_excel_instance
|
82
82
|
excel_instance.ole_excel unless excel_instance.nil?
|
83
83
|
else
|
84
84
|
current_excel
|
85
85
|
end
|
86
86
|
end
|
87
|
-
connected = (not ole_xl.nil?)
|
87
|
+
connected = (not ole_xl.nil?) && win32ole_excel.nil?
|
88
88
|
ole_xl ||= WIN32OLE.new('Excel.Application')
|
89
89
|
hwnd = ole_xl.HWnd
|
90
90
|
stored = hwnd2excel(hwnd)
|
@@ -97,18 +97,15 @@ module RobustExcelOle
|
|
97
97
|
@@hwnd2excel[hwnd] = WeakRef.new(result)
|
98
98
|
end
|
99
99
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
options = { :displayalerts => :if_visible, :visible => false, :screenupdating => true }.merge(options)
|
105
|
-
end
|
106
|
-
result.visible = options[:visible] unless options[:visible].nil?
|
107
|
-
result.displayalerts = options[:displayalerts] unless options[:displayalerts].nil?
|
108
|
-
result.calculation = options[:calculation] unless options[:calculation].nil?
|
109
|
-
result.screenupdating = options[:screenupdating] unless options[:screenupdating].nil?
|
110
|
-
result.created = !reused
|
100
|
+
begin
|
101
|
+
reused = options[:reuse] && stored && stored.alive?
|
102
|
+
unless reused || connected
|
103
|
+
options = { :displayalerts => :if_visible, :visible => false, :screenupdating => true }.merge(options)
|
111
104
|
end
|
105
|
+
result.visible = options[:visible] unless options[:visible].nil?
|
106
|
+
result.displayalerts = options[:displayalerts] unless options[:displayalerts].nil?
|
107
|
+
result.calculation = options[:calculation] unless options[:calculation].nil?
|
108
|
+
result.screenupdating = options[:screenupdating] unless options[:screenupdating].nil?
|
112
109
|
end
|
113
110
|
result
|
114
111
|
end
|
@@ -246,8 +243,8 @@ module RobustExcelOle
|
|
246
243
|
end
|
247
244
|
begin
|
248
245
|
@ole_excel.Workbooks.Close
|
249
|
-
rescue
|
250
|
-
if
|
246
|
+
rescue
|
247
|
+
if $!.message =~ /kann nicht zugeordnet werden/ or $!.message =~ /800A03EC/
|
251
248
|
raise ExcelREOError, 'user canceled or runtime error'
|
252
249
|
else
|
253
250
|
raise UnexpectedREOError, "unknown WIN32OLERuntimeError: #{msg.message}"
|
@@ -658,11 +655,6 @@ module RobustExcelOle
|
|
658
655
|
ole_workbooks.each do |ow|
|
659
656
|
wb = workbook_class.new(ow, opts)
|
660
657
|
block_given? ? (yield wb) : wb
|
661
|
-
#if block_given?
|
662
|
-
# yield workbook_class.new(ow, opts)
|
663
|
-
#else
|
664
|
-
# workbook_class.new(ow, opts)
|
665
|
-
#end
|
666
658
|
end
|
667
659
|
end
|
668
660
|
|
@@ -694,7 +686,10 @@ module RobustExcelOle
|
|
694
686
|
# @param [String] name the name of the range
|
695
687
|
# @param [Variant] value the contents of the range
|
696
688
|
def []=(name, value)
|
697
|
-
|
689
|
+
old_color_if_modified = workbook.color_if_modified
|
690
|
+
workbook.color_if_modified = 42 unless workbook.nil? # aqua-marin
|
691
|
+
set_namevalue_glob(name,value)
|
692
|
+
workbook.color_if_modified = old_color_if_modified
|
698
693
|
end
|
699
694
|
|
700
695
|
# @private
|
@@ -6,7 +6,7 @@ module General
|
|
6
6
|
def absolute_path(file)
|
7
7
|
file = File.expand_path(file)
|
8
8
|
file = RobustExcelOle::Cygwin.cygpath('-w', file) if RUBY_PLATFORM =~ /cygwin/
|
9
|
-
WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName(file)
|
9
|
+
WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName(file).tr('/','\\')
|
10
10
|
end
|
11
11
|
|
12
12
|
# @private
|
@@ -64,33 +64,26 @@ end
|
|
64
64
|
|
65
65
|
# @private
|
66
66
|
class WIN32OLE
|
67
|
+
|
68
|
+
include RobustExcelOle
|
67
69
|
|
68
70
|
# promoting WIN32OLE objects to RobustExcelOle objects
|
69
71
|
def to_reo
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
class2method = [{Excel => :Hwnd}, {Workbook => :FullName}, {Worksheet => :Copy}, {Range => :Address}]
|
73
|
+
class2method.each do |element|
|
74
|
+
classname = element.first.first
|
75
|
+
method = element.first.last
|
74
76
|
begin
|
75
|
-
self.
|
76
|
-
|
77
|
+
self.send(method)
|
78
|
+
return classname.new(self)
|
77
79
|
rescue
|
78
|
-
|
79
|
-
self.Copy
|
80
|
-
RobustExcelOle::Worksheet.new(self)
|
81
|
-
rescue
|
82
|
-
begin
|
83
|
-
self.Address
|
84
|
-
RobustExcelOle::Range.new(self)
|
85
|
-
rescue
|
86
|
-
self
|
87
|
-
end
|
88
|
-
end
|
80
|
+
next
|
89
81
|
end
|
90
82
|
end
|
91
83
|
end
|
92
84
|
end
|
93
85
|
|
86
|
+
|
94
87
|
# @private
|
95
88
|
class ::String
|
96
89
|
def / path_part
|
@@ -61,18 +61,16 @@ module RobustExcelOle
|
|
61
61
|
# sets the contents of a range
|
62
62
|
# @param [String] name the name of a range
|
63
63
|
# @param [Variant] value the contents of the range
|
64
|
-
|
65
|
-
# @param [Hash] opts :color [FixNum] the color when setting the contents
|
66
|
-
def set_namevalue_glob(name, value, opts = { :color => 0 })
|
64
|
+
def set_namevalue_glob(name, value, opts = { }) # opts is deprecated
|
67
65
|
begin
|
68
66
|
name_obj = begin
|
69
67
|
name_object(name)
|
70
68
|
rescue NameNotFound => msg
|
71
69
|
raise
|
72
|
-
end
|
70
|
+
end
|
73
71
|
ole_range = name_object(name).RefersToRange
|
74
|
-
|
75
|
-
|
72
|
+
workbook.color_if_modified = opts[:color] unless opts[:color].nil?
|
73
|
+
ole_range.Interior.ColorIndex = workbook.color_if_modified unless workbook.color_if_modified.nil?
|
76
74
|
if RUBY_PLATFORM !~ /java/
|
77
75
|
ole_range.Value = value
|
78
76
|
else
|
@@ -128,19 +126,17 @@ module RobustExcelOle
|
|
128
126
|
|
129
127
|
# assigns a value to a range given a locally defined name
|
130
128
|
# @param [String] name the name of a range
|
131
|
-
# @param [Variant] value the assigned value
|
132
|
-
|
133
|
-
def set_namevalue(name, value, opts = { :color => 0 })
|
129
|
+
# @param [Variant] value the assigned value
|
130
|
+
def set_namevalue(name, value, opts = { }) # opts is deprecated
|
134
131
|
begin
|
135
|
-
return set_namevalue_glob(name, value, opts) if self.is_a?(Workbook)
|
132
|
+
return set_namevalue_glob(name, value, opts) if self.is_a?(Workbook) # opts deprecated
|
136
133
|
ole_range = self.Range(name)
|
137
134
|
rescue # WIN32OLERuntimeError
|
138
135
|
raise NameNotFound, "name #{name.inspect} not in #{self.inspect}"
|
139
136
|
end
|
140
137
|
begin
|
141
|
-
|
142
|
-
|
143
|
-
#range.Value = value
|
138
|
+
workbook.color_if_modified = opts[:color] unless opts[:color].nil?
|
139
|
+
ole_range.Interior.ColorIndex = workbook.color_if_modified unless workbook.color_if_modified.nil?
|
144
140
|
if RUBY_PLATFORM !~ /java/
|
145
141
|
ole_range.Value = value
|
146
142
|
else
|
@@ -164,8 +160,8 @@ module RobustExcelOle
|
|
164
160
|
end
|
165
161
|
|
166
162
|
# @private
|
167
|
-
def set_nameval(name, value
|
168
|
-
set_namevalue_glob(name, value
|
163
|
+
def set_nameval(name, value) # :deprecated: #
|
164
|
+
set_namevalue_glob(name, value)
|
169
165
|
end
|
170
166
|
|
171
167
|
# @private
|
@@ -174,8 +170,8 @@ module RobustExcelOle
|
|
174
170
|
end
|
175
171
|
|
176
172
|
# @private
|
177
|
-
def set_rangeval(name, value
|
178
|
-
set_namevalue(name, value
|
173
|
+
def set_rangeval(name, value) # :deprecated: #
|
174
|
+
set_namevalue(name, value)
|
179
175
|
end
|
180
176
|
|
181
177
|
# creates a range from a given defined name or address
|
@@ -195,10 +191,7 @@ module RobustExcelOle
|
|
195
191
|
end
|
196
192
|
if self.is_a?(Worksheet) && (range.nil? || (address2 != :__not_provided))
|
197
193
|
address = name_or_address
|
198
|
-
address = [name_or_address,address2] unless address2 == :__not_provided
|
199
|
-
#self.Names.Add('Name' => '__dummy001', 'RefersToR1C1' => '=' + Address.r1c1(address))
|
200
|
-
#not_given = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_NULL)
|
201
|
-
#self.Names.Add('__dummy001',not_given,true,not_given,not_given,not_given,not_given,not_given,not_given,'=' + Address.r1c1(address))
|
194
|
+
address = [name_or_address,address2] unless address2 == :__not_provided
|
202
195
|
self.Names.Add('__dummy001',nil,true,nil,nil,nil,nil,nil,nil,'=' + Address.r1c1(address))
|
203
196
|
range = RobustExcelOle::Range.new(name_object('__dummy001').RefersToRange)
|
204
197
|
self.Names.Item('__dummy001').Delete
|
@@ -222,10 +215,7 @@ module RobustExcelOle
|
|
222
215
|
# @params [Address] address of the range
|
223
216
|
def add_name(name, addr, addr_deprecated = :__not_provided)
|
224
217
|
addr = [addr,addr_deprecated] unless addr_deprecated == :__not_provided
|
225
|
-
begin
|
226
|
-
#self.Names.Add('Name' => name, 'RefersToR1C1' => '=' + Address.r1c1(addr))
|
227
|
-
#not_given = WIN32OLE_VARIANT.new(nil, WIN32OLE::VARIANT::VT_NULL)
|
228
|
-
#self.Names.Add(name, not_given, true, not_given, not_given, not_given, not_given, not_given, not_given, '=' + Address.r1c1(addr))
|
218
|
+
begin
|
229
219
|
self.Names.Add(name, nil, true, nil, nil, nil, nil, nil, nil, '=' + Address.r1c1(addr))
|
230
220
|
rescue # WIN32OLERuntimeError => msg
|
231
221
|
raise RangeNotEvaluatable, "cannot add name #{name.inspect} to range #{addr.inspect}"
|
@@ -243,12 +233,12 @@ module RobustExcelOle
|
|
243
233
|
def rename_range(name, new_name)
|
244
234
|
begin
|
245
235
|
item = self.Names.Item(name)
|
246
|
-
rescue WIN32OLERuntimeError
|
236
|
+
rescue # WIN32OLERuntimeError
|
247
237
|
raise NameNotFound, "name #{name.inspect} not in #{File.basename(self.stored_filename).inspect}"
|
248
238
|
end
|
249
239
|
begin
|
250
240
|
item.Name = new_name
|
251
|
-
rescue WIN32OLERuntimeError
|
241
|
+
rescue # WIN32OLERuntimeError
|
252
242
|
raise UnexpectedREOError, "name error in #{File.basename(self.stored_filename).inspect}"
|
253
243
|
end
|
254
244
|
end
|