robust_excel_ole 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +53 -116
- data/README_detail.rdoc +510 -0
- data/TodoList.md +21 -11
- data/examples/open_save_close/example_control_to_excel.rb +1 -1
- data/examples/open_save_close/example_default_excel.rb +1 -1
- data/examples/open_save_close/example_force_excel.rb +2 -2
- data/examples/open_save_close/example_if_unsaved_forget.rb +1 -1
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +2 -2
- data/examples/open_save_close/example_rename_cells.rb +1 -1
- data/examples/open_save_close/example_reuse.rb +1 -1
- data/examples/open_save_close/example_simple.rb +1 -1
- data/lib/robust_excel_ole/book.rb +77 -75
- data/lib/robust_excel_ole/book_store.rb +51 -27
- data/lib/robust_excel_ole/excel.rb +0 -1
- data/lib/robust_excel_ole/version.rb +1 -1
- data/robust_excel_ole.gemspec +2 -7
- data/spec/book_spec.rb +382 -95
- data/spec/book_store_spec.rb +179 -25
- data/spec/excel_spec.rb +1 -4
- metadata +9 -88
data/README.rdoc
CHANGED
@@ -1,20 +1,8 @@
|
|
1
1
|
= RobustExcelOle
|
2
2
|
|
3
|
-
robust_excel_ole
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
robust_excel_ole started as a simple fork from tomiacannondale's wrap_excel adapted to Ruby 1.8.6.
|
8
|
-
The functionality of wrap_excel is optimised and extended by new features.
|
9
|
-
Most notable extensions include:
|
10
|
-
* books can be opened in already running Excel instances (instead of opening a new Excel whenever a book is opened)
|
11
|
-
* a book management system stores all books that have been open. This book store is being used, e.g., for reopening a book that has been closed before. It provides transperency identity, i.e., equal Excel books correspond to equal Book objects of RobustExcelOle.
|
12
|
-
|
13
|
-
Some features in robust_excel_ole that are not compatible with wrap_excel:
|
14
|
-
* +open+ uses by default a running Excel instance instead of creating a new one,
|
15
|
-
and opens a book by default in writable mode instead of read_only
|
16
|
-
* +close+ closes the workbook instead of closing all workbooks and the Excel instance.
|
17
|
-
* +save_as+ instead of +save+.
|
3
|
+
robust_excel_ole processes Excel files, allows to perform all win32ole operations,
|
4
|
+
provides convenient methods for opening, saving, closing, and modifying Excel files,
|
5
|
+
and implements an Excel file management system.
|
18
6
|
|
19
7
|
This is work in progress.
|
20
8
|
|
@@ -28,115 +16,84 @@ This is work in progress.
|
|
28
16
|
|
29
17
|
== Usage
|
30
18
|
|
31
|
-
===
|
19
|
+
=== Opening a book.
|
32
20
|
|
33
21
|
include RobustExcelOle
|
34
22
|
|
35
|
-
=== Opening a book.
|
36
|
-
|
37
23
|
Example:
|
38
24
|
|
39
25
|
book = Book.open('simple.xls')
|
40
26
|
|
41
|
-
|
27
|
+
Opening a book with a block.
|
42
28
|
The semantics is similar to, e.g., File.open.
|
43
29
|
|
44
30
|
Book.open('simple.xls') do |book|
|
45
31
|
# do something
|
46
32
|
end
|
47
33
|
|
48
|
-
Options are
|
34
|
+
Options are +default_excel+, +force_excel+, +if_unsaved+, +if_obstructed+, +read_only+, +visible+, +displayalerts+.
|
49
35
|
|
50
|
-
|
51
|
-
+:force_excel+:: open in a new or given Excel instance (defaut: +:new+)
|
52
|
-
+:if_unsaved+:: specify behaviour if the book was unsaved (default: +raise+)
|
53
|
-
+:if_obstructed+:: specidy behaviour if the book is blocked by another book (default: +raise+)
|
54
|
-
+:read_only+:: open in read-only mode (default: +false+)
|
55
|
-
+:displayalerts+:: allow display alerts in Excel (default: +false+)
|
56
|
-
+:visible+:: make visibe in Excel (default: +false+)
|
36
|
+
Here are a few examples:
|
57
37
|
|
58
|
-
|
38
|
+
Opening another book in a new Excel instance and make it visible.
|
59
39
|
|
60
|
-
|
40
|
+
second_book = Book.open('simple.xls', :force_excel => :new, :visible => true)
|
61
41
|
|
62
|
-
|
63
|
-
+:
|
64
|
-
[instance]:: Open in a given Excel instance.
|
42
|
+
Opening a book with the same name in a different path.
|
43
|
+
The option +:if_unsaved => :forget+ causes the old book to close such that it does not block the new book anymore.
|
65
44
|
|
66
|
-
|
45
|
+
third_book = Book.open('more/simple.xls', :if_obstructed => :forget)
|
67
46
|
|
68
|
-
|
47
|
+
Opening another book with the same file name in the running Excel. With the option +:if_unsaved => :accept+ the book remains open if it contains unsaved changes.
|
69
48
|
|
70
|
-
|
71
|
-
[instance]:: Open in a given Excel instance.
|
49
|
+
forth_book = Book.open('simple.xls', :if_unsaved => :accept)
|
72
50
|
|
73
|
-
The option +:if_unsaved+ :
|
74
51
|
|
75
|
-
|
52
|
+
=== Closing a book.
|
76
53
|
|
77
|
-
|
78
|
-
+:accept+:: Let the unsaved book open.
|
79
|
-
+:forget+:: Discard any changes and reopen the book.
|
80
|
-
+:new_excel+:: Open the new book in a new Excel instance
|
81
|
-
+:alert+:: Give control to Excel.
|
54
|
+
book.close
|
82
55
|
|
83
|
-
The option +:
|
56
|
+
The option is : +:if_unsaved+. Example:
|
84
57
|
|
85
|
-
|
58
|
+
Closing the book and saving it before if it has unsaved changes.
|
86
59
|
|
87
|
-
|
88
|
-
+:forget+:: Close the old book, open the new book.
|
89
|
-
+:save+:: Save the old book, close it, open the new book
|
90
|
-
+:close_if_saved+:: Close the old book and open the new book, if the old book is saved, raise an exception otherwise
|
91
|
-
+:new_excel+:: Open the new book in a new Excel instance.
|
60
|
+
book.close(:if_unsaved => :save)
|
92
61
|
|
93
|
-
The values :displayalerts and :visible are reached to the class Excel that controls opening and closing Excel instances.
|
94
62
|
|
95
|
-
===
|
63
|
+
=== Reopening books.
|
96
64
|
|
97
|
-
|
65
|
+
The books can be reopened after closing them. Example:
|
98
66
|
|
67
|
+
book = Book.open('simple.xls')
|
99
68
|
book.close
|
69
|
+
reopened_book = Book.open('simple.xls')
|
100
70
|
|
101
|
-
|
102
|
-
|
103
|
-
+:if_unsaved+, +:raise+ (default), +:save+, +:forget+, +:alert+
|
104
|
-
|
105
|
-
The option specifies: If the book is unsaved, then
|
71
|
+
robust_excel_ole provides transperency identity. That is the same Book objects refer to the same Excel files, and vice versa.
|
106
72
|
|
107
|
-
|
108
|
-
|
109
|
-
+:forget+:: Close the book.
|
110
|
-
+:alert+:: Give control to Excel.
|
73
|
+
reopened_book == book
|
74
|
+
=> true
|
111
75
|
|
112
76
|
|
113
77
|
=== Saving a book.
|
114
78
|
|
115
|
-
Simple save.
|
116
|
-
|
117
79
|
book.save
|
118
80
|
|
119
81
|
Saving a book with a file name.
|
120
82
|
|
121
83
|
book.save_as('another_simple.xls')
|
122
84
|
|
123
|
-
|
85
|
+
The option is +:if_exists+. Example:
|
124
86
|
|
125
|
-
|
87
|
+
Saving a book and overwriting the file if it exists before.
|
126
88
|
|
127
|
-
|
89
|
+
book.save_as('another_simple.xls', :if_exists => :overwrite)
|
128
90
|
|
129
|
-
If a book with the file name already exists, then
|
130
|
-
|
131
|
-
+:raise+:: Raise an exeption. Don't write the file.
|
132
|
-
+:overwrite+:: Delete the existing file and write the file. If the book is open in an Excel instance, then raise an exception.
|
133
|
-
+:alert+:: Give the control to Excel.
|
134
|
-
|
135
91
|
|
136
92
|
=== Unobtrusively modifying a book
|
137
93
|
|
138
|
-
When modifying
|
94
|
+
Sometimes the user wants to read and possibly modify a book, no matter if it is open in some Excel instance or not, is saved or unsaved. The method +unobtrusively+ provides this service. When modifying a book unobtrusively, its status remains unchanged. This status includes, wheter the book is opened or closed, saved or unsaved, readonly or writable. If the books were closed and the Excel instance are still running, then the book is opened in the Excel instance where it was opened most recently or in a new Excel. This is relevant if the book has references to other books.
|
139
95
|
|
96
|
+
Options are +:if_readonly+, +:use_this+, +:keep_open+, +:visible+
|
140
97
|
|
141
98
|
Book.unobtrusively('simple.xls') do |book|
|
142
99
|
# some modification
|
@@ -150,49 +107,21 @@ Returning the value of a cell or range that has a with a defined name.
|
|
150
107
|
|
151
108
|
book.nvalue(name)
|
152
109
|
|
153
|
-
===
|
154
|
-
|
155
|
-
Checking whether two referenced Excel workbooks are identical.
|
156
|
-
|
157
|
-
if book1 == book2 then puts "Both referenced Excel workbooks are identical."
|
158
|
-
|
159
|
-
=== Alive.
|
110
|
+
=== Alive?.
|
160
111
|
|
161
112
|
Checking whether the referenced Excel workbook responds to methods.
|
162
113
|
|
163
|
-
if book.alive? then
|
164
|
-
|
165
|
-
=== File name.
|
166
|
-
|
167
|
-
Getting the file name of the book with the absolute path that contains slash (/) instead of back slash (\).
|
168
|
-
|
169
|
-
book.filename
|
114
|
+
if book.alive? then sheet = book[0] end
|
170
115
|
|
171
|
-
===
|
116
|
+
=== Making an Excel visible or invisible, and enable and disable DisplayAlerts.
|
172
117
|
|
173
|
-
Make
|
174
|
-
|
175
|
-
book.visible = true
|
176
|
-
|
177
|
-
Options: +true+ -> make visible , +false+ -> make invisible
|
178
|
-
|
179
|
-
Check whether the book is visible.
|
180
|
-
|
181
|
-
if book.visible then p "visible"
|
118
|
+
Make an Excel visible
|
182
119
|
|
183
|
-
|
120
|
+
book.excel.visible = true
|
184
121
|
|
185
122
|
Enable DisplayAlerts.
|
186
123
|
|
187
|
-
book.displayalerts = true
|
188
|
-
|
189
|
-
Options: +true+ -> enable DisplayAlerts , +false+ -> Disable DisplayAlerts
|
190
|
-
|
191
|
-
|
192
|
-
Check whether DisplayAlerts is enabled.
|
193
|
-
|
194
|
-
if book.displayalerts then p "DisplayAlerts enabled"
|
195
|
-
|
124
|
+
book.excel.displayalerts = true
|
196
125
|
|
197
126
|
|
198
127
|
=== Accessing a sheet.
|
@@ -298,7 +227,7 @@ Getting a running Excel instance and reusing it.
|
|
298
227
|
|
299
228
|
Reusing a running Excel instance, making it visible and turning on displayalerts.
|
300
229
|
|
301
|
-
excel2 = Excel.new(:reuse => true, :visible => true, displayalerts => true).
|
230
|
+
excel2 = Excel.new(:reuse => true, :visible => true, :displayalerts => true).
|
302
231
|
|
303
232
|
Reusing a certain running Excel instance.
|
304
233
|
|
@@ -310,7 +239,6 @@ Making Excel visible.
|
|
310
239
|
|
311
240
|
excel = Excel.create
|
312
241
|
excel.visible = true
|
313
|
-
puts "visible" if excel.visible
|
314
242
|
|
315
243
|
Making Excel invisible
|
316
244
|
|
@@ -322,7 +250,6 @@ Turning DisplayAlerts on.
|
|
322
250
|
|
323
251
|
excel = Excel.create
|
324
252
|
excel.displayalerts = true
|
325
|
-
puts "allows displayalerts" if excel.displayalerts
|
326
253
|
|
327
254
|
Turning DisplayAlerts off.
|
328
255
|
|
@@ -343,10 +270,6 @@ Turning on and off in a block.
|
|
343
270
|
|
344
271
|
=== Examples
|
345
272
|
|
346
|
-
Including robust_excel_ole.
|
347
|
-
|
348
|
-
include RobustExcelOle
|
349
|
-
|
350
273
|
=== Example 1
|
351
274
|
|
352
275
|
Opening a book.
|
@@ -502,9 +425,23 @@ The book is modified, but its status is unchanged.
|
|
502
425
|
=> true
|
503
426
|
|
504
427
|
|
428
|
+
=== Development
|
429
|
+
|
430
|
+
robust_excel_ole started as a simple fork from tomiacannondale's wrap_excel adapted to Ruby 1.8.6.
|
431
|
+
The functionality of wrap_excel is optimised and extended by new features.
|
432
|
+
Most notable extensions include:
|
433
|
+
* books can be opened in already running Excel instances (instead of opening a new Excel whenever a book is opened)
|
434
|
+
* a book management system stores all books that have been open. This book store is being used, e.g., for reopening a book that has been closed before. It provides transperency identity, i.e., equal Excel books correspond to equal Book objects of RobustExcelOle.
|
435
|
+
|
436
|
+
Some features in robust_excel_ole that are not compatible with wrap_excel:
|
437
|
+
* +open+ uses by default a running Excel instance instead of creating a new one,
|
438
|
+
and opens a book by default in writable mode instead of read_only
|
439
|
+
* +close+ closes the workbook instead of closing all workbooks and the Excel instance.
|
440
|
+
* +save_as+ instead of +save+.
|
441
|
+
|
442
|
+
|
505
443
|
=== Want to do more things
|
506
444
|
|
507
|
-
All RobustExcelOle objects include the win32ole instance.
|
508
445
|
If you want to do something that not provide a function, you can use win32ole methods.
|
509
446
|
|
510
447
|
== Support
|