robust_excel_ole 1.29 → 1.34
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +35 -1
- data/README.rdoc +86 -49
- 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 +20 -16
- 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 -48
- data/lib/robust_excel_ole/base.rb +4 -6
- data/lib/robust_excel_ole/bookstore.rb +3 -17
- 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 +136 -201
- data/lib/robust_excel_ole/general.rb +265 -254
- data/lib/robust_excel_ole/list_object.rb +186 -210
- data/lib/robust_excel_ole/list_row.rb +166 -0
- data/lib/robust_excel_ole/range.rb +118 -96
- data/lib/robust_excel_ole/range_owners.rb +54 -135
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +237 -197
- data/lib/robust_excel_ole/worksheet.rb +264 -133
- 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 +19 -17
- 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 +141 -43
- data/spec/list_object_spec.rb +259 -81
- data/spec/list_row_spec.rb +220 -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 +87 -46
- 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 +52 -45
- data/spec/workbook_specs/workbook_open_spec.rb +109 -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 +550 -392
- data/spec/worksheet_spec.rb +552 -308
- 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: 367d0c217ed968287f98cbf62cc786df14d364799f2dec633848af78eb6ce1f0
|
4
|
+
data.tar.gz: de1a58c99a761ae005142a7bf302cab13b3b64021605e000e05ec2d783246fa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65361e347cb55f05bc6d24c6a85f3f3b19696cf057dbc71c14cb86a7c3d8bfc28aca247231cc3a90409d933ca3944104f40e006d2591dfe55f60f84a30f75619
|
7
|
+
data.tar.gz: db86b776ff9359c8ebb3893d1bbc103aacfae6f408dc0358f7b32367312b80096d47a3aed682b7ec367f2a41eb64cef9ac8c3aa9fcc021c8ac05b9e8babb70cf
|
data/Changelog
CHANGED
@@ -1,6 +1,40 @@
|
|
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
|
+
|
30
|
+
## [1.30] 2020-18-11
|
31
|
+
|
32
|
+
## [1.29] 2020-05-11
|
33
|
+
|
34
|
+
### Added
|
35
|
+
- Workbook.open can also take a Pathname object
|
36
|
+
- General#init_reo_for_win32ole
|
37
|
+
|
4
38
|
## [1.28] 2020-23-10
|
5
39
|
|
6
40
|
## [1.27] 2020-16-10
|
@@ -179,7 +213,7 @@ All notable changes to this project will be documented in this file.
|
|
179
213
|
## [1.1.4] - 2018-10-6
|
180
214
|
|
181
215
|
### Added
|
182
|
-
- Book#open: for the options:
|
216
|
+
- Book#open: for the options: simplifiction: :force can be left out
|
183
217
|
- Excel#for_this_instance
|
184
218
|
- Excel#for_all_workbooks
|
185
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: excel1)
|
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
|
|
@@ -277,7 +270,7 @@ We can read and change the worksheet name.
|
|
277
270
|
|
278
271
|
We can copy the first worksheet, name it and add it before the third worksheet.
|
279
272
|
|
280
|
-
workbook.add_or_copy_sheet(sheet, :
|
273
|
+
workbook.add_or_copy_sheet(sheet, as: "copied_name, before: workbook.last_sheet)
|
281
274
|
|
282
275
|
For more details about processing worksheets see {README_sheet}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_sheet.rdoc]
|
283
276
|
|
@@ -287,21 +280,9 @@ We can define a rectangular range by providing the top left and the bottum down
|
|
287
280
|
|
288
281
|
worksheet.range([1..3,1..4])
|
289
282
|
|
290
|
-
We can read the first three cells of the first row
|
291
|
-
|
292
|
-
worksheet.row_range(1, 1..3).values # => ["foo","workbook","sheet1"]
|
293
|
-
|
294
|
-
and the third column
|
295
|
-
|
296
|
-
worksheet.col_range(3).values # => ["sheet1", 2.0, 4.0]
|
297
|
-
|
298
283
|
We can read the first cell, using
|
299
284
|
|
300
|
-
worksheet[1,1].
|
301
|
-
|
302
|
-
or
|
303
|
-
|
304
|
-
worksheet.row_range(1)[0].value # => "foo"
|
285
|
+
worksheet[1,1]. # => "foo"
|
305
286
|
|
306
287
|
Then we modify it.
|
307
288
|
|
@@ -317,10 +298,71 @@ and set another value to that range.
|
|
317
298
|
|
318
299
|
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]
|
319
300
|
|
301
|
+
=== List Objects (Tables)
|
302
|
+
|
303
|
+
We can define a list object (or table) from scratch
|
304
|
+
|
305
|
+
table = ListObject.new(worksheet, "table 1", [1,1], 3, ["Person","AmountSales"])
|
306
|
+
|
307
|
+
or get a given list object in a worksheet given its table number or name.
|
308
|
+
|
309
|
+
table = worksheet.table(1)
|
310
|
+
|
311
|
+
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.
|
312
|
+
|
313
|
+
row1 = table[1]
|
314
|
+
|
315
|
+
row1 = table[{"Number": 1, "Person": "John"}]
|
316
|
+
|
317
|
+
You can get all or a maximal number of list rows matching the key.
|
318
|
+
|
319
|
+
rows = table[{"Number": 1}, limit: nil]
|
320
|
+
rows = table[{"Number": 1}, limit: 2]
|
321
|
+
|
322
|
+
Now we can set value of a cell of the table with help of methods that are equal to or are underscored variants of the column names, e.g.
|
323
|
+
|
324
|
+
row1.person = "John"
|
325
|
+
|
326
|
+
or
|
327
|
+
|
328
|
+
row1["Person"] = "John"
|
329
|
+
|
330
|
+
Similarly you can get the values. We can also read all values in a row.
|
331
|
+
|
332
|
+
table[1].to_a
|
333
|
+
# => ["John", 40]
|
334
|
+
|
335
|
+
table[1].to_h
|
336
|
+
# => {"Person": "John", "AmountSales": 40}
|
337
|
+
|
338
|
+
We can set the values in a whole row.
|
339
|
+
|
340
|
+
table[1].values = ["Herber", 80]
|
341
|
+
|
342
|
+
Similarly, we can read and set the values in a whole column, e.g.
|
343
|
+
|
344
|
+
table.column_values("Person")
|
345
|
+
# => ["John", "Peter"]
|
346
|
+
|
347
|
+
and
|
348
|
+
|
349
|
+
table.set_column_values(1, ["Herbert","Paul"])
|
350
|
+
|
351
|
+
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]
|
320
352
|
|
321
353
|
=== More features
|
322
354
|
|
323
|
-
1. The
|
355
|
+
1. 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
|
356
|
+
|
357
|
+
range.ole_range.copy([4,3])
|
358
|
+
|
359
|
+
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
|
360
|
+
|
361
|
+
using ToReoRefinement
|
362
|
+
|
363
|
+
range = sheet.Names.Item("firstcell").to_reo
|
364
|
+
|
365
|
+
2. The method +General.change_current_binding+ allows to change the value of self within the current binding, while preserving the local variables, without starting another repl. Assume, +object+ shall be the self, then you would put
|
324
366
|
|
325
367
|
General.change_current_binding(object)
|
326
368
|
|
@@ -334,14 +376,9 @@ or
|
|
334
376
|
|
335
377
|
However, this command also starts another pry repl (with another binding). Moreover, local variables in the previous binding are forgotten.
|
336
378
|
|
379
|
+
=== Design issues
|
337
380
|
|
338
|
-
|
339
|
-
|
340
|
-
range.ole_range.copy([4,3])
|
341
|
-
|
342
|
-
Likewise it is possible to convert ("type-lift") Win32Ole objects into the corresponding RobustExcelOle object, using General.to_reo.
|
343
|
-
|
344
|
-
range = sheet.Names.Item("firstcell").to_reo
|
381
|
+
We don't consider active worksheets or workbooks in our implementation, because this has been proven to be very error-prone.
|
345
382
|
|
346
383
|
=== Examples
|
347
384
|
|
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
|
|