robust_excel_ole 0.2.1 → 0.2.2.1
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.
- data/README.rdoc +130 -77
- data/examples/edit_sheets/example_print_cells.rb +43 -0
- data/examples/open_save_close/example_control_to_excel.rb +10 -6
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +9 -6
- data/examples/open_save_close/example_if_obstructed_forget.rb +9 -6
- data/examples/open_save_close/example_if_obstructed_save.rb +7 -5
- data/examples/open_save_close/example_if_unsaved_accept.rb +6 -3
- data/examples/open_save_close/example_if_unsaved_forget.rb +7 -4
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +38 -0
- data/examples/open_save_close/example_read_only.rb +8 -6
- data/examples/open_save_close/example_reuse.rb +7 -4
- data/examples/open_save_close/example_simple.rb +9 -5
- data/examples/save_sheets/example_save_sheets.rb +22 -14
- data/lib/robust_excel_ole.rb +1 -1
- data/lib/robust_excel_ole/book.rb +42 -55
- data/lib/robust_excel_ole/cell.rb +1 -1
- data/lib/robust_excel_ole/{excel_app.rb → excel.rb} +97 -89
- data/lib/robust_excel_ole/range.rb +1 -1
- data/lib/robust_excel_ole/robustexcelole.sublime-workspace +347 -347
- data/lib/robust_excel_ole/sheet.rb +1 -1
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/spec_helper.rb +3 -3
- data/spec/book_spec.rb +53 -67
- data/spec/cell_spec.rb +10 -2
- data/spec/data/merge_cells.xls +0 -0
- data/spec/data/simple.xls +0 -0
- data/spec/{excel_app_spec.rb → excel_spec.rb} +52 -36
- data/spec/helpers/create_temporary_dir.rb +11 -0
- data/spec/helpers/key_sender.rb +1 -1
- data/spec/range_spec.rb +9 -1
- data/spec/sheet_spec.rb +11 -3
- data/spec/spec_helper.rb +3 -3
- metadata +9 -7
- data/examples/print_cells/example_print_cells.rb +0 -43
- data/robust_excel_ole_example.rb +0 -29
@@ -2,15 +2,17 @@
|
|
2
2
|
# open with :if_unsaved => :forget, :new_app, close with :if_unsaved => :save
|
3
3
|
|
4
4
|
require File.join(File.dirname(__FILE__), '../../lib/robust_excel_ole')
|
5
|
+
require File.join(File.dirname(__FILE__), '../../spec/helpers/create_temporary_dir')
|
6
|
+
require "fileutils"
|
5
7
|
|
6
8
|
include RobustExcelOle
|
7
9
|
|
8
|
-
|
10
|
+
Excel.close_all
|
9
11
|
begin
|
10
|
-
dir =
|
12
|
+
dir = create_tmpdir
|
11
13
|
file_name = dir + 'simple.xls'
|
12
14
|
book = Book.open(file_name) # open a book
|
13
|
-
|
15
|
+
Excel.current.Visible = true # make Excel visible
|
14
16
|
sleep 1
|
15
17
|
sheet = book[0] # access a sheet
|
16
18
|
first_cell = sheet[0,0].value
|
@@ -30,5 +32,6 @@ begin
|
|
30
32
|
new_book.close(:if_unsaved => :forget )
|
31
33
|
another_book.close
|
32
34
|
ensure
|
33
|
-
|
35
|
+
Excel.close_all # close all workbooks, quit Excel application
|
36
|
+
rm_tmp(dir)
|
34
37
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# example_ifunsaved_forget_more.rb:
|
2
|
+
# open with :if_unsaved => :forget, :new_app, close with :if_unsaved => :save
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__), '../../lib/robust_excel_ole')
|
5
|
+
require File.join(File.dirname(__FILE__), '../../spec/helpers/create_temporary_dir')
|
6
|
+
require "fileutils"
|
7
|
+
|
8
|
+
include RobustExcelOle
|
9
|
+
|
10
|
+
Excel.close_all
|
11
|
+
begin
|
12
|
+
dir = create_tmpdir
|
13
|
+
file_name = dir + 'simple.xls'
|
14
|
+
book = Book.open(file_name) # open a book
|
15
|
+
Excel.current.Visible = true # make Excel visible
|
16
|
+
sleep 1
|
17
|
+
sheet = book[0] # access a sheet
|
18
|
+
first_cell = sheet[0,0].value
|
19
|
+
sheet[0,0] = first_cell == "simple" ? "complex" : "simple" # change a cell
|
20
|
+
sleep 1
|
21
|
+
new_book = Book.open(file_name, :if_unsaved => :new_app, :visible => true) # open another book with the same file name in a new Excel
|
22
|
+
sheet_new_book = new_book[0]
|
23
|
+
if (not book.alive?) && new_book.alive? && sheet_new_book[0,0].value == first_cell then # check whether the unsaved book
|
24
|
+
puts "open with :if_unsaved => :forget : the unsaved book is closed and not saved." # is closed and was not saved
|
25
|
+
end
|
26
|
+
sleep 1
|
27
|
+
sheet_new_book[0,0] = sheet_new_book[0,0].value == "simple" ? "complex" : "simple" # change a cell
|
28
|
+
# open another book in the running Excel application, and make Excel visible, closing the unsaved book
|
29
|
+
another_book = Book.open(file_name, :if_unsaved => :forget, :visible => true)
|
30
|
+
sleep 1
|
31
|
+
sheet_another_book = another_book[0]
|
32
|
+
sheet_another_book[0,0] = sheet_another_book[0,0].value == "simple" ? "complex" : "simple" # change a cell
|
33
|
+
another_book.close(:if_unsaved => :forget ) # close the last book without saving it.
|
34
|
+
book.close(:if_unsaved => :save) # close the first book and save it before
|
35
|
+
ensure
|
36
|
+
Excel.close_all # close all workbooks, quit Excel application
|
37
|
+
rm_tmp(dir)
|
38
|
+
end
|
@@ -1,17 +1,18 @@
|
|
1
1
|
# example_read_only: open with read_only mode. save, close
|
2
2
|
|
3
3
|
require File.join(File.dirname(__FILE__), '../../lib/robust_excel_ole')
|
4
|
+
require File.join(File.dirname(__FILE__), '../../spec/helpers/create_temporary_dir')
|
5
|
+
require "fileutils"
|
4
6
|
|
5
7
|
include RobustExcelOle
|
6
8
|
|
7
|
-
|
9
|
+
Excel.close_all
|
8
10
|
begin
|
9
|
-
dir =
|
11
|
+
dir = create_tmpdir
|
10
12
|
file_name = dir + 'simple.xls'
|
11
13
|
other_file_name = dir + 'different_simple.xls'
|
12
|
-
# open a book with read_only and make Excel visible
|
13
|
-
|
14
|
-
sheet = book[0] # access a sheet
|
14
|
+
book = Book.open(file_name, :read_only => true, :visible => true) # open a book with read_only and make Excel visible
|
15
|
+
sheet = book[0] # access a sheet
|
15
16
|
sleep 1
|
16
17
|
sheet[0,0] = sheet[0,0].value == "simple" ? "complex" : "simple" # change a cell
|
17
18
|
sleep 1
|
@@ -22,6 +23,7 @@ begin
|
|
22
23
|
end
|
23
24
|
book.close # close the book without saving it
|
24
25
|
ensure
|
25
|
-
|
26
|
+
Excel.close_all # close workbooks, quit Excel application
|
27
|
+
rm_tmp(dir)
|
26
28
|
end
|
27
29
|
|
@@ -1,18 +1,20 @@
|
|
1
1
|
# example_reuse.rb: open a book in a running Excel application and in a new one. make visible
|
2
2
|
|
3
3
|
require File.join(File.dirname(__FILE__), '../../lib/robust_excel_ole')
|
4
|
+
require File.join(File.dirname(__FILE__), '../../spec/helpers/create_temporary_dir')
|
5
|
+
require "fileutils"
|
4
6
|
|
5
7
|
include RobustExcelOle
|
6
8
|
|
7
|
-
|
9
|
+
Excel.close_all
|
8
10
|
begin
|
9
|
-
dir =
|
11
|
+
dir = create_tmpdir
|
10
12
|
file_name1 = dir + 'simple.xls'
|
11
13
|
file_name2 = dir + 'different_simple.xls'
|
12
14
|
file_name3 = dir + 'different_simple.xls'
|
13
15
|
file_name4 = dir + 'book_with_blank.xls'
|
14
16
|
book1 = Book.open(file_name1) # open a book in a new Excel application since no Excel is open
|
15
|
-
|
17
|
+
Excel.current.Visible = true # make Excel visible
|
16
18
|
sleep 2
|
17
19
|
book2 = Book.open(file_name2) # open a new book in the same Excel application
|
18
20
|
sleep 2 # (by default: :reuse => true)
|
@@ -25,7 +27,8 @@ begin
|
|
25
27
|
book3.close
|
26
28
|
book4.close
|
27
29
|
ensure
|
28
|
-
|
30
|
+
Excel.close_all # close all workbooks, quit Excel application
|
31
|
+
rm_tmp(dir)
|
29
32
|
end
|
30
33
|
|
31
34
|
|
@@ -1,16 +1,19 @@
|
|
1
|
-
# example_simple.rb:
|
1
|
+
# example_simple.rb:
|
2
|
+
# open a book, simple save, save_as, close
|
2
3
|
|
3
4
|
require File.join(File.dirname(__FILE__), '../../lib/robust_excel_ole')
|
5
|
+
require File.join(File.dirname(__FILE__), '../../spec/helpers/create_temporary_dir')
|
6
|
+
require "fileutils"
|
4
7
|
|
5
8
|
include RobustExcelOle
|
6
9
|
|
7
|
-
|
10
|
+
Excel.close_all
|
8
11
|
begin
|
9
|
-
dir =
|
12
|
+
dir = create_tmpdir
|
10
13
|
file_name = dir + 'simple.xls'
|
11
14
|
other_file_name = dir + 'different_simple.xls'
|
12
15
|
book = Book.open(file_name) # open a book. default: :read_only => false
|
13
|
-
|
16
|
+
Excel.current.Visible = true # make Excel visible
|
14
17
|
sheet = book[0] # access a sheet
|
15
18
|
sleep 1
|
16
19
|
sheet[0,0] = sheet[0,0].value == "simple" ? "complex" : "simple" # change a cell
|
@@ -25,6 +28,7 @@ begin
|
|
25
28
|
puts "save_as: saved successfully with option :if_exists => :overwrite"
|
26
29
|
book.close # close the book
|
27
30
|
ensure
|
28
|
-
|
31
|
+
Excel.close_all # close workbooks, quit Excel application
|
32
|
+
rm_tmp(dir)
|
29
33
|
end
|
30
34
|
|
@@ -1,30 +1,38 @@
|
|
1
|
-
#
|
1
|
+
# example_save_sheets.rb:
|
2
|
+
# save the sheets of a book as separate books
|
2
3
|
|
3
4
|
require File.join(File.dirname(__FILE__), '../../lib/robust_excel_ole')
|
4
|
-
|
5
|
+
require File.join(File.dirname(__FILE__), '../../spec/helpers/create_temporary_dir')
|
5
6
|
require "fileutils"
|
6
7
|
|
7
8
|
include RobustExcelOle
|
8
9
|
|
9
|
-
|
10
|
+
Excel.close_all
|
10
11
|
begin
|
11
|
-
dir =
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
dir = create_tmpdir
|
13
|
+
suffix = '.xls'
|
14
|
+
book_name = dir + 'book_with_blank'
|
15
|
+
book = Book.open(book_name + suffix) # open a book with several sheets
|
16
|
+
Excel.current.Visible = true # make Excel visible
|
16
17
|
i = 0
|
17
18
|
book.each do |sheet|
|
18
19
|
i = i + 1
|
19
20
|
puts "#{i}. sheet:"
|
20
|
-
|
21
|
-
puts "
|
22
|
-
|
21
|
+
sheet_name = book_name + "_sheet#{i}"
|
22
|
+
puts "sheet_name: #{sheet_name}"
|
23
|
+
excel = Excel.create
|
24
|
+
excel.Workbooks.Add # generate an empty workbook
|
25
|
+
empty_workbook = excel.Workbooks.Item(1) # save it
|
26
|
+
empty_workbook.SaveAs(absolute_path(sheet_name), XlExcel8) # close it
|
27
|
+
empty_workbook.Close
|
28
|
+
sheet_book = Book.open(absolute_path(sheet_name) + suffix) # open the book
|
29
|
+
sheet_book.add_sheet sheet # add the sheet
|
30
|
+
sheet_book.save # save it
|
31
|
+
sheet_book.close # close it
|
23
32
|
end
|
24
|
-
# generate empty book
|
25
|
-
# book_sheet = ExcelApp.Workbooks.Add
|
26
33
|
|
27
34
|
ensure
|
28
|
-
|
35
|
+
Excel.close_all # close workbooks, quit Excel application
|
36
|
+
rm_tmp(dir)
|
29
37
|
end
|
30
38
|
|
data/lib/robust_excel_ole.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require "win32ole"
|
2
|
-
require File.join(File.dirname(__FILE__), 'robust_excel_ole/
|
2
|
+
require File.join(File.dirname(__FILE__), 'robust_excel_ole/excel')
|
3
3
|
require File.join(File.dirname(__FILE__), 'robust_excel_ole/book')
|
4
4
|
require File.join(File.dirname(__FILE__), 'robust_excel_ole/sheet')
|
5
5
|
require File.join(File.dirname(__FILE__), 'robust_excel_ole/cell')
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
|
2
3
|
require 'weakref'
|
3
4
|
|
4
5
|
module RobustExcelOle
|
@@ -8,7 +9,7 @@ module RobustExcelOle
|
|
8
9
|
|
9
10
|
|
10
11
|
class << self
|
11
|
-
|
12
|
+
|
12
13
|
# opens a book.
|
13
14
|
#
|
14
15
|
# options:
|
@@ -17,7 +18,7 @@ module RobustExcelOle
|
|
17
18
|
# :raise -> raise an exception (default)
|
18
19
|
# :forget -> close the unsaved book, open the new book
|
19
20
|
# :accept -> let the unsaved book open
|
20
|
-
# :
|
21
|
+
# :alert -> give control to excel
|
21
22
|
# :new_app -> open the new book in a new excel application
|
22
23
|
# :if_obstructed if a book with the same name in a different path is open, then
|
23
24
|
# :raise -> raise an exception (default)
|
@@ -27,7 +28,7 @@ module RobustExcelOle
|
|
27
28
|
# raise an exception otherwise
|
28
29
|
# :new_app -> open the new book in a new excel application
|
29
30
|
# :reuse use a running Excel-application (default: true)
|
30
|
-
# :
|
31
|
+
# :excel an Excel application (default: nil)
|
31
32
|
# :displayalerts allow display alerts in Excel (default: false)
|
32
33
|
# :visible make visibe in Excel (default: false)
|
33
34
|
def open(file, options={ :reuse => true}, &block)
|
@@ -39,22 +40,22 @@ module RobustExcelOle
|
|
39
40
|
def initialize(file, opts={ }, &block)
|
40
41
|
@options = {
|
41
42
|
:reuse => true,
|
42
|
-
:
|
43
|
+
:excel => nil,
|
43
44
|
:read_only => false,
|
44
45
|
:if_unsaved => :raise,
|
45
46
|
:if_obstructed => :raise
|
46
47
|
}.merge(opts)
|
47
|
-
|
48
|
+
excel_options = {:reuse => true}.merge(opts).delete_if{|k,v|
|
48
49
|
k== :read_only || k== :if_unsaved || k == :if_obstructed}
|
49
50
|
if not File.exist?(file)
|
50
51
|
raise ExcelErrorOpen, "file #{file} not found"
|
51
52
|
end
|
52
|
-
@
|
53
|
-
workbooks = @
|
53
|
+
@excel = @options[:excel] ? excel_options[:excel] : Excel.new(excel_options)
|
54
|
+
workbooks = @excel.Workbooks
|
54
55
|
@workbook = workbooks.Item(File.basename(file)) rescue nil
|
55
56
|
if @workbook then
|
56
57
|
obstructed_by_other_book = (File.basename(file) == File.basename(@workbook.Fullname)) &&
|
57
|
-
(not (absolute_path(file) == @workbook.Fullname))
|
58
|
+
(not (RobustExcelOle::absolute_path(file) == @workbook.Fullname))
|
58
59
|
if obstructed_by_other_book then
|
59
60
|
# @workbook is not the desired workbook
|
60
61
|
case @options[:if_obstructed]
|
@@ -72,8 +73,8 @@ module RobustExcelOle
|
|
72
73
|
@workbook.Close
|
73
74
|
end
|
74
75
|
when :new_app
|
75
|
-
|
76
|
-
@
|
76
|
+
excel_options[:reuse] = false
|
77
|
+
@excel = Excel.new(excel_options)
|
77
78
|
@workbook = nil
|
78
79
|
else
|
79
80
|
raise ExcelErrorOpen, ":if_obstructed: invalid option"
|
@@ -89,12 +90,12 @@ module RobustExcelOle
|
|
89
90
|
@workbook.Close
|
90
91
|
when :accept
|
91
92
|
#nothing
|
92
|
-
when :
|
93
|
-
old_displayalerts = @
|
94
|
-
@
|
93
|
+
when :alert
|
94
|
+
old_displayalerts = @excel.DisplayAlerts # :nodoc:
|
95
|
+
@excel.DisplayAlerts = true # :nodoc:
|
95
96
|
when :new_app
|
96
|
-
|
97
|
-
@
|
97
|
+
excel_options[:reuse] = false
|
98
|
+
@excel = Excel.new(excel_options)
|
98
99
|
@workbook = nil
|
99
100
|
else
|
100
101
|
raise ExcelErrorOpen, ":if_unsaved: invalid option"
|
@@ -104,17 +105,17 @@ module RobustExcelOle
|
|
104
105
|
end
|
105
106
|
begin
|
106
107
|
# if book not open (was not open,was closed with option :forget or shall be opened in new application)
|
107
|
-
# or :if_unsaved => :
|
108
|
-
if ((not alive?) || (@options[:if_unsaved] == :
|
108
|
+
# or :if_unsaved => :alert
|
109
|
+
if ((not alive?) || (@options[:if_unsaved] == :alert)) then
|
109
110
|
begin
|
110
|
-
@workbook = @
|
111
|
+
@workbook = @excel.Workbooks.Open(RobustExcelOle::absolute_path(file),{ 'ReadOnly' => @options[:read_only] })
|
111
112
|
rescue WIN32OLERuntimeError
|
112
113
|
raise ExcelUserCanceled, "open: canceled by user"
|
113
114
|
end
|
114
115
|
end
|
115
116
|
ensure
|
116
|
-
if @options[:if_unsaved] == :
|
117
|
-
@
|
117
|
+
if @options[:if_unsaved] == :alert then
|
118
|
+
@excel.DisplayAlerts = old_displayalerts # :nodoc:
|
118
119
|
end
|
119
120
|
end
|
120
121
|
if block
|
@@ -134,7 +135,7 @@ module RobustExcelOle
|
|
134
135
|
# :raise -> raise an exception (default)
|
135
136
|
# :save -> save the book before it is closed
|
136
137
|
# :forget -> close the book
|
137
|
-
# :
|
138
|
+
# :alert -> give control to excel
|
138
139
|
def close(opts = {:if_unsaved => :raise})
|
139
140
|
if ((alive?) && (not @workbook.Saved) && (not @options[:read_only])) then
|
140
141
|
case opts[:if_unsaved]
|
@@ -144,9 +145,9 @@ module RobustExcelOle
|
|
144
145
|
save
|
145
146
|
when :forget
|
146
147
|
#nothing
|
147
|
-
when :
|
148
|
-
old_displayalerts = @
|
149
|
-
@
|
148
|
+
when :alert
|
149
|
+
old_displayalerts = @excel.DisplayAlerts # :nodoc:
|
150
|
+
@excel.DisplayAlerts = true # :nodoc:
|
150
151
|
else
|
151
152
|
raise ExcelErrorClose, ":if_unsaved: invalid option"
|
152
153
|
end
|
@@ -154,14 +155,14 @@ module RobustExcelOle
|
|
154
155
|
begin
|
155
156
|
@workbook.Close if alive?
|
156
157
|
@workbook = nil unless alive?
|
157
|
-
raise ExcelUserCanceled, "close: canceled by user" if alive? && opts[:if_unsaved] == :
|
158
|
+
raise ExcelUserCanceled, "close: canceled by user" if alive? && opts[:if_unsaved] == :alert && (not @workbook.Saved)
|
158
159
|
ensure
|
159
|
-
if opts[:if_unsaved] == :
|
160
|
-
@
|
160
|
+
if opts[:if_unsaved] == :alert then
|
161
|
+
@excel.DisplayAlerts = old_displayalerts # :nodoc:
|
161
162
|
end
|
162
163
|
end
|
163
|
-
#@
|
164
|
-
#@
|
164
|
+
#@excel.Workbooks.Close
|
165
|
+
#@excel.Quit
|
165
166
|
end
|
166
167
|
|
167
168
|
# returns true, if the work book is alive, false otherwise
|
@@ -184,12 +185,12 @@ module RobustExcelOle
|
|
184
185
|
# returns true, if the full book names and excel appications are identical, false, otherwise
|
185
186
|
def == other_book
|
186
187
|
other_book.is_a?(Book) &&
|
187
|
-
@
|
188
|
+
@excel == other_book.excel &&
|
188
189
|
self.filename == other_book.filename
|
189
190
|
end
|
190
191
|
|
191
192
|
|
192
|
-
attr_reader :
|
193
|
+
attr_reader :excel
|
193
194
|
|
194
195
|
# saves a book.
|
195
196
|
# returns true, if successfully saved, nil otherwise
|
@@ -209,7 +210,7 @@ module RobustExcelOle
|
|
209
210
|
# :if_exists if a file with the same name exists, then
|
210
211
|
# :raise -> raise an exception, dont't write the file (default)
|
211
212
|
# :overwrite -> write the file, delete the old file
|
212
|
-
# :
|
213
|
+
# :alert -> give control to Excel
|
213
214
|
# returns true, if successfully saved, nil otherwise
|
214
215
|
def save_as(file = nil, opts = {:if_exists => :raise} )
|
215
216
|
raise IOError, "Not opened for writing(open with :read_only option)" if @options[:read_only]
|
@@ -223,23 +224,14 @@ module RobustExcelOle
|
|
223
224
|
if File.exist?(file) then
|
224
225
|
case opts[:if_exists]
|
225
226
|
when :overwrite
|
226
|
-
# if a book is open with the name of file, then raise error
|
227
|
-
# bräuchte alle Excel-Applikationen.
|
228
|
-
# mit ExcelApp.reuse bzw. running_app bzw. connect bekomme ich nur die 1. Excel-Applikation
|
229
|
-
#open_workbook = ExcelApp.reuse.Workbooks(basename) rescue nil
|
230
227
|
begin
|
231
228
|
File.delete(file)
|
232
|
-
rescue
|
229
|
+
rescue Errno::EACCES
|
233
230
|
raise ExcelErrorSave, "book is open and used in Excel"
|
234
231
|
end
|
235
|
-
|
236
|
-
#
|
237
|
-
#
|
238
|
-
# raise ExcelErrorSave, "book is open and used in Excel"
|
239
|
-
#end
|
240
|
-
when :excel
|
241
|
-
old_displayalerts = @excel_app.DisplayAlerts # :nodoc:
|
242
|
-
@excel_app.DisplayAlerts = true # :nodoc:
|
232
|
+
when :alert
|
233
|
+
old_displayalerts = @excel.DisplayAlerts # :nodoc:
|
234
|
+
@excel.DisplayAlerts = true # :nodoc:
|
243
235
|
when :raise
|
244
236
|
raise ExcelErrorSave, "book already exists: #{basename}"
|
245
237
|
else
|
@@ -247,10 +239,10 @@ module RobustExcelOle
|
|
247
239
|
end
|
248
240
|
end
|
249
241
|
begin
|
250
|
-
@workbook.SaveAs(absolute_path(File.join(dirname, basename)), file_format)
|
242
|
+
@workbook.SaveAs(RobustExcelOle::absolute_path(File.join(dirname, basename)), file_format)
|
251
243
|
rescue WIN32OLERuntimeError => msg
|
252
244
|
if msg.message =~ /SaveAs/ and msg.message =~ /Workbook/ then
|
253
|
-
if opts[:if_exists] == :
|
245
|
+
if opts[:if_exists] == :alert then
|
254
246
|
raise ExcelErrorSave, "not saved or canceled by user"
|
255
247
|
else
|
256
248
|
return nil
|
@@ -260,8 +252,8 @@ module RobustExcelOle
|
|
260
252
|
raise ExcelErrorSaveUnknown, "unknown WIN32OELERuntimeError:\n#{msg.message}"
|
261
253
|
end
|
262
254
|
ensure
|
263
|
-
if opts[:if_exists] == :
|
264
|
-
@
|
255
|
+
if opts[:if_exists] == :alert then
|
256
|
+
@excel.DisplayAlerts = old_displayalerts # :nodoc:
|
265
257
|
end
|
266
258
|
end
|
267
259
|
true
|
@@ -291,16 +283,11 @@ module RobustExcelOle
|
|
291
283
|
base_sheet = base_sheet.sheet
|
292
284
|
sheet ? sheet.Copy({ after_or_before.to_s => base_sheet }) : @workbook.WorkSheets.Add({ after_or_before.to_s => base_sheet })
|
293
285
|
|
294
|
-
new_sheet = RobustExcelOle::Sheet.new(@
|
286
|
+
new_sheet = RobustExcelOle::Sheet.new(@excel.Activesheet)
|
295
287
|
new_sheet.name = new_sheet_name if new_sheet_name
|
296
288
|
new_sheet
|
297
289
|
end
|
298
290
|
|
299
|
-
def absolute_path(file)
|
300
|
-
file = File.expand_path(file)
|
301
|
-
file = RobustExcelOle::Cygwin.cygpath('-w', file) if RUBY_PLATFORM =~ /cygwin/
|
302
|
-
WIN32OLE.new('Scripting.FileSystemObject').GetAbsolutePathName(file)
|
303
|
-
end
|
304
291
|
end
|
305
292
|
|
306
293
|
end
|