robust_excel_ole 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +13 -0
- data/README.rdoc +107 -73
- data/{README_excel.rdoc → docs/README_excel.rdoc} +2 -0
- data/{README_open.rdoc → docs/README_open.rdoc} +12 -16
- data/{README_ranges.rdoc → docs/README_ranges.rdoc} +1 -1
- data/{README_save_close.rdoc → docs/README_save_close.rdoc} +0 -0
- data/{README_sheet.rdoc → docs/README_sheet.rdoc} +0 -0
- data/examples/open_save_close/example_control_to_excel.rb +3 -3
- data/examples/open_save_close/example_default_excel.rb +2 -2
- data/examples/open_save_close/example_force_excel.rb +2 -2
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +2 -2
- data/examples/open_save_close/example_if_obstructed_forget.rb +2 -2
- data/examples/open_save_close/example_if_obstructed_save.rb +2 -2
- data/examples/open_save_close/example_if_unsaved_accept.rb +3 -3
- data/examples/open_save_close/example_if_unsaved_forget.rb +7 -3
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +1 -1
- data/examples/open_save_close/example_read_only.rb +2 -2
- data/examples/open_save_close/example_rename_cells.rb +2 -2
- data/examples/open_save_close/example_reuse.rb +2 -2
- data/examples/open_save_close/example_simple.rb +1 -1
- data/examples/open_save_close/example_unobtrusively.rb +2 -2
- data/lib/robust_excel_ole/book.rb +75 -76
- data/lib/robust_excel_ole/bookstore.rb +9 -9
- data/lib/robust_excel_ole/excel.rb +5 -5
- data/lib/robust_excel_ole/general.rb +11 -4
- data/lib/robust_excel_ole/reo_common.rb +3 -0
- data/lib/robust_excel_ole/version.rb +1 -1
- data/robust_excel_ole.gemspec +2 -2
- data/spec/book_spec.rb +67 -63
- data/spec/book_specs/book_close_spec.rb +12 -10
- data/spec/book_specs/book_misc_spec.rb +279 -279
- data/spec/book_specs/book_open_spec.rb +258 -105
- data/spec/book_specs/book_save_spec.rb +28 -28
- data/spec/book_specs/book_unobtr_spec.rb +862 -164
- data/spec/bookstore_spec.rb +22 -22
- data/spec/data/another_workbook.xls +0 -0
- data/spec/data/different_workbook.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +256 -254
- data/spec/general_spec.rb +7 -7
- data/spec/ruby1.8.6_rspec2.14/book_spec.rb +1421 -0
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_all_spec.rb +22 -0
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_close_spec.rb +252 -0
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_misc_spec.rb +1070 -0
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_open_spec.rb +1855 -0
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_save_spec.rb +514 -0
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_sheet_spec.rb +395 -0
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_subclass_spec.rb +51 -0
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_unobtr_spec.rb +1737 -0
- data/spec/ruby1.8.6_rspec2.14/bookstore_spec.rb +495 -0
- data/spec/ruby1.8.6_rspec2.14/cell_spec.rb +76 -0
- data/spec/ruby1.8.6_rspec2.14/cygwin_spec.rb +42 -0
- data/spec/ruby1.8.6_rspec2.14/excel_spec.rb +1820 -0
- data/spec/ruby1.8.6_rspec2.14/general_spec.rb +212 -0
- data/spec/ruby1.8.6_rspec2.14/range_spec.rb +131 -0
- data/spec/ruby1.8.6_rspec2.14/reo_common_spec.rb +130 -0
- data/spec/ruby1.8.6_rspec2.14/sheet_spec.rb +663 -0
- data/spec/ruby1.8.6_rspec2.14/spec_helper.rb +35 -0
- data/spec/sheet_spec.rb +2 -2
- metadata +28 -12
- data/README_detail.rdoc +0 -852
- data/README_development.rdoc +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94e2b8cc2f0306a63e377d70378a04063e6b5cf2
|
4
|
+
data.tar.gz: 6d4c94aa56956a25ba723746bf05e23320aa36bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f46997852585e4560db9ccb679a0dccc11a6128b59022b374d8393771531ae2aab2973fa10d0f342f882181dcaaca2cdf4af7151ed918446bdebdb5f57faf8dc
|
7
|
+
data.tar.gz: 99d74fe8c6c16ab52c40c6d5362cba29a07539acf695fbc546619b8fb18086b860258005ccd63429c19655aaf6212096c5d1d76924c4ff85be565cf7dc88e34a
|
data/Changelog
CHANGED
@@ -1,9 +1,22 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [1.1.5] - 2018-10-7
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- Book#unobtrusively:
|
8
|
+
option :writable
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
- Book#unobtrusively:
|
12
|
+
option :rw_change_excel instead :readonly_excel
|
13
|
+
|
14
|
+
### Added
|
15
|
+
|
4
16
|
## [1.1.4] - 2018-10-6
|
5
17
|
|
6
18
|
### Added
|
19
|
+
- Book#open: for the options: simplifiaction: :force can be left out
|
7
20
|
- Excel#for_this_instance
|
8
21
|
- Excel#for_all_workbooks
|
9
22
|
- Book#for_this_workbooks
|
data/README.rdoc
CHANGED
@@ -1,22 +1,26 @@
|
|
1
1
|
= RobustExcelOle
|
2
2
|
|
3
|
-
This
|
3
|
+
This library automates reading, modifying, and writing Excel workbooks. It is designed to support several kinds of concurrency of both simultaneously running Excel instances and simultanously happening user interactions.
|
4
4
|
RobustExcelOle deals with various cases of Excel and user behaviour,
|
5
5
|
and implements workarounds for some Excel bugs.
|
6
6
|
The gem provides convenient methods for common tasks, and facilitates referenced libraries.
|
7
|
-
It can be used for any recent Excel Office version, and is tested for Excel 2010.
|
8
7
|
|
9
|
-
RobustExcelOle works by sending VBA methods via Win32OLE.
|
10
|
-
It implements a management system and keeps track of Excel files and Excel instances.
|
8
|
+
RobustExcelOle works by sending VBA methods via Win32OLE. It keeps track of Excel workbooks and Excel instances.
|
11
9
|
|
12
10
|
== Requirements
|
13
11
|
|
14
12
|
* Ruby 1.8.6 or higher
|
15
13
|
|
16
|
-
==
|
14
|
+
== Installation
|
15
|
+
|
16
|
+
You can install the gem by running the command
|
17
17
|
|
18
18
|
gem install robust_excel_ole
|
19
19
|
|
20
|
+
or by using bundler and putting the following line in your Gemfile.
|
21
|
+
|
22
|
+
gem 'robust_excel_ole'
|
23
|
+
|
20
24
|
== Usage
|
21
25
|
|
22
26
|
RobustExcelOle can be used either for scripts
|
@@ -30,79 +34,110 @@ or as a console
|
|
30
34
|
|
31
35
|
The call of the console will include RobustExcelOle for you.
|
32
36
|
|
33
|
-
The following examples can be used for both scripts and console.
|
37
|
+
The following examples can be used for both scripts and console. If you are in the path of the gem and start the console, you can just put these examples.
|
34
38
|
|
35
39
|
== Description
|
36
40
|
|
37
|
-
|
41
|
+
In the following example, we want to open a workbook, modify a cell, save and close the workbook.
|
38
42
|
|
39
|
-
|
43
|
+
Let's open a workbook.
|
40
44
|
|
41
45
|
workbook = Workbook.open 'spec/data/workbook.xls'
|
42
46
|
|
43
|
-
|
47
|
+
Now we have a Workbook object that wraps a win32ole object. That is, you can send any win32ole (VBA) method to it. For example, you can determine the name and the saved-status of the workbook.
|
44
48
|
|
45
|
-
|
46
|
-
|
47
|
-
|
49
|
+
workbook.Name
|
50
|
+
# => "workbook.xls"
|
51
|
+
|
52
|
+
workbook.Visible
|
53
|
+
# => false
|
48
54
|
|
49
|
-
|
55
|
+
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.
|
50
56
|
|
51
|
-
|
57
|
+
First we want to make the workbook visible.
|
52
58
|
|
53
59
|
workbook.visible = true
|
54
60
|
|
55
|
-
|
61
|
+
This method makes both the Excel instance and the window of the Workbook-win32ole-object visible.
|
56
62
|
|
57
|
-
|
63
|
+
Let's read the value of a named cell.
|
58
64
|
|
59
|
-
|
65
|
+
value = workbook['firstcell']
|
66
|
+
# => "foo"
|
60
67
|
|
61
|
-
|
68
|
+
Now we want to write a new value into this cell.
|
62
69
|
|
63
|
-
|
70
|
+
workbook['firstcell'] = "new"
|
64
71
|
|
65
|
-
|
72
|
+
Then we'll save the workbook.
|
66
73
|
|
67
|
-
|
74
|
+
workbook.save
|
68
75
|
|
69
|
-
|
70
|
-
# => "foo"
|
76
|
+
Finally we want to close the workbook.
|
71
77
|
|
72
|
-
|
78
|
+
workbook.close
|
73
79
|
|
74
|
-
|
80
|
+
One special feature of RobustExcelOle is that it enables reopening workbooks.
|
75
81
|
|
76
|
-
|
82
|
+
workbook.reopen
|
77
83
|
|
78
|
-
|
84
|
+
The workbook is now open again and ready for applying further operations, e.g.
|
79
85
|
|
86
|
+
workbook['firstcell'] = "another_value"
|
80
87
|
workbook.save
|
88
|
+
workbook.close
|
81
89
|
|
82
|
-
|
90
|
+
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).
|
83
91
|
|
84
|
-
|
92
|
+
Workbook.for_modifying('spec/data/workbook.xls') do |workbook|
|
93
|
+
# do something
|
94
|
+
end
|
85
95
|
|
86
|
-
|
96
|
+
Workbook.for_reading('spec/data/workbook.xls') do |workbook|
|
97
|
+
# do something
|
98
|
+
end
|
87
99
|
|
88
|
-
|
100
|
+
=== More features when opening, modifying, saving and closing workbooks
|
89
101
|
|
90
|
-
We
|
102
|
+
We can open the workbook using a block, similar to, e.g., +File.open+.
|
91
103
|
|
92
|
-
workbook.
|
104
|
+
Workbook.open('spec/data/workbook.xls') do |workbook|
|
105
|
+
# do something
|
106
|
+
end
|
93
107
|
|
94
|
-
|
95
|
-
{README_save_close}[https://github.com/Thomas008/robust_excel_ole/blob/master/README_save_close.rdoc]
|
108
|
+
Once we have a workbook, we can set some options, e.g.
|
96
109
|
|
97
|
-
|
110
|
+
workbook.for_this_workbook(:visible => true, :read_only => false)
|
98
111
|
|
99
|
-
|
112
|
+
We can also open the workbook and provide the options in one step, e.g.
|
113
|
+
|
114
|
+
workbook = Workbook.open('spec/data/workbook.xls', :visible => true)
|
115
|
+
|
116
|
+
or, using abbreviations,
|
117
|
+
|
118
|
+
workbook = Workbook.open('spec/data/workbook.xls', :v => true)
|
119
|
+
|
120
|
+
For more details about opening workbooks see {README_open}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_open.rdoc]
|
121
|
+
|
122
|
+
We can do a simple save
|
123
|
+
|
124
|
+
workbook.save
|
125
|
+
|
126
|
+
or save the workbook under a different name.
|
127
|
+
|
128
|
+
workbook.save_as('spec/data/new_workbook.xls')
|
129
|
+
|
130
|
+
Finally we can save and close the workbook in one step.
|
131
|
+
|
132
|
+
workbook.close(:if_unsaved => :save)
|
133
|
+
|
134
|
+
For more details about saving and closing workbooks see
|
135
|
+
{README_save_close}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_save_close.rdoc]
|
100
136
|
|
101
|
-
Technically, this feature is implemented in such way, that a Workbook object is a proxy of an Excel 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 the same Workbook objects refer to the same workbooks, and vice versa.
|
102
137
|
|
103
138
|
=== Using Excel instances
|
104
139
|
|
105
|
-
|
140
|
+
We can start a new Excel instance with
|
106
141
|
|
107
142
|
excel1 = Excel.create
|
108
143
|
|
@@ -110,7 +145,7 @@ or
|
|
110
145
|
|
111
146
|
excel1 = Excel.new(:reuse => false)
|
112
147
|
|
113
|
-
|
148
|
+
We can also obtain an Excel object by connecting to the already running Excel instance.
|
114
149
|
|
115
150
|
excel2 = Excel.current
|
116
151
|
|
@@ -130,17 +165,17 @@ Closing all Excel instances is done by
|
|
130
165
|
|
131
166
|
Excel.close_all(:if_unsaved => :forget)
|
132
167
|
|
133
|
-
For hard terminating all Excel processes
|
168
|
+
For hard terminating all Excel processes we can use
|
134
169
|
|
135
170
|
Excel.kill_all
|
136
171
|
|
137
|
-
For more details about creating Excel instances see README_excel[https://github.com/Thomas008/robust_excel_ole/blob/master/README_excel_rdoc]
|
172
|
+
For more details about creating Excel instances see README_excel[https://github.com/Thomas008/robust_excel_ole/blob/master/README/README_excel_rdoc]
|
138
173
|
|
139
174
|
=== Opening workbooks in several Excel instances
|
140
175
|
|
141
176
|
RobustExcelOle enables opening and processing workbooks in several Excel instances. Using more than one Excel process allows, e.g., running a script that operates in one Excel instance, while a user (or another script) modifies workbooks in another Excel instance.
|
142
177
|
|
143
|
-
For example, suppose
|
178
|
+
For example, suppose we want to open a workbook.
|
144
179
|
|
145
180
|
workbook1 = Workbook.open('spec/data/workbook.xls')
|
146
181
|
|
@@ -162,41 +197,31 @@ If this Excel instance is damaged or closed, then options control whether the wo
|
|
162
197
|
|
163
198
|
workbook1 = Workbook.open('spec/data/workbook.xls', :default => {:excel => :new})
|
164
199
|
|
165
|
-
Without the option +:default+, the workbook
|
200
|
+
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.
|
166
201
|
|
167
202
|
workbook2 = Workbook.open('spec/data/workbook.xls', :excel => excel1)
|
168
203
|
|
169
|
-
As a further feature, RobustExcelOle allows processing workbooks, while still supporting user's interactions: The commands enable to open, close, reopen, read, modify, write and save Excel
|
204
|
+
As a further feature, RobustExcelOle allows 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.
|
170
205
|
|
171
|
-
For example, suppose
|
206
|
+
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 before opening the workbook, e.g.
|
172
207
|
|
173
208
|
workbook = Workbook.open('workbook.xls', :if_unsaved => :accept)
|
174
209
|
|
175
|
-
Similarly, if the user has opened a workbook that has the same name but a different path, the conflict
|
210
|
+
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.
|
176
211
|
|
177
212
|
workbook1 = Workbook.open('spec/data/workbook.xls')
|
178
213
|
# do something
|
179
214
|
workbook2 = Workbook.open('spec/data/more/workbook.xls', :if_obstructed => :forget)
|
180
215
|
|
181
|
-
|
182
|
-
|
183
|
-
Workbook.for_modifying('workbook.xls') do |book|
|
184
|
-
# do something
|
185
|
-
end
|
186
|
-
|
187
|
-
Workbook.for_reading('workbook.xls') do |book|
|
188
|
-
# do something
|
189
|
-
end
|
190
|
-
|
191
|
-
For more details about opening and closing workbooks in Excel instances see {README_open}[https://github.com/Thomas008/robust_excel_ole/blob/master/README_open.rdoc]
|
216
|
+
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]
|
192
217
|
|
193
|
-
===
|
218
|
+
=== Operating on worksheets
|
194
219
|
|
195
|
-
|
220
|
+
Assume we have opened a workbook
|
196
221
|
|
197
222
|
workbook = Workbook.open('spec/data/workbook.xls')
|
198
223
|
|
199
|
-
|
224
|
+
We access the first worksheet by
|
200
225
|
|
201
226
|
sheet = workbook.sheet(1)
|
202
227
|
|
@@ -208,14 +233,22 @@ or
|
|
208
233
|
|
209
234
|
sheet = workbook.first_sheet
|
210
235
|
|
211
|
-
|
236
|
+
We can read and change the worksheet name.
|
212
237
|
|
213
238
|
sheet.name
|
214
239
|
# => "Sheet1"
|
215
240
|
|
216
241
|
sheet.name = "new_sheet"
|
217
242
|
|
218
|
-
|
243
|
+
We can copy the first worksheet, name it and add it before the third worksheet.
|
244
|
+
|
245
|
+
workbook.add_or_copy_sheet(sheet, :as => "copied_name, :before => workbook.last_sheet)
|
246
|
+
|
247
|
+
For more details about processing worksheets see {README_sheet}[https://github.com/Thomas008/robust_excel_ole/blob/master/docs/README_sheet.rdoc]
|
248
|
+
|
249
|
+
=== Reading and writing ranges in worksheets
|
250
|
+
|
251
|
+
We can read the first three cells of the first row
|
219
252
|
|
220
253
|
sheet.row_range(1, 1..3).values # => ["foo","workbook","sheet1"]
|
221
254
|
|
@@ -223,7 +256,7 @@ and the third column
|
|
223
256
|
|
224
257
|
sheet.col_range(3).values # => ["sheet1", 2.0, 4.0]
|
225
258
|
|
226
|
-
|
259
|
+
We can read the first cell, using
|
227
260
|
|
228
261
|
sheet[1,1].value # => "foo"
|
229
262
|
|
@@ -235,7 +268,7 @@ Then we modify it
|
|
235
268
|
|
236
269
|
sheet[1,1] = "hello"
|
237
270
|
|
238
|
-
|
271
|
+
We get the value of a named range
|
239
272
|
|
240
273
|
sheet["firstcell"] # => "hello"
|
241
274
|
|
@@ -243,20 +276,21 @@ and set another value to that range.
|
|
243
276
|
|
244
277
|
sheet["firstcell"] = "new_value"
|
245
278
|
|
246
|
-
|
279
|
+
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]
|
247
280
|
|
248
|
-
|
281
|
+
=== Examples
|
282
|
+
|
283
|
+
You can run the examples included in the directory +examples+, e.g.
|
249
284
|
|
250
|
-
|
285
|
+
ruby examples\open_save_close\example_unobtrusively.rb
|
251
286
|
|
252
|
-
|
287
|
+
== Development
|
253
288
|
|
254
|
-
|
255
|
-
{README_development}[https://github.com/Thomas008/robust_excel_ole/blob/master/README_development.rdoc]
|
289
|
+
This project RobustExcelOle is work in progress. We are happy to implement further features. So we invite you to send your pull requests. We then strive to realize them as soon as possible. If you have any feedback, or you find use cases that RobustExcelOle does not satisfy, please let us know.
|
256
290
|
|
257
|
-
|
291
|
+
RobustExcelOle is being tested for Excel 2010. It can be used for any recent Excel Office version.
|
258
292
|
|
259
|
-
|
293
|
+
The tests of RobustExcelOle are optimised with help of the rcov tool.
|
260
294
|
|
261
295
|
== Support
|
262
296
|
|
@@ -76,6 +76,8 @@ You can turn off and off DisplayAlerts in a block.
|
|
76
76
|
# do something
|
77
77
|
end
|
78
78
|
|
79
|
+
Notice, that when the Excel instance is set to visible, its DisplayAlerts is set to true by default, if DisplayAlerts is not explicitely set to false.
|
80
|
+
|
79
81
|
=== Setting Calculation mode.
|
80
82
|
|
81
83
|
You can set the calculation mode of an Excel instance to manual or automatic.
|
@@ -107,6 +107,7 @@ If you want to open the workbook and make its window visible, then use
|
|
107
107
|
|
108
108
|
book = Workbook.open('workbook.xls', :visible => true)
|
109
109
|
|
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.
|
110
111
|
You can combine options, e.g.
|
111
112
|
|
112
113
|
Workbook.open('workbook.xls', :excel => :new, :visible => true, :default => {:excel => excel1})
|
@@ -139,13 +140,7 @@ A special feature of RobustExcelOle is that it allows to reopen workbooks after
|
|
139
140
|
|
140
141
|
The closed workbook is now alive again, i.e. is open and responds to Excel methods.
|
141
142
|
|
142
|
-
|
143
|
-
|
144
|
-
=== The Workbook objects and transperence identity
|
145
|
-
|
146
|
-
An Excel file (or workbook) is represented by a Workbook object. A Workbook object is defined by the full name of the workbook and the Excel instance in which it is opened. RobustExcelOle aims to ensure identity transperency.
|
147
|
-
Identity transparence means that the same Workbook objects refer to the same Excel files, and vice versa.
|
148
|
-
In other words, a Workbook objects is a proxy of an Excel file.
|
143
|
+
Technically, this feature is implemented in such way, that a Workbook object is a proxy of an Excel 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 the same Workbook objects refer to the same workbooks, and vice versa.
|
149
144
|
|
150
145
|
=== Promoting a workbook to a Workbook object
|
151
146
|
|
@@ -153,22 +148,23 @@ A Workbook object can be created when giving an Excel workbook.
|
|
153
148
|
|
154
149
|
book = Workbook.new(win32ole_workbook)
|
155
150
|
|
156
|
-
|
157
151
|
=== Unobtrusively modifying a workbook
|
158
152
|
|
159
153
|
The method +unobtrusively+ enables the user to read or modify a workbook, no matter if it is open in some Excel instance, if it is saved or unsaved, and if it is writable or not. When opening a workbook unobtrusively, its status remains unchanged. This status includes, whether the workbook is opened or closed, saved or unsaved, readonly or writable, visible or invisible, calculation mode is automatic or manual, and checking compatibility is turned on or off.
|
160
154
|
|
161
|
-
One option chooses the Excel instance in which a closed workbook is opened. The option +:current+ (or +:active+, or +:reuse) (default) indicates that the closed workbook is opened in the Excel instance of the workbook, if it exists, or that another Excel instance is reused. Moreover, an Excel instance can be given directly where to open the closed workbook.
|
162
|
-
|
163
155
|
Options are the following:
|
164
156
|
|
165
|
-
+:current+ (or +:active, or +:reuse+:): (default) : open a closed workbook in the Excel instance where it was opened most recently, if such an Excel instance exists, otherwise open it in the current (first opened) Excel instance
|
157
|
+
+:if_closed+:: +:current+ (or +:active, or +:reuse+:): (default) : open a closed workbook in the Excel instance where it was opened most recently, if such an Excel instance exists, otherwise open it in the current (first opened) Excel instance
|
166
158
|
|
167
|
-
+:read_only+::
|
168
|
-
+:
|
169
|
-
|
170
|
-
|
171
|
-
|
159
|
+
+:read_only+:: Whether the workbook shall be forced to be open in ReadOnly mode (default: +false+)
|
160
|
+
+:writable+:: Whether changes in the workbook shall be saved (default: +true+)
|
161
|
+
|
162
|
+
+:rw_change_excel+:: Excel instance in which the workbook with the
|
163
|
+
changed read-write permissions shall be opened
|
164
|
+
:current (default), :new or an Excel instance
|
165
|
+
|
166
|
+
+:keep_open+:: Whether the workbook shall be open after unobtrusively opening (default: false)
|
167
|
+
|
172
168
|
|
173
169
|
Workbook.unobtrusively('workbook.xls') do |book|
|
174
170
|
# some modification
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
== Reading and writing the contents of ranges and cells
|
4
4
|
|
5
|
-
RobustExcelOle enables to read and write the contents of ranges and cells in
|
5
|
+
RobustExcelOle enables to read and write the contents of ranges and cells in workbooks. This can be done from a Sheet, a Book or an Excel object representing a Worksheet, Workbook, or Application object in VBA.
|
6
6
|
|
7
7
|
=== Reading and writing the contents of a named range in a workbook.
|
8
8
|
|
File without changes
|
File without changes
|
@@ -7,7 +7,7 @@ require "fileutils"
|
|
7
7
|
|
8
8
|
include RobustExcelOle
|
9
9
|
|
10
|
-
Excel.
|
10
|
+
Excel.kill_all
|
11
11
|
begin
|
12
12
|
dir = create_tmpdir
|
13
13
|
file_name = dir + 'workbook.xls'
|
@@ -19,7 +19,7 @@ begin
|
|
19
19
|
sleep 1
|
20
20
|
begin
|
21
21
|
new_book = Book.open(file_name, :if_unsaved => :alert) # open another book with the same file name
|
22
|
-
rescue
|
22
|
+
rescue WorkbookREOError => msg # if the user chooses not open the book,
|
23
23
|
puts "#{msg.message}" # an exeptions is raised
|
24
24
|
end
|
25
25
|
puts "new book has opened" if new_book
|
@@ -39,6 +39,6 @@ begin
|
|
39
39
|
new_book.close # close the new book, if the user chose to open it
|
40
40
|
end
|
41
41
|
ensure
|
42
|
-
Excel.
|
42
|
+
Excel.kill_all # close ALL workbooks, quit Excel application
|
43
43
|
rm_tmp(dir)
|
44
44
|
end
|