robust_excel_ole 1.35 → 1.38

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Changelog +25 -2
  4. data/README.rdoc +31 -95
  5. data/docs/README_excel.rdoc +5 -6
  6. data/docs/README_listobjects.rdoc +8 -15
  7. data/docs/README_open.rdoc +53 -27
  8. data/docs/README_ranges.rdoc +7 -10
  9. data/docs/README_save_close.rdoc +4 -5
  10. data/docs/README_sheet.rdoc +4 -8
  11. data/examples/introductory_examples/example_introductory.rb +1 -1
  12. data/examples/introductory_examples/example_open.rb +1 -1
  13. data/examples/modifying_sheets/example_access_sheets_and_cells.rb +1 -1
  14. data/examples/modifying_sheets/example_add_names.rb +1 -1
  15. data/examples/modifying_sheets/example_listobjects.rb +2 -2
  16. data/examples/modifying_sheets/example_ranges.rb +1 -1
  17. data/lib/robust_excel_ole/cygwin.rb +12 -0
  18. data/lib/robust_excel_ole/excel.rb +128 -32
  19. data/lib/robust_excel_ole/general.rb +18 -6
  20. data/lib/robust_excel_ole/list_object.rb +11 -19
  21. data/lib/robust_excel_ole/list_row.rb +74 -19
  22. data/lib/robust_excel_ole/range.rb +6 -1
  23. data/lib/robust_excel_ole/range_owners.rb +24 -17
  24. data/lib/robust_excel_ole/version.rb +1 -1
  25. data/lib/robust_excel_ole/workbook.rb +173 -92
  26. data/lib/robust_excel_ole/worksheet.rb +1 -1
  27. data/robust_excel_ole.gemspec +0 -1
  28. data/spec/bookstore_spec.rb +1 -2
  29. data/spec/cygwin_spec.rb +17 -10
  30. data/spec/data/more_data/workbook.xls +0 -0
  31. data/spec/data/workbook.xls +0 -0
  32. data/spec/data/workbook.xlsm +0 -0
  33. data/spec/data/workbook.xlsx +0 -0
  34. data/spec/data/workbook_linked3.xlsm +0 -0
  35. data/spec/data/workbook_listobjects.xlsx +0 -0
  36. data/spec/data/workbook_unsaved.xlsm +0 -0
  37. data/spec/excel_spec.rb +14 -4
  38. data/spec/general_spec.rb +1 -2
  39. data/spec/list_object_spec.rb +26 -9
  40. data/spec/list_row_spec.rb +34 -20
  41. data/spec/range_spec.rb +9 -0
  42. data/spec/workbook_spec.rb +2 -2
  43. data/spec/workbook_specs/workbook_misc_spec.rb +258 -4
  44. data/spec/workbook_specs/workbook_open_spec.rb +364 -17
  45. data/spec/workbook_specs/workbook_unobtr_spec.rb +225 -60
  46. data/spec/worksheet_spec.rb +2 -2
  47. metadata +4 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80365f36774968b6f55052177932c00dbe57b7fb3bee76762474a0b21637440b
4
- data.tar.gz: a352fd270609529688869edf581bc2d1c20eee9c0b9b8ec61198dcfafc82fd2b
3
+ metadata.gz: f2639b34c270ac16732d4de9ff06be54e2ba33cf5c1cf9d7842ed7a639044b4c
4
+ data.tar.gz: 3533deb112141e2221b00479d6f4207891b7977c0ac1cf6ff37b40ade580fea1
5
5
  SHA512:
