robust_excel_ole 1.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Changelog +26 -12
- data/README.rdoc +35 -27
- data/README_detail.rdoc +66 -50
- data/examples/edit_sheets/example_access_sheets_and_cells.rb +4 -4
- data/examples/edit_sheets/example_adding_sheets.rb +1 -1
- data/examples/edit_sheets/example_concating.rb +2 -2
- data/examples/edit_sheets/example_copying.rb +2 -2
- data/examples/edit_sheets/example_expanding.rb +2 -2
- data/examples/edit_sheets/example_naming.rb +2 -2
- data/examples/edit_sheets/example_saving.rb +4 -4
- data/examples/open_save_close/example_default_excel.rb +5 -5
- data/examples/open_save_close/example_force_excel.rb +4 -4
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +3 -3
- data/examples/open_save_close/example_if_obstructed_forget.rb +4 -4
- data/examples/open_save_close/example_if_obstructed_save.rb +3 -3
- data/examples/open_save_close/example_if_unsaved_accept.rb +3 -3
- data/examples/open_save_close/example_if_unsaved_forget.rb +3 -3
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +3 -3
- data/examples/open_save_close/example_read_only.rb +1 -1
- data/examples/open_save_close/example_rename_cells.rb +1 -1
- data/examples/open_save_close/example_reuse.rb +4 -4
- data/examples/open_save_close/example_simple.rb +1 -1
- data/examples/open_save_close/example_unobtrusively.rb +2 -2
- data/lib/reo_console.rb +1 -1
- data/lib/robust_excel_ole/book.rb +56 -23
- data/lib/robust_excel_ole/excel.rb +35 -25
- data/lib/robust_excel_ole/general.rb +1 -1
- data/lib/robust_excel_ole/sheet.rb +99 -66
- data/lib/robust_excel_ole/version.rb +1 -1
- data/reo.bat +1 -1
- data/spec/book_spec.rb +7 -1
- data/spec/book_specs/book_misc_spec.rb +0 -4
- data/spec/data/another_workbook.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +11 -17
- data/spec/sheet_spec.rb +11 -11
- metadata +38 -60
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e288f5c2c1de7a23b3f3d38bcefa7dc9fb78661b
|
4
|
+
data.tar.gz: 8c396bc079707bf0602ed3b6e6083d4f04569a0a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 195f2c061fdffdb4ae22bb19f245b059a5620f894998cb754a14685a25d31f1f8b227dac7c3c8f9e34d9598d3b9a9ead74a333795fe3c7ea49be609aef6111ae
|
7
|
+
data.tar.gz: e77b113d6b9791e4a3304bbc629f3ba067594c49f20a61d54e5f1d1b6cba12bcfd9322b2ed541ccfddca6914865fd6efb47ce7170db12f388bf9ae4e9a4db5e7
|
data/Changelog
CHANGED
@@ -1,8 +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.1] - 2018-20-4
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- Book#save, save_as: options: discoloring
|
8
|
+
- Book#set_nameval, Sheet, Excel#set_nameval, set_rangeval: option :color
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
|
12
|
+
- renamed: Excel.known_excel_instances instead of excel_processes
|
13
|
+
|
4
14
|
## [1.1] - 2017-09-29
|
5
15
|
|
16
|
+
### Added
|
17
|
+
|
18
|
+
- Book.save, save_as, close
|
19
|
+
|
6
20
|
## [1.0.4] - 2017-08-30
|
7
21
|
|
8
22
|
## [1.0.3] - 2017-08-27
|
@@ -23,8 +37,8 @@ All notable changes to this project will be documented in this file.
|
|
23
37
|
|
24
38
|
### Added
|
25
39
|
|
26
|
-
- Book
|
27
|
-
- Excel
|
40
|
+
- Book.open : options :calculation
|
41
|
+
- Excel.new : options :calculation, :screen_updating
|
28
42
|
- Excel#calculation, calculation=, screen_updating, screenupdating=
|
29
43
|
|
30
44
|
### Changed
|
@@ -123,18 +137,18 @@ All notable changes to this project will be documented in this file.
|
|
123
137
|
## [0.3.7] - 2015-12-04
|
124
138
|
|
125
139
|
### Added
|
126
|
-
- Book
|
140
|
+
- Book.new: includes lifting Win32Ole objects
|
127
141
|
- Book: class synonym: Workbook
|
128
|
-
- Book
|
142
|
+
- Book.open: can force_excel can contain an win32ole object
|
129
143
|
- Book#excel_of
|
130
144
|
- Book: consider Excel version for opening linked workbooks
|
131
145
|
- Book#close: with keep_open
|
132
|
-
- Excel
|
133
|
-
- Excel
|
146
|
+
- Excel.new: includes lifting Win32ole objects
|
147
|
+
- Excel.close_all: with a little time out
|
134
148
|
- Excel: sublassing for Books
|
135
149
|
|
136
150
|
### Changed
|
137
|
-
- Excel
|
151
|
+
- Excel.close_all: bug fix
|
138
152
|
- Excel#recreate: reopening closed workbooks, restrict reopening, visible, displayalerts
|
139
153
|
|
140
154
|
|
@@ -143,12 +157,12 @@ All notable changes to this project will be documented in this file.
|
|
143
157
|
|
144
158
|
### Added
|
145
159
|
- Excel#recreate: reopening a closed Excel
|
146
|
-
- Excel
|
160
|
+
- Excel.new(:reuse => <WIN32OLE_excel>):
|
147
161
|
uplifting an Excel represented as object of the class WIN32OLE to an object of the class Excel
|
148
|
-
- Excel#close, Excel
|
149
|
-
- Excel
|
150
|
-
- Excel
|
151
|
-
- Book
|
162
|
+
- Excel#close, Excel.close_all: with managing unsaved workbooks
|
163
|
+
- Excel.kill_all
|
164
|
+
- Excel.excel_processes: yield Excel objects opened with RobustExcelOle
|
165
|
+
- Book.new: uplifting a WIN32OLE object to a Book object
|
152
166
|
- Subclassing for Sheet
|
153
167
|
- Method missing: error messages for dead objects
|
154
168
|
- trace to stdout or file
|
data/README.rdoc
CHANGED
@@ -32,16 +32,16 @@ RobustExcelOle enables opening and processing Excel files (or workbooks) in seve
|
|
32
32
|
|
33
33
|
For example, suppose you want to open a workbook and make it visible.
|
34
34
|
|
35
|
-
book1 =
|
35
|
+
book1 = Workbook.open('workbook.xls', :visible => true)
|
36
36
|
|
37
37
|
Now we want to open another workbook in a different Excel instance.
|
38
38
|
|
39
|
-
book2 =
|
39
|
+
book2 = Workbook.open('workbook2.xls', :force => {:excel => :new}, :visible => true)
|
40
40
|
|
41
41
|
We can also create a third Excel instance and open another workbook in this instance.
|
42
42
|
|
43
43
|
excel1 = Excel.create
|
44
|
-
book3 =
|
44
|
+
book3 = Workbook.open('workbook3.xls', :force => {:excel => excel1}, :visible => true)
|
45
45
|
|
46
46
|
Another feature that RobustExcelOle povides is reopening workbooks after closing them.
|
47
47
|
|
@@ -51,45 +51,45 @@ Another feature that RobustExcelOle povides is reopening workbooks after closing
|
|
51
51
|
A workbook is opened by default in the Excel instance where it was open before most recently.
|
52
52
|
|
53
53
|
book1.close
|
54
|
-
book1 =
|
54
|
+
book1 = Workbook.open('workbook.xls')
|
55
55
|
|
56
56
|
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.
|
57
57
|
|
58
|
-
book1 =
|
58
|
+
book1 = Workbook.open('workbook.xls', :default => {:excel => :new})
|
59
59
|
|
60
60
|
The workbook can also be forced to be opened in the current, new or given Excel instance, no matter if and where it was opened before, e.g.
|
61
61
|
|
62
|
-
book2 =
|
62
|
+
book2 = Workbook.open('workbook.xls', :force => {:excel => excel1})
|
63
63
|
|
64
64
|
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 files, 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 Excel files 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.
|
65
65
|
|
66
66
|
For example, suppose you 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 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:
|
67
67
|
|
68
|
-
book =
|
68
|
+
book = Workbook.open('workbook.xls', :if_unsaved => :accept)
|
69
69
|
|
70
70
|
Similarly, if the user has opened a workbook that has the same name but a different path, the conflict is solved via an option.
|
71
71
|
|
72
|
-
book1 =
|
72
|
+
book1 = Workbook.open('path1/workbook.xls')
|
73
73
|
...
|
74
|
-
book2 =
|
74
|
+
book2 = Workbook.open('workbook.xls', :if_obstructed => :forget)
|
75
75
|
|
76
76
|
There are twelve options that control opening workbooks.
|
77
77
|
|
78
78
|
Finally, 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.
|
79
79
|
|
80
|
-
|
80
|
+
Workbook.for_modifying('workbook.xls') do |book|
|
81
81
|
# do something
|
82
82
|
end
|
83
83
|
|
84
|
-
|
84
|
+
Workbook.for_reading('workbook.xls') do |book|
|
85
85
|
# do something
|
86
86
|
end
|
87
87
|
|
88
|
-
=== The
|
88
|
+
=== The Workbook objects and identity transparency
|
89
89
|
|
90
|
-
An Excel file (or workbook) is represented by a
|
91
|
-
Identity transparency means that the same
|
92
|
-
In other words, a
|
90
|
+
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 transparency.
|
91
|
+
Identity transparency means that the same Workbook objects refer to the same Excel files, and vice versa.
|
92
|
+
In other words, a Workbook objects is a proxy of an Excel file.
|
93
93
|
|
94
94
|
Here are some more details about opening, closing, reading, writing and modifying Excel files.
|
95
95
|
|
@@ -97,11 +97,11 @@ Here are some more details about opening, closing, reading, writing and modifyin
|
|
97
97
|
|
98
98
|
Let's have a look at an example. Suppose, we want to open a workbook.
|
99
99
|
|
100
|
-
book =
|
100
|
+
book = Workbook.open('workbook.xls')
|
101
101
|
|
102
102
|
We could do this in a block as well. The semantics is similar to, e.g., +File.open+.
|
103
103
|
|
104
|
-
|
104
|
+
Workbook.open('workbook.xls') do |book|
|
105
105
|
# do something with book
|
106
106
|
end
|
107
107
|
|
@@ -111,15 +111,15 @@ Now let's make the workbook visible.
|
|
111
111
|
|
112
112
|
We can do this in one step as well.
|
113
113
|
|
114
|
-
book =
|
114
|
+
book = Workbook.open('workbook.xls', :visible => true)
|
115
115
|
|
116
116
|
Now we want to open another workbook in a new Excel instance.
|
117
117
|
|
118
|
-
book2 =
|
118
|
+
book2 = Workbook.open('another_workbook.xls', :force => {:excel => :new}, :visible => true)
|
119
119
|
|
120
120
|
Then we open a third workbook in the second Excel instance.
|
121
121
|
|
122
|
-
book3 =
|
122
|
+
book3 = Workbook.open('different_workbook.xls', :force => {:excel => book2.excel})
|
123
123
|
|
124
124
|
We close the second workbook.
|
125
125
|
|
@@ -143,9 +143,9 @@ Now we assign a new value to this range.
|
|
143
143
|
|
144
144
|
book2["new"] = "bar"
|
145
145
|
|
146
|
-
or
|
146
|
+
or, with coloring the cell,
|
147
147
|
|
148
|
-
book2.set_nameval("new", "bar")
|
148
|
+
book2.set_nameval("new", "bar", :color => 4)
|
149
149
|
|
150
150
|
Then we access the first worksheet by
|
151
151
|
|
@@ -183,9 +183,9 @@ We get the value of a range
|
|
183
183
|
|
184
184
|
sheet1.nameval("firstcell") # => "hello"
|
185
185
|
|
186
|
-
and set the value
|
186
|
+
and set the value, while coloring the cell
|
187
187
|
|
188
|
-
sheet1.set_nameval("firstcell", "foo")
|
188
|
+
sheet1.set_nameval("firstcell", "foo", :color => 4)
|
189
189
|
|
190
190
|
We get the value of a range of a locally defined name.
|
191
191
|
|
@@ -221,6 +221,14 @@ Simple saving and closing can be also done in one step by
|
|
221
221
|
|
222
222
|
book2.close(:if_unsaved => :save)
|
223
223
|
|
224
|
+
When you want discolor all cells that have been colored when modifying them, then use
|
225
|
+
|
226
|
+
book2.save(:discoloring => true)
|
227
|
+
|
228
|
+
or
|
229
|
+
|
230
|
+
book2.save_as('example_workbook.xls', :if_exists => :overwrite, :discoloring => true)
|
231
|
+
|
224
232
|
=== Operating on Excel instances.
|
225
233
|
|
226
234
|
Suppose we want to create an Excel object by connecting to the already running Excel instance.
|
@@ -241,7 +249,7 @@ or
|
|
241
249
|
|
242
250
|
We open a workbook in this Excel instance.
|
243
251
|
|
244
|
-
book4 =
|
252
|
+
book4 = Workbook.open('more_data/workbook', {:force => {:excel => excel2}})
|
245
253
|
|
246
254
|
We close the Excel instance by
|
247
255
|
|
@@ -263,9 +271,9 @@ and set the value of this range by using
|
|
263
271
|
|
264
272
|
excel2["firstcell"] = "bar"
|
265
273
|
|
266
|
-
or
|
274
|
+
or, with coloring the cell,
|
267
275
|
|
268
|
-
excel2.set_nameval("firstcell", "bar")
|
276
|
+
excel2.set_nameval("firstcell", "bar", :color => 4)
|
269
277
|
|
270
278
|
We get and set the value of a range with a locally defined named by
|
271
279
|
|
data/README_detail.rdoc
CHANGED
@@ -27,12 +27,12 @@ The tool is optimised with help of rcov.
|
|
27
27
|
|
28
28
|
Example:
|
29
29
|
|
30
|
-
book =
|
30
|
+
book = Workbook.open('workbook.xls')
|
31
31
|
|
32
32
|
You can also open a workbook with a block.
|
33
33
|
The semantics is similar to, e.g., +File.open+.
|
34
34
|
|
35
|
-
|
35
|
+
Workbook.open('workbook.xls') do |book|
|
36
36
|
# do something
|
37
37
|
end
|
38
38
|
|
@@ -92,49 +92,49 @@ Here are a few examples:
|
|
92
92
|
|
93
93
|
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
|
94
94
|
|
95
|
-
|
95
|
+
Workbook.open('workbook.xls', :default => {:excel => :current})
|
96
96
|
|
97
97
|
or
|
98
98
|
|
99
|
-
|
99
|
+
Workbook.open('workbook.xls')
|
100
100
|
|
101
101
|
In case you want to open such a workbook in a new Excel instance, then use
|
102
102
|
|
103
|
-
|
103
|
+
Workbook.open('workbook.xls', :default => {:excel => :new})
|
104
104
|
|
105
105
|
If you want to open a workbook in a new Excel instance, no matter if it was opened before, you can write
|
106
106
|
|
107
|
-
|
107
|
+
Workbook.open('workbook.xls', :force => {:excel => :new})
|
108
108
|
|
109
109
|
You can also specify an Excel instance
|
110
110
|
|
111
111
|
excel1 = Excel.create
|
112
112
|
# something
|
113
|
-
|
113
|
+
Workbook.open('workbook.xls', :force => {:excel => excel1})
|
114
114
|
|
115
115
|
If you want to open the workbook and make its window visible, then use
|
116
116
|
|
117
|
-
book =
|
117
|
+
book = Workbook.open('workbook.xls', :force => {:visible => true})
|
118
118
|
|
119
119
|
or
|
120
120
|
|
121
|
-
book =
|
121
|
+
book = Workbook.open('workbook.xls', :visible => true)
|
122
122
|
|
123
123
|
You can combine options, e.g.
|
124
124
|
|
125
|
-
|
125
|
+
Workbook.open('workbook.xls', :force => {:excel => :new, :visible => true})
|
126
126
|
|
127
127
|
You can use some abbreviations, e.g. in this case
|
128
128
|
|
129
|
-
|
129
|
+
Workbook.open('workbook.xls', :f => {:e => :new, :v => true})
|
130
130
|
|
131
131
|
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
|
132
132
|
|
133
|
-
book =
|
133
|
+
book = Workbook.open('workbook.xls', :if_unsaved => :accept)
|
134
134
|
|
135
135
|
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_obstructed+ handles this situation, e.g.
|
136
136
|
|
137
|
-
book =
|
137
|
+
book = Workbook.open('path/workbook.xls', :if_obstructed => :forget)
|
138
138
|
|
139
139
|
Remarks:
|
140
140
|
|
@@ -163,7 +163,7 @@ The option specifies: If the workbook is unsaved, then
|
|
163
163
|
|
164
164
|
A special feature of robust_excel_ole is that it allows to reopen workbooks after closing them.
|
165
165
|
|
166
|
-
book =
|
166
|
+
book = Workbook.open('workbook.xls')
|
167
167
|
book.close
|
168
168
|
book.reopen
|
169
169
|
|
@@ -171,17 +171,17 @@ The closed workbook is now alive again, i.e. is open and responds to Excel metho
|
|
171
171
|
|
172
172
|
This feature is a result of providing identity transparence and storing the file name.
|
173
173
|
|
174
|
-
=== The
|
174
|
+
=== The Workbook objects and transperence identity
|
175
175
|
|
176
|
-
An Excel file (or workbook) is represented by a
|
177
|
-
Identity transparence means that the same
|
178
|
-
In other words, a
|
176
|
+
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.
|
177
|
+
Identity transparence means that the same Workbook objects refer to the same Excel files, and vice versa.
|
178
|
+
In other words, a Workbook objects is a proxy of an Excel file.
|
179
179
|
|
180
|
-
=== Promoting a workbook to a
|
180
|
+
=== Promoting a workbook to a Workbook object
|
181
181
|
|
182
|
-
A
|
182
|
+
A Workbook object can be created when giving an Excel workbook.
|
183
183
|
|
184
|
-
book =
|
184
|
+
book = Workbook.new(win32ole_workbook)
|
185
185
|
|
186
186
|
|
187
187
|
=== Saving a workbook.
|
@@ -215,27 +215,27 @@ If you want to save a workbook and overwrite the file if it exists before, then
|
|
215
215
|
|
216
216
|
If a workbook blocks the workbook that should be saved, then the former one can be saved and closed before.
|
217
217
|
|
218
|
-
book =
|
219
|
-
book2 =
|
218
|
+
book = Workbook.open('workbook.xls')
|
219
|
+
book2 = Workbook.open('another_workbook.xls')
|
220
220
|
book2.save_as('dir/workbook.xls', :if_exists => :overwrite, :if_obstructed => :save)
|
221
221
|
|
222
222
|
=== Opening, closing and saving a workbook under a certain name
|
223
223
|
|
224
224
|
You can open a workbook with given file name.
|
225
225
|
|
226
|
-
book =
|
226
|
+
book = Workbook.open('workbook.xls')
|
227
227
|
|
228
228
|
You can save a workbook with given file name, if it is open.
|
229
229
|
|
230
|
-
|
230
|
+
Workbook.save('workbook.xls')
|
231
231
|
|
232
232
|
The workbook can be saved under a new file name, if it is open.
|
233
233
|
|
234
|
-
|
234
|
+
Workbook.save_as('workbook.xls', 'new_workbook.xls')
|
235
235
|
|
236
236
|
Finally the workbook can be closed with a given filename.
|
237
237
|
|
238
|
-
|
238
|
+
Workbook.close('workbook.xls')
|
239
239
|
|
240
240
|
=== Unobtrusively modifying a workbook
|
241
241
|
|
@@ -254,7 +254,7 @@ Options are the following:
|
|
254
254
|
otherwise open in a new excel instance
|
255
255
|
+:keep_open+:: let the workbook open after unobtrusively opening (default: false)
|
256
256
|
|
257
|
-
|
257
|
+
Workbook.unobtrusively('workbook.xls') do |book|
|
258
258
|
# some modification
|
259
259
|
sheet = book[0]
|
260
260
|
sheet[1,1] = "c"
|
@@ -262,7 +262,7 @@ Options are the following:
|
|
262
262
|
|
263
263
|
The methods +for_reading+ and +for_modifying+ indicate unobtrusively reading or modifying.
|
264
264
|
|
265
|
-
|
265
|
+
Workbook.for_modifying('workbook.xls') do |book|
|
266
266
|
# some modification
|
267
267
|
sheet = book[0]
|
268
268
|
sheet[1,1] = "c"
|
@@ -272,14 +272,14 @@ The methods +for_reading+ and +for_modifying+ indicate unobtrusively reading or
|
|
272
272
|
|
273
273
|
This method ensures keeping the save status of the workbook
|
274
274
|
|
275
|
-
book =
|
275
|
+
book = Workbook.open('workbook.xls')
|
276
276
|
book.retain_saved do
|
277
277
|
# some reading or modifying
|
278
278
|
end
|
279
279
|
|
280
280
|
=== Checking whether the workbook is alive.
|
281
281
|
|
282
|
-
This method finds out whether the Excel workbook that is referenced by the
|
282
|
+
This method finds out whether the Excel workbook that is referenced by the Workbook object responds to methods.
|
283
283
|
|
284
284
|
if book.alive? then sheet = book[0] end
|
285
285
|
|
@@ -301,7 +301,11 @@ You can set the contents of a range with
|
|
301
301
|
|
302
302
|
or
|
303
303
|
|
304
|
-
book.set_nameval("name"
|
304
|
+
book.set_nameval("name", value)
|
305
|
+
|
306
|
+
You can also specify the color of a changed range:
|
307
|
+
|
308
|
+
book.set_nameval("name", value, :color => 4)
|
305
309
|
|
306
310
|
=== Bringing a workbook to the focus.
|
307
311
|
|
@@ -345,7 +349,7 @@ and
|
|
345
349
|
|
346
350
|
sheet = book.last_sheet
|
347
351
|
|
348
|
-
You can access all sheet objects by using the methods
|
352
|
+
You can access all sheet objects by using the methods Workbook#each.
|
349
353
|
|
350
354
|
book.each do |sheet|
|
351
355
|
# do something with sheet
|
@@ -431,6 +435,10 @@ and set the value of this range by
|
|
431
435
|
|
432
436
|
sheet.set_rangeval(name,value)
|
433
437
|
|
438
|
+
You can also specify the color of a modified range:
|
439
|
+
|
440
|
+
sheet.set_rangeval(name, value, :color => 4)
|
441
|
+
|
434
442
|
=== Adding and copying a worksheet.
|
435
443
|
|
436
444
|
You can add (append) an empty worksheet using
|
@@ -592,7 +600,7 @@ You can set the calculation mode of an Excel instance to manual or automatic.
|
|
592
600
|
You can do it in a block:
|
593
601
|
|
594
602
|
excel = Excel.create
|
595
|
-
book =
|
603
|
+
book = Workbook.open('workbook.xls')
|
596
604
|
excel.with_calculation(:manual) do
|
597
605
|
# do something
|
598
606
|
end
|
@@ -600,7 +608,7 @@ You can do it in a block:
|
|
600
608
|
=== Getting and setting the contents of a named range in an Excel application
|
601
609
|
|
602
610
|
excel = Excel.create
|
603
|
-
book =
|
611
|
+
book = Workbook.open('another_workbook.xls')
|
604
612
|
|
605
613
|
You can get the value of a range by using
|
606
614
|
|
@@ -618,6 +626,10 @@ or
|
|
618
626
|
|
619
627
|
excel.set_nameval(name,value)
|
620
628
|
|
629
|
+
You can also specify the color of a changed range:
|
630
|
+
|
631
|
+
excel.set_nameval(name, value, :color => 4)
|
632
|
+
|
621
633
|
=== Retaining the saved-status of all workbooks
|
622
634
|
|
623
635
|
You can operate in some Excel instance and retain the saved-status of all workbooks.
|
@@ -635,6 +647,10 @@ You can get the value of a range of a locally defined name by
|
|
635
647
|
and set the value of this range with
|
636
648
|
|
637
649
|
excel.set_rangeval(name,value)
|
650
|
+
|
651
|
+
You can also specify the color of a changed range:
|
652
|
+
|
653
|
+
excel.set_rangeval(name, value, :color => 4)
|
638
654
|
|
639
655
|
|
640
656
|
=== Examples
|
@@ -643,7 +659,7 @@ and set the value of this range with
|
|
643
659
|
|
644
660
|
We open a workbook.
|
645
661
|
|
646
|
-
book =
|
662
|
+
book = Workbook.open('workbook.xls')
|
647
663
|
|
648
664
|
Then we access a sheet via its name.
|
649
665
|
|
@@ -669,15 +685,15 @@ Finally we close the workbook.
|
|
669
685
|
|
670
686
|
We open a workbook.
|
671
687
|
|
672
|
-
book =
|
688
|
+
book = Workbook.open('workbook.xls')
|
673
689
|
|
674
690
|
open it also in a new Excel instance and make it visible.
|
675
691
|
|
676
|
-
new_book =
|
692
|
+
new_book = Workbook.open('workbook.xls', :force => {:excel => :new}, :visible => true)
|
677
693
|
|
678
694
|
and open another workbook in a the first Excel instance.
|
679
695
|
|
680
|
-
another_book =
|
696
|
+
another_book = Workbook.open('another_workbook.xls', :force => {:excel => book.excel})
|
681
697
|
|
682
698
|
Then we close the workbooks.
|
683
699
|
|
@@ -696,14 +712,14 @@ The writable workbook is being prefered.
|
|
696
712
|
|
697
713
|
We want to open yet another workbook. Since the workbook was not open before, reopening the workbook fails and the :default-excel option applies. According to :default => {:excel => :new} a new Excel is created, and the workbook is opened there.
|
698
714
|
|
699
|
-
different_book =
|
715
|
+
different_book = Workbook.open('different.xls', :default => {:excel => :new})
|
700
716
|
|
701
717
|
|
702
718
|
=== Example 3
|
703
719
|
|
704
720
|
We open a workbook.
|
705
721
|
|
706
|
-
book =
|
722
|
+
book = Workbook.open('workbook.xls')
|
707
723
|
|
708
724
|
We want to add a copy of the first sheet and insert it after the second sheet.
|
709
725
|
|
@@ -711,7 +727,7 @@ We want to add a copy of the first sheet and insert it after the second sheet.
|
|
711
727
|
|
712
728
|
Then we open a new workbook with the same name in a new Excel, and leave the workbook that contains unsaved changes in the old Excel.
|
713
729
|
|
714
|
-
new_book =
|
730
|
+
new_book = Workbook.open('workbook.xls', :if_unsaved => :new_excel)
|
715
731
|
|
716
732
|
We acccess the first sheet and change the first cell.
|
717
733
|
|
@@ -720,7 +736,7 @@ We acccess the first sheet and change the first cell.
|
|
720
736
|
|
721
737
|
Then we open a workbook with the same name in the running Excel while discarding the workbook that contained unsaved changes.
|
722
738
|
|
723
|
-
third_book =
|
739
|
+
third_book = Workbook.open('workbook.xls', :if_unsaved => :forget)
|
724
740
|
|
725
741
|
Now we add a sheet.
|
726
742
|
|
@@ -738,11 +754,11 @@ We close the first workbook and save it before.
|
|
738
754
|
|
739
755
|
We open a workbook.
|
740
756
|
|
741
|
-
book1 =
|
757
|
+
book1 = Workbook.open('workbook.xls')
|
742
758
|
|
743
759
|
Then we open a workbook with the same name in a different path, while closing the workbook opened before.
|
744
760
|
|
745
|
-
book2 =
|
761
|
+
book2 = Workbook.open('more/workbook.xls', :if_obstructed => :forget)
|
746
762
|
|
747
763
|
We change its first cell.
|
748
764
|
|
@@ -751,12 +767,12 @@ We change its first cell.
|
|
751
767
|
|
752
768
|
Now we open a workbook with the same name again in a different path. while saving and closing the other workbook.
|
753
769
|
|
754
|
-
book3 =
|
770
|
+
book3 = Workbook.open('workbook.xls', :if_obstructed => :save)
|
755
771
|
|
756
772
|
Then we open a workbook with the same name in a different path.
|
757
773
|
The other workbook will be closed, because it does not contain unsaved changes.
|
758
774
|
|
759
|
-
book4 =
|
775
|
+
book4 = Workbook.open('more/workbook.xls', :if_obstructed => :close_if_unsaved)
|
760
776
|
|
761
777
|
|
762
778
|
Finally we close this workbook.
|
@@ -768,7 +784,7 @@ Finally we close this workbook.
|
|
768
784
|
|
769
785
|
We open a workbook
|
770
786
|
|
771
|
-
book =
|
787
|
+
book = Workbook.open('workbook.xls')
|
772
788
|
|
773
789
|
and print its first cell.
|
774
790
|
|
@@ -777,7 +793,7 @@ and print its first cell.
|
|
777
793
|
|
778
794
|
Then we unobtrusively modify the workbook.
|
779
795
|
|
780
|
-
|
796
|
+
Workbook.unobtrusively('workbook.xls') do |book|
|
781
797
|
sheet = book.sheet(1)
|
782
798
|
sheet[1,1] = 'simple'
|
783
799
|
end
|
@@ -794,7 +810,7 @@ RobustExcelOle started as a simple fork from tomiacannondale's wrap_excel adapte
|
|
794
810
|
The functionality of wrap_excel is optimised and extended by a lot of new features.
|
795
811
|
Most notable extensions include:
|
796
812
|
* workbooks can be opened in already running Excel instances (instead of opening a new Excel whenever a book is opened)
|
797
|
-
* a workbook management system stores all workbooks that have been open. This workbook store is being used, e.g., for reopening a workbook that has been closed before. It provides transparency identity, i.e., equal Excel workbooks correspond to equal
|
813
|
+
* a workbook management system stores all workbooks that have been open. This workbook store is being used, e.g., for reopening a workbook that has been closed before. It provides transparency identity, i.e., equal Excel workbooks correspond to equal Workbook objects of RobustExcelOle.
|
798
814
|
|
799
815
|
Some features in RobustExcelOle that are not compatible with wrap_excel:
|
800
816
|
* +open+ uses by default a running Excel instance instead of creating a new one,
|