robust_excel_ole 1.30 → 1.35
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +27 -1
- data/README.rdoc +61 -61
- data/___dummy_workbook.xls +0 -0
- data/benchmarking/creek_example.rb +1 -1
- data/benchmarking/reo_example.rb +1 -1
- data/benchmarking/reo_example1.rb +1 -1
- data/benchmarking/reo_example2.rb +1 -1
- data/benchmarking/roo_example.rb +1 -1
- data/benchmarking/simple_xlsx_reader_example.rb +1 -1
- data/benchmarking/spreadsheet_example.rb +1 -1
- data/docs/README_excel.rdoc +16 -24
- data/docs/README_listobjects.rdoc +176 -0
- data/docs/README_open.rdoc +12 -12
- data/docs/README_ranges.rdoc +72 -55
- data/docs/README_save_close.rdoc +3 -3
- data/docs/README_sheet.rdoc +19 -20
- data/examples/example_ruby_library.rb +2 -2
- data/examples/introductory_examples/example_open.rb +11 -0
- data/examples/introductory_examples/example_range.rb +2 -2
- data/examples/modifying_sheets/example_access_sheets_and_cells.rb +6 -6
- data/examples/modifying_sheets/example_add_names.rb +1 -1
- data/examples/modifying_sheets/example_concating.rb +1 -1
- data/examples/modifying_sheets/example_copying.rb +2 -2
- data/examples/modifying_sheets/example_listobjects.rb +86 -0
- data/examples/modifying_sheets/example_naming.rb +1 -1
- data/examples/modifying_sheets/example_ranges.rb +1 -1
- data/examples/open_save_close/example_control_to_excel.rb +1 -1
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +1 -1
- data/examples/open_save_close/example_if_obstructed_save.rb +3 -3
- data/examples/open_save_close/example_if_unsaved_accept.rb +1 -1
- data/examples/open_save_close/example_if_unsaved_forget.rb +3 -3
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +4 -4
- data/examples/open_save_close/example_read_only.rb +1 -1
- data/examples/open_save_close/example_simple.rb +1 -1
- data/examples/open_save_close/example_unobtrusively.rb +3 -3
- data/lib/robust_excel_ole.rb +18 -14
- data/lib/robust_excel_ole/address_tool.rb +57 -46
- data/lib/robust_excel_ole/base.rb +4 -6
- data/lib/robust_excel_ole/bookstore.rb +2 -16
- data/lib/robust_excel_ole/cell.rb +17 -22
- data/lib/robust_excel_ole/cygwin.rb +2 -0
- data/lib/robust_excel_ole/excel.rb +131 -186
- data/lib/robust_excel_ole/general.rb +114 -119
- data/lib/robust_excel_ole/list_object.rb +213 -208
- data/lib/robust_excel_ole/list_row.rb +160 -0
- data/lib/robust_excel_ole/range.rb +113 -95
- data/lib/robust_excel_ole/range_owners.rb +52 -66
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +216 -185
- data/lib/robust_excel_ole/worksheet.rb +200 -137
- data/lib/spec_helper.rb +1 -1
- data/robust_excel_ole.gemspec +4 -3
- data/spec/address_tool_spec.rb +2 -2
- data/spec/base_spec.rb +2 -2
- data/spec/bookstore_spec.rb +10 -16
- data/spec/cell_spec.rb +10 -10
- data/spec/cygwin_spec.rb +1 -1
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/excel_spec.rb +133 -86
- data/spec/general_spec.rb +138 -43
- data/spec/list_object_spec.rb +259 -81
- data/spec/list_row_spec.rb +234 -0
- data/spec/more_data/workbook.xls +0 -0
- data/spec/range_spec.rb +77 -43
- data/spec/spec_helper.rb +16 -2
- data/spec/workbook_spec.rb +76 -35
- data/spec/workbook_specs/workbook_all_spec.rb +8 -28
- data/spec/workbook_specs/workbook_close_spec.rb +1 -1
- data/spec/workbook_specs/workbook_misc_spec.rb +23 -16
- data/spec/workbook_specs/workbook_open_spec.rb +98 -54
- data/spec/workbook_specs/workbook_save_spec.rb +22 -23
- data/spec/workbook_specs/workbook_sheet_spec.rb +4 -4
- data/spec/workbook_specs/workbook_subclass_spec.rb +1 -1
- data/spec/workbook_specs/workbook_unobtr_spec.rb +339 -361
- data/spec/worksheet_spec.rb +550 -306
- metadata +43 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80365f36774968b6f55052177932c00dbe57b7fb3bee76762474a0b21637440b
|
4
|
+
data.tar.gz: a352fd270609529688869edf581bc2d1c20eee9c0b9b8ec61198dcfafc82fd2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5246534fa3c3767e9fe4c8081d37aac6d54070238b6008d1ea289792cc3fa2bbf3b855b36eab4959b16103af6e5f8a83d7d326dc82923ff25c82ab8b9f61ae1e
|
7
|
+
data.tar.gz: '070856a21a1786fa7f9fd3de02edaa6bf661e936329c02afb78e9d5ddbd8623b95a49ec1f22be64e4d205c47e4c7e7c2bf964a00d2928a2d4dbe4a6640bf3a40'
|
data/Changelog
CHANGED
@@ -1,6 +1,32 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [1.33] 2021-01-06
|
5
|
+
|
6
|
+
## [1.32] 2021-23-04
|
7
|
+
|
8
|
+
### Added
|
9
|
+
- Excel#each
|
10
|
+
- ListObject#each, value, rows_number, position, ==
|
11
|
+
- ListObject#[] extended with options
|
12
|
+
- ListRow#to_h, to_a, values=, keys_values, ==
|
13
|
+
- RangeOwners#names
|
14
|
+
- Worksheet#each_cell
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
- Worksheet#[]: returning range values given address or defined name (instead of returning a cell when giving address)
|
18
|
+
- Worksheet#each traversing row values instead of cells
|
19
|
+
- Excel#excels_number renamed to #instance_count
|
20
|
+
- Excel#known_excels_number renamed to #known_instance_count
|
21
|
+
- Excel#known_excel_instance renamed to #known_running_instance
|
22
|
+
- Excel#known_excel_instances renamed to #known_running_instances
|
23
|
+
- RangeOwners#rename_range renamed to #rename_name
|
24
|
+
|
25
|
+
## [1.31] 2021-14-01
|
26
|
+
|
27
|
+
### Added
|
28
|
+
- Worksheet#table
|
29
|
+
|
4
30
|
## [1.30] 2020-18-11
|
5
31
|
|
6
32
|
## [1.29] 2020-05-11
|
@@ -187,7 +213,7 @@ All notable changes to this project will be documented in this file.
|
|
187
213
|
## [1.1.4] - 2018-10-6
|
188
214
|
|
189
215
|
### Added
|
190
|
-
- Book#open: for the options:
|
216
|
+
- Book#open: for the options: simplifiction: :force can be left out
|
191
217
|
- Excel#for_this_instance
|
192
218
|
- Excel#for_all_workbooks
|
193
219
|
- Book#for_this_workbooks
|
data/README.rdoc
CHANGED
@@ -105,7 +105,7 @@ Then we'll save the workbook.
|
|
105
105
|
|
106
106
|
workbook.save
|
107
107
|
|
108
|
-
===
|
108
|
+
=== Unobtrusively opening workbooks
|
109
109
|
|
110
110
|
RobustExcelOle allows unobtrusively reading and modifying workbooks, i.e. accessing workbooks without changing their "status". The status comprises whether the workbook is open or closed, saved or unsaved, read-only or writable, visible or invisible, whether the calculation mode is manual or automatic, and checking compatibility is done or not done.
|
111
111
|
|
@@ -121,9 +121,11 @@ RobustExcelOle allows unobtrusively reading and modifying workbooks, i.e. access
|
|
121
121
|
# do something
|
122
122
|
end
|
123
123
|
|
124
|
-
|
124
|
+
=== More featrues about creating, opening, saving and closing workbooks
|
125
125
|
|
126
|
-
|
126
|
+
We can create a new, empty workbook.
|
127
|
+
|
128
|
+
Workbook.create('spec/data/new_workbook.xls', visible: true)
|
127
129
|
|
128
130
|
Moreover, we can open the workbook using a block, similar to, e.g., +File.open+.
|
129
131
|
|
@@ -133,15 +135,15 @@ Moreover, we can open the workbook using a block, similar to, e.g., +File.open+.
|
|
133
135
|
|
134
136
|
Once we have a workbook, we can set some options, e.g.
|
135
137
|
|
136
|
-
workbook.for_this_workbook(:
|
138
|
+
workbook.for_this_workbook(visible: true, read_only: false)
|
137
139
|
|
138
140
|
We can also open the workbook and provide the options in one step, e.g.
|
139
141
|
|
140
|
-
workbook = Workbook.open('spec/data/workbook.xls', :
|
142
|
+
workbook = Workbook.open('spec/data/workbook.xls', visible: true)
|
141
143
|
|
142
144
|
or, using abbreviations,
|
143
145
|
|
144
|
-
workbook = Workbook.open('spec/data/workbook.xls', :
|
146
|
+
workbook = Workbook.open('spec/data/workbook.xls', v: true)
|
145
147
|
|
146
148
|
Note that +Workbook.open+ can also connect to workbooks which were not opened via RobustExcelOle (but had been opened before by some user).
|
147
149
|
|
@@ -157,11 +159,11 @@ or save the workbook under a different name.
|
|
157
159
|
|
158
160
|
Finally we can close the workbook
|
159
161
|
|
160
|
-
workbook.
|
162
|
+
workbook.close
|
161
163
|
|
162
164
|
or save and close the workbook in one step.
|
163
165
|
|
164
|
-
workbook.close(:
|
166
|
+
workbook.close(if_unsaved: :save)
|
165
167
|
|
166
168
|
For more details about saving and closing workbooks see
|
167
169
|
{README_save_close}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_save_close.rdoc]
|
@@ -175,7 +177,7 @@ We can start a new Excel instance with
|
|
175
177
|
|
176
178
|
or
|
177
179
|
|
178
|
-
excel1 = Excel.new(:
|
180
|
+
excel1 = Excel.new(reuse: false)
|
179
181
|
|
180
182
|
We can also obtain an Excel object by connecting to the already running Excel instance.
|
181
183
|
|
@@ -183,19 +185,15 @@ We can also obtain an Excel object by connecting to the already running Excel in
|
|
183
185
|
|
184
186
|
or
|
185
187
|
|
186
|
-
excel2 = Excel.new(:
|
188
|
+
excel2 = Excel.new(reuse: true)
|
187
189
|
|
188
190
|
We close the Excel instance using
|
189
191
|
|
190
192
|
excel1.close
|
191
193
|
|
192
|
-
Closed Excel instances can be reopened.
|
193
|
-
|
194
|
-
excel1.recreate(:reopen_workbooks => true, :visible => true)
|
195
|
-
|
196
194
|
Closing all Excel instances is done by
|
197
195
|
|
198
|
-
Excel.close_all(:
|
196
|
+
Excel.close_all(if_unsaved: :forget)
|
199
197
|
|
200
198
|
For hard terminating all Excel processes we can use
|
201
199
|
|
@@ -214,39 +212,34 @@ For example, suppose we want to open a workbook.
|
|
214
212
|
|
215
213
|
Now we want to open another workbook in a different Excel instance.
|
216
214
|
|
217
|
-
workbook2 = Workbook.open('spec/data/different_workbook.xls', :
|
218
|
-
|
219
|
-
We can also create a third Excel instance and open another workbook in this instance.
|
220
|
-
|
221
|
-
excel1 = Excel.create
|
222
|
-
workbook3 = Workbook.open('spec/data/another_workbook.xls', :excel => excel1)
|
215
|
+
workbook2 = Workbook.open('spec/data/different_workbook.xls', excel: :new)
|
223
216
|
|
224
217
|
A workbook is opened by default in the Excel instance where it was open before most recently.
|
225
218
|
|
226
219
|
workbook1.close
|
227
220
|
workbook1 = Workbook.open('spec/data/workbook.xls')
|
228
221
|
|
229
|
-
If
|
222
|
+
If the Excel instance is damaged or closed, then options control whether the workbook shall be opened in the current (active), a new or a given Excel instance.
|
230
223
|
|
231
|
-
workbook1 = Workbook.open('spec/data/workbook.xls', :
|
224
|
+
workbook1 = Workbook.open('spec/data/workbook.xls', default: {excel: new})
|
232
225
|
|
233
226
|
Without the option +:default+, the workbook can be forced to be opened in the current, new or given Excel instance, no matter if and where it was opened before, e.g.
|
234
227
|
|
235
|
-
workbook2 = Workbook.open('spec/data/workbook.xls', :
|
228
|
+
workbook2 = Workbook.open('spec/data/workbook.xls', excel: new)
|
236
229
|
|
237
230
|
=== Managing conflicts with unsaved and blocking workbooks
|
238
231
|
|
239
|
-
RobustExcelOle enables processing workbooks, while
|
232
|
+
RobustExcelOle enables processing workbooks, while supporting user's interactions: The commands enable to open, close, reopen, read, modify, write and save Excel workbooks, without the need of the user's interaction, and even without the user noticing. Thus, while running a script containing RobustExcelOle commands, the user can open and process workbooks in any Excel instances at any time. RobustExcelOle manages the complex cases of conflicts that might occur such that the user does not need to interfere and the script can continue.
|
240
233
|
|
241
234
|
For example, suppose we want to process a list of workbooks. RobustExcelOle allows to rapidly open, manipulate, close and save these workbooks. Now assume, the workbook "workbook.xls" is being processed, while the user has already opened this workbook, has modified but not saved it yet. Excel would prompt a message and ask the user what to do. RobustExcelOle solves this conflict by using an option that states whether the changes of the user should be saved (accepted) or discarded (forgotten) before opening the workbook, e.g.
|
242
235
|
|
243
|
-
workbook = Workbook.open('workbook.xls', :
|
236
|
+
workbook = Workbook.open('workbook.xls', if_unsaved: :accept)
|
244
237
|
|
245
238
|
Similarly, if the user has opened a workbook that has the same name but a different path, the conflict can be solved via an option.
|
246
239
|
|
247
240
|
workbook1 = Workbook.open('spec/data/workbook.xls')
|
248
241
|
# do something
|
249
|
-
workbook2 = Workbook.open('spec/data/more/workbook.xls', :
|
242
|
+
workbook2 = Workbook.open('spec/data/more/workbook.xls', if_blocked: :forget)
|
250
243
|
|
251
244
|
For more details about opening and closing workbooks in Excel instances see {README_open}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_open.rdoc]
|
252
245
|
|
@@ -260,14 +253,6 @@ We access the first worksheet by
|
|
260
253
|
|
261
254
|
worksheet = workbook.sheet(1)
|
262
255
|
|
263
|
-
or
|
264
|
-
|
265
|
-
worksheet = workbook.sheet('Sheet1')
|
266
|
-
|
267
|
-
or
|
268
|
-
|
269
|
-
worksheet = workbook.first_sheet
|
270
|
-
|
271
256
|
We can read and change the worksheet name.
|
272
257
|
|
273
258
|
worksheet.name
|
@@ -277,7 +262,7 @@ We can read and change the worksheet name.
|
|
277
262
|
|
278
263
|
We can copy the first worksheet, name it and add it before the third worksheet.
|
279
264
|
|
280
|
-
workbook.add_or_copy_sheet(sheet, :
|
265
|
+
workbook.add_or_copy_sheet(sheet, as: "copied_name, before: workbook.last_sheet)
|
281
266
|
|
282
267
|
For more details about processing worksheets see {README_sheet}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_sheet.rdoc]
|
283
268
|
|
@@ -287,62 +272,77 @@ We can define a rectangular range by providing the top left and the bottum down
|
|
287
272
|
|
288
273
|
worksheet.range([1..3,1..4])
|
289
274
|
|
290
|
-
We can read
|
275
|
+
We can read and modify the first cell, e.g.
|
291
276
|
|
292
|
-
worksheet
|
277
|
+
worksheet[1,1]
|
278
|
+
# => "foo"
|
279
|
+
worksheet[1,1] = "hello"
|
280
|
+
|
281
|
+
We get the value of a named range
|
293
282
|
|
294
|
-
|
283
|
+
worksheet["firstcell"] # => "hello"
|
295
284
|
|
296
|
-
|
285
|
+
and set another value to that range.
|
297
286
|
|
298
|
-
|
287
|
+
worksheet["firstcell"] = "new_value"
|
299
288
|
|
300
|
-
|
289
|
+
For more details about reading and writing contents of cells and ranges see {README_ranges}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_ranges.rdoc]
|
301
290
|
|
302
|
-
|
291
|
+
=== List Objects (Tables)
|
303
292
|
|
304
|
-
|
293
|
+
We can define a list object (or table) from scratch
|
305
294
|
|
306
|
-
|
295
|
+
table = ListObject.new(worksheet, "table 1", [1,1], 3, ["Person","AmountSales"])
|
307
296
|
|
308
|
-
|
297
|
+
or get a given list object in a worksheet given its table number or name.
|
309
298
|
|
310
|
-
|
299
|
+
table = worksheet.table(1)
|
311
300
|
|
312
|
-
|
301
|
+
A list row can be accessed by providing either the row number or a key, i.e. hash of column name - value pairs, e.g.
|
313
302
|
|
314
|
-
|
303
|
+
row1 = table[1]
|
315
304
|
|
316
|
-
|
305
|
+
row1 = table[{"Number": 1, "Person": "John"}]
|
317
306
|
|
318
|
-
|
307
|
+
You can get all or a maximal number of list rows matching the key.
|
319
308
|
|
309
|
+
rows = table[{"Number": 1}, limit: nil]
|
310
|
+
rows = table[{"Number": 1}, limit: 2]
|
320
311
|
|
321
|
-
|
312
|
+
Now we can read and set the value of a cell of the table with help of methods that are underscored variants of the column names, e.g.
|
322
313
|
|
323
|
-
|
314
|
+
row1.person = "John"
|
324
315
|
|
325
|
-
|
316
|
+
or with help of the column name
|
326
317
|
|
327
|
-
|
318
|
+
row1["Person"] = "John"
|
328
319
|
|
329
|
-
|
320
|
+
We can also read all values in a row.
|
330
321
|
|
331
|
-
|
322
|
+
table[1].to_a
|
323
|
+
# => ["John", 40]
|
332
324
|
|
333
|
-
|
325
|
+
table[1].to_h
|
326
|
+
# => {"Person": "John", "AmountSales": 40}
|
334
327
|
|
335
|
-
|
328
|
+
For more details about using and processing list objects see {README_listobjects}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_listobjects.rdoc]
|
336
329
|
|
330
|
+
=== More features
|
337
331
|
|
338
|
-
|
332
|
+
The class WIN32OLE is being extended such that RobustExcelOle methods can be applied to WIN32OLE objects. As mentioned above, the RobustExcelOle objects are wrapper of corresponding WIN32OLE objects. So now the RobustExcelOle objects and their wrapped WIN32OLE objects are interchangeable. One example would be
|
339
333
|
|
340
334
|
range.ole_range.copy([4,3])
|
341
335
|
|
342
|
-
Likewise it is possible to convert ("type-lift")
|
336
|
+
Likewise it is possible to convert ("type-lift") WIN32OLE objects into the corresponding RobustExcelOle object, using the method +to_reo+. It is a refinement of the class WIN32OLE. So you can write
|
337
|
+
|
338
|
+
using ToReoRefinement
|
343
339
|
|
344
340
|
range = sheet.Names.Item("firstcell").to_reo
|
345
341
|
|
342
|
+
=== Design issues
|
343
|
+
|
344
|
+
We don't consider active worksheets or workbooks in our implementation, because this has been proven to be very error-prone.
|
345
|
+
|
346
346
|
=== Examples
|
347
347
|
|
348
348
|
You can run the examples included in the directory +examples+, e.g.
|
data/___dummy_workbook.xls
CHANGED
Binary file
|
@@ -10,7 +10,7 @@ start_time = Time.now
|
|
10
10
|
workbook = Creek::Book.new './sample_excel_files/xlsx_500_rows.xlsx'
|
11
11
|
|
12
12
|
worksheets = workbook.sheets
|
13
|
-
puts "Found #{worksheets.
|
13
|
+
puts "Found #{worksheets.size} worksheets"
|
14
14
|
|
15
15
|
worksheets.each do |worksheet|
|
16
16
|
puts "Reading: #{worksheet.name}"
|
data/benchmarking/reo_example.rb
CHANGED
data/benchmarking/roo_example.rb
CHANGED
@@ -9,7 +9,7 @@ start_time = Time.now
|
|
9
9
|
workbook = Roo::Spreadsheet.open './sample_excel_files/xlsx_500_rows.xlsx'
|
10
10
|
|
11
11
|
worksheets = workbook.sheets
|
12
|
-
puts "Found #{worksheets.
|
12
|
+
puts "Found #{worksheets.size} worksheets"
|
13
13
|
|
14
14
|
worksheets.each do |worksheet|
|
15
15
|
puts "Reading: #{worksheet}"
|
@@ -10,7 +10,7 @@ start_time = Time.now
|
|
10
10
|
workbook = SimpleXlsxReader.open './sample_excel_files/xlsx_500_rows.xlsx'
|
11
11
|
|
12
12
|
worksheets = workbook.sheets
|
13
|
-
puts "Found #{worksheets.
|
13
|
+
puts "Found #{worksheets.size} worksheets"
|
14
14
|
|
15
15
|
worksheets.each do |worksheet|
|
16
16
|
puts "Reading: #{worksheet.name}"
|
@@ -11,7 +11,7 @@ start_time = Time.now
|
|
11
11
|
workbook = Spreadsheet.open './sample_excel_files/xls_25000_rows.xls'
|
12
12
|
|
13
13
|
worksheets = workbook.worksheets
|
14
|
-
puts "Found #{worksheets.
|
14
|
+
puts "Found #{worksheets.size} worksheets"
|
15
15
|
|
16
16
|
|
17
17
|
worksheets.each do |worksheet|
|
data/docs/README_excel.rdoc
CHANGED
@@ -12,7 +12,7 @@ You can create a new Excel instance by
|
|
12
12
|
|
13
13
|
or
|
14
14
|
|
15
|
-
excel1 = Excel.new(:
|
15
|
+
excel1 = Excel.new(reuse: false)
|
16
16
|
|
17
17
|
In case you want to reuse an already running Excel instance, write
|
18
18
|
|
@@ -20,7 +20,7 @@ In case you want to reuse an already running Excel instance, write
|
|
20
20
|
|
21
21
|
or
|
22
22
|
|
23
|
-
excel2 = Excel.new(:
|
23
|
+
excel2 = Excel.new(reuse: true)
|
24
24
|
|
25
25
|
Options of the methods +create+ and +new+ are +:reuse+ (+true+, +false+), +:visible+ (+true+, +false+), +:displayalerts+ (+true+, +false+, +:if_visible+), +:calculation+ (+:manual+, +:automatic+, +nil+) and +:screenupdating+ (+true+, +false+).
|
26
26
|
|
@@ -28,7 +28,7 @@ The option +:calculation+ specifies, whether the calculation mode is being force
|
|
28
28
|
|
29
29
|
You can also type-lift an Excel instance represented as WIN32OLE object to an Excel object.
|
30
30
|
|
31
|
-
excel = Excel.new(win32ole_object, :
|
31
|
+
excel = Excel.new(win32ole_object, visible: true)
|
32
32
|
|
33
33
|
Once you have got an Excel object, you can apply all VBA methods that you would apply to a VBA Application object
|
34
34
|
(see https://docs.microsoft.com/en-us/office/vba/api/excel.application(object)#methods).
|
@@ -40,17 +40,17 @@ You can set all options in a given Excel instance
|
|
40
40
|
|
41
41
|
excel = Excel.current
|
42
42
|
|
43
|
-
excel.
|
43
|
+
excel.set_options(visible: true, displayalerts: true, calculation: :manual)
|
44
44
|
|
45
45
|
=== Making an Excel visible or invisible
|
46
46
|
|
47
47
|
You can create a new Excel instance and make it visible.
|
48
48
|
|
49
|
-
excel1 = Excel.create(:
|
49
|
+
excel1 = Excel.create(visible: true)
|
50
50
|
|
51
51
|
or
|
52
52
|
|
53
|
-
excel1 = Excel.new(:
|
53
|
+
excel1 = Excel.new(reuse: false, visible: true)
|
54
54
|
|
55
55
|
or
|
56
56
|
|
@@ -62,7 +62,7 @@ or
|
|
62
62
|
|
63
63
|
You can enable DisplayAlerts with, e.g.
|
64
64
|
|
65
|
-
excel1 = Excel.new(:
|
65
|
+
excel1 = Excel.new(reuse: true, displayalerts: true)
|
66
66
|
|
67
67
|
or
|
68
68
|
|
@@ -99,30 +99,22 @@ You can do it in a block:
|
|
99
99
|
|
100
100
|
You can set options for all workbooks of an Excel instance.
|
101
101
|
|
102
|
-
excel.
|
102
|
+
excel.each_workook(visible: true, read_only: true)
|
103
103
|
|
104
104
|
|
105
|
-
=== Showing and traversing
|
105
|
+
=== Showing and traversing all workbooks
|
106
106
|
|
107
|
-
You can yield an array of all Workbook objects of an Excel instance
|
107
|
+
The method +each+ provides an enumerator traversing all workbook objects. You can yield an array of all Workbook objects of an Excel instance, by applying +to_a+ or
|
108
108
|
|
109
109
|
excel.workbooks
|
110
110
|
|
111
|
-
You can access all Workbook objects by using the methods Excel#each_workbook and Excel#each_workbook_with_index. Here are some examples:
|
111
|
+
You can access all Workbook objects supplying options by using the methods Excel#each_workbook and Excel#each_workbook_with_index. Here are some examples:
|
112
112
|
|
113
|
-
excel.each_workbook {|w| puts w.filename}
|
113
|
+
excel.each_workbook(displayalerts: true) {|w| puts w.filename}
|
114
114
|
|
115
115
|
and
|
116
116
|
|
117
|
-
excel.each_workbook.with_index {|w,i| puts w,i }
|
118
|
-
|
119
|
-
With help of these methods you can also supply options, e.g. without a block,
|
120
|
-
|
121
|
-
excel.each_workbook(:visible => true)
|
122
|
-
|
123
|
-
or, with a block,
|
124
|
-
|
125
|
-
excel.each_workbook(:visible => true) {|w| puts w}
|
117
|
+
excel.each_workbook.with_index(displayalerts: true) {|w,i| puts w,i }
|
126
118
|
|
127
119
|
=== Accessing the active workbook
|
128
120
|
|
@@ -143,7 +135,7 @@ The method +close has the option +:if_unsaved+ with the values +:raise+, +:save+
|
|
143
135
|
|
144
136
|
For example, if you want to close an Excel instance and save unsaved workbooks, use
|
145
137
|
|
146
|
-
excel.close(:
|
138
|
+
excel.close(if_unsaved: :save)
|
147
139
|
|
148
140
|
=== Recreating an Excel instance
|
149
141
|
|
@@ -154,7 +146,7 @@ Closed Excel instances can also be reopened. This includes reopening all workboo
|
|
154
146
|
|
155
147
|
The options are +:reopen_workbooks+, +:visible+ and +:displayalerts+.
|
156
148
|
|
157
|
-
excel.recreate(:
|
149
|
+
excel.recreate(reopen_workbooks: true, visible: true, displayalerts: true)
|
158
150
|
|
159
151
|
=== Providing Excel instances
|
160
152
|
|
@@ -168,7 +160,7 @@ Providing all Excel instances (opened via RobustExcelOle) as objects of the clas
|
|
168
160
|
|
169
161
|
This method has the option +:if_unsaved+ as described above. For example, if you want to close all Excel instances containing saved workbooks and raise an error for Excel instances with unsaved workbooks, use
|
170
162
|
|
171
|
-
Excel.close_all(:
|
163
|
+
Excel.close_all(if_unsaved: :raise)
|
172
164
|
|
173
165
|
=== Terminating all Excel processes
|
174
166
|
|