6
- metadata.gz: 5246534fa3c3767e9fe4c8081d37aac6d54070238b6008d1ea289792cc3fa2bbf3b855b36eab4959b16103af6e5f8a83d7d326dc82923ff25c82ab8b9f61ae1e
7
- data.tar.gz: '070856a21a1786fa7f9fd3de02edaa6bf661e936329c02afb78e9d5ddbd8623b95a49ec1f22be64e4d205c47e4c7e7c2bf964a00d2928a2d4dbe4a6640bf3a40'
6
+ metadata.gz: 19071fbe4d293f73f02081c9cb23f706d2102a97d3a038324551e912a6b17929282e0fff738b98f30a2377bf7f2f48b9fb5eaa699a4439b989f2e174a1ff9a63
7
+ data.tar.gz: 8da4acac7393db1c62b352842aa6b8944b0ecb1fc410077b62d9b0f618a82e07df69612afb0077c0fedfedb824d1962e97c90041a762e4cbadd6691534f1d3f7
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,29 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.37] 2021-30-11
5
+
6
+ ### Added
7
+ - Excel#visible,displayalerts
8
+
9
+ ## [1.36] 2021-29-10
10
+
11
+ ### Added
12
+ - Workbook.open: option if_blocked: :accept
13
+ - ListRow#methods, respond_to?, alive?
14
+ - Range#workbook, ListObject#workbook, ListRow#workbook
15
+ - Workbook#writable=
16
+
17
+ ### Changed
18
+ - Workbook#open instead of Workbook#reopen
19
+
20
+
21
+ ## [1.35] 2021-24-07
22
+
23
+ ## [1.34] 2021-21-06
24
+
25
+ ## [1.34] 2021-15-06
26
+
4
27
  ## [1.33] 2021-01-06
5
28
 
6
29
  ## [1.32] 2021-23-04
@@ -125,14 +148,14 @@ All notable changes to this project will be documented in this file.
125
148
  - Workbook#save, save_as: removed parameter :discoloring
126
149
  - RangeOwners#set_namevalue, set_namevalue_glob, Worksheet#set_cellval:
127
150
  removed optional parameter for color
128
- - Workbook#open: removed option :excel => :reserved_new
151
+ - Workbook.open: removed option :excel => :reserved_new
129
152
 
130
153
 
131
154
  ## [1.11]
132
155
 
133
156
  ### Added
134
157
  - Range#==, Worksheet#==
135
- - Workbook#open: options :if_blocked is synonym to :if_obstructed
158
+ - Workbook.open: options :if_blocked is synonym to :if_obstructed
136
159
  - Simplified Code
137
160
 
138
161
  ## [1.10]
data/README.rdoc CHANGED
@@ -2,17 +2,18 @@
2
2
 
3
3
  RobustExcelOle helps controlling Excel.
4
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
+
5
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.
6
12
 
7
13
  RobustExcelOle deals with various cases of Excel (and user) behaviour, and
8
14
  supplies workarounds for some Excel and JRuby bugs.
9
15
 
10
- It supports handling workbooks across Excel instances by keeping track of workbooks and instances. Conflicts are managed before Excel notices.
11
-
12
- Library references are supported.
13
-
14
- RobustExcelOle works by sending VBA methods via WIN32OlE.
15
- Therefore, it runs on Windows only.
16
+ Because it uses VBA methods, RobustExcelOle runs on Windows only.
16
17
 
17
18
  == Features
18
19
 
@@ -101,27 +102,24 @@ Now we want to write a new value into this cell.
101
102
 
102
103
  workbook['firstcell'] = "new"
103
104
 
104
- Then we'll save the workbook.
105
+ Then we'll save and close the workbook.
105
106
 
106
107
  workbook.save
108
+ workbook.close
107
109
 
108
110
  === Unobtrusively opening workbooks
109
111
 
110
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.
111
113
 
112
- Workbook.unobtrusively('spec/data/workbook.xls') do |workbook|
113
- # do something
114
- end
115
-
116
114
  Workbook.for_modifying('spec/data/workbook.xls') do |workbook|
117
- # do something
115
+ workbook.sheet(1)[1,1] = "bar"
118
116
  end
119
117
 
120
118
  Workbook.for_reading('spec/data/workbook.xls') do |workbook|
121
- # do something
119
+ value = workbook.sheet(1)[1,1]
122
120
  end
123
121
 
124
- === More featrues about creating, opening, saving and closing workbooks
122
+ === More features about creating and opening workbooks
125
123
 
126
124
  We can create a new, empty workbook.
127
125
 
@@ -133,73 +131,25 @@ Moreover, we can open the workbook using a block, similar to, e.g., +File.open+.
133
131
  # do something
134
132
  end
135
133
 
136
- Once we have a workbook, we can set some options, e.g.
137
-
138
- workbook.for_this_workbook(visible: true, read_only: false)
139
-
140
- We can also open the workbook and provide the options in one step, e.g.
141
-
142
- workbook = Workbook.open('spec/data/workbook.xls', visible: true)
143
-
144
- or, using abbreviations,
145
-
146
- workbook = Workbook.open('spec/data/workbook.xls', v: true)
147
-
148
134
  Note that +Workbook.open+ can also connect to workbooks which were not opened via RobustExcelOle (but had been opened before by some user).
