robust_excel_ole 0.3.1 → 0.3.2
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 +69 -56
- data/README_detail.rdoc +44 -34
- data/TodoList.md +8 -6
- data/examples/edit_sheets/example_access_sheets_and_cells.rb +6 -6
- data/examples/edit_sheets/example_adding_sheets.rb +2 -2
- data/examples/edit_sheets/example_ranges.rb +3 -3
- data/examples/open_save_close/example_control_to_excel.rb +2 -2
- data/examples/open_save_close/example_default_excel.rb +2 -2
- data/examples/open_save_close/example_force_excel.rb +1 -1
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +4 -4
- data/examples/open_save_close/example_if_obstructed_forget.rb +2 -2
- data/examples/open_save_close/example_if_obstructed_save.rb +2 -2
- data/examples/open_save_close/example_if_unsaved_accept.rb +1 -1
- data/examples/open_save_close/example_if_unsaved_forget.rb +1 -1
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +1 -1
- data/examples/open_save_close/example_read_only.rb +2 -2
- data/examples/open_save_close/example_rename_cells.rb +1 -1
- data/examples/open_save_close/example_reuse.rb +3 -3
- data/examples/open_save_close/example_simple.rb +2 -2
- data/examples/open_save_close/example_unobtrusively.rb +1 -1
- data/lib/robust_excel_ole/book.rb +97 -128
- data/lib/robust_excel_ole/book_store.rb +23 -23
- data/lib/robust_excel_ole/excel.rb +12 -14
- data/lib/robust_excel_ole/version.rb +1 -1
- data/spec/book_spec.rb +462 -289
- data/spec/book_store_spec.rb +36 -55
- data/spec/data/book_with_blank.xls +0 -0
- data/spec/data/{different_simple.xls → different_workbook.xls} +0 -0
- data/spec/data/merge_cells.xls +0 -0
- data/spec/data/{more_simple.xls → more_workbook.xls} +0 -0
- data/spec/data/protected_sheet.xls +0 -0
- data/spec/data/{simple.xls → workbook.xls} +0 -0
- data/spec/data/{simple.xlsm → workbook.xlsm} +0 -0
- data/spec/data/{simple.xlsx → workbook.xlsx} +0 -0
- data/spec/excel_spec.rb +40 -0
- metadata +9 -9
data/README.rdoc
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
= RobustExcelOle
|
2
2
|
|
3
|
-
robust_excel_ole
|
4
|
-
provides convenient methods for opening,
|
5
|
-
|
3
|
+
robust_excel_ole implements methods for accessing Excel files using win32ole.
|
4
|
+
It provides convenient methods for opening, modifying, saving and closing Excel files.
|
5
|
+
Furthermore all VBA methods can be sent.
|
6
|
+
|
7
|
+
robust_excel_ole manages Excel workbooks that have been opened in several Excel instances.
|
6
8
|
|
7
9
|
This is work in progress.
|
8
10
|
|
@@ -16,86 +18,93 @@ This is work in progress.
|
|
16
18
|
|
17
19
|
== Usage
|
18
20
|
|
19
|
-
=== Opening a
|
20
|
-
|
21
|
-
include RobustExcelOle
|
21
|
+
=== Opening a workbook.
|
22
22
|
|
23
23
|
Example:
|
24
24
|
|
25
|
-
|
25
|
+
include RobustExcelOle
|
26
|
+
book = Book.open('workbook.xls')
|
26
27
|
|
27
|
-
Opening a
|
28
|
+
Opening a workbook with a block.
|
28
29
|
The semantics is similar to, e.g., File.open.
|
29
30
|
|
30
|
-
Book.open('
|
31
|
+
Book.open('workbook.xls') do |book|
|
31
32
|
# do something
|
32
33
|
end
|
33
34
|
|
34
|
-
Options are
|
35
|
+
Options are +:default_excel+, +:force_excel+, +:if_absent+, +:if_unsaved+, +:if_obstructed+, +:read_only+, +:visible+, +:displayalerts+.
|
35
36
|
|
36
37
|
Here are a few examples:
|
37
38
|
|
38
|
-
Opening
|
39
|
+
Opening a workbook in a new Excel instance and make it visible.
|
39
40
|
|
40
|
-
|
41
|
+
book = Book.open('workbook.xls', :force_excel => :new, :visible => true)
|
41
42
|
|
42
|
-
Opening a
|
43
|
-
The option +:
|
43
|
+
Opening a workbook with the same name in a different path.
|
44
|
+
The option +:if_obstructed+ => +:forget+ causes the old workbook to close such that it does not block the new workbook anymore.
|
44
45
|
|
45
|
-
|
46
|
+
book2 = Book.open('path/workbook.xls', :if_obstructed => :forget)
|
46
47
|
|
47
|
-
Opening another
|
48
|
+
Opening another workbook with the same file name in the running Excel. The option +:if_unsaved+ => +:accept+ has the effect that if the workbook contains unsaved changes, then the workbook remains open, but no error is raised, i.e. the program can continue.
|
48
49
|
|
49
|
-
|
50
|
+
book3 = Book.open('workbook.xls', :if_unsaved => :accept)
|
50
51
|
|
51
52
|
|
52
|
-
=== Closing a
|
53
|
+
=== Closing a workbook.
|
53
54
|
|
54
55
|
book.close
|
55
56
|
|
56
57
|
The option is : +:if_unsaved+. Example:
|
57
58
|
|
58
|
-
Closing the
|
59
|
+
Closing the workbook and saving it before if it has unsaved changes.
|
59
60
|
|
60
61
|
book.close(:if_unsaved => :save)
|
61
62
|
|
62
63
|
|
63
|
-
=== Reopening
|
64
|
+
=== Reopening workbooks.
|
64
65
|
|
65
|
-
|
66
|
+
A special feature of robust_excel_ole is that it allows to reopen books after closing them.
|
66
67
|
|
67
|
-
book = Book.open('
|
68
|
+
book = Book.open('workbook.xls')
|
68
69
|
book.close
|
69
|
-
reopened_book = Book.open('
|
70
|
+
reopened_book = Book.open('workbook.xls')
|
70
71
|
|
71
|
-
|
72
|
+
The closed book is now alive again, i.e. responds to Excel methods.
|
72
73
|
|
73
|
-
|
74
|
+
book.alive?
|
74
75
|
=> true
|
75
76
|
|
77
|
+
This feature is achieved by providing identity transperence and by storing the file name.
|
78
|
+
Identity transperence means that the same Book objects refer to the same Excel files, and vice versa.
|
79
|
+
In other words, a Book objects is a proxy of an Excel file.
|
80
|
+
|
81
|
+
reopened_book === book
|
82
|
+
=> true
|
76
83
|
|
77
|
-
=== Saving a
|
84
|
+
=== Saving a workbook.
|
78
85
|
|
79
86
|
book.save
|
80
87
|
|
81
|
-
Saving a
|
88
|
+
Saving a workbook with a file name.
|
82
89
|
|
83
|
-
book.save_as('
|
90
|
+
book.save_as('another_workbook.xls')
|
84
91
|
|
85
92
|
The option is +:if_exists+. Example:
|
86
93
|
|
87
|
-
Saving a
|
94
|
+
Saving a workbook and overwriting the file if it exists before.
|
88
95
|
|
89
|
-
book.save_as('
|
96
|
+
book.save_as('another_workbook.xls', :if_exists => :overwrite)
|
90
97
|
|
91
98
|
|
92
|
-
=== Unobtrusively
|
99
|
+
=== Unobtrusively opening a workbook
|
93
100
|
|
94
|
-
|
101
|
+
The method +unobtrusively+ enables the user to read or modify a workbook, no matter if it is open in some Excel instance, if it is saved or unsaved, and if it is writable or not. When opening a workbook unobtrusively, its status remains unchanged. This status includes, whether the book is opened or closed, saved or unsaved, readonly or writable.
|
95
102
|
|
96
|
-
Options are +:
|
103
|
+
Options are +:if_closed+, +:read_only+, +:use_readonly_excel+, +:keep_open, +:visible+
|
97
104
|
|
98
|
-
|
105
|
+
The option +:if_closed+ => +:hidden+ provokes that a closed book is opened unobtrusively in a separate Excel instance that is not visible and has no DisplayAlerts. Any following closed book would be opened in this Excel instance as well when using this option.
|
106
|
+
|
107
|
+
Book.unobtrusively('workbook.xls', :if_closed => :hidden) do |book|
|
99
108
|
# some modification
|
100
109
|
sheet = book[0]
|
101
110
|
sheet[0,0] = "c"
|
@@ -107,9 +116,9 @@ Returning the value of a cell or range that has a with a defined name.
|
|
107
116
|
|
108
117
|
book.nvalue(name)
|
109
118
|
|
110
|
-
===
|
119
|
+
=== Checking whether the workbook is alive.
|
111
120
|
|
112
|
-
|
121
|
+
This method finds out whether the Excel workbook that is referenced by the Book object responds to methods.
|
113
122
|
|
114
123
|
if book.alive? then sheet = book[0] end
|
115
124
|
|
@@ -168,10 +177,12 @@ Reading a cell from a range object.
|
|
168
177
|
row_range[0] => first cell in row_range
|
169
178
|
column_range[1] => second cell in column_range
|
170
179
|
|
180
|
+
Methods to a cell are just delegated. Example:
|
181
|
+
|
171
182
|
Reading the value of a cell.
|
172
183
|
|
173
184
|
cell = sheet[0,0]
|
174
|
-
cell.
|
185
|
+
cell.Value => value of the cell.
|
175
186
|
|
176
187
|
Writing a cell
|
177
188
|
|
@@ -261,7 +272,7 @@ Turning on and off in a block.
|
|
261
272
|
|
262
273
|
excel = Excel.create
|
263
274
|
excel.with_displayalerts true do
|
264
|
-
book = Book.open('
|
275
|
+
book = Book.open('workbook.xls')
|
265
276
|
end
|
266
277
|
|
267
278
|
=== Closing all Excel instances.
|
@@ -274,7 +285,7 @@ Turning on and off in a block.
|
|
274
285
|
|
275
286
|
Opening a book.
|
276
287
|
|
277
|
-
book = Book.open('
|
288
|
+
book = Book.open('workbook.xls')
|
278
289
|
|
279
290
|
Accessing a sheet via its name.
|
280
291
|
|
@@ -290,7 +301,7 @@ Saving the book.
|
|
290
301
|
|
291
302
|
Saving the book with a different name, and overwrite if a file with this name exists.
|
292
303
|
|
293
|
-
book.save_as('
|
304
|
+
book.save_as('different_workbook.xls', :if_exists => :overwrite)
|
294
305
|
|
295
306
|
Closing the book.
|
296
307
|
|
@@ -300,15 +311,15 @@ Closing the book.
|
|
300
311
|
|
301
312
|
Opening a book.
|
302
313
|
|
303
|
-
book = Book.open('
|
314
|
+
book = Book.open('workbook.xls')
|
304
315
|
|
305
316
|
Opening the book in a new Excel instance and make it visible.
|
306
317
|
|
307
|
-
new_book = Book.open('
|
318
|
+
new_book = Book.open('workbook.xls', :force_excel => :new, :visible => true)
|
308
319
|
|
309
320
|
Opening the book in a given Excel instance.
|
310
321
|
|
311
|
-
another_book = Book.open('
|
322
|
+
another_book = Book.open('workbook.xls', :force_excel => book.excel)
|
312
323
|
|
313
324
|
Closing the books.
|
314
325
|
|
@@ -318,11 +329,11 @@ Closing the books.
|
|
318
329
|
|
319
330
|
Reopening the book.
|
320
331
|
|
321
|
-
reopened_book = Book.open('
|
332
|
+
reopened_book = Book.open('workbook.xls')
|
322
333
|
|
323
334
|
The writable book is being prefered.
|
324
335
|
|
325
|
-
reopened_book
|
336
|
+
reopened_book === book
|
326
337
|
=> true
|
327
338
|
|
328
339
|
Opening another book.
|
@@ -336,17 +347,15 @@ According to :default_excel => :new a new Excel is created, and the book is open
|
|
336
347
|
|
337
348
|
Opening a book.
|
338
349
|
|
339
|
-
book = Book.open('
|
350
|
+
book = Book.open('workbook.xls')
|
340
351
|
|
341
352
|
Adding a copy of the first sheet after the second sheet.
|
342
353
|
|
343
354
|
book.add_sheet(book[0], :as => 'Sheet1_copy', :after => book[1])
|
344
355
|
|
345
|
-
Close the book.
|
346
|
-
|
347
356
|
Opening a new book with the same name in a new Excel. Leave the book that contains unsaved changes in the old Excel.
|
348
357
|
|
349
|
-
new_book = Book.open('
|
358
|
+
new_book = Book.open('workbook.xls', :if_unsaved => :new_excel)
|
350
359
|
|
351
360
|
Accessing a sheet and change a cell.
|
352
361
|
|
@@ -355,7 +364,7 @@ Accessing a sheet and change a cell.
|
|
355
364
|
|
356
365
|
Opening another book with the same name in the running Excel. The book that contains unsaved changes will be closed before.
|
357
366
|
|
358
|
-
third_book = Book.open('
|
367
|
+
third_book = Book.open('workbook.xls', :if_unsaved => :forget)
|
359
368
|
|
360
369
|
Adding a sheet.
|
361
370
|
|
@@ -373,11 +382,11 @@ Closing the first book and saving it before.
|
|
373
382
|
|
374
383
|
Opening a book.
|
375
384
|
|
376
|
-
book1 = Book.open('
|
385
|
+
book1 = Book.open('workbook.xls')
|
377
386
|
|
378
387
|
Opening a book with the same name in a different path. Close the old book.
|
379
388
|
|
380
|
-
book2 = Book.open('more/
|
389
|
+
book2 = Book.open('more/workbook.xls', :if_obstructed => :forget)
|
381
390
|
|
382
391
|
Changing its cell.
|
383
392
|
|
@@ -386,11 +395,11 @@ Changing its cell.
|
|
386
395
|
|
387
396
|
Opening a book with the same name in a different path. The old book that was modified will be saved and closed before.
|
388
397
|
|
389
|
-
book3 = Book.open('
|
398
|
+
book3 = Book.open('workbook.xls', :if_obstructed => :save)
|
390
399
|
|
391
400
|
Opening a book with the same name in a different path. The other book will be closed, because it does not contain unsaved changes.
|
392
401
|
|
393
|
-
book4 = Book.open('more/
|
402
|
+
book4 = Book.open('more/workbook.xls', :if_obstructed => :close_if_unsaved)
|
394
403
|
|
395
404
|
Closing the book.
|
396
405
|
|
@@ -401,7 +410,7 @@ Closing the book.
|
|
401
410
|
|
402
411
|
Opening a book.
|
403
412
|
|
404
|
-
book = Book.open('
|
413
|
+
book = Book.open('workbook.xls')
|
405
414
|
|
406
415
|
Printing its first cell.
|
407
416
|
|
@@ -410,7 +419,7 @@ Printing its first cell.
|
|
410
419
|
|
411
420
|
Unobtrusively modify the book.
|
412
421
|
|
413
|
-
Book.unobtrusively('
|
422
|
+
Book.unobtrusively('workbook.xls') do |book|
|
414
423
|
sheet = book[0]
|
415
424
|
sheet[0,0] = 'simple'
|
416
425
|
end
|
@@ -425,6 +434,10 @@ The book is modified, but its status is unchanged.
|
|
425
434
|
=> true
|
426
435
|
|
427
436
|
|
437
|
+
=== More Details
|
438
|
+
|
439
|
+
For more details about usage: see link:Readme_detail_rdoc.html
|
440
|
+
|
428
441
|
=== Development
|
429
442
|
|
430
443
|
robust_excel_ole started as a simple fork from tomiacannondale's wrap_excel adapted to Ruby 1.8.6.
|
data/README_detail.rdoc
CHANGED
@@ -21,12 +21,12 @@ This is work in progress.
|
|
21
21
|
|
22
22
|
Example:
|
23
23
|
|
24
|
-
book = Book.open('
|
24
|
+
book = Book.open('workbook.xls')
|
25
25
|
|
26
26
|
Open a book with a block.
|
27
27
|
The semantics is similar to, e.g., File.open.
|
28
28
|
|
29
|
-
Book.open('
|
29
|
+
Book.open('workbook.xls') do |book|
|
30
30
|
# do something
|
31
31
|
end
|
32
32
|
|
@@ -34,6 +34,7 @@ Options are the following:
|
|
34
34
|
|
35
35
|
+:default_excel+:: open in the Excel instance used before if the book was once open (default: +reuse+)
|
36
36
|
+:force_excel+:: open in a new or given Excel instance (defaut: +:new+)
|
37
|
+
+:if_absent+:: create a new workbook and save it if it does not exists (default: +create+)
|
37
38
|
+:if_unsaved+:: specify behaviour if the book was unsaved (default: +new_excel+)
|
38
39
|
+:if_obstructed+:: specidy behaviour if the book is blocked by another book (default: +new_excel+)
|
39
40
|
+:read_only+:: open in read-only mode (default: +false+)
|
@@ -44,7 +45,7 @@ The option +:defaut_excel+ :
|
|
44
45
|
|
45
46
|
If the book was open before, then open it in the Excel instance used before. If the book cannot be reopened, then
|
46
47
|
|
47
|
-
+:reuse+:: Connect to a running Excel, if it exists, open a new Excel
|
48
|
+
+:reuse+:: Connect to a running Excel, if it exists, otherwise open a new Excel.
|
48
49
|
+:new+:: Open in a new Excel.
|
49
50
|
[instance]:: Open in a given Excel instance.
|
50
51
|
|
@@ -55,6 +56,13 @@ No matter if the book was open before,
|
|
55
56
|
+:new+:: Open in a new Excel.
|
56
57
|
[instance]:: Open in a given Excel instance.
|
57
58
|
|
59
|
+
The option +:if_absent :
|
60
|
+
|
61
|
+
If the Excel file does not exists, then
|
62
|
+
|
63
|
+
+:create+:: Create a new Excel file
|
64
|
+
+:raise+:: Raise an exception.
|
65
|
+
|
58
66
|
The option +:if_unsaved+ :
|
59
67
|
|
60
68
|
If an unsaved book with the same name is open, then
|
@@ -72,8 +80,8 @@ If a book with same name in a different path is open, then
|
|
72
80
|
+:raise+:: Raise an exception. Don't open the book.
|
73
81
|
+:forget+:: Close the old book, open the new book.
|
74
82
|
+:save+:: Save the old book, close it, open the new book
|
75
|
-
+:close_if_saved+:: Close the old book and open the new book, if the old book is saved, raise an exception
|
76
|
-
+:new_excel+::
|
83
|
+
+:close_if_saved+:: Close the old book and open the new book, if the old book is saved, otherwise raise an exception.
|
84
|
+
+:new_excel+:: Open the new book in a new Excel instance.
|
77
85
|
|
78
86
|
The values :displayalerts and :visible are reached to the class Excel that controls opening and closing Excel instances.
|
79
87
|
|
@@ -85,7 +93,7 @@ Simple close.
|
|
85
93
|
|
86
94
|
The option is : +:if_unsaved+ . It can have one of the following values:
|
87
95
|
|
88
|
-
+:
|
96
|
+
+:raise+ (default), +:save+, +:forget+, +:alert+
|
89
97
|
|
90
98
|
The option specifies: If the book is unsaved, then
|
91
99
|
|
@@ -103,7 +111,7 @@ Simple save.
|
|
103
111
|
|
104
112
|
Saving a book with a file name.
|
105
113
|
|
106
|
-
book.save_as('
|
114
|
+
book.save_as('another_workbook.xls')
|
107
115
|
|
108
116
|
Options are the following:
|
109
117
|
|
@@ -124,17 +132,17 @@ Sometimes the user wants to read and possibly modify a book, no matter if it is
|
|
124
132
|
|
125
133
|
Options are the following:
|
126
134
|
|
135
|
+
+:if_closed+:: :hidden (default) : open closed books in one separate Excel instance that is not visible and has no displayaslerts
|
136
|
+
:reuse : open closed books in the Excel instance of the book, if it exists, otherwise reuse another Excel
|
127
137
|
+:read_only+:: Open the book unobtrusively for reading only (default: false)
|
128
|
-
+:
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
Book.unobtrusively('simple.xls') do |book|
|
138
|
+
+:use_readonly_excel+:: if the book is opened only as ReadOnly and shall be modified, then
|
139
|
+
true: close it and open it as writable in the excel instance where it was open so far
|
140
|
+
false (default) open it as writable in another running excel instance, if it exists,
|
141
|
+
otherwise open in a new excel instance
|
142
|
+
+:visible+:: Make the Excel instance of the book visible (default: false)
|
143
|
+
+:keep_open+:: let the book open after unobtrusively opening (default: false)
|
144
|
+
|
145
|
+
Book.unobtrusively('workbook.xls') do |book|
|
138
146
|
# some modification
|
139
147
|
sheet = book[0]
|
140
148
|
sheet[0,0] = "c"
|
@@ -209,10 +217,12 @@ Reading a cell from a range object.
|
|
209
217
|
row_range[0] => first cell in row_range
|
210
218
|
column_range[1] => second cell in column_range
|
211
219
|
|
220
|
+
Methods to cell are just delegated as VBA methods. Example:
|
221
|
+
|
212
222
|
Reading the value of a cell.
|
213
223
|
|
214
224
|
cell = sheet[0,0]
|
215
|
-
cell.
|
225
|
+
cell.Value => value of the cell.
|
216
226
|
|
217
227
|
Writing a cell
|
218
228
|
|
@@ -304,7 +314,7 @@ Turning on and off in a block.
|
|
304
314
|
|
305
315
|
excel = Excel.create
|
306
316
|
excel.with_displayalerts true do
|
307
|
-
book = Book.open('
|
317
|
+
book = Book.open('workbook.xls')
|
308
318
|
end
|
309
319
|
|
310
320
|
=== Closing all Excel instances.
|
@@ -321,7 +331,7 @@ Including robust_excel_ole.
|
|
321
331
|
|
322
332
|
Opening a book.
|
323
333
|
|
324
|
-
book = Book.open('
|
334
|
+
book = Book.open('workbook.xls')
|
325
335
|
|
326
336
|
Accessing a sheet via its name.
|
327
337
|
|
@@ -337,7 +347,7 @@ Saving the book.
|
|
337
347
|
|
338
348
|
Saving the book with a different name, and overwrite if a file with this name exists.
|
339
349
|
|
340
|
-
book.save_as('
|
350
|
+
book.save_as('different_workbook.xls', :if_exists => :overwrite)
|
341
351
|
|
342
352
|
Closing the book.
|
343
353
|
|
@@ -347,15 +357,15 @@ Closing the book.
|
|
347
357
|
|
348
358
|
Opening a book.
|
349
359
|
|
350
|
-
book = Book.open('
|
360
|
+
book = Book.open('workbook.xls')
|
351
361
|
|
352
362
|
Opening the book in a new Excel instance and make it visible.
|
353
363
|
|
354
|
-
new_book = Book.open('
|
364
|
+
new_book = Book.open('workbook.xls', :force_excel => :new, :visible => true)
|
355
365
|
|
356
366
|
Opening the book in a given Excel instance.
|
357
367
|
|
358
|
-
another_book = Book.open('
|
368
|
+
another_book = Book.open('workbook.xls', :force_excel => book.excel)
|
359
369
|
|
360
370
|
Closing the books.
|
361
371
|
|
@@ -365,7 +375,7 @@ Closing the books.
|
|
365
375
|
|
366
376
|
Reopening the book.
|
367
377
|
|
368
|
-
reopened_book = Book.open('
|
378
|
+
reopened_book = Book.open('workbook.xls')
|
369
379
|
|
370
380
|
The writable book is being prefered.
|
371
381
|
|
@@ -383,7 +393,7 @@ According to :default_excel => :new a new Excel is created, and the book is open
|
|
383
393
|
|
384
394
|
Opening a book.
|
385
395
|
|
386
|
-
book = Book.open('
|
396
|
+
book = Book.open('workbook.xls')
|
387
397
|
|
388
398
|
Adding a copy of the first sheet after the second sheet.
|
389
399
|
|
@@ -393,7 +403,7 @@ Close the book.
|
|
393
403
|
|
394
404
|
Opening a new book with the same name in a new Excel. Leave the book that contains unsaved changes in the old Excel.
|
395
405
|
|
396
|
-
new_book = Book.open('
|
406
|
+
new_book = Book.open('workbook.xls', :if_unsaved => :new_excel)
|
397
407
|
|
398
408
|
Accessing a sheet and change a cell.
|
399
409
|
|
@@ -402,7 +412,7 @@ Accessing a sheet and change a cell.
|
|
402
412
|
|
403
413
|
Opening another book with the same name in the running Excel. The book that contains unsaved changes will be closed before.
|
404
414
|
|
405
|
-
third_book = Book.open('
|
415
|
+
third_book = Book.open('workbook.xls', :if_unsaved => :forget)
|
406
416
|
|
407
417
|
Adding a sheet.
|
408
418
|
|
@@ -420,11 +430,11 @@ Closing the first book and saving it before.
|
|
420
430
|
|
421
431
|
Opening a book.
|
422
432
|
|
423
|
-
book1 = Book.open('
|
433
|
+
book1 = Book.open('workbook.xls')
|
424
434
|
|
425
435
|
Opening a book with the same name in a different path. Close the old book.
|
426
436
|
|
427
|
-
book2 = Book.open('more/
|
437
|
+
book2 = Book.open('more/workbook.xls', :if_obstructed => :forget)
|
428
438
|
|
429
439
|
Changing its cell.
|
430
440
|
|
@@ -433,11 +443,11 @@ Changing its cell.
|
|
433
443
|
|
434
444
|
Opening a book with the same name in a different path. The old book that was modified will be saved and closed before.
|
435
445
|
|
436
|
-
book3 = Book.open('
|
446
|
+
book3 = Book.open('workbook.xls', :if_obstructed => :save)
|
437
447
|
|
438
448
|
Opening a book with the same name in a different path. The other book will be closed, because it does not contain unsaved changes.
|
439
449
|
|
440
|
-
book4 = Book.open('more/
|
450
|
+
book4 = Book.open('more/workbook.xls', :if_obstructed => :close_if_unsaved)
|
441
451
|
|
442
452
|
Closing the book.
|
443
453
|
|
@@ -448,7 +458,7 @@ Closing the book.
|
|
448
458
|
|
449
459
|
Opening a book.
|
450
460
|
|
451
|
-
book = Book.open('
|
461
|
+
book = Book.open('workbook.xls')
|
452
462
|
|
453
463
|
Printing its first cell.
|
454
464
|
|
@@ -457,7 +467,7 @@ Printing its first cell.
|
|
457
467
|
|
458
468
|
Unobtrusively modify the book.
|
459
469
|
|
460
|
-
Book.unobtrusively('
|
470
|
+
Book.unobtrusively('workbook.xls') do |book|
|
461
471
|
sheet = book[0]
|
462
472
|
sheet[0,0] = 'simple'
|
463
473
|
end
|
data/TodoList.md
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
|
2
2
|
### immediately
|
3
3
|
|
4
|
-
--- 2015
|
5
|
-
|
6
|
-
--- 2015-04-
|
7
|
-
--- 2015-04-27 documentation: a crisp one and a detailed one, better examples
|
8
|
-
--- 2015-04-02 set options: make it dry
|
9
|
-
--- 2015-04-17 acceptance test from Testschmiede
|
4
|
+
--- 2015-05-21 documentation: link to detailed, Book accessible in git hub
|
5
|
+
--- 2015-05-21 opening connected Excel files
|
6
|
+
--- 2015-04-17 acceptance tests
|
10
7
|
|
11
8
|
### quick
|
12
9
|
|
13
10
|
--- 2015-05-09 open with option :reuse_excel:
|
14
11
|
choose the last opened Excel that is different to a certain Excel, if it exists,
|
15
12
|
open a new Excel, else
|
13
|
+
use this in unobtrusively
|
16
14
|
|
17
15
|
### short-term
|
18
16
|
|
@@ -27,6 +25,10 @@
|
|
27
25
|
|
28
26
|
### done
|
29
27
|
|
28
|
+
--- 2015-04-02 set options: make it dry
|
29
|
+
--- 2015.05-05 unobtrusively: if_closed: hidden
|
30
|
+
--- 2015-04-27 documentation: a crisp one and a detailed one, better examples
|
31
|
+
--- 2015-04-27 excel.rb: implement sucht that remove attr_writer
|
30
32
|
--- 2015-04-17 unobtrusively: readonly
|
31
33
|
--- 2015-04-27 tests for life cycle (weakrefs to books)
|
32
34
|
--- 2015-04-01 examples for unobtrusively
|
@@ -10,18 +10,18 @@ include RobustExcelOle
|
|
10
10
|
Excel.close_all
|
11
11
|
begin
|
12
12
|
dir = create_tmpdir
|
13
|
-
simple_file = dir + '
|
14
|
-
simple_save_file = dir + '
|
13
|
+
simple_file = dir + 'workbook.xls'
|
14
|
+
simple_save_file = dir + 'workbook_save.xls'
|
15
15
|
File.delete simple_save_file rescue nil
|
16
16
|
book = Book.open(simple_file) # open a book
|
17
17
|
sheet = book[0] # access a sheet via integer
|
18
18
|
cell = sheet[0,0] # access the first cell
|
19
|
-
puts "1st cell: #{cell.
|
19
|
+
puts "1st cell: #{cell.Value}" # put the value of the first cell
|
20
20
|
sheet[0,0] = "complex" # write a value into a cell
|
21
|
-
puts "new cell: #{sheet[0,0].
|
21
|
+
puts "new cell: #{sheet[0,0].Value}"
|
22
22
|
puts "all cells:"
|
23
23
|
sheet.each do |cell| # access all cells
|
24
|
-
puts "#{cell.
|
24
|
+
puts "#{cell.Value}" # for each row: for every column: put the value of the cells
|
25
25
|
end
|
26
26
|
|
27
27
|
sheet_enum = proc do |enum_method| # put each cell, each row or each column
|
@@ -34,7 +34,7 @@ begin
|
|
34
34
|
when :each_row : "row"
|
35
35
|
when :each_column : "column"
|
36
36
|
end
|
37
|
-
puts "#{item_name} #{i}: #{item.
|
37
|
+
puts "#{item_name} #{i}: #{item.Value}" # put values of the item of the sheet
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -10,8 +10,8 @@ include RobustExcelOle
|
|
10
10
|
Excel.close_all
|
11
11
|
begin
|
12
12
|
dir = create_tmpdir
|
13
|
-
simple_file = dir + '
|
14
|
-
simple_save_file = dir + '
|
13
|
+
simple_file = dir + 'workbook.xls'
|
14
|
+
simple_save_file = dir + 'workbook_save.xls'
|
15
15
|
File.delete simple_save_file rescue nil
|
16
16
|
@book = Book.open(simple_file) # open a book
|
17
17
|
|
@@ -10,8 +10,8 @@ include RobustExcelOle
|
|
10
10
|
Excel.close_all
|
11
11
|
begin
|
12
12
|
dir = create_tmpdir
|
13
|
-
simple_file = dir + '
|
14
|
-
simple_save_file = dir + '
|
13
|
+
simple_file = dir + 'workbook.xls'
|
14
|
+
simple_save_file = dir + 'workbook_save.xls'
|
15
15
|
File.delete simple_save_file rescue nil
|
16
16
|
book = Book.open(simple_file) # open a book
|
17
17
|
sheet = book['Sheet1'] # access a sheet via the name
|
@@ -20,7 +20,7 @@ begin
|
|
20
20
|
cell = col_r[0] # access the first cell of these cells
|
21
21
|
puts "row range of 1st row: #{row_r.values}" # puts the values of the first row
|
22
22
|
puts "1st and 2nd cell of the 1st column : #{col_r.values}" # and the first two cells of the first column
|
23
|
-
puts "1st cell of these cells of the 1st columns: #{cell.
|
23
|
+
puts "1st cell of these cells of the 1st columns: #{cell.Value}" # and the first cell of the row range of the 1st row
|
24
24
|
|
25
25
|
i = 0
|
26
26
|
row_r.values.each do |value| # access the values of the first row
|
@@ -10,12 +10,12 @@ include RobustExcelOle
|
|
10
10
|
Excel.close_all
|
11
11
|
begin
|
12
12
|
dir = create_tmpdir
|
13
|
-
file_name = dir + '
|
13
|
+
file_name = dir + 'workbook.xls'
|
14
14
|
book = Book.open(file_name) # open a book
|
15
15
|
book.excel.visible = true # make current Excel visible
|
16
16
|
sleep 1
|
17
17
|
sheet = book[0] # access a sheet
|
18
|
-
sheet[0,0] = sheet[0,0].
|
18
|
+
sheet[0,0] = sheet[0,0].Value == "simple" ? "complex" : "simple" # change a cell
|
19
19
|
sleep 1
|
20
20
|
begin
|
21
21
|
new_book = Book.open(file_name, :if_unsaved => :alert) # open another book with the same file name
|
@@ -10,8 +10,8 @@ include RobustExcelOle
|
|
10
10
|
Excel.close_all
|
11
11
|
begin
|
12
12
|
dir = create_tmpdir
|
13
|
-
file_name1 = dir + '
|
14
|
-
file_name2 = dir + '
|
13
|
+
file_name1 = dir + 'workbook.xls'
|
14
|
+
file_name2 = dir + 'different_workbook.xls'
|
15
15
|
file_name3 = dir + 'book_with_blank.xls'
|
16
16
|
file_name4 = dir + 'merge_cells.xls'
|
17
17
|
book1 = Book.open(file_name1) # open a book in a new Excel instance since no Excel is open
|