robust_excel_ole 1.32 → 1.36

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Changelog +22 -2
  4. data/README.rdoc +44 -210
  5. data/___dummy_workbook.xls +0 -0
  6. data/docs/README_excel.rdoc +5 -6
  7. data/docs/README_listobjects.rdoc +8 -15
  8. data/docs/README_open.rdoc +48 -25
  9. data/docs/README_ranges.rdoc +7 -10
  10. data/docs/README_save_close.rdoc +4 -5
  11. data/docs/README_sheet.rdoc +4 -8
  12. data/examples/introductory_examples/example_introductory.rb +1 -1
  13. data/examples/introductory_examples/example_open.rb +1 -1
  14. data/lib/robust_excel_ole/address_tool.rb +6 -5
  15. data/lib/robust_excel_ole/excel.rb +98 -16
  16. data/lib/robust_excel_ole/general.rb +53 -23
  17. data/lib/robust_excel_ole/list_object.rb +32 -7
  18. data/lib/robust_excel_ole/list_row.rb +83 -23
  19. data/lib/robust_excel_ole/range.rb +19 -28
  20. data/lib/robust_excel_ole/range_owners.rb +24 -17
  21. data/lib/robust_excel_ole/version.rb +1 -1
  22. data/lib/robust_excel_ole/workbook.rb +113 -42
  23. data/lib/robust_excel_ole/worksheet.rb +15 -5
  24. data/robust_excel_ole.gemspec +0 -1
  25. data/spec/bookstore_spec.rb +6 -12
  26. data/spec/data/more_data/workbook.xls +0 -0
  27. data/spec/data/workbook_linked.xlsm +0 -0
  28. data/spec/data/workbook_linked3.xlsm +0 -0
  29. data/spec/data/workbook_linked_sub.xlsm +0 -0
  30. data/spec/data/workbook_listobjects.xlsx +0 -0
  31. data/spec/data/workbook_unsaved.xlsm +0 -0
  32. data/spec/excel_spec.rb +6 -6
  33. data/spec/general_spec.rb +74 -39
  34. data/spec/list_object_spec.rb +26 -9
  35. data/spec/list_row_spec.rb +36 -6
  36. data/spec/more_data/workbook.xls +0 -0
  37. data/spec/range_spec.rb +12 -3
  38. data/spec/workbook_spec.rb +3 -3
  39. data/spec/workbook_specs/workbook_all_spec.rb +1 -2
  40. data/spec/workbook_specs/workbook_misc_spec.rb +249 -2
  41. data/spec/workbook_specs/workbook_open_spec.rb +312 -19
  42. data/spec/workbook_specs/workbook_unobtr_spec.rb +197 -43
  43. data/spec/worksheet_spec.rb +8 -0
  44. metadata +9 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f56e6aaeeeec6c073cc4f871ea99185428523959c420e1165d199792979074c5
4
- data.tar.gz: 79dd7f6ea160e0045592a3dd8ae31a5b8a162c71b6986dcbcef157eba54c93b4
3
+ metadata.gz: 0d53d040d2a0079556bfca8d89a531f65b75f8e27d361378e339d38ac8ec7fdf
4
+ data.tar.gz: 68658a532b13b21815f61e5ce7a286b8df42693711142ee7ff9c15c26cf6fa07
5
5
  SHA512:
