robust_excel_ole 0.2.0.8 → 0.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 +47 -61
- data/examples/open_save_close/example_control_to_excel.rb +40 -0
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +33 -0
- data/examples/open_save_close/example_if_obstructed_forget.rb +30 -0
- data/examples/open_save_close/example_if_obstructed_save.rb +31 -0
- data/examples/open_save_close/example_if_unsaved_accept.rb +38 -0
- data/examples/open_save_close/example_if_unsaved_forget.rb +34 -0
- data/examples/open_save_close/example_read_only.rb +27 -0
- data/examples/open_save_close/example_reuse.rb +31 -0
- data/examples/open_save_close/example_simple.rb +30 -0
- data/examples/print_cells/example_print_cells.rb +43 -0
- data/examples/save_sheets/example_save_sheets.rb +30 -0
- data/lib/robust_excel_ole/book.rb +36 -27
- data/lib/robust_excel_ole/excel_app.rb +7 -7
- data/lib/robust_excel_ole/version.rb +1 -1
- data/robust_excel_ole.gemspec +1 -0
- data/spec/book_spec.rb +46 -23
- data/spec/data/book_with_blank.xls +0 -0
- data/spec/data/different_simple.xls +0 -0
- data/spec/data/simple.xls +0 -0
- data/spec/excel_app_spec.rb +24 -12
- data/version.rb +1 -5
- metadata +20 -18
- data/examples/example1.rb +0 -38
- data/examples/example2.rb +0 -33
- data/examples/example3.rb +0 -32
- data/examples/example4.rb +0 -29
- data/examples/example5.rb +0 -35
- data/examples/example6.rb +0 -34
- data/examples/example7.rb +0 -41
- data/examples/example8.rb +0 -32
- data/examples/example9.rb +0 -13
- data/lib/robust_excel_ole/sp +0 -3
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robust_excel_ole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
|
11
|
-
version: 0.2.0.8
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- traths
|
@@ -16,7 +15,7 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date: 2014-
|
18
|
+
date: 2014-10-07 00:00:00 +02:00
|
20
19
|
default_executable:
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
@@ -132,15 +131,17 @@ files:
|
|
132
131
|
- LICENSE
|
133
132
|
- README.rdoc
|
134
133
|
- Rakefile
|
135
|
-
- examples/
|
136
|
-
- examples/
|
137
|
-
- examples/
|
138
|
-
- examples/
|
139
|
-
- examples/
|
140
|
-
- examples/
|
141
|
-
- examples/
|
142
|
-
- examples/
|
143
|
-
- examples/
|
134
|
+
- examples/open_save_close/example_control_to_excel.rb
|
135
|
+
- examples/open_save_close/example_if_obstructed_closeifsaved.rb
|
136
|
+
- examples/open_save_close/example_if_obstructed_forget.rb
|
137
|
+
- examples/open_save_close/example_if_obstructed_save.rb
|
138
|
+
- examples/open_save_close/example_if_unsaved_accept.rb
|
139
|
+
- examples/open_save_close/example_if_unsaved_forget.rb
|
140
|
+
- examples/open_save_close/example_read_only.rb
|
141
|
+
- examples/open_save_close/example_reuse.rb
|
142
|
+
- examples/open_save_close/example_simple.rb
|
143
|
+
- examples/print_cells/example_print_cells.rb
|
144
|
+
- examples/save_sheets/example_save_sheets.rb
|
144
145
|
- lib/robust_excel_ole.rb
|
145
146
|
- lib/robust_excel_ole/book.rb
|
146
147
|
- lib/robust_excel_ole/cell.rb
|
@@ -150,7 +151,6 @@ files:
|
|
150
151
|
- lib/robust_excel_ole/robustexcelole.sublime-project
|
151
152
|
- lib/robust_excel_ole/robustexcelole.sublime-workspace
|
152
153
|
- lib/robust_excel_ole/sheet.rb
|
153
|
-
- lib/robust_excel_ole/sp
|
154
154
|
- lib/robust_excel_ole/version.rb
|
155
155
|
- lib/spec_helper.rb
|
156
156
|
- robust_excel_ole.gemspec
|
@@ -189,10 +189,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
189
189
|
requirements:
|
190
190
|
- - ">="
|
191
191
|
- !ruby/object:Gem::Version
|
192
|
-
hash:
|
192
|
+
hash: 59
|
193
193
|
segments:
|
194
|
-
-
|
195
|
-
|
194
|
+
- 1
|
195
|
+
- 8
|
196
|
+
- 6
|
197
|
+
version: 1.8.6
|
196
198
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
199
|
none: false
|
198
200
|
requirements:
|
data/examples/example1.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# example 1: open a book, print the cells, rows, and columns of a sheet
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
|
4
|
-
|
5
|
-
module RobustExcelOle
|
6
|
-
|
7
|
-
ExcelApp.close_all
|
8
|
-
begin
|
9
|
-
simple_file = '../spec/data/simple.xls'
|
10
|
-
simple_save_file = '../spec/data/simple_save.xls'
|
11
|
-
File.delete @simple_save_file rescue nil
|
12
|
-
#FileUtils.copy simple_file, simple_save_file
|
13
|
-
book = RobustExcelOle::Book.open(simple_save_file)
|
14
|
-
sheet = book[0]
|
15
|
-
cell = sheet[0,0]
|
16
|
-
i = 0
|
17
|
-
sheet.each do |cell|
|
18
|
-
i = i + 1
|
19
|
-
puts "#{i}. cell: #{cell.value}"
|
20
|
-
end
|
21
|
-
i = 0
|
22
|
-
sheet.each_row do |row|
|
23
|
-
i = i + 1
|
24
|
-
puts "#{i}. row: #{row.value}"
|
25
|
-
end
|
26
|
-
i = 0
|
27
|
-
sheet.each_column do |column|
|
28
|
-
i = i + 1
|
29
|
-
puts "#{i}. column: #{column.value}"
|
30
|
-
end
|
31
|
-
sheet[0,0] = "complex"
|
32
|
-
book.save
|
33
|
-
book.close
|
34
|
-
ensure
|
35
|
-
ExcelApp.close_all
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
data/examples/example2.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# example 2: open a book in a running Excel application and in a new one. make visible
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
|
4
|
-
|
5
|
-
module RobustExcelOle
|
6
|
-
|
7
|
-
ExcelApp.close_all
|
8
|
-
begin
|
9
|
-
dir = '../spec/data/'
|
10
|
-
file_name1 = dir + 'simple.xls'
|
11
|
-
file_name2 = dir + 'different_simple.xls'
|
12
|
-
file_name3 = dir + 'different_simple.xls'
|
13
|
-
file_name4 = dir + 'book_with_blank.xls'
|
14
|
-
book1 = RobustExcelOle::Book.open(file_name1) # open a book in a new Excel application since no Excel is open
|
15
|
-
ExcelApp.reuse_if_possible.Visible = true # make Excel visible
|
16
|
-
sleep 2
|
17
|
-
book2 = RobustExcelOle::Book.open(file_name2) # open a new book in the same Excel application
|
18
|
-
sleep 2 # (by default: :reuse => true)
|
19
|
-
book3 = RobustExcelOle::Book.open(file_name3, :reuse => false, :visible => true)
|
20
|
-
# open another book in a new Excel application, make Excel visible
|
21
|
-
sleep 2
|
22
|
-
book4 = RobustExcelOle::Book.open(file_name4, :reuse => true, :visible => true)
|
23
|
-
# open anther book, and use a running Excel application
|
24
|
-
sleep 2 # (Excel chooses the first Excel application)
|
25
|
-
book1.close # close the books
|
26
|
-
book2.close
|
27
|
-
book3.close
|
28
|
-
book4.close
|
29
|
-
ensure
|
30
|
-
ExcelApp.close_all # close workbooks, quit Excel application
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
data/examples/example3.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# example 3: open a book, simple save, save_as, close
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
|
4
|
-
|
5
|
-
module RobustExcelOle
|
6
|
-
|
7
|
-
ExcelApp.close_all
|
8
|
-
begin
|
9
|
-
dir = '../spec/data/'
|
10
|
-
file_name = dir + 'simple.xls'
|
11
|
-
other_file_name = dir + 'different_simple.xls'
|
12
|
-
book = RobustExcelOle::Book.open(file_name) # open a book. default: :read_only => false
|
13
|
-
ExcelApp.reuse_if_possible.Visible = true # make Excel visible
|
14
|
-
sheet = book[0] # access a sheet
|
15
|
-
sleep 1
|
16
|
-
sheet[0,0] =
|
17
|
-
sheet[0,0].value == "simple" ? "complex" : "simple" # change a cell
|
18
|
-
sleep 1
|
19
|
-
book.save # simple save
|
20
|
-
begin
|
21
|
-
book.save_as(other_file_name) # save_as : default :if_exists => :raise
|
22
|
-
rescue ExcelErrorSave => msg
|
23
|
-
puts "save_as error: #{msg.message}"
|
24
|
-
end
|
25
|
-
book.save_as(other_file_name, :if_exists => :overwrite) # save_as with :if_exists => :overwrite
|
26
|
-
puts "save_as: saved successfully with option :if_exists => :overwrite"
|
27
|
-
book.close # close the book
|
28
|
-
ensure
|
29
|
-
ExcelApp.close_all # close workbooks, quit Excel application
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
data/examples/example4.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# example 4: open with read_only mode. save, close
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
|
4
|
-
|
5
|
-
module RobustExcelOle
|
6
|
-
|
7
|
-
ExcelApp.close_all
|
8
|
-
begin
|
9
|
-
dir = '../spec/data/'
|
10
|
-
file_name = dir + 'simple.xls'
|
11
|
-
other_file_name = dir + 'different_simple.xls'
|
12
|
-
# open a book with read_only and make Excel visible
|
13
|
-
book = RobustExcelOle::Book.open(file_name, :read_only => true, :visible => true)
|
14
|
-
sheet = book[0] # access a sheet
|
15
|
-
sleep 1
|
16
|
-
sheet[0,0] =
|
17
|
-
sheet[0,0].value == "simple" ? "complex" : "simple" # change a cell
|
18
|
-
sleep 1
|
19
|
-
begin
|
20
|
-
book.save # simple save.
|
21
|
-
rescue ExcelErrorSave => msg # raises exception because book is opened in of read_only mode
|
22
|
-
puts "save_as error: #{msg.message}"
|
23
|
-
end
|
24
|
-
book.close # close the book without saving it.
|
25
|
-
ensure
|
26
|
-
ExcelApp.close_all # close workbooks, quit Excel application
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
data/examples/example5.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# example 5: open with :if_unsaved => :accept, close with :if_unsaved => :save
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
|
4
|
-
|
5
|
-
module RobustExcelOle
|
6
|
-
|
7
|
-
ExcelApp.close_all
|
8
|
-
begin
|
9
|
-
file_name = '../spec/data/simple.xls'
|
10
|
-
book = RobustExcelOle::Book.open(file_name) # open a book
|
11
|
-
sheet = book[0] # access a sheet
|
12
|
-
sheet[0,0] = sheet[0,0].value == "simple" ? "complex" : "simple" # change a cell
|
13
|
-
begin
|
14
|
-
new_book = RobustExcelOle::Book.open(file_name) # open another book with the same file name
|
15
|
-
rescue ExcelErrorOpen => msg # by default: raises an exception:
|
16
|
-
puts "open error: #{msg.message}" # a book with the same name is already open and unsaved
|
17
|
-
end
|
18
|
-
new_book = RobustExcelOle::Book.open(file_name, :if_unsaved => :accept) # open another book with the same file name
|
19
|
-
# and let the unsaved book open
|
20
|
-
if book.alive? && new_book.alive? then # check whether the referenced workbooks
|
21
|
-
puts "open with :if_unsaved => :accept : the two books are alive." # respond to methods
|
22
|
-
end
|
23
|
-
begin
|
24
|
-
book.close # close the book. by default: raises an exception:
|
25
|
-
rescue ExcelErrorClose => msg # book is unsaved
|
26
|
-
puts "close error: #{msg.message}"
|
27
|
-
end
|
28
|
-
book.close(:if_unsaved => :save) # save the book before closing it
|
29
|
-
puts "closed the book successfully with option :if_unsaved => :save"
|
30
|
-
new_book.close # close the other book. It is already saved.
|
31
|
-
ensure
|
32
|
-
ExcelApp.close_all # close workbooks, quit Excel application
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
data/examples/example6.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# example 6: open with :if_unsaved => :forget, :new_app, close with :if_unsaved => :save
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
|
4
|
-
|
5
|
-
module RobustExcelOle
|
6
|
-
|
7
|
-
ExcelApp.close_all
|
8
|
-
begin
|
9
|
-
file_name = '../spec/data/simple.xls'
|
10
|
-
book = RobustExcelOle::Book.open(file_name) # open a book
|
11
|
-
ExcelApp.reuse_if_possible.Visible = true # make Excel visible
|
12
|
-
sleep 1
|
13
|
-
sheet = book[0] # access a sheet
|
14
|
-
first_cell = sheet[0,0].value
|
15
|
-
sheet[0,0] = first_cell == "simple" ? "complex" : "simple" # change a cell
|
16
|
-
sleep 1
|
17
|
-
new_book = RobustExcelOle::Book.open(file_name, :if_unsaved => :forget) # open another book with the same file name
|
18
|
-
# and close the unsaved book without saving it
|
19
|
-
sheet_new_book = new_book[0]
|
20
|
-
if (not book.alive?) && new_book.alive? && sheet_new_book[0,0].value == first_cell then # check whether the unsaved book
|
21
|
-
puts "open with :if_unsaved => :forget : the unsaved book is closed and not saved." # is closed and was not saved
|
22
|
-
end
|
23
|
-
sleep 1
|
24
|
-
sheet_new_book[0,0] = sheet_new_book[0,0].value == "simple" ? "complex" : "simple" # change a cell
|
25
|
-
# open another book in a new Excel application, and make Excel visible
|
26
|
-
another_book = RobustExcelOle::Book.open(file_name, :if_unsaved => :new_app, :visible => true)
|
27
|
-
sleep 3 # leaving the unsaved book open
|
28
|
-
new_book.close(:if_unsaved => :forget ) # close the unsaved book without saving it
|
29
|
-
another_book.close
|
30
|
-
ensure
|
31
|
-
ExcelApp.close_all # close workbooks, quit Excel application
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
data/examples/example7.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# example 7: open, close, save with giving control to Excel
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
|
4
|
-
|
5
|
-
module RobustExcelOle
|
6
|
-
|
7
|
-
ExcelApp.close_all
|
8
|
-
begin
|
9
|
-
file_name = '../spec/data/simple.xls'
|
10
|
-
book = RobustExcelOle::Book.open(file_name, :visible => true) # open a book
|
11
|
-
ExcelApp.reuse_if_possible.Visible = true # make Excel visible
|
12
|
-
sleep 1
|
13
|
-
sheet = book[0] # access a sheet
|
14
|
-
sheet[0,0] = sheet[0,0].value == "simple" ? "complex" : "simple" # change a cell
|
15
|
-
sleep 1
|
16
|
-
begin
|
17
|
-
new_book = RobustExcelOle::Book.open(file_name, :if_unsaved => :excel) # open another book with the same file name
|
18
|
-
rescue ExcelUserCanceled => msg # if the user chooses not open the book,
|
19
|
-
puts "#{msg.message}" # an exeptions is raised
|
20
|
-
end
|
21
|
-
puts "new book has opened" if new_book
|
22
|
-
ExcelApp.reuse_if_possible.Visible = true
|
23
|
-
begin
|
24
|
-
book.close(:if_unsaved => :excel) # close the unsaved book.
|
25
|
-
rescue ExcelUserCanceled => msg # user is asked whether the unsaved book shall be saved
|
26
|
-
puts "#{msg.message}" # if the user chooses to cancel, then an expeption is raised
|
27
|
-
end
|
28
|
-
if new_book then
|
29
|
-
begin
|
30
|
-
new_book.save_as(file_name, :if_exists => :excel) # save the new book, if it was opened
|
31
|
-
rescue ExcelErrorSave => msg # user is asked, whether the existing file shall be overwritten
|
32
|
-
puts "save_as: #{msg.message}" # if the user chooses "no" or "cancel", an exception is raised
|
33
|
-
end
|
34
|
-
|
35
|
-
new_book.close # close the new book, if the user chose to open it
|
36
|
-
end
|
37
|
-
ensure
|
38
|
-
ExcelApp.close_all # close workbooks, quit Excel application
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
data/examples/example8.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# example 8: open with :if_blocking_other:
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
|
4
|
-
|
5
|
-
module RobustExcelOle
|
6
|
-
|
7
|
-
ExcelApp.close_all
|
8
|
-
begin
|
9
|
-
dir = '../spec/data/'
|
10
|
-
file_name = dir + 'simple.xls'
|
11
|
-
other_dir = '../spec/data/more_data/'
|
12
|
-
other_file_name = other_dir + 'simple.xls'
|
13
|
-
book = RobustExcelOle::Book.open(file_name, :visible => true) # open a book, make Excel application visible
|
14
|
-
sleep 3
|
15
|
-
begin
|
16
|
-
new_book = RobustExcelOle::Book.open(other_file_name) # open a book with the same file name in a different path
|
17
|
-
rescue ExcelErrorOpen => msg # by default: raises an exception
|
18
|
-
puts "open: #{msg.message}"
|
19
|
-
end
|
20
|
-
# open a new book with the same file name in a different path. close the old book before.
|
21
|
-
new_book = RobustExcelOle::Book.open(other_file_name, :if_blocking_other => :forget)
|
22
|
-
# open another book with the same file name in a different path. Use a new Excel application
|
23
|
-
sleep 3
|
24
|
-
another_book = RobustExcelOle::Book.open(file_name, :if_blocking_other => :new_app, :visible => true)
|
25
|
-
sleep 3
|
26
|
-
new_book.close # close the books
|
27
|
-
another_book.close
|
28
|
-
ensure
|
29
|
-
ExcelApp.close_all # close workbooks, quit Excel application
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
data/examples/example9.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# example 9: save the sheets of a book as separate books
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
|
4
|
-
|
5
|
-
module RobustExcelOle
|
6
|
-
|
7
|
-
ExcelApp.close_all
|
8
|
-
begin
|
9
|
-
ensure
|
10
|
-
ExcelApp.close_all # close workbooks, quit Excel application
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
data/lib/robust_excel_ole/sp
DELETED