robust_excel_ole 1.35 → 1.36
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Changelog +20 -2
- data/README.rdoc +31 -95
- data/docs/README_excel.rdoc +5 -6
- data/docs/README_listobjects.rdoc +8 -15
- data/docs/README_open.rdoc +48 -25
- data/docs/README_ranges.rdoc +7 -10
- data/docs/README_save_close.rdoc +4 -5
- data/docs/README_sheet.rdoc +4 -8
- data/examples/introductory_examples/example_introductory.rb +1 -1
- data/examples/introductory_examples/example_open.rb +1 -1
- data/lib/robust_excel_ole/excel.rb +98 -16
- data/lib/robust_excel_ole/general.rb +18 -6
- data/lib/robust_excel_ole/list_object.rb +11 -19
- data/lib/robust_excel_ole/list_row.rb +74 -19
- data/lib/robust_excel_ole/range.rb +6 -1
- data/lib/robust_excel_ole/range_owners.rb +24 -17
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +107 -42
- data/lib/robust_excel_ole/worksheet.rb +1 -1
- data/robust_excel_ole.gemspec +0 -1
- data/spec/bookstore_spec.rb +1 -2
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/data/workbook_linked3.xlsm +0 -0
- data/spec/data/workbook_listobjects.xlsx +0 -0
- data/spec/data/workbook_unsaved.xlsm +0 -0
- data/spec/excel_spec.rb +4 -4
- data/spec/general_spec.rb +1 -2
- data/spec/list_object_spec.rb +26 -9
- data/spec/list_row_spec.rb +34 -20
- data/spec/range_spec.rb +9 -0
- data/spec/workbook_spec.rb +2 -2
- data/spec/workbook_specs/workbook_misc_spec.rb +249 -2
- data/spec/workbook_specs/workbook_open_spec.rb +307 -16
- data/spec/workbook_specs/workbook_unobtr_spec.rb +196 -42
- metadata +4 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d53d040d2a0079556bfca8d89a531f65b75f8e27d361378e339d38ac8ec7fdf
|
4
|
+
data.tar.gz: 68658a532b13b21815f61e5ce7a286b8df42693711142ee7ff9c15c26cf6fa07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08f8abee9ca47bf37d4d27e3d13ecfcb31f1ae019370450bb052911ccd5a56ec5116c007d1f1475c19a29226857281f7d9d80747c5d2e5a7ac605de5d4d96660'
|
7
|
+
data.tar.gz: 7243013b9b0af1c07c0e0eebb240c448be063d55f0dc5e2e15919df474aec957c444e45211eea4c093288e429111e3057f1860d7cc49ab4ffa5d160744a490cd
|
data/.gitignore
CHANGED
data/Changelog
CHANGED
@@ -1,6 +1,24 @@
|
|
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
|
+
|
4
22
|
## [1.33] 2021-01-06
|
5
23
|
|
6
24
|
## [1.32] 2021-23-04
|
@@ -125,14 +143,14 @@ All notable changes to this project will be documented in this file.
|
|
125
143
|
- Workbook#save, save_as: removed parameter :discoloring
|
126
144
|
- RangeOwners#set_namevalue, set_namevalue_glob, Worksheet#set_cellval:
|
127
145
|
removed optional parameter for color
|
128
|
-
- Workbook
|
146
|
+
- Workbook.open: removed option :excel => :reserved_new
|
129
147
|
|
130
148
|
|
131
149
|
## [1.11]
|
132
150
|
|
133
151
|
### Added
|
134
152
|
- Range#==, Worksheet#==
|
135
|
-
- Workbook
|
153
|
+
- Workbook.open: options :if_blocked is synonym to :if_obstructed
|
136
154
|
- Simplified Code
|
137
155
|
|
138
156
|
## [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
|
-
|
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
|
-
|
115
|
+
workbook.sheet(1)[1,1] = "bar"
|
118
116
|
end
|
119
117
|
|
120
118
|
Workbook.for_reading('spec/data/workbook.xls') do |workbook|
|
121
|
-
|
119
|
+
value = workbook.sheet(1)[1,1]
|
122
120
|
end
|
123
121
|
|
124
|
-
=== More
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
146
|
+
workbook = Workbook.open('workbook.xls', if_unsaved: :accept)
|
199
147
|
|
200
|
-
|
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
|
-
|
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
|
-
|
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
|
229
|
+
We obtain a given list object in a worksheet given its table number or name.
|
294
230
|
|
295
|
-
table =
|
231
|
+
table = worksheet.table(1)
|
296
232
|
|
297
|
-
|
233
|
+
We can also define a list object from scratch
|
298
234
|
|
299
|
-
table = worksheet
|
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
|
|
data/docs/README_excel.rdoc
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
|
1
|
+
== Managing Excel instances
|
2
2
|
|
3
|
-
|
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
|
-
|
6
|
+
=== Creating, using and closing Excel instances
|
6
7
|
|
7
|
-
|
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
|
66
|
-
|
67
|
-
|
68
|
-
or
|
62
|
+
row1[:AmountSales] = 40
|
63
|
+
|
64
|
+
Similarly you can get the values, e.g.
|
69
65
|
|
70
|
-
row1
|
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
|
|
data/docs/README_open.rdoc
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
|
1
|
+
== Opening workbooks
|
2
2
|
|
3
|
-
|
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
|
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
|
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
|
61
|
+
If a workbook contains unsaved changes and the workbook shall be re-opened, then
|
59
62
|
|
60
|
-
+:raise+:: Raise an exeption.
|
61
|
-
+:accept+::
|
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
|
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
|
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
|
73
|
-
+:
|
74
|
-
+:
|
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
|
-
|
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
|
-
|
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.
|
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
|
-
===
|
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]
|
data/docs/README_ranges.rdoc
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
|
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]
|
data/docs/README_save_close.rdoc
CHANGED
@@ -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]
|
data/docs/README_sheet.rdoc
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
-
|
1
|
+
== Opening and modifying worksheets
|
2
2
|
|
3
|
-
|
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
|
-
|
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]
|