149
135
 
150
- For more details about opening workbooks see {README_open}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_open.rdoc]
151
-
152
- We can do a simple save
153
-
154
- workbook.save
155
-
156
- or save the workbook under a different name.
157
-
158
- workbook.save_as('spec/data/new_workbook.xls')
159
-
160
- Finally we can close the workbook
161
-
162
- workbook.close
163
-
164
- or save and close the workbook in one step.
165
-
166
- workbook.close(if_unsaved: :save)
167
-
168
- For more details about saving and closing workbooks see
169
- {README_save_close}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_save_close.rdoc]
170
-
171
-
172
- === Using Excel instances
173
-
174
- We can start a new Excel instance with
175
-
176
- excel1 = Excel.create
177
-
178
- or
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].
179
139
 
180
- excel1 = Excel.new(reuse: false)
181
-
182
- We can also obtain an Excel object by connecting to the already running Excel instance.
183
-
184
- excel2 = Excel.current
185
-
186
- or
187
-
188
- excel2 = Excel.new(reuse: true)
189
-
190
- We close the Excel instance using
191
-
192
- excel1.close
140
+ === Managing conflicts with unsaved and blocking workbooks
193
141
 
194
- 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.
195
143
 
196
- 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.
197
145
 
198
- For hard terminating all Excel processes we can use
146
+ workbook = Workbook.open('workbook.xls', if_unsaved: :accept)
199
147
 
200
- 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.
201
149
 
202
- 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)
203
153
 
204
154
 
205
155
  === Opening workbooks in several Excel instances
@@ -223,25 +173,11 @@ If the Excel instance is damaged or closed, then options control whether the wor
223
173
 
224
174
  workbook1 = Workbook.open('spec/data/workbook.xls', default: {excel: new})
225
175
 
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.
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.
227
177
 
228
178
  workbook2 = Workbook.open('spec/data/workbook.xls', excel: new)
229
179
 
230
- === Managing conflicts with unsaved and blocking workbooks
231
-
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.
233
-
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.
235
-
236
- workbook = Workbook.open('workbook.xls', if_unsaved: :accept)
237
-
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.
239
-
240
- workbook1 = Workbook.open('spec/data/workbook.xls')
241
- # do something
242
- workbook2 = Workbook.open('spec/data/more/workbook.xls', if_blocked: :forget)
243
-
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]
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].
245
181
 
246
182
  === Operating on worksheets
247
183
 
@@ -264,7 +200,7 @@ We can copy the first worksheet, name it and add it before the third worksheet.
264
200
 
265
201
  workbook.add_or_copy_sheet(sheet, as: "copied_name, before: workbook.last_sheet)
266
202
 
267
- 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].
268
204
 
269
205
  === Reading and writing ranges in worksheets
270
206
 
@@ -290,13 +226,13 @@ For more details about reading and writing contents of cells and ranges see {REA
290
226
 
291
227
  === List Objects (Tables)
292
228
 
293
- We can define a list object (or table) from scratch
229
+ We obtain a given list object in a worksheet given its table number or name.
294
230
 
295
- table = ListObject.new(worksheet, "table 1", [1,1], 3, ["Person","AmountSales"])
231
+ table = worksheet.table(1)
296
232
 
297
- or get a given list object in a worksheet given its table number or name.
233
+ We can also define a list object from scratch
298
234
 
299
- table = worksheet.table(1)
235
+ table = ListObject.new(worksheet, "table 1", [1,1], 3, ["Person","AmountSales"])
300
236
 
301
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.
302
238
 
@@ -325,7 +261,7 @@ We can also read all values in a row.
325
261
  table[1].to_h
326
262
  # => {"Person": "John", "AmountSales": 40}
327
263
 
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]
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].
329
265
 
330
266
  === More features
331
267
 
