robust_excel_ole 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bc4f05390e7e89a7d95a262e280e94dff090063
4
- data.tar.gz: db6443cf724e5f58acbe8607ab427fc1734afa08
3
+ metadata.gz: 8c842707a42ecf41966021d1c4b46de412d598a5
4
+ data.tar.gz: 2ac4026904e8fab21e087bdeaae0b123d14d41cc
5
5
  SHA512:
6
- metadata.gz: f789655b7ae560eecf54132d0470e2441b04d902b95c72c3fb165987e02ef7395235e4f0e3723519928a5df86897b6f6f7340adebb0dde9f66e7aeda493588ad
7
- data.tar.gz: 7b4110169af5c687a5be28535b8c0359f95f4c30217df5d8d90f26e5a5c54dc28153bf4b8e0bfa9411961a44cc064118cbc681df68b95061a337b61efd247e27
6
+ metadata.gz: 93acf54dc229f58aa5e1cb5b1ad59f0d28fa77e513af12adc52e1bf5daaeae2920d3206637a196cc7dd78d2b40c5feb2bbfb2599e88d70ac273396dd5545bf9e
7
+ data.tar.gz: 468faa1ad3c10feeb8316fc9de2d827ba1be7444108af0c0f9cd0d7d89ba33538e87e9af5e9ae694a11ca25bef2b2ccafbd475880a753923417a011bc85baaa0
data/.gitignore CHANGED
@@ -8,3 +8,4 @@ vendor/bundle
8
8
  doc/*
9
9
  *.sublime-workspace
10
10
  .yardoc
11
+ TodoList.md
data/Changelog CHANGED
@@ -1,7 +1,15 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [1.1.3] - 2018-10-6
4
+ ## [1.1.4] - 2018-10-6
5
+
6
+ ### Added
7
+ - Excel#for_this_instance
8
+ - Excel#for_all_workbooks
9
+ - Book#for_this_workbooks
10
+ - Book#reopen : wirth options
11
+
12
+ ## [1.1.3] - 2018-13-5
5
13
 
6
14
  ## [1.1.2] - 2018-10-5
7
15
 
data/README.rdoc CHANGED
@@ -4,7 +4,7 @@ This ruby gem automates reading, modifying, and writing Excel files. It is desig
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 supports Excel 2010.
7
+ It can be used for any recent Excel Office version, and is tested for Excel 2010.
8
8
 
9
9
  RobustExcelOle works by sending VBA methods via Win32OLE.
10
10
  It implements a management system and keeps track of Excel files and Excel instances.
@@ -19,287 +19,240 @@ It implements a management system and keeps track of Excel files and Excel insta
19
19
 
20
20
  == Usage
21
21
 
22
+ RobustExcelOle can be used either for scripts
23
+
22
24
  require 'robust_excel_ole'
23
25
  include RobustExcelOle
24
26
 
25
- or call the console
26
-
27
- reo.bat
28
-
29
- == Description
30
-
31
- In the following, some features of RobustExcelOle are depicted.
32
-
33
- RobustExcelOle enables opening and processing Excel files (or 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.
34
-
35
- For example, suppose you want to open a workbook and make it visible.
36
-
37
- book1 = Workbook.open('workbook.xls', :visible => true)
38
-
39
- Now we want to open another workbook in a different Excel instance.
40
-
41
- book2 = Workbook.open('workbook2.xls', :force => {:excel => :new}, :visible => true)
42
-
43
- We can also create a third Excel instance and open another workbook in this instance.
44
-
45
- excel1 = Excel.create
46
- book3 = Workbook.open('workbook3.xls', :force => {:excel => excel1}, :visible => true)
47
-
48
- Another feature that RobustExcelOle povides is reopening workbooks after closing them.
49
-
50
- book1.close
51
- book1.reopen
52
-
53
- A workbook is opened by default in the Excel instance where it was open before most recently.
54
-
55
- book1.close
56
- book1 = Workbook.open('workbook.xls')
57
-
58
- 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.
27
+ or as a console
59
28
 
60
- book1 = Workbook.open('workbook.xls', :default => {:excel => :new})
29
+ reo
61
30
 
62
- 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.
31
+ The call of the console will include RobustExcelOle for you.
63
32
 
64
- book2 = Workbook.open('workbook.xls', :force => {:excel => excel1})
33
+ The following examples can be used for both scripts and console. You can try them directly.
65
34
 
66
- 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.
67
-
68
- 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:
69
-
70
- book = Workbook.open('workbook.xls', :if_unsaved => :accept)
35
+ == Description
71
36
 
72
- Similarly, if the user has opened a workbook that has the same name but a different path, the conflict is solved via an option.
37
+ RobustExcelOle enables opening and processing Excel files (or workbooks). In the following example, we want to open a workbook, modify a cell, save and close the workbook.
73
38
 
74
- book1 = Workbook.open('path1/workbook.xls')
75
- ...
76
- book2 = Workbook.open('workbook.xls', :if_obstructed => :forget)
39
+ First we open a workbook.
77
40
 
78
- There are twelve options that control opening workbooks.
41
+ workbook = Workbook.open 'spec/data/workbook.xls'
79
42
 
80
- 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.
43
+ We can also open the workbook using a block, similar to, e.g., +File.open+.
81
44
 
82
- Workbook.for_modifying('workbook.xls') do |book|
83
- # do something
84
- end
85
-
86
- Workbook.for_reading('workbook.xls') do |book|
45
+ Workbook.open('spec/data/workbook.xls') do |workbook|
87
46
  # do something
88
47
  end
89
48
 
90
- === The Workbook objects and identity transparency
49
+ Now we have a Workbook object that wraps a win32ole object. That is, you can send any win32ole (VBA) method to it. For some common tasks and for considering various cases of Excel and user behaviour, more convenient methods are implemented.
91
50
 
92
- 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.
93
- Identity transparency means that the same Workbook objects refer to the same Excel files, and vice versa.
94
- In other words, a Workbook objects is a proxy of an Excel file.
51
+ For example, we can make the workbook visible, using
95
52
 
96
- Here are some more details about opening, closing, reading, writing and modifying Excel files.
53
+ workbook.visible = true
97
54
 
98
- === Opening and closing workbooks
99
-
100
- Let's have a look at an example. Suppose, we want to open a workbook.
101
-
102
- book = Workbook.open('workbook.xls')
103
-
104
- We could do this in a block as well. The semantics is similar to, e.g., +File.open+.
105
-
106
- Workbook.open('workbook.xls') do |book|
107
- # do something with book
108
- end
55
+ or
109
56
 
110
- Now let's make the workbook visible.
57
+ workbook.for_this_workbook(:visible => true)
111
58
 
112
- book.visible = true
59
+ You can also open a workbook and make it visible in one step.
113
60
 
114
- We can do this in one step as well.
61
+ workbook = Workbook.open('spec/data/workbook.xls', :visible => true)
115
62
 
116
- book = Workbook.open('workbook.xls', :visible => true)
63
+ or
117
64
 
118
- Now we want to open another workbook in a new Excel instance.
65
+ workbook = Workbook.open('spec/data/workbook.xls', :v => true)
119
66
 
120
- book2 = Workbook.open('another_workbook.xls', :force => {:excel => :new}, :visible => true)
67
+ Then we read the value of a cell.
121
68
 
122
- Then we open a third workbook in the second Excel instance.
69
+ value = workbook['firstcell']
70
+ # => "foo"
123
71
 
124
- book3 = Workbook.open('different_workbook.xls', :force => {:excel => book2.excel})
72
+ Now we write a new value in this cell.
125
73
 
126
- We close the second workbook.
74
+ workbook['firstcell'] = "new"
127
75
 
128
- book2.close
76
+ For more details about reading and writing contents of cells and ranges see {README_ranges}[https://github.com/Thomas008/robust_excel_ole/blob/master/README_ranges.rdoc]
129
77
 
130
- Reopening this workbook is done by
78
+ Then we save the workbook.
131
79
 
132
- book2.reopen
80
+ workbook.save
133
81
 
134
- === Reading and modifying workbooks
82
+ We can also save the workbook under a different name.
135
83
 
136
- We can get the value of a named range.
84
+ workbook.save_as('spec/data/new_workbook.xls')
137
85
 
138
- book2["new"] # => foo
86
+ Finally we close the workbook.
139
87
 
140
- or
88
+ workbook.close
141
89
 
142
- book2.nameval("new") # => "foo"
90
+ We could also have saved and closed the workbook in one step.
143
91
 
144
- Now we assign a new value to this range.
92
+ workbook.close(:if_unsaved => :save)
145
93
 
146
- book2["new"] = "bar"
94
+ For more details about saving and closing workbooks see
95
+ {README_save_close}[https://github.com/Thomas008/robust_excel_ole/blob/master/README_save_close.rdoc]
147
96
 
148
- or, with coloring the cell,
97
+ One special feature of RobustExcelOle is that it enables reopening workbooks.
149
98
 
150
- book2.set_nameval("new", "bar", :color => 4)
99
+ workbook.reopen
151
100
 
152
- Then we access the first worksheet by
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.
153
102
 
154
- sheet1 = book2.sheet(1)
103
+ === Using Excel instances
155
104
 
156
- or
105
+ You can start a new Excel instance with
157
106
 
158
- sheet1 = book2.sheet('Sheet1')
107
+ excel1 = Excel.create
159
108
 
160
109
  or
161
-
162
- sheet1 = book2.first_sheet
163
110
 
164
- We can read the first three cells of the first row
111
+ excel1 = Excel.new(:reuse => false)
165
112
 
166
- sheet1.row_range(1, 1..3).values # => ["foo","workbook","sheet1"]
113
+ You can also have an Excel object by connecting to the already running Excel instance.
167
114
 
168
- and the third column
115
+ excel2 = Excel.current
169
116
 
170
- sheet1.col_range(3).values # => ["sheet1", 2.0, 4.0]
117
+ or
171
118
 
172
- Then we read first cell
119
+ excel2 = Excel.new(:reuse => true)
173
120
 
174
- sheet1[1,1].value # => "foo"
121
+ We close the Excel instance using
175
122
 
176
- or
123
+ excel1.close
177
124
 
178
- sheet1.row_range(1)[0].value # => "foo"
125
+ Closed Excel instances can be reopened.
179
126
 
180
- Then we modify it
127
+ excel1.recreate(:reopen_workbooks => true, :visible => true)
181
128
 
182
- sheet1[1,1] = "hello"
129
+ Closing all Excel instances is done by
183
130
 
184
- We get the value of a range
131
+ Excel.close_all(:if_unsaved => :forget)
185
132
 
186
- sheet1.nameval("firstcell") # => "hello"
133
+ For hard terminating all Excel processes you can use
187
134
 
188
- and set the value, while coloring the cell
135
+ Excel.kill_all
189
136
 
190
- sheet1.set_nameval("firstcell", "foo", :color => 4)
137
+ For more details about creating Excel instances see README_excel[https://github.com/Thomas008/robust_excel_ole/blob/master/README_excel_rdoc]
191
138
 
192
- We get the value of a range of a locally defined name.
139
+ === Opening workbooks in several Excel instances
193
140
 
194
- sheet1.rangeval("firstcell") # => "foo"
141
+ 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.
195
142
 
196
- or
143
+ For example, suppose you want to open a workbook.
197
144
 
198
- sheet1.rangeval("A1") # => "foo"
145
+ workbook1 = Workbook.open('spec/data/workbook.xls')
199
146
 
200
- Then we set the value of this range.
147
+ Now we want to open another workbook in a different Excel instance.
201
148
 
202
- sheet1.set_rangeval("firstcell", "bar")
149
+ workbook2 = Workbook.open('spec/data/different_workbook.xls', :excel => :new)
203
150
 
204
- We can copy the first worksheet, name it and add it before the third worksheet.
151
+ We can also create a third Excel instance and open another workbook in this instance.
205
152
 
206
- book2.add_or_copy_sheet(sheet1, :as => "copied_name, :before => book2.last_sheet)
153
+ excel1 = Excel.create
154
+ book3 = Workbook.open('spec/data/another_workbook.xls', :excel => excel1)
207
155
 
208
- === Saving (writing) workbooks
156
+ A workbook is opened by default in the Excel instance where it was open before most recently.
209
157
 
210
- Simple save is done by
158
+ book1.close
159
+ book1 = Workbook.open('spec/data/workbook.xls')
211
160
 
212
- book2.save
161
+ 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.
213
162
 
214
- We could save the workbook under a different name, and overwrite, if a file with the same name exists.
163
+ workbook1 = Workbook.open('spec/data/workbook.xls', :default => {:excel => :new})
215
164
 
216
- book2.save_as('example_workbook.xls', :if_exists => :overwrite)
165
+ Without the option +:default+, the workbook is forced to be opened in the current, new or given Excel instance, no matter if and where it was opened before, e.g.
217
166
 
218
- Then we close this workbook.
167
+ workbook2 = Workbook.open('spec/data/workbook.xls', :excel => excel1)
219
168
 
220
- book2.close
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 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.
221
170
 
222
- Simple saving and closing can be also done in one step by
171
+ 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, e.g.
223
172
 
224
- book2.close(:if_unsaved => :save)
173
+ workbook = Workbook.open('workbook.xls', :if_unsaved => :accept)
225
174
 
226
- When you want discolor all cells that have been colored when modifying them, then use
227
-
228
- book2.save(:discoloring => true)
175
+ Similarly, if the user has opened a workbook that has the same name but a different path, the conflict is solved via an option.
229
176
 
230
- or
177
+ workbook1 = Workbook.open('spec/data/workbook.xls')
178
+ # do something
179
+ workbook2 = Workbook.open('spec/data/more/workbook.xls', :if_obstructed => :forget)
231
180
 
232
- book2.save_as('example_workbook.xls', :if_exists => :overwrite, :discoloring => true)
181
+ 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.
233
182
 
234
- === Operating on Excel instances.
183
+ Workbook.for_modifying('workbook.xls') do |book|
184
+ # do something
185
+ end
235
186
 
236
- Suppose we want to create an Excel object by connecting to the already running Excel instance.
187
+ Workbook.for_reading('workbook.xls') do |book|
188
+ # do something
189
+ end
237
190
 
238
- excel1 = Excel.current
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]
239
192
 
240
- or
193
+ === Processing worksheets
241
194
 
242
- excel1 = Excel.new(:reuse => true)
195
+ Assime you have opened a workbook
196
+
197
+ workbook = Workbook.open('spec/data/workbook.xls')
243
198
 
244
- Now we want to start a new, visible Excel instance.
199
+ You access the first worksheet by
245
200
 
246
- excel2 = Excel.create(:visible => true)
201
+ sheet = workbook.sheet(1)
247
202
 
248
203
  or
249
204
 
250
- excel2 = Excel.new(:reuse => false, :visible => true)
205
+ sheet = workbook.sheet('Sheet1')
251
206
 
252
- We open a workbook in this Excel instance.
207
+ or
208
+
209
+ sheet = workbook.first_sheet
253
210
 
254
- book4 = Workbook.open('more_data/workbook', {:force => {:excel => excel2}})
211
+ You can read and change the worksheet name.
255
212
 
256
- We close the Excel instance by
213
+ sheet.name
214
+ # => "Sheet1"
257
215
 
258
- excel1.close
216
+ sheet.name = "new_sheet"
259
217
 
260
- Closed Excel instances can be reopened.
218
+ You can read the first three cells of the first row
261
219
 
262
- excel1.recreate(:reopen_workbooks => true, :visible => true)
220
+ sheet.row_range(1, 1..3).values # => ["foo","workbook","sheet1"]
263
221
 
264
- We can get the value of a range in an Excel instance by
222
+ and the third column
265
223
 
266
- excel2["firstcell"] => "foo"
267
-
268
- or
224
+ sheet.col_range(3).values # => ["sheet1", 2.0, 4.0]
269
225
 
270
- excel2.nameval("firstcell") = "foo"
226
+ You can read the first cell, using
271
227
 
272
- and set the value of this range by using
228
+ sheet[1,1].value # => "foo"
273
229
 
274
- excel2["firstcell"] = "bar"
230
+ or
275
231
 
276
- or, with coloring the cell,
232
+ sheet.row_range(1)[0].value # => "foo"
277
233
 
278
- excel2.set_nameval("firstcell", "bar", :color => 4)
234
+ Then we modify it
279
235
 
280
- We get and set the value of a range with a locally defined named by
236
+ sheet[1,1] = "hello"
281
237
 
282
- excel2.rangeval("firstcell")
238
+ You can get the value of a named range
283
239
 
284
- and set its value by
240
+ sheet["firstcell"] # => "hello"
285
241
 
286
- excel2.set_rangeval("firstcell, "bar")
242
+ and set another value to that range.
287
243
 
288
- Closing all Excel instances is done by
244
+ sheet["firstcell"] = "new_value"
289
245
 
290
- Excel.close_all(:if_unsaved => :forget)
246
+ You can copy the first worksheet, name it and add it before the third worksheet.
291
247
 
292
- Hard terminating all Excel processes is done by
248
+ workbook.add_or_copy_sheet(sheet, :as => "copied_name, :before => workbook.last_sheet)
293
249
 
294
- Excel.kill_all
250
+ For more details about processing worksheets see {README_sheet}[https://github.com/Thomas008/robust_excel_ole/blob/master/README_sheet.rdoc]
295
251
 
296
252
  === Development
297
253
 
298
- The tests of RobustExcelOle are optimised with help of the rcov tool.
299
-
300
- === More details
301
-
302
- {README_detail.rdoc}[https://github.com/Thomas008/robust_excel_ole/blob/master/README_detail.rdoc]
254
+ For some details about developing RobustExcelOle see
255
+ {README_development}[https://github.com/Thomas008/robust_excel_ole/blob/master/README_development.rdoc]
303
256
 
304
257
  === Want to do more things
305
258