robust_excel_ole 1.13 → 1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Changelog +47 -4
- data/README.rdoc +52 -47
- data/___dummy_workbook.xls +0 -0
- data/docs/README_excel.rdoc +9 -3
- data/docs/README_open.rdoc +86 -44
- data/docs/README_ranges.rdoc +90 -81
- data/docs/README_save_close.rdoc +9 -9
- data/docs/README_sheet.rdoc +17 -17
- data/examples/example_ruby_library.rb +27 -0
- data/extconf.rb +7 -0
- data/lib/robust_excel_ole.rb +7 -4
- data/lib/robust_excel_ole/{address.rb → address_tool.rb} +23 -22
- data/lib/robust_excel_ole/{reo_common.rb → base.rb} +3 -92
- data/lib/robust_excel_ole/bookstore.rb +14 -77
- data/lib/robust_excel_ole/cell.rb +30 -18
- data/lib/robust_excel_ole/excel.rb +138 -92
- data/lib/robust_excel_ole/general.rb +40 -15
- data/lib/robust_excel_ole/range.rb +42 -19
- data/lib/robust_excel_ole/range_owners.rb +40 -25
- data/lib/robust_excel_ole/vba_objects.rb +30 -0
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +320 -319
- data/lib/robust_excel_ole/worksheet.rb +51 -25
- data/robust_excel_ole.gemspec +1 -0
- data/spec/address_tool_spec.rb +175 -0
- data/spec/{reo_common_spec.rb → base_spec.rb} +19 -34
- data/spec/bookstore_spec.rb +3 -3
- data/spec/cell_spec.rb +67 -25
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/excel_spec.rb +137 -369
- data/spec/general_spec.rb +21 -27
- data/spec/range_spec.rb +57 -3
- data/spec/workbook_spec.rb +11 -79
- data/spec/workbook_specs/workbook_misc_spec.rb +29 -40
- data/spec/workbook_specs/workbook_open_spec.rb +599 -31
- data/spec/workbook_specs/workbook_unobtr_spec.rb +760 -93
- data/spec/worksheet_spec.rb +36 -4
- metadata +12 -7
- data/spec/address_spec.rb +0 -174
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f98eac7f4995b60c16017d6be170e0621eaf77b708c4f796b4bde1b0bdb17fc
|
4
|
+
data.tar.gz: bdad471c90fbda86803c03860077e29d2eba3583ec94173d782f8f80b1eb3480
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8a472ec475629d7f9cb2d6886ed009a23e1a5598ba79152accca7f21dde87b05ff46f4a6f776acc6b75ea21538249df31e94145883946d379e0b71dcdcae05f
|
7
|
+
data.tar.gz: 90aa4909eaec50fc74b57c75ad5112ba4216e49177263532dbf703ad4d3694b5a64f7f4c69613dac528fc9cf7874dae98d39900bef5aa62eee3bfb0a860bc215
|
data/Changelog
CHANGED
@@ -1,6 +1,49 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [1.18] 2020-30-4
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- Workbook#worksheets, worksheets_count
|
8
|
+
- Worksheet#each_value
|
9
|
+
- Range#value, value=
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
- Range#initialize: optional paramter worksheet
|
13
|
+
|
14
|
+
## [1.17]
|
15
|
+
|
16
|
+
### Added
|
17
|
+
- Excel#active_workbook
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
- Excel#namevalue, set_namevalue, namevalue_glob, set_namevalue_glob are being removed
|
21
|
+
|
22
|
+
## [1.16]
|
23
|
+
|
24
|
+
### Added
|
25
|
+
- RangeOwners#set_namevalue, set_namevalue_glob, Worksheet#set_cellval:
|
26
|
+
optional parameter for color
|
27
|
+
|
28
|
+
### Changed
|
29
|
+
- Workbook#color_if_modified removed
|
30
|
+
|
31
|
+
## [1.15]
|
32
|
+
|
33
|
+
### Added
|
34
|
+
- Workbook#unobtrusively, Workbook#for_reading, Workbook#for_modifying
|
35
|
+
|
36
|
+
### Changed
|
37
|
+
- Workbook.unobtrusively: removed parameter :rw_change_excel
|
38
|
+
|
39
|
+
## [1.14]
|
40
|
+
|
41
|
+
- no interface change
|
42
|
+
|
43
|
+
## [1.13]
|
44
|
+
|
45
|
+
- no interface change
|
46
|
+
|
4
47
|
## [1.12]
|
5
48
|
|
6
49
|
### Added
|
@@ -8,9 +51,10 @@ All notable changes to this project will be documented in this file.
|
|
8
51
|
- Workbook#color_if_modified
|
9
52
|
|
10
53
|
### Changed:
|
11
|
-
- Workbook#save, save_as:
|
54
|
+
- Workbook#save, save_as: removed parameter :discoloring
|
12
55
|
- RangeOwners#set_namevalue, set_namevalue_glob, Worksheet#set_cellval:
|
13
|
-
|
56
|
+
removed optional parameter for color
|
57
|
+
- Workbook#open: removed option :excel => :reserved_new
|
14
58
|
|
15
59
|
|
16
60
|
## [1.11]
|
@@ -23,7 +67,6 @@ All notable changes to this project will be documented in this file.
|
|
23
67
|
## [1.10]
|
24
68
|
|
25
69
|
### Added
|
26
|
-
- workarounds for running in Jruby
|
27
70
|
- Range,Cell#v
|
28
71
|
|
29
72
|
## [1.9]
|
@@ -74,7 +117,7 @@ All notable changes to this project will be documented in this file.
|
|
74
117
|
- ReoCommon#namevalue, namevalue_glob, set_namevalue, set_namevalue_glob replace
|
75
118
|
set_namevalue replaces set_rangeval, set_namevalue_glob, respectively
|
76
119
|
|
77
|
-
## [1.2.1] 2018-9-
|
120
|
+
## [1.2.1] 2018-9-12
|
78
121
|
|
79
122
|
## [1.2] - 2018-11-8
|
80
123
|
|
data/README.rdoc
CHANGED
@@ -14,10 +14,27 @@ Library references are supported.
|
|
14
14
|
RobustExcelOle works by sending VBA methods via Win32OLE.
|
15
15
|
Therefore, it runs on Windows only.
|
16
16
|
|
17
|
+
== Feature list
|
18
|
+
|
19
|
+
- opening and processing workbooks across various Excel instances
|
20
|
+
- reading and writing workbooks (cells and ranges)
|
21
|
+
- reopening and unobtrusively opening workbooks
|
22
|
+
- convenient methods for standard tasks (like opening, reading, writing, closing, saving workbooks, naming, adding, and copying ranges and worksheets)
|
23
|
+
- dealing with various cases of Excel and user behaviour, e.g. managing conflicts when opening workbooks (e.g. blocking or unsaved workbooks),
|
24
|
+
even with simultanously happening user interactions
|
25
|
+
- workarounds for Excel bugs and JRuby bugs
|
26
|
+
- various workbook formats, e.g. .xlsx, .xls, .xlsm are supported
|
27
|
+
- library references are supported
|
28
|
+
- console for convenient usage
|
29
|
+
|
30
|
+
== What's new?
|
31
|
+
|
32
|
+
- removing methods to operate on ranges directly from an Excel instance. However, you can use the method Excel.active_workbook to do so.
|
33
|
+
See ChangeLogs.
|
17
34
|
|
18
35
|
== Requirements
|
19
36
|
|
20
|
-
Ruby 2.1 or higher.
|
37
|
+
Ruby 2.1 or higher.
|
21
38
|
|
22
39
|
== Installation
|
23
40
|
|
@@ -44,11 +61,7 @@ and go into the path of the gem 'robust_excel_ole'. There you start the console
|
|
44
61
|
|
45
62
|
reo
|
46
63
|
|
47
|
-
|
48
|
-
|
49
|
-
jreo
|
50
|
-
|
51
|
-
depending on whether you are using ruby or jruby.
|
64
|
+
If you don't want to use a version manager to switch between ruby and jruby, you can apply the command +reo+ when using ruby, and +jreo+ when using jruby.
|
52
65
|
|
53
66
|
The call of the console will include RobustExcelOle for you.
|
54
67
|
|
@@ -62,24 +75,21 @@ Let's open a workbook.
|
|
62
75
|
|
63
76
|
workbook = Workbook.open 'spec/data/workbook.xls'
|
64
77
|
|
65
|
-
Now we have a Workbook object that wraps a
|
78
|
+
Now we have a Workbook object that wraps a WIN32OLE object. That is, you can send any WIN32OLE (VBA) method to it. See
|
66
79
|
https://docs.microsoft.com/en-us/office/vba/api/excel.workbook#methods.
|
67
80
|
|
68
|
-
For example, you can determine the name
|
81
|
+
For example, you can determine the name of the workbook.
|
69
82
|
|
70
83
|
workbook.Name
|
71
84
|
# => "workbook.xls"
|
72
85
|
|
73
|
-
workbook.Visible
|
74
|
-
# => false
|
75
|
-
|
76
86
|
For some common tasks and for considering various complex cases of Excel and user behaviour, more convenient methods are implemented. For example, RobustExcelOle provides methods for reading and writing the contents of ranges, for opening, saving, closing, reopening and unobtrusively opening workbooks, and for setting options.
|
77
87
|
|
78
88
|
First we want to make the workbook visible.
|
79
89
|
|
80
90
|
workbook.visible = true
|
81
91
|
|
82
|
-
This method makes both the Excel instance and the window of the Workbook
|
92
|
+
This method makes both the Excel instance and the window of the Workbook WIN32OLE object visible.
|
83
93
|
|
84
94
|
Let's read the value of a named cell.
|
85
95
|
|
@@ -94,21 +104,13 @@ Then we'll save the workbook.
|
|
94
104
|
|
95
105
|
workbook.save
|
96
106
|
|
97
|
-
|
98
|
-
|
99
|
-
workbook.close
|
100
|
-
|
101
|
-
One special feature of RobustExcelOle is that it enables reopening workbooks.
|
102
|
-
|
103
|
-
workbook.reopen
|
107
|
+
=== More features when opening, modifying, creating, saving and closing workbooks
|
104
108
|
|
105
|
-
The workbook is
|
109
|
+
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.
|
106
110
|
|
107
|
-
workbook
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
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 (the Workbook object remembers its properties).
|
111
|
+
Workbook.unobtrusively('spec/data/workbook.xls') do |workbook|
|
112
|
+
# do something
|
113
|
+
end
|
112
114
|
|
113
115
|
Workbook.for_modifying('spec/data/workbook.xls') do |workbook|
|
114
116
|
# do something
|
@@ -122,9 +124,7 @@ You can also create a new, empty workbook.
|
|
122
124
|
|
123
125
|
Workbook.create('spec/data/new_workbook.xls', :visible => true)
|
124
126
|
|
125
|
-
|
126
|
-
|
127
|
-
We can open the workbook using a block, similar to, e.g., +File.open+.
|
127
|
+
Moreover, you can open the workbook using a block, similar to, e.g., +File.open+.
|
128
128
|
|
129
129
|
Workbook.open('spec/data/workbook.xls') do |workbook|
|
130
130
|
# do something
|
@@ -142,7 +142,7 @@ or, using abbreviations,
|
|
142
142
|
|
143
143
|
workbook = Workbook.open('spec/data/workbook.xls', :v => true)
|
144
144
|
|
145
|
-
Note that Workbook.open can also connect to workbooks which were not opened via RobustExcelOle (but had been opened before by some user).
|
145
|
+
Note that +Workbook.open+ can also connect to workbooks which were not opened via RobustExcelOle (but had been opened before by some user).
|
146
146
|
|
147
147
|
For more details about opening workbooks see {README_open}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_open.rdoc]
|
148
148
|
|
@@ -154,7 +154,11 @@ or save the workbook under a different name.
|
|
154
154
|
|
155
155
|
workbook.save_as('spec/data/new_workbook.xls')
|
156
156
|
|
157
|
-
Finally we can
|
157
|
+
Finally we can close the workbook
|
158
|
+
|
159
|
+
workbook.save
|
160
|
+
|
161
|
+
or save and close the workbook in one step.
|
158
162
|
|
159
163
|
workbook.close(:if_unsaved => :save)
|
160
164
|
|
@@ -196,7 +200,8 @@ For hard terminating all Excel processes we can use
|
|
196
200
|
|
197
201
|
Excel.kill_all
|
198
202
|
|
199
|
-
For more details about
|
203
|
+
For more details about opening Excel instances see {README_excel}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_excel.rdoc]
|
204
|
+
|
200
205
|
|
201
206
|
=== Opening workbooks in several Excel instances
|
202
207
|
|
@@ -213,12 +218,12 @@ Now we want to open another workbook in a different Excel instance.
|
|
213
218
|
We can also create a third Excel instance and open another workbook in this instance.
|
214
219
|
|
215
220
|
excel1 = Excel.create
|
216
|
-
|
221
|
+
workbook3 = Workbook.open('spec/data/another_workbook.xls', :excel => excel1)
|
217
222
|
|
218
223
|
A workbook is opened by default in the Excel instance where it was open before most recently.
|
219
224
|
|
220
|
-
|
221
|
-
|
225
|
+
workbook1.close
|
226
|
+
workbook1 = Workbook.open('spec/data/workbook.xls')
|
222
227
|
|
223
228
|
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.
|
224
229
|
|
@@ -252,22 +257,22 @@ Assume we have opened a workbook
|
|
252
257
|
|
253
258
|
We access the first worksheet by
|
254
259
|
|
255
|
-
|
260
|
+
worksheet = workbook.sheet(1)
|
256
261
|
|
257
262
|
or
|
258
263
|
|
259
|
-
|
264
|
+
worksheet = workbook.sheet('Sheet1')
|
260
265
|
|
261
266
|
or
|
262
267
|
|
263
|
-
|
268
|
+
worksheet = workbook.first_sheet
|
264
269
|
|
265
270
|
We can read and change the worksheet name.
|
266
271
|
|
267
|
-
|
272
|
+
worksheet.name
|
268
273
|
# => "Sheet1"
|
269
274
|
|
270
|
-
|
275
|
+
worksheet.name = "new_sheet"
|
271
276
|
|
272
277
|
We can copy the first worksheet, name it and add it before the third worksheet.
|
273
278
|
|
@@ -279,35 +284,35 @@ For more details about processing worksheets see {README_sheet}[https://github.c
|
|
279
284
|
|
280
285
|
We can define a rectangular range by providing the top left and the bottum down cell.
|
281
286
|
|
282
|
-
|
287
|
+
worksheet.range([1..3,1..4])
|
283
288
|
|
284
289
|
We can read the first three cells of the first row
|
285
290
|
|
286
|
-
|
291
|
+
worksheet.row_range(1, 1..3).values # => ["foo","workbook","sheet1"]
|
287
292
|
|
288
293
|
and the third column
|
289
294
|
|
290
|
-
|
295
|
+
worksheet.col_range(3).values # => ["sheet1", 2.0, 4.0]
|
291
296
|
|
292
297
|
We can read the first cell, using
|
293
298
|
|
294
|
-
|
299
|
+
worksheet[1,1].value # => "foo"
|
295
300
|
|
296
301
|
or
|
297
302
|
|
298
|
-
|
303
|
+
worksheet.row_range(1)[0].value # => "foo"
|
299
304
|
|
300
305
|
Then we modify it.
|
301
306
|
|
302
|
-
|
307
|
+
worksheet[1,1] = "hello"
|
303
308
|
|
304
309
|
We get the value of a named range
|
305
310
|
|
306
|
-
|
311
|
+
worksheet["firstcell"] # => "hello"
|
307
312
|
|
308
313
|
and set another value to that range.
|
309
314
|
|
310
|
-
|
315
|
+
worksheet["firstcell"] = "new_value"
|
311
316
|
|
312
317
|
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]
|
313
318
|
|
Binary file
|
data/docs/README_excel.rdoc
CHANGED
@@ -26,7 +26,7 @@ Options of the methods +create+ and +new+ are +:reuse+ (+true+, +false+), +:visi
|
|
26
26
|
|
27
27
|
The option +:calculation+ specifies, whether the calculation mode is being forced to be manual (:manual), automatic (+:automatic+) or is not being forced (+nil+).
|
28
28
|
|
29
|
-
You can also
|
29
|
+
You can also type-lift an Excel instance represented as WIN32OLE object to an Excel object.
|
30
30
|
|
31
31
|
excel = Excel.new(win32ole_object, :visible => true)
|
32
32
|
|
@@ -110,7 +110,7 @@ You can yield an array of all Workbook objects of an Excel instance.
|
|
110
110
|
|
111
111
|
You can access all Workbook objects by using the methods Excel#each_workbook and Excel#each_workbook_with_index. Here are some examples:
|
112
112
|
|
113
|
-
excel.
|
113
|
+
excel.each_workbook {|w| puts w.filename}
|
114
114
|
|
115
115
|
and
|
116
116
|
|
@@ -124,6 +124,12 @@ or, with a block,
|
|
124
124
|
|
125
125
|
excel.each_workbook(:visible => true) {|w| puts w}
|
126
126
|
|
127
|
+
=== Accessing the active workbook
|
128
|
+
|
129
|
+
You can operate on the active workbook with help of the method Workbook#active_workbook, e.g.
|
130
|
+
|
131
|
+
workbook = excel.active_workbook
|
132
|
+
|
127
133
|
=== Bringing an Excel instance to the foreground
|
128
134
|
|
129
135
|
excel1.focus
|
@@ -146,7 +152,7 @@ Closed Excel instances can also be reopened. This includes reopening all workboo
|
|
146
152
|
excel.close
|
147
153
|
excel.recreate
|
148
154
|
|
149
|
-
The options are
|
155
|
+
The options are +:reopen_workbooks+, +:visible+ and +:displayalerts+.
|
150
156
|
|
151
157
|
excel.recreate(:reopen_workbooks => true, :visible => true, :displayalerts => true)
|
152
158
|
|
data/docs/README_open.rdoc
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
=== Opening a workbook.
|
4
4
|
|
5
|
-
If you want to open a workbook, use
|
5
|
+
If you want to open a workbook, you can use the methods +open+ or +new+.
|
6
6
|
|
7
|
-
|
7
|
+
workbook = Workbook.open('spec/data/workbook.xls')
|
8
8
|
|
9
9
|
Once you have got an Workbook object, you can apply all VBA methods that you would apply to a VBA Workbook object
|
10
10
|
(see https://docs.microsoft.com/en-us/office/vba/api/excel.workbook#methods).
|
@@ -46,7 +46,7 @@ You can use the following abbreviations or synonyms: +:f+ for +:force+, +:d+ fo
|
|
46
46
|
|
47
47
|
The option +:excel+ :
|
48
48
|
|
49
|
-
Valid values are : +:current+ (or +:active+ or +:reuse+), +:new+,
|
49
|
+
Valid values are : +:current+ (or +:active+ or +:reuse+), +:new+, or a given Excel instance (default: +:current).
|
50
50
|
|
51
51
|
The option +:if_unsaved+ :
|
52
52
|
|
@@ -80,32 +80,28 @@ Here are a few examples:
|
|
80
80
|
|
81
81
|
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
|
82
82
|
|
83
|
-
|
83
|
+
workbook = Workbook.open('spec/data/workbook.xls', :default => {:excel => :current})
|
84
84
|
|
85
85
|
or
|
86
86
|
|
87
|
-
|
87
|
+
workbook = Workbook.open('spec/data/workbook.xls')
|
88
88
|
|
89
89
|
In case you want to open such a workbook in a new Excel instance, then use
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
You can also open the workbook in a separate, reserved Excel instance.
|
94
|
-
|
95
|
-
book = Workbook.open('spec/data/workbook.xls', :default => {:excel => :reserved_new})
|
91
|
+
workbook = Workbook.open('spec/data/workbook.xls', :default => {:excel => :new})
|
96
92
|
|
97
93
|
If you want to open a workbook in a new Excel instance, no matter if it was opened before, you can write
|
98
94
|
|
99
|
-
|
95
|
+
workbook = Workbook.open('spec/data/workbook.xls', :force => {:excel => :new})
|
100
96
|
|
101
97
|
For simplicity, you can also leave out the +:force+ option (but not the +:default+ option).
|
102
98
|
|
103
|
-
|
99
|
+
workbook = Workbook.open('spec/data/workbook.xls', :excel => :new)
|
104
100
|
|
105
101
|
You can also specify an Excel instance
|
106
102
|
|
107
103
|
excel1 = Excel.create
|
108
|
-
|
104
|
+
workbook = Workbook.open('spec/data/workbook.xls', :excel => excel1)
|
109
105
|
|
110
106
|
If you want to open the workbook and make its window visible, then use
|
111
107
|
|
@@ -114,22 +110,24 @@ If you want to open the workbook and make its window visible, then use
|
|
114
110
|
Notice, that when the workbook is visible, the DisplayAlerts of the respective Excel instance is true, if not explicitely DisplayAlerts is set to false in this Excel instance.
|
115
111
|
You can combine options, e.g.
|
116
112
|
|
117
|
-
|
113
|
+
workbook = Workbook.open('spec/data/workbook.xls', :visible => true, :default => {:excel => excel1})
|
118
114
|
|
119
115
|
You can use the abbreviations, e.g. in this case
|
120
116
|
|
121
|
-
|
117
|
+
workbook = Workbook.open('spec/data/workbook.xls', :v => true, :d => {:e => excel1})
|
122
118
|
|
123
119
|
If a workbook contains unsaved changes and a workbook with the same filename shall be opened, then the option +:if_unsaved+ manages this conflict. For example, if the workbook with the unsaved changes shall remain open, you can use
|
124
120
|
|
125
|
-
|
121
|
+
workbook = Workbook.open('spec/data/workbook.xls', :if_unsaved => :accept)
|
126
122
|
|
127
123
|
If a workbook is open and a workbook with the same name but in different path shall be opened, i.e. the first workbook blocks opening the other workbook, then the option +:if_blocked+ handles this situation, e.g.
|
128
124
|
|
129
|
-
|
125
|
+
workbook = Workbook.open('path/workbook.xls', :if_blocked => :forget)
|
130
126
|
|
131
127
|
Remarks:
|
132
128
|
|
129
|
+
The methods +open+ and +new+ connect to workbooks opened outside of RobustExcelOle as well.
|
130
|
+
|
133
131
|
Opening linked workbooks for EXCEL 2007 is supported
|
134
132
|
|
135
133
|
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.
|
@@ -138,23 +136,58 @@ Doing updating links seems to be dependent on calculation mode: updates happen,
|
|
138
136
|
|
139
137
|
A special feature of RobustExcelOle is that it allows to reopen workbooks after closing them.
|
140
138
|
|
141
|
-
|
142
|
-
|
143
|
-
|
139
|
+
workbook = Workbook.open('spec/data/workbook.xls')
|
140
|
+
workbook.close
|
141
|
+
workbook.reopen
|
144
142
|
|
145
143
|
The closed workbook is now alive again, i.e. is open and responds to Excel methods.
|
146
144
|
|
147
|
-
|
145
|
+
=== Type-lifting WIN32OLE objects to RobustExcelOle objects
|
146
|
+
|
147
|
+
Type-lifting means here: enriching a given object of a certain class by properties and methods of another class.
|
148
|
+
The method +General.to_reo+ enables type-lifting WIN32OLE objects to RobustExcelOle objects, in the sense that the attributes and methods of RobustExcelOle can be applied to these objects. For example, assume we have a WIN32OLE workbook +win32ole_workbook+:
|
149
|
+
|
150
|
+
win32ole_workbook.to_class
|
151
|
+
=> WIN32OLE
|
152
|
+
|
153
|
+
This object can be type-lifted to a RobustExcelOle workbook.
|
154
|
+
|
155
|
+
workbook = win32ole_workbook.to_reo
|
156
|
+
|
157
|
+
workbook.to_class
|
158
|
+
=> RobustExcelOle::Workbook
|
159
|
+
|
160
|
+
Similarly, Excel, Worksheet, and Range WIN32OLE objects can be type-lifted to corresponding RobustExcelOle objects.
|
161
|
+
|
162
|
+
The method +to_reo+ uses the method +new+. You can apply the method +new+ directly.
|
163
|
+
|
164
|
+
workbook = Workbook.new(win32ole_workbook)
|
165
|
+
|
166
|
+
You can supply options, e.g. +:visible+.
|
167
|
+
|
168
|
+
workbook = Workbook.new(win32ole_workbook, :visible => true)
|
169
|
+
|
170
|
+
You can also supply a workbook and options, e.g.
|
171
|
+
|
172
|
+
new_workbook = Workbook.new(workbook, :visible => true)
|
148
173
|
|
149
|
-
===
|
174
|
+
=== Identity transperence ===
|
150
175
|
|
151
|
-
A Workbook object
|
176
|
+
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.
|
152
177
|
|
153
|
-
|
178
|
+
Similarly, each Excel, Worksheet and a Range object in RobustExcelOle is a proxy of a corresponding Excel, Worksheet and a Range object in WIN32OLE. For these objects identity transperence holds as well.
|
154
179
|
|
155
|
-
|
180
|
+
=== Opening workbooks given a network path and a hostname share path ===
|
156
181
|
|
157
|
-
|
182
|
+
RobustExcelOle allows opening workbooks via a network path starting with a drive letter different from the default drive (mostly 'C'), e.g.
|
183
|
+
|
184
|
+
workbook = Workbook.open('N:/data workbook.xls')
|
185
|
+
|
186
|
+
Likewise the corresponding hostname share path can be used, starting with '//', e.g.
|
187
|
+
|
188
|
+
workbook = Workbook.open("//DESKTOP-A5D5GJ5/spec/data/workbook.xls")
|
189
|
+
|
190
|
+
where 'DESKTOP-A5D5GJ5' shall be the hostname, and 'data' be the share.
|
158
191
|
|
159
192
|
=== Unobtrusively modifying a workbook
|
160
193
|
|
@@ -162,48 +195,57 @@ The method +unobtrusively+ enables the user to read or modify a workbook, no mat
|
|
162
195
|
|
163
196
|
Options are the following:
|
164
197
|
|
165
|
-
+:if_closed+::
|
166
|
-
|
198
|
+
+:if_closed+:: the Excel instance in which to open the workbook, if it was closed (default: +:current+). (Note: this option works workbooks opened via RobustExcelOle only.)
|
199
|
+
|
167
200
|
+:read_only+:: Whether the workbook shall be forced to be open in ReadOnly mode
|
168
201
|
+:writable+:: Whether changes in the workbook shall be saved
|
169
202
|
|
170
|
-
+:
|
171
|
-
changed read-write permissions shall be opened
|
172
|
-
:current (default), :new or an Excel instance
|
173
|
-
|
174
|
-
+:keep_open+:: Whether the workbook shall be open after unobtrusively opening (default: false)
|
203
|
+
+:keep_open+:: Whether the workbook shall be open after unobtrusively opening (default: false)
|
175
204
|
|
205
|
+
There are the class method and the instance method of +unobtrusively+. Here is an example of the class method:
|
176
206
|
|
177
207
|
Workbook.unobtrusively('spec/data/workbook.xls') do |book|
|
178
208
|
# some modification
|
179
|
-
sheet =
|
180
|
-
sheet[1,1] = "c"
|
209
|
+
book.sheet(1)[1,1] = "c"
|
181
210
|
end
|
182
|
-
|
183
|
-
|
211
|
+
|
212
|
+
Here is an example of the instance method:
|
213
|
+
|
214
|
+
book.unobtrusively do
|
215
|
+
# some modification
|
216
|
+
book.sheet(1)[1,1] = "c"
|
217
|
+
end
|
218
|
+
|
219
|
+
The methods +for_reading+ and +for_modifying+ indicate unobtrusively reading or modifying.
|
184
220
|
|
185
221
|
Workbook.for_modifying('spec/data/workbook.xls') do |book|
|
186
222
|
# some modification
|
187
|
-
sheet =
|
188
|
-
sheet[1,1] = "c"
|
223
|
+
book.sheet(1)[1,1] = "c"
|
189
224
|
end
|
190
225
|
|
191
|
-
|
226
|
+
An example of the instance method would be
|
227
|
+
|
228
|
+
book.for_modifying do
|
229
|
+
# some modification
|
230
|
+
book.sheet(1)[1,1] = "c"
|
231
|
+
end
|
232
|
+
|
233
|
+
Note, that the methods +unobtrusively+, +for_reading+ and +for_modifying+ work not only for workbooks opened via RobustExcelOle, but connect to workbooks opened outside RobustExcelOle as well.
|
192
234
|
|
193
235
|
=== Retaining the saved-status
|
194
236
|
|
195
237
|
This method ensures keeping the save status of the workbook
|
196
238
|
|
197
|
-
|
198
|
-
|
239
|
+
workbook = Workbook.open('spec/data/workbook.xls')
|
240
|
+
workbook.retain_saved do
|
199
241
|
# some reading or modifying
|
200
242
|
end
|
201
243
|
|
202
244
|
=== Checking whether the workbook is alive.
|
203
245
|
|
204
|
-
|
246
|
+
The method +alive?+ finds out whether the Excel workbook that is referenced by the Workbook object responds to methods. For example
|
205
247
|
|
206
|
-
|
248
|
+
workbook.alive?
|
207
249
|
# => true
|
208
250
|
|
209
251
|
== Code
|