@@ -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
- +:read_only+:: opens in read-only mode (default: +false+)
45
+ +:read_only+:: opens in read-only (+true+) or read-write mode (+false+) (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,21 +133,23 @@ 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
 
136
- Opening linked workbooks for EXCEL 2007 is supported
140
+ Opening linked workbooks for EXCEL 2007 is supported. Changing linked, unsaved workbooks from read-only to read-write causes a query whether to save the changes. This case cannot be
141
+ controlled (e.g. with help of some options) so far.
137
142
 
138
143
  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
144
 
140
- === Reopening a workbook.
145
+
146
+ === Reopening a workbook
141
147
 
142
148
  A special feature of RobustExcelOle is that it allows to reopen workbooks after closing them.
143
149
 
144
150
  workbook = Workbook.open('spec/data/workbook.xls')
145
151
  workbook.close
146
- workbook.reopen
152
+ workbook.open
147
153
 
148
154
  The closed workbook is now alive again, i.e. is open and responds to Excel methods.
149
155
 
@@ -176,7 +182,7 @@ You can also supply a workbook and options, e.g.
176
182
 
177
183
  new_workbook = Workbook.new(workbook, visible: true)
178
184
 
179
- === Identity transperence ===
185
+ === Identity transperence
180
186
 
181
187
  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
188
 
@@ -245,13 +251,33 @@ This method ensures keeping the save status of the workbook
245
251
  # some reading or modifying
246
252
  end
247
253
 
248
- === Checking whether the workbook is alive.
254
+ === Changing ReadOnly-mode
255
+
256
+ When you want to change the read-only mode, you can use the method +writable=+.
257
+
258
+ workbook = Workbook('spec/data/workbook.xls')
259
+ workbook.writable = false
260
+ workbook.writable
261
+ # => false
262
+ workbook.ReadOnly
263
+ # => true
264
+ workbook.writable = true
265
+
266
+ If the workbook is unsaved, use the option +if_unsaved+ as desribed above.
267
+
268
+ workbook.writable = false, {if_unsaved: :forget}
269
+
270
+ Changing from read-only to read-write for linked, unsaved workbooks is not being supported yet.
271
+
272
+ === Checking whether the workbook is alive
249
273
 
250
274
  The method +alive?+ finds out whether the Excel workbook that is referenced by the Workbook object responds to methods. For example
251
275
 
252
276
  workbook.alive?
253
277
  # => true
254
278
 
255
- == Code
279
+ === Setting options
280
+
281
+ Once we have a workbook, we can set some options, e.g.
256
282
 
257
- workbook.rb[https://github.com/Thomas008/robust_excel_ole/blob/master/lib/robust_excel_ole/workbook.rb]
283
+ workbook.for_this_workbook(visible: true, read_only: false)
@@ -1,9 +1,10 @@
1
- = RobustExcelOle
2
-
3
- == Reading and writing the contents of ranges and cells
1
+ == Ranges and cells
4
2
 
5
3
  RobustExcelOle enables to read and write the contents of ranges and cells in workbooks. This can be done from a Worksheet, a Workbook or an Excel object representing a Worksheet, Workbook, or Application object, respectively. You can use VBA methods or methods provided by RobustExcelOle.
6
4
 
5
+ The details are essentially covered in ruby documentation of the classes Range[https://www.rubydoc.info/gems/robust_excel_ole/RobustExcelOle/Range] and
6
+ Worksheet[https://www.rubydoc.info/gems/robust_excel_ole/RobustExcelOle/Worksheet].
7
+
7
8
  === Introducing Example
8
9
 
9
10
  Suppose you have opened a workbook.
@@ -26,6 +27,9 @@ or, using the A1-format,
26
27
 
27
28
  range = worksheet.range("B1")
28
29
 
30
+ Once you have got an Range object, you can apply all VBA methods that you would apply to a VBA Range object
31
+ (see https://docs.microsoft.com/en-us/office/vba/api/excel.range#methods).
32
+
29
33
  Similarly you can access a rectangular range. Using VBA methods we provide the row and column of the top left cell and the row and column of the bottum right cell.
30
34
 
31
35
  range = worksheet.Range(sheet.Cells(1,1), sheet.Cells(3,4))
@@ -414,10 +418,3 @@ Similarly, you can write a cell.
414
418
  or
415
419
 
416
420
  worksheet.set_cellval(1,1,"new_value")
417
-
418
-
419
- == Code
420
-
421
- range.rb[https://github.com/Thomas008/robust_excel_ole/blob/master/lib/robust_excel_ole/range.rb]
422
-
423
- worksheet.rb[https://github.com/Thomas008/robust_excel_ole/blob/master/lib/robust_excel_ole/worksheet.rb]
@@ -1,7 +1,9 @@
1
- = RobustExcelOle
2
-
3
1
  == Saving and closing workbooks
4
2
 
3
+ RobustExcelOle helps to control the saving and the closing of workbooks.
4
+ The details are essentially covered in the ruby documentation of the class
5
+ Workbook[https://www.rubydoc.info/gems/robust_excel_ole/RobustExcelOle/Workbook].
6
+
5
7
  === Saving a workbook.
6
8
 
7
9
  Imagine, you have opened a workbook with
@@ -76,6 +78,3 @@ Finally the workbook can be closed with a given filename.
76
78
 
77
79
  Workbook.close('spec/data/workbook.xls')
78
80
 
79
- == Code
80
-
81
- workbook.rb[https://github.com/Thomas008/robust_excel_ole/blob/master/lib/robust_excel_ole/workbook.rb]
@@ -1,15 +1,14 @@
1
- = RobustExcelOle
1
+ == Opening and modifying worksheets
2
2
 
3
- == Accessing and processing worksheets
3
+ Details are essentially covered in the ruby documentation of the class
4
+ Worksheet[https://www.rubydoc.info/gems/robust_excel_ole/RobustExcelOle/Worksheet].
4
5
 
5
- Worksheets are represented by Worksheet objects.
6
+ === Accessing a worksheet.
6
7
 
7
8
  Assume you have opened a workbook
8
9
 
9
10
  workbook = Workbook.open('spec/data/workbook.xls', visible: true)
10
11
 
11
- === Accessing a worksheet.
12
-
13
12
  You can access a worksheet by giving the number
14
13
 
15
14
  worksheet = book.sheet(1)
@@ -147,6 +146,3 @@ Here are some examples:
147
146
  row1.VerticalAlignment = XlVAlignCenter
148
147
  row1.HorizontalAlignment = XlHAlignLeft
149
148
 
150
- == Code
151
-
152
- worksheet.rb[https://github.com/Thomas008/robust_excel_ole/blob/master/lib/robust_excel_ole/worksheet.rb]
@@ -29,7 +29,7 @@ puts "close the workbook"
29
29
  workbook.close
30
30
  # reopening the workbook
31
31
  puts "reopen the workbook"
32
- workbook.reopen
32
+ workbook.open
33
33
  # further operations
34
34
  workbook['firstcell'] = "another_value"
35
35
  # saved status of the workbook
@@ -46,7 +46,7 @@ puts "close the first workbook"
46
46
  book.close
47
47
  # reopen the workbook
48
48
  puts "reopen the workbook"
49
- book4 = book.reopen
49
+ book4 = book.open
50
50
  puts "book4: #{book4}"
51
51
  # unobtrusively opening a workbook
52
52
  puts "unobtrusively opening the workbook"
@@ -7,7 +7,7 @@ require "fileutils"
7
7
 
8
8
  include RobustExcelOle
9
9
 
10
- Excel.close_all
10
+ Excel.close_all(if_unsaved: :forget)
11
11
  begin
12
12
  dir = create_tmpdir
13
13
  simple_file = dir + 'workbook.xls'
@@ -26,7 +26,7 @@ begin
26
26
 
27
27
  def define_columns sheet, columns_ids
28
28
  puts "define_columns:"
29
- first_column = sheet.range("A")
29
+ first_column = sheet.range("A:A")
30
30
  puts "first_column: #{first_column}"
31
31
 
32
32
  columns_ids.each_with_index do |id,idx|
@@ -9,7 +9,7 @@ include RobustExcelOle
9
9
 
10
10
  using StringRefinement
11
11
 
12
- Excel.close_all
12
+ Excel.close_all(if_unsaved: :forget)
13
13
  begin
14
14
  dir = create_tmpdir
15
15
  table_file = dir + 'workbook_listobjects.xlsx'
@@ -79,7 +79,7 @@ begin
79
79
  book.close(:if_unsaved => :forget)
80
80
 
81
81
  ensure
82
- Excel.close_all
82
+ Excel.close_all(if_unsaved: forget)
83
83
  rm_tmp(dir)
84
84
  end
85
85
 
@@ -7,7 +7,7 @@ require "fileutils"
7
7
 
8
8
  include RobustExcelOle
9
9
 
10
- Excel.close_all
10
+ Excel.close_all(if_unsaved: :forget)
11
11
  begin
12
12
  dir = create_tmpdir
13
13
  simple_file = dir + 'workbook.xls'