6
- metadata.gz: 894959ff3e8c48c8413bbb137013cf8ad7612bb991292f1461b1df9b3371d15c16132ecf0df0dbf78403171381064cfb43d9400604bc2155214f8aa2a514ea7c
7
- data.tar.gz: 508b37f27ef7c0e554b565f21263386e1b180cb5269f6a843b2da927eaa3f6eebe5a111a362d5dc96de4726a1c3648673b062b02589739eb7e5ff2a0bb7f59cc
6
+ metadata.gz: '08f8abee9ca47bf37d4d27e3d13ecfcb31f1ae019370450bb052911ccd5a56ec5116c007d1f1475c19a29226857281f7d9d80747c5d2e5a7ac605de5d4d96660'
7
+ data.tar.gz: 7243013b9b0af1c07c0e0eebb240c448be063d55f0dc5e2e15919df474aec957c444e45211eea4c093288e429111e3057f1860d7cc49ab4ffa5d160744a490cd
data/.gitignore CHANGED
@@ -9,5 +9,6 @@ doc/*
9
9
  *.sublime-workspace
10
10
  .yardoc
11
11
  TodoList.md
12
+ spec/data/*.xls
12
13
  spec/data/*.xls*
13
14
  spec/data/workbook_listobjects.xlsx
data/Changelog CHANGED
@@ -1,6 +1,26 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.36] 2021-29-10
5
+
6
+ ### Added
7
+ - Workbook.open: option if_blocked: :accept
8
+ - ListRow#methods, respond_to?, alive?
9
+ - Range#workbook, ListObject#workbook, ListRow#workbook
10
+ - Workbook#writable=
11
+
12
+ ### Changed
13
+ - Workbook#open instead of Workbook#reopen
14
+
15
+
16
+ ## [1.35] 2021-24-07
17
+
18
+ ## [1.34] 2021-21-06
19
+
20
+ ## [1.34] 2021-15-06
21
+
22
+ ## [1.33] 2021-01-06
23
+
4
24
  ## [1.32] 2021-23-04
5
25
 
6
26
  ### Added
@@ -123,14 +143,14 @@ All notable changes to this project will be documented in this file.
123
143
  - Workbook#save, save_as: removed parameter :discoloring
124
144
  - RangeOwners#set_namevalue, set_namevalue_glob, Worksheet#set_cellval:
125
145
  removed optional parameter for color
126
- - Workbook#open: removed option :excel => :reserved_new
146
+ - Workbook.open: removed option :excel => :reserved_new
127
147
 
128
148
 
129
149
  ## [1.11]
130
150
 
131
151
  ### Added
132
152
  - Range#==, Worksheet#==
133
- - Workbook#open: options :if_blocked is synonym to :if_obstructed
153
+ - Workbook.open: options :if_blocked is synonym to :if_obstructed
134
154
  - Simplified Code
135
155
 
136
156
  ## [1.10]
data/README.rdoc CHANGED
@@ -1,44 +1,19 @@
1
- = News
2
-
3
- == New Interface of #[]
4
-
5
- Worksheet#[] now returns a value instead of a range, e.g.
6
-
7
- worksheet[1,1]
8
- # => "foo"
9
-
10
- Transformation: To yield the range, write range() instead of (). For example,
11
-
12
- worksheet.range(1,1)
13
-
14
- or
15
-
16
- worksheet.range([1,1])
17
-
18
- This returns the range of cell with address 1,1.
19
-
20
- With this new interface, we want to be compatible with the standard syntax of other known Excel libraries, e.g. +spreadsheet+ or +axlsx+.
21
-
22
- == Using own WIN32OLE objects
23
-
24
- If you use WIN32OLE objects and define your own methods, please use upper-case method names.
25
- The reason is that we extend the class WIN32OLE such that RobustExcelOle methods can be applied to WIN32OLE objects, such the RobustExcelOle objects and their wrapped WIN32OLE objects are interchangeable. We want to develop a refinement such that the name space is not being desturbed.
26
-
27
1
  = RobustExcelOle
28
2
 
29
3
  RobustExcelOle helps controlling Excel.
30
4
  This obviously includes standard tasks like reading and writing Excel workbooks.
5
+
6
+ RobustExcelOle objects wrap WIN32OLE objects, like workbooks, worksheets and ranges.
7
+ All applicable VBA methods can be sent to those objects.
8
+ For solving complex tasks, convenient methods are added.
9
+
31
10
  The gem is designed to manage simultaneously running Excel instances, even with simultanously happening user interactions.
11
+ It supports handling workbooks across those Excel instances by keeping track of workbooks and instances. Conflicts are managed before Excel notices.
32
12
 
33
13
  RobustExcelOle deals with various cases of Excel (and user) behaviour, and
34
14
  supplies workarounds for some Excel and JRuby bugs.
35
15
 
36
- It supports handling workbooks across Excel instances by keeping track of workbooks and instances. Conflicts are managed before Excel notices.
37
-
38
- Library references are supported.
39
-
40
- RobustExcelOle works by sending VBA methods via WIN32OlE.
41
- Therefore, it runs on Windows only.
16
+ Because it uses VBA methods, RobustExcelOle runs on Windows only.
42
17
 
43
18
  == Features
44
19
 
@@ -127,27 +102,26 @@ Now we want to write a new value into this cell.
127
102
 
128
103
  workbook['firstcell'] = "new"
129
104
 
130
- Then we'll save the workbook.
105
+ Then we'll save and close the workbook.
131
106
 
132
107
  workbook.save
108
+ workbook.close
133
109
 
134
- === More features when opening, modifying, creating, saving and closing workbooks
110
+ === Unobtrusively opening workbooks
135
111
 
136
112
  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.
137
113
 
138
- Workbook.unobtrusively('spec/data/workbook.xls') do |workbook|
139
- # do something
140
- end
141
-
142
114
  Workbook.for_modifying('spec/data/workbook.xls') do |workbook|
143
- # do something
115
+ workbook.sheet(1)[1,1] = "bar"
144
116
  end
145
117
 
146
118
  Workbook.for_reading('spec/data/workbook.xls') do |workbook|
147
- # do something
119
+ value = workbook.sheet(1)[1,1]
148
120
  end
149
121
 
150
- We can also create a new, empty workbook.
122
+ === More features about creating and opening workbooks
123
+
124
+ We can create a new, empty workbook.
151
125
 
152
126
  Workbook.create('spec/data/new_workbook.xls', visible: true)
153
127
 
@@ -157,77 +131,25 @@ Moreover, we can open the workbook using a block, similar to, e.g., +File.open+.
157
131
  # do something
158
132
  end
159
133
 
160
- Once we have a workbook, we can set some options, e.g.
161
-
162
- workbook.for_this_workbook(visible: true, read_only: false)
163
-
164
- We can also open the workbook and provide the options in one step, e.g.
165
-
166
- workbook = Workbook.open('spec/data/workbook.xls', visible: true)
167
-
168
- or, using abbreviations,
169
-
170
- workbook = Workbook.open('spec/data/workbook.xls', v: true)
171
-
172
134
  Note that +Workbook.open+ can also connect to workbooks which were not opened via RobustExcelOle (but had been opened before by some user).
173
135
 
174
- For more details about opening workbooks see {README_open}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_open.rdoc]
175
-
176
- We can do a simple save
177
-
178
- workbook.save
179
-
180
- or save the workbook under a different name.
181
-
182
- workbook.save_as('spec/data/new_workbook.xls')
183
-
184
- Finally we can close the workbook
185
-
186
- workbook.save
187
-
188
- or save and close the workbook in one step.
189
-
190
- workbook.close(if_unsaved: :save)
191
-
192
- For more details about saving and closing workbooks see
193
- {README_save_close}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_save_close.rdoc]
194
-
195
-
196
- === Using Excel instances
197
-
198
- We can start a new Excel instance with
199
-
200
- excel1 = Excel.create
136
+ For more details about opening workbooks see {README_open}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_open.rdoc].
137
+ For saving and closing workbooks see
138
+ {README_save_close}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_save_close.rdoc].
201
139
 
202
- or
203
-
204
- excel1 = Excel.new(reuse: false)
205
-
206
- We can also obtain an Excel object by connecting to the already running Excel instance.
207
-
208
- excel2 = Excel.current
209
-
210
- or
211
-
212
- excel2 = Excel.new(reuse: true)
213
-
214
- We close the Excel instance using
215
-
216
- excel1.close
217
-
218
- Closed Excel instances can be reopened.
219
-
220
- excel1.recreate(reopen_workbooks: true, visible: true)
140
+ === Managing conflicts with unsaved and blocking workbooks
221
141
 
222
- Closing all Excel instances is done by
142
+ 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.
223
143
 
224
- Excel.close_all(if_unsaved: :forget)
144
+ 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.
225
145
 
226
- For hard terminating all Excel processes we can use
146
+ workbook = Workbook.open('workbook.xls', if_unsaved: :accept)
227
147
 
228
- Excel.kill_all
148
+ 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.
229
149
 
230
- For more details about opening Excel instances see {README_excel}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_excel.rdoc]
150
+ workbook1 = Workbook.open('spec/data/workbook.xls')
151
+ # do something
152
+ workbook2 = Workbook.open('spec/data/more/workbook.xls', if_blocked: :forget)
231
153
 
232
154
 
233
155
  === Opening workbooks in several Excel instances
@@ -242,39 +164,20 @@ Now we want to open another workbook in a different Excel instance.
242
164
 
243
165
  workbook2 = Workbook.open('spec/data/different_workbook.xls', excel: :new)
244
166
 
245
- We can also create a third Excel instance and open another workbook in this instance.
246
-
247
- excel1 = Excel.create
248
- workbook3 = Workbook.open('spec/data/another_workbook.xls', excel: excel1)
249
-
250
167
  A workbook is opened by default in the Excel instance where it was open before most recently.
251
168
 
252
169
  workbook1.close
253
170
  workbook1 = Workbook.open('spec/data/workbook.xls')
254
171
 
255
- If this 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.
172
+ 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.
256
173
 
257
174
  workbook1 = Workbook.open('spec/data/workbook.xls', default: {excel: new})
258
175
 
259
- 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.
176
+ Without the option +:default+, the workbook can be forced to be opened in the current, a new or a given Excel instance, no matter if and where it was opened before, e.g.
260
177
 
261
- workbook2 = Workbook.open('spec/data/workbook.xls', excel: excel1)
178
+ workbook2 = Workbook.open('spec/data/workbook.xls', excel: new)
262
179
 
263
- === Managing conflicts with unsaved and blocking workbooks
264
-
265
- RobustExcelOle enables processing workbooks, while still 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.
266
-
267
- 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.
268
-
269
- workbook = Workbook.open('workbook.xls', if_unsaved: :accept)
270
-
271
- 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.
272
-
273
- workbook1 = Workbook.open('spec/data/workbook.xls')
274
- # do something
275
- workbook2 = Workbook.open('spec/data/more/workbook.xls', if_blocked: :forget)
276
-
277
- 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]
180
+ For more details about opening Excel instances see {README_open}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_open.rdoc] and {README_excel}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_excel.rdoc].
278
181
 
279
182
  === Operating on worksheets
280
183
 
@@ -286,14 +189,6 @@ We access the first worksheet by
286
189
 
287
190
  worksheet = workbook.sheet(1)
288
191
 
289
- or
290
-
291
- worksheet = workbook.sheet('Sheet1')
292
-
293
- or
294
-
295
- worksheet = workbook.first_sheet
296
-
297
192
  We can read and change the worksheet name.
298
193
 
299
194
  worksheet.name
@@ -305,7 +200,7 @@ We can copy the first worksheet, name it and add it before the third worksheet.
305
200
 
306
201
  workbook.add_or_copy_sheet(sheet, as: "copied_name, before: workbook.last_sheet)
307
202
 
308
- For more details about processing worksheets see {README_sheet}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_sheet.rdoc]
203
+ For more details about processing worksheets see {README_sheet}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_sheet.rdoc].
309
204
 
310
205
  === Reading and writing ranges in worksheets
311
206
 
@@ -313,24 +208,10 @@ We can define a rectangular range by providing the top left and the bottum down
313
208
 
314
209
  worksheet.range([1..3,1..4])
315
210
 
316
- We can read the first three cells of the first row
317
-
318
- worksheet.row_range(1, 1..3).values # => ["foo","workbook","sheet1"]
319
-
320
- and the third column
321
-
322
- worksheet.col_range(3).values # => ["sheet1", 2.0, 4.0]
323
-
324
- We can read the first cell, using
325
-
326
- worksheet[1,1]. # => "foo"
327
-
328
- or
329
-
330
- worksheet.row_range(1)[0].value # => "foo"
331
-
332
- Then we modify it.
211
+ We can read and modify the first cell, e.g.
333
212
 
213
+ worksheet[1,1]
214
+ # => "foo"
334
215
  worksheet[1,1] = "hello"
335
216
 
336
217
  We get the value of a named range
@@ -343,20 +224,15 @@ and set another value to that range.
343
224
 
344
225
  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]
345
226
 
346
-
347
227
  === List Objects (Tables)
348
228
 
349
- We can define a list object (or table) from scratch
350
-
351
- table = ListObject.new(worksheet, "table 1", [1,1], 3, ["Person","AmountSales"])
352
-
353
- or get a given list object in a worksheet given its table number or name.
229
+ We obtain a given list object in a worksheet given its table number or name.
354
230
 
355
231
  table = worksheet.table(1)
356
232
 
357
- or
233
+ We can also define a list object from scratch
358
234
 
359
- table = worksheet.table("table1")
235
+ table = ListObject.new(worksheet, "table 1", [1,1], 3, ["Person","AmountSales"])
360
236
 
361
237
  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.
362
238
 
@@ -366,18 +242,18 @@ A list row can be accessed by providing either the row number or a key, i.e. has
366
242
 
367
243
  You can get all or a maximal number of list rows matching the key.
368
244
 
369
- rows = table[{"Number": 1}, limit: 2]
370
245
  rows = table[{"Number": 1}, limit: nil]
246
+ rows = table[{"Number": 1}, limit: 2]
371
247
 
372
- 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.
248
+ 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.
373
249
 
374
250
  row1.person = "John"
375
251
 
376
- or
252
+ or with help of the column name
377
253
 
378
254
  row1["Person"] = "John"
379
255
 
380
- Similarly you can get the values. We can also read all values in a row.
256
+ We can also read all values in a row.
381
257
 
382
258
  table[1].to_a
383
259
  # => ["John", 40]
@@ -385,57 +261,15 @@ Similarly you can get the values. We can also read all values in a row.
385
261
  table[1].to_h
386
262
  # => {"Person": "John", "AmountSales": 40}
387
263
 
388
- We can set the values in a whole row.
389
-
390
- table[1].values = ["Herber", 80]
391
-
392
- Similarly, we can read and set the values in a whole column, e.g.
393
-
394
- table.column_values("Person")
395
- # => ["John", "Peter"]
396
-
397
- and
398
-
399
- table.set_column_values(1, ["Herbert","Paul"])
400
-
401
- We can add and delete rows and columns, supplying optionally their name, the position and contents.
402
-
403
- table.add_column("column_name", 3, ["John", "Paul"])
404
- table.add_row(3, ["John", 40, 2, 2004])
405
-
406
- table.delete_column_values("column_name")
407
- table[2].delete_values
408
-
409
- Finally we can delete empty rows and columns.
410
-
411
- table.delete_empty_rows
412
- table.delete_empty_columns
413
-
414
- 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]
415
-
264
+ 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].
416
265
 
417
266
  === More features
418
267
 
419
- 1. 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
420
-
421
- General.change_current_binding(object)
422
-
423
- Without this method, the ruby shell 'pry' allows to change the value of 'self' in the console as well, e.g.
424
-
425
- object.pry
426
-
427
- or
428
-
429
- cd object
430
-
431
- However, this command also starts another pry repl (with another binding). Moreover, local variables in the previous binding are forgotten.
432
-
433
-
434
- 2. 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 the RobustExcelOle objects and their wrapped WIN32OLE objects are interchangeable. One example would be
268
+ 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
435
269
 
436
270
  range.ole_range.copy([4,3])
437
271
 
438
- 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
272
+ 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
439
273
 
440
274
  using ToReoRefinement
441
275
 
Binary file
@@ -1,10 +1,11 @@
1
- = RobustExcelOle
1
+ == Managing Excel instances
2
2
 
3
- == Creating, using and closing Excel instances
3
+ Details are essentially covered in the ruby documentation of the class
4
+ Excel[https://www.rubydoc.info/gems/robust_excel_ole/RobustExcelOle/Excel].
4
5
 
5
- RobustExcelOle enables simultanously running Excel instances. An Excel application is represented by an Excel object.
6
+ === Creating, using and closing Excel instances
6
7
 
7
- === Creating and reusing an Excel instance.
8
+ RobustExcelOle enables simultanously running Excel instances. An Excel application is represented by an Excel object.
8
9
 
9
10
  You can create a new Excel instance by
10
11
 
@@ -168,6 +169,4 @@ This method has the option +:if_unsaved+ as described above. For example, if you
168
169
 
169
170
  This method kills all Excel instances no matter whether they contain unsaved workbooks.
170
171
 
171
- == Code
172
172
 
173
- excel.rb[https://github.com/Thomas008/robust_excel_ole/blob/master/lib/robust_excel_ole/excel.rb]
@@ -1,7 +1,9 @@
1
- = RobustExcelOle
2
-
3
1
  == List Objects
4
2
 
3
+ A List object in a worksheet represents a table.
4
+ The details are essentially covered in the ruby docmentation of the class
5
+ ListObject[https://www.rubydoc.info/gems/robust_excel_ole/RobustExcelOle/ListObject].
6
+
5
7
  === Creating List Objects
6
8
 
7
9
  We can define a list object (or table) from scratch.
@@ -54,20 +56,14 @@ or
54
56
  or
55
57
 
56
58
  row1["AmountSales"] = 40
57
-
58
- Similarly you can get the values.
59
-
60
- row1.AmountSales
61
- # => 40
62
59
 
63
60
  or
64
61
 
65
- row1.amount_sales
66
- # => 40
67
-
68
- or
62
+ row1[:AmountSales] = 40
63
+
64
+ Similarly you can get the values, e.g.
69
65
 
70
- row1["AmountSales"]
66
+ row1.amount_sales
71
67
  # => 40
72
68
 
73
69
  We can also read the values in a whole row.
@@ -170,7 +166,4 @@ You can sort a table according to a given column and sort order, e.g.
170
166
 
171
167
  table.sort("Person", :ascending)
172
168
 
173
- == Code
174
-
175
- listobjects.rb[https://github.com/Thomas008/robust_excel_ole/blob/master/lib/robust_excel_ole/listobjects.rb]
176
169
 
@@ -1,6 +1,9 @@
1
- = RobustExcelOle
1
+ == Opening workbooks
2
2
 
3
- === Opening a workbook.
3
+ The details are essentially covered in the ruby documentation of the
4
+ class Workbook[https://www.rubydoc.info/gems/robust_excel_ole/RobustExcelOle/Workbook].
5
+
6
+ === How to open a workbook
4
7
 
5
8
  If you want to open a workbook, you can use the methods +open+ or +new+.
6
9
 
@@ -36,12 +39,12 @@ The options are the following:
36
39
 
37
40
  +:if_unsaved+:: specifies behaviour if the workbook was unsaved (default: +:raise+)
38
41
 
39
- +:if_blocked:: specifies behaviour if the workbook is blocked by another book (default: +:raise+)
42
+ +:if_blocked+:: specifies behaviour if the workbook is blocked by another book (default: +:raise+)
40
43
 
41
44
 
42
45
  +:read_only+:: opens in read-only mode (default: +false+)
43
46
 
44
- +:check_compatibility:: checks compatibility when saving
47
+ +:check_compatibility+:: checks compatibility when saving
45
48
 
46
49
  +:calculation+:: forces the calculation mode to be manual (:manual) or automatic (:automatic)
47
50
 
@@ -49,39 +52,40 @@ The options are the following:
49
52
 
50
53
  You can use the following abbreviations or synonyms: +:f+ for +:force+, +:d+ for +:default+, +:e+ for +:excel+, and +:v+ for +:visible+, +:if_obstructed+ for +:if_blocked+. Finally you can leave out the option +:force+ or +:f+.
51
54
 
52
- The option +:excel+ :
55
+ === The option +:excel+ :
53
56
 
54
57
  Valid values are : +:current+ (or +:active+ or +:reuse+), +:new+, or a given Excel instance (default: +:current).
55
58
 
56
- The option +:if_unsaved+ :
59
+ === The option +:if_unsaved+ :
57
60
 
58
- If a workbook contains unsaved changes and a new workbook with the same file name shall be opened, then
61
+ If a workbook contains unsaved changes and the workbook shall be re-opened, then
59
62
 
60
- +:raise+:: Raise an exeption. Don't open the workbook.
61
- +:accept+:: Let the unsaved workbook open.
63
+ +:raise+:: Raise an exeption. Leave the unsaved workbook open.
64
+ +:accept+:: Leave the unsaved workbook open.
62
65
  +:forget+:: Discard any changes and reopen the workbook.
63
66
  +:save+:: Save any changes and reopen the workbook
64
- +:new_excel+:: Open the new workbook in a new Excel instance
67
+ +:new_excel+:: Open the workbook in a new Excel instance
65
68
  +:alert+:: Give control to Excel.
66
69
 
67
- The option +:if_blocked+ :
70
+ === The option +:if_blocked+ :
68
71
 
69
- If a workbook is open and a new workbook with same name and a different path is open, then
72
+ If a workbook is open and a workbook with same base name but in a different path shall be opened, then the first workbook blocks opening the latter one. In this case:
70
73
 
71
- +:raise+:: Raise an exception. Don't open the workbook.
72
- +:forget+:: Close the old workbook, open the new workbook.
73
- +:save+:: Save the old workbook, close it, open the new workbook
74
- +:close_if_saved+:: Close the old workbook and open the new workbook, if the old workbook is saved, otherwise raise an exception.
74
+ +:raise+:: Raise an exception. Don't open the workbook. Leave the blocking workbook open.
75
+ +:forget+:: Close the blocking workbook, open the new workbook.
76
+ +:accept+:: Leave the blocking workbook open.
77
+ +:save+:: Save the blocking workbook, close it, open the new workbook
78
+ +:close_if_saved+:: Close the blocking workbook and open the new workbook, if the blocking workbook is saved, otherwise raise an exception.
75
79
  +:new_excel+:: Open the new workbook in a new Excel instance.
76
80
 
77
- The option +:if_absent :
81
+ === The option +:if_absent+ :
78
82
 
79
83
  If the Excel file does not exists, then
80
84
 
81
85
  +:create+:: Create a new Excel file
82
86
  +:raise+:: Raise an exception.
83
87
 
84
- Here are a few examples:
88
+ === Examples:
85
89
 
86
90
  If you want to open a workbook that was not opened before, or reopen a workbook that was open in an Excel instance that is now closed, in the current (active) Excel instance, then use
87
91
 
@@ -129,7 +133,7 @@ If a workbook is open and a workbook with the same name but in different path sh
129
133
 
130
134
  workbook = Workbook.open('path/workbook.xls', if_blocked: :forget)
131
135
 
132
- Remarks:
136
+ === Remarks
133
137
 
134
138
  The methods +open+ and +new+ connect to workbooks opened outside of RobustExcelOle as well.
135
139
 
@@ -137,13 +141,18 @@ Opening linked workbooks for EXCEL 2007 is supported
137
141
 
138
142
  Doing updating links seems to be dependent on calculation mode: updates happen, if the calcultion mode is automatic, and does not happen, if calculation mode is manual.
139
143
 
140
- === Reopening a workbook.
144
+ Once we have a workbook, we can set some options, e.g.
145
+
146
+ workbook.for_this_workbook(visible: true, read_only: false)
147
+
148
+
149
+ === Reopening a workbook
141
150
 
142
151
  A special feature of RobustExcelOle is that it allows to reopen workbooks after closing them.
143
152
 
144
153
  workbook = Workbook.open('spec/data/workbook.xls')
145
154
  workbook.close
146
- workbook.reopen
155
+ workbook.open
147
156
 
148
157
  The closed workbook is now alive again, i.e. is open and responds to Excel methods.
149
158
 
@@ -176,7 +185,7 @@ You can also supply a workbook and options, e.g.
176
185
 
177
186
  new_workbook = Workbook.new(workbook, visible: true)
178
187
 
179
- === Identity transperence ===
188
+ === Identity transperence
180
189
 
181
190
  A RobustExcelOle Workbook object is a proxy of an Excel WIN32OLE workbook. A Workbook object is defined by the full workbook name and the Excel instance in which it is opened. RobustExcelOle ensures identity transparency which means that identical Workbook objects refer to identical Excel workbooks, and vice versa. Identity transperence ensures that, no matter how a Workbook object was created - by filename or by type-lifting an Excel workbook - two Workbook objects are identical, if and only if the Excel workbooks, they are referring to, are identical.
182
191
 
@@ -245,13 +254,27 @@ This method ensures keeping the save status of the workbook
245
254
  # some reading or modifying
246
255
  end
247
256
 
248
- === Checking whether the workbook is alive.
257
+ === Changing ReadOnly-mode
258
+
259
+ When you want to change the read-only mode, you can use the method +writable=+.
260
+
261
+ workbook = Workbook('spec/data/workbook.xls')
262
+ workbook.writable = false
263
+ workbook.writable
264
+ # => false
265
+ workbook.ReadOnly
266
+ # => true
267
+ workbook.writable = true
268
+
269
+ If the workbook is unsaved, use the option +if_unsaved+ as desribed above.
270
+
271
+ workbook.writable = false, {if_unsaved: :forget}
272
+
273
+ === Checking whether the workbook is alive
249
274
 
250
275
  The method +alive?+ finds out whether the Excel workbook that is referenced by the Workbook object responds to methods. For example
251
276
 
252
277
  workbook.alive?
253
278
  # => true
254
279
 
255
- == Code
256
280
 
257
- workbook.rb[https://github.com/Thomas008/robust_excel_ole/blob/master/lib/robust_excel_ole/workbook.rb]