robust_excel_ole 1.2 → 1.3

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: 11b718a2903204d3521cdfad3ef539537841dd06
4
- data.tar.gz: 07a2911b36560a7f505c17914ed441c3ee2add3c
3
+ metadata.gz: ffc7730bef4461a766a8be04f470304e77c9a518
4
+ data.tar.gz: 74fbedab450da21841ac9d3d7663d8199792a80c
5
5
  SHA512:
6
- metadata.gz: 7086927359fd13e8f573ab33eb7aa81ba8d7f19ffcdf1b42d2a61fdfa02414bcfbeabc6846114a0eebddf30b8f28f5d14682f756222122b404bf237bc784a217
7
- data.tar.gz: eb1e7673ba0fbb4402e8fd81669a2f9d80b75f7305044aa8093ca15260d3573178c6e30c79e671e9ed6997b6e1b79bbf30301b86ca78e60124faed430b82c4c2
6
+ metadata.gz: adb1b208ae94315fc104b310d36c983c7f6e17f5be2d6bc64a42148d3d5cf1bf645f0682806ca930cb4fe48225ff472f358acf6001ed35187bc07322be02b3c4
7
+ data.tar.gz: 022d0ecaf1fb85517989c217bed5128c9e9bbe462373923aaaa9e5dbaacc3397398eb1bbe1bf2b780a9ee0f401821216e7d69068547ef0779ac61fc93c390797
data/Changelog CHANGED
@@ -1,6 +1,26 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.3.1]
5
+
6
+ ### Added
7
+ - Book#open: option :excel => :reserved_new
8
+
9
+ ## [1.2.2]
10
+
11
+ ### Added
12
+ - ReoCommon#add_name, rename_range, delete_name
13
+ - Sheet#range
14
+ - Range#copy
15
+
16
+ ### Changed:
17
+ - ReoCommon#namevalue, namevalue_glob, set_namevalue, set_namevalue_glob replace
18
+ set_namevalue replaces set_rangeval, set_namevalue_glob, respectively
19
+
20
+ ## [1.2.1] 2018-9-2
21
+
22
+ ## [1.2] - 2018-11-8
23
+
4
24
  ## [1.1.6] - 2018-20-7
5
25
 
6
26
  ### Added
data/README.rdoc CHANGED
@@ -44,7 +44,10 @@ Let's open a workbook.
44
44
 
45
45
  workbook = Workbook.open 'spec/data/workbook.xls'
46
46
 
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.
47
+ Now we have a Workbook object that wraps a win32ole object. That is, you can send any win32ole (VBA) method to it. See
48
+ https://docs.microsoft.com/en-us/office/vba/api/excel.workbook#methods.
49
+
50
+ For example, you can determine the name and the saved-status of the workbook.
48
51
 
49
52
  workbook.Name
50
53
  # => "workbook.xls"
@@ -248,6 +251,10 @@ For more details about processing worksheets see {README_sheet}[https://github.c
248
251
 
249
252
  === Reading and writing ranges in worksheets
250
253
 
254
+ We can define a rectangular range by providing the top left and the bottum down cell.
255
+
256
+ sheet.range(1..3,1..4)
257
+
251
258
  We can read the first three cells of the first row
252
259
 
253
260
  sheet.row_range(1, 1..3).values # => ["foo","workbook","sheet1"]
@@ -6,7 +6,7 @@ RobustExcelOle enables simultanously running Excel instances. An Excel applicati
6
6
 
7
7
  === Creating and reusing an Excel instance.
8
8
 
9
- You can start a new Excel instance by
9
+ You can create a new Excel instance by
10
10
 
11
11
  excel1 = Excel.create
12
12
 
@@ -30,6 +30,10 @@ You can also promote an Excel instance represented as WIN32OLE object to an Exce
30
30
 
31
31
  excel = Excel.new(win32ole_object, :visible => true)
32
32
 
33
+ Once you have got an Excel object, you can apply all VBA methods that you would apply to a VBA Application object
34
+ (see https://docs.microsoft.com/en-us/office/vba/api/excel.application(object)#methods).
35
+ For some common and complex tasks you can use the methods of RobustExcelOle.
36
+
33
37
  === Setting options
34
38
 
35
39
  You can set all options in a given Excel instance
@@ -86,13 +90,11 @@ You can set the calculation mode of an Excel instance to manual or automatic.
86
90
  You can do it in a block:
87
91
 
88
92
  excel = Excel.create
89
- book = Workbook.open('workbook.xls')
93
+ book = Workbook.open('spec/data/workbook.xls')
90
94
  excel.with_calculation(:manual) do
91
95
  # do something
92
96
  end
93
97
 
94
-
95
-
96
98
  === Setting options for all workbooks
97
99
 
98
100
  You can set options for all workbooks of an Excel instance.
@@ -4,12 +4,16 @@
4
4
 
5
5
  If you want to open a workbook, use
6
6
 
7
- book = Workbook.open('workbook.xls')
7
+ book = Workbook.open('spec/data/workbook.xls')
8
+
9
+ Once you have got an Book object, you can apply all VBA methods that you would apply to a VBA Workbook object
10
+ (see https://docs.microsoft.com/en-us/office/vba/api/excel.workbook#methods).
11
+ For some common and complex tasks you can use the methods of RobustExcelOle.
8
12
 
9
13
  You can also open a workbook with a block.
10
14
  The semantics is similar to, e.g., +File.open+.
11
15
 
12
- Workbook.open('workbook.xls') do |book|
16
+ Workbook.open('spec/data/workbook.xls') do |book|
13
17
  # do something
14
18
  end
15
19
 
@@ -41,7 +45,7 @@ You can use the following abbreviations: +:f+ for +:force+, +:d+ for +:default+
41
45
 
42
46
  The option +:excel+ :
43
47
 
44
- Valid values are : +:current+ (or +:active+ or +:reuse+), +:new+, or a given Excel instance (default: +:current).
48
+ Valid values are : +:current+ (or +:active+ or +:reuse+), +:new+, +:reserved_new+, or a given Excel instance (default: +:current).
45
49
 
46
50
  The option +:if_unsaved+ :
47
51
 
@@ -74,45 +78,49 @@ Here are a few examples:
74
78
 
75
79
  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
76
80
 
77
- Workbook.open('workbook.xls', :default => {:excel => :current})
81
+ book = Workbook.open('spec/data/workbook.xls', :default => {:excel => :current})
78
82
 
79
83
  or
80
84
 
81
- Workbook.open('workbook.xls')
85
+ book = Workbook.open('spec/data/workbook.xls')
82
86
 
83
87
  In case you want to open such a workbook in a new Excel instance, then use
84
88
 
85
- Workbook.open('workbook.xls', :default => {:excel => :new})
89
+ book = Workbook.open('spec/data/workbook.xls', :default => {:excel => :new})
90
+
91
+ You can also open the workbook in a separate, reserved Excel instance.
92
+
93
+ book = Workbook.open('spec/data/workbook.xls', :default => {:excel => :reserved_new})
86
94
 
87
95
  If you want to open a workbook in a new Excel instance, no matter if it was opened before, you can write
88
96
 
89
- Workbook.open('workbook.xls', :force => {:excel => :new})
97
+ book = Workbook.open('spec/data/workbook.xls', :force => {:excel => :new})
90
98
 
91
99
  For simplicity, you can also leave out the +:force+ option (but not the +:default+ option).
92
100
 
93
- Workbook.open('workbook.xls', :excel => :new)
101
+ book = Workbook.open('spec/data/workbook.xls', :excel => :new)
94
102
 
95
103
  You can also specify an Excel instance
96
104
 
97
105
  excel1 = Excel.create
98
- Workbook.open('workbook.xls', :excel => excel1)
106
+ book = Workbook.open('spec/data/workbook.xls', :excel => excel1)
99
107
 
100
108
  If you want to open the workbook and make its window visible, then use
101
109
 
102
- book = Workbook.open('workbook.xls', :visible => true)
110
+ book = Workbook.open('spec/data/workbook.xls', :visible => true)
103
111
 
104
112
  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.
105
113
  You can combine options, e.g.
106
114
 
107
- Workbook.open('workbook.xls', :excel => :new, :visible => true, :default => {:excel => excel1})
115
+ book = Workbook.open('spec/data/workbook.xls', :excel => :new, :visible => true, :default => {:excel => excel1})
108
116
 
109
117
  You can use the abbreviations, e.g. in this case
110
118
 
111
- Workbook.open('workbook.xls', :e => :new, :v => true, :d => {:e => excel1})
119
+ book = Workbook.open('spec/data/workbook.xls', :e => :new, :v => true, :d => {:e => excel1})
112
120
 
113
121
  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
114
122
 
115
- book = Workbook.open('workbook.xls', :if_unsaved => :accept)
123
+ book = Workbook.open('spec/data/workbook.xls', :if_unsaved => :accept)
116
124
 
117
125
  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.
118
126
 
@@ -128,7 +136,7 @@ Doing updating links seems to be dependent on calculation mode: updates happen,
128
136
 
129
137
  A special feature of RobustExcelOle is that it allows to reopen workbooks after closing them.
130
138
 
131
- book = Workbook.open('workbook.xls')
139
+ book = Workbook.open('spec/data/workbook.xls')
132
140
  book.close
133
141
  book.reopen
134
142
 
@@ -160,7 +168,7 @@ Options are the following:
160
168
  +:keep_open+:: Whether the workbook shall be open after unobtrusively opening (default: false)
161
169
 
162
170
 
163
- Workbook.unobtrusively('workbook.xls') do |book|
171
+ Workbook.unobtrusively('spec/data/workbook.xls') do |book|
164
172
  # some modification
165
173
  sheet = book[0]
166
174
  sheet[1,1] = "c"
@@ -168,7 +176,7 @@ Options are the following:
168
176
 
169
177
  The methods +for_reading+ and +for_modifying+ indicate unobtrusively reading or modifying.
170
178
 
171
- Workbook.for_modifying('workbook.xls') do |book|
179
+ Workbook.for_modifying('spec/data/workbook.xls') do |book|
172
180
  # some modification
173
181
  sheet = book[0]
174
182
  sheet[1,1] = "c"
@@ -180,7 +188,7 @@ Remark: The methods +unobtrusively+, +for_reading+ and +for_modifying+ work only
180
188
 
181
189
  This method ensures keeping the save status of the workbook
182
190
 
183
- book = Workbook.open('workbook.xls')
191
+ book = Workbook.open('spec/data/workbook.xls')
184
192
  book.retain_saved do
185
193
  # some reading or modifying
186
194
  end
@@ -2,27 +2,193 @@
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 workbooks. This can be done from a Sheet, a Book or an Excel object representing a Worksheet, Workbook, or Application object, respectively, in VBA.
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, respectively. You can use VBA methods or methods provided by RobustExcelOle.
6
+
7
+ === Introducing Example
8
+
9
+ Suppose you have opened a workbook.
10
+
11
+ book = Workbook.open('spec/data/workbook.xls', :visible => true)
12
+
13
+ We can access a range consisting of one cell by providing the row and and the column of a cell. With help of VBA methods you can put
14
+
15
+ sheet.Range(sheet.Cells(1,1))
16
+
17
+ or using RobustExcelOle
18
+
19
+ range = sheet.range(1,1)
20
+
21
+ Similarly you can access a rectangular range. Using VBA methods we provide the row and column of the top left cell and the row and column of the bottum right cell.
22
+
23
+ range = sheet.Range(sheet.Cells(1,1), sheet.Cells(3,4))
24
+
25
+ In RobustExcelOle we would supply the rows and columns as integer ranges.
26
+
27
+ range = sheet.range(1..3,1..4)
28
+
29
+ You can read the values by
30
+
31
+ range.values
32
+
33
+ Now we copy and paste a range. With help of VBA methods you would do
34
+
35
+ range.Copy(:destination => sheet.range(6,2).ole_range)
36
+
37
+ or with help of RobustExcelOle
38
+
39
+ range.copy(6,2)
40
+
41
+ You can also copy a range into another worksheet in another workbook.
42
+
43
+ book2 = Workbook.open('spec/data/another_workbook.xls', :excel => :new, :visible => true)
44
+ range.copy(5,8,book2.sheet(3))
45
+
46
+ Now we define a name that refers to a range consisting of only the first cell, i.e. the 1st row and 1st column. Using VBA methods, you can use
47
+
48
+ book.Names.Add("Name" => "name", "RefersToR1C1" => "=Z1S1")
49
+
50
+ RobustExcelOle provides the method +add_name+.
51
+
52
+ book.add_name("name",1,1)
53
+
54
+ We define a name of a rectangular range. With help of VBA methods this is done by supplying the row and column of the top left cell and the row and columns of the bottum right cell of the range.
55
+
56
+ book.Names.Add("Name" => "name", "RefersToR1C1" => "=Z1S3:Z2S4")
57
+
58
+ Using RobustExcelOle Defining a name referring to a rectangular range is done by providing the rows and columns as integer range.
59
+
60
+ book.add_name("name",1..2,3..4)
61
+
62
+ Now we can assign a value to that named range. With help of VBA methods this can be done by
63
+
64
+ book.Names.Item("name").RefersToRange.Value = "bar"
65
+
66
+ Using RobustExcelOle the assignment can be done by
67
+
68
+ book["name"] = "bar"
69
+
70
+ Similarly, we can read the value of the range, using VBA methods
71
+
72
+ book.Names.Item("name").RefersToRange.Value
73
+ => "bar"
74
+
75
+ or RobustExcelOle
76
+
77
+ book["name"]
78
+ => "bar"
79
+
80
+ Finally we can rename a range, and delete the name of a range. With help of VBA methods this can be achieved by
81
+
82
+ book.Names.Item("name").Name = "new_name"
83
+ book.Names.Item("new_name").Delete
84
+
85
+ Using RobustExcelOle, we write
86
+
87
+ book.rename_range("name", "new_name")
88
+ book.delete_name("name")
89
+
90
+ Suppose you have a worksheet
91
+
92
+ sheet1 = book.sheet(1)
93
+
94
+ Now we can read the value of cell simply by providing the row and the column
95
+
96
+ sheet.Cells.Item(1,1).Value
97
+
98
+ or with RobustExcelOle
99
+
100
+ sheet[1,1].value
101
+ => "foo
102
+
103
+ Similarly, you can write a cell.
104
+
105
+ sheet.Cells.Item(1,1).Value = "new_value"
106
+
107
+ or using RobustExcelOle
108
+
109
+ sheet[1,1] = "new_value"
110
+
111
+ Suppose you want to define a named range consisting of several cells forming a rectangular. Using VBA methods this can be done by
112
+
113
+ book.Names.Add("Name" => "rec_name", "RefersToR1C1" => "=Z1S2:Z3S4")
114
+
115
+ and using RobustExcelOle
116
+
117
+ book.add_name("rec_name",1,2,3,4)
118
+
119
+ We assign values to the cells of that range
120
+
121
+ book.Names.Item("rec_name").RefersToRange.Value =
122
+ [["foo", nil, "bar"], [nil, "foobar", nil], ["is", "nice", nil]]
123
+
124
+ or
125
+
126
+ book["rec_name"] = [["foo", nil, "bar"], [nil, "foobar", nil], ["is", "nice", nil]]
127
+
128
+ Now we can read value of that range.
129
+
130
+ book.Names.Item("rec_name").RefersToRange.Value
131
+ => [["workbook", "sheet1", nil], [nil, "foobaaa", nil], ["is", "nice", nil]]
132
+
133
+ or
134
+
135
+ book["rec_name"]
136
+ => [["workbook", "sheet1", nil], [nil, "foobaaa", nil], ["is", "nice", nil]]
137
+
138
+ In the following some details are being summarized.
139
+
140
+ === Accessing a range
141
+
142
+ You can access a range consisting of one cell by providing the row and and the column of a cell.
143
+
144
+ range = sheet.range(1,1)
145
+
146
+ You can access a rectangular range by providing the row and column of the top left cell and the row and column of the bottum right cell.
147
+
148
+ range = sheet.range(1..3,1..4)
149
+
150
+ You get the values of the range with
151
+
152
+ range.values
153
+
154
+ === Copying a range
155
+
156
+ You can copy and paste a range.
157
+
158
+ range.copy(6,2)
159
+
160
+ You can also copy a range into another worksheet in another workbook, and even another Excel instance. When copying into another Excel instance the destination shall be a cell (a rectangular range destination is not being considered)
161
+
162
+ book2 = Workbook.open('spec/data/another_workbook.xls', :excel => :new, :visible => true)
163
+ range.copy(5,8,book2.sheet(3))
164
+
165
+ === Naming a cell
166
+
167
+ You can (re-) define a name referring to a cell with help of VBA methods by stating its name, and the row and the column of the cell.
168
+
169
+ book.add_name("name",1,1)
170
+
171
+ Most methods can be done for Workbook, Sheet, and Excel objects.
6
172
 
7
173
  === Reading and writing the contents of a named range in a workbook.
8
174
 
9
175
  Assume you have opened a workbook:
10
176
 
11
- book = Workbook.open('workbook.xls', :visible => true)
177
+ book = Workbook.open('spec/data/workbook.xls', :visible => true)
12
178
 
13
- You can get the contents of a range with a defined name with help of the method [] or +nameval+.
179
+ You can get the contents of a range with a defined name with help of the method [] or +namevalue_glob+.
14
180
 
15
181
  book["name"]
16
182
  => "value"
17
183
 
18
184
  or
19
185
 
20
- book.nameval("name")
186
+ book.namevalue_glob("name")
21
187
  => "value"
22
188
 
23
- Using +nameval+, via the option +:default+ you can provide a value that is returned when the name cannot be found or some other error would occur.
189
+ Using +namevalue_glob+, via the option +:default+ you can provide a value that is returned when the name cannot be found or some other error would occur.
24
190
 
25
- book.namval("name", :default => "default_value")
191
+ book.namvalue_glob("name", :default => "default_value")
26
192
 
27
193
  You can set the contents of a range with
28
194
 
@@ -30,11 +196,11 @@ You can set the contents of a range with
30
196
 
31
197
  or
32
198
 
33
- book.set_nameval("name", "new_value")
199
+ book.set_namevalue_glob("name", "new_value")
34
200
 
35
- The method []= colors the written cell. You can specify the color of a changed range via the method +set_nameval+.
201
+ The method []= colors the written cell. You can specify the color of a changed range via the method +set_namevalue_glob+.
36
202
 
37
- book.set_nameval("name", "new_value", :color => 4)
203
+ book.set_namevalue_glob("name", "new_value", :color => 4)
38
204
 
39
205
  Similarly, the contents of a named range can be read and modified in a worksheet
40
206
 
@@ -60,31 +226,31 @@ When saving, the written cells get discolored when using the option :discoloring
60
226
 
61
227
  or
62
228
 
63
- book.save_as('workbook.xls', :discoloring => true)
229
+ book.save_as('spec/data/workbook.xls', :discoloring => true)
64
230
 
65
231
  === Reading and writing the contents of a range with a locally defined name
66
232
 
67
233
  The contents of locally defined ranges can be read by
68
234
 
69
- sheet.rangeval("name")
235
+ sheet.namevalue("name")
70
236
  => "value"
71
237
 
72
238
  or
73
239
 
74
- excel.rangeval("name")
240
+ excel.namevalue("name")
75
241
  => "value"
76
242
 
77
243
  and be modified by
78
244
 
79
- sheet.set_rangeval("name", "value")
245
+ sheet.set_namevalue("name", "value")
80
246
 
81
247
  or
82
248
 
83
- excel.set_rangeval("name", "value")
249
+ excel.set_namevalue("name", "value")
84
250
 
85
- Similarly to nameval, you can provide a default value that is returned when ocurring an error.
251
+ Similarly to namevalue, you can provide a default value that is returned when ocurring an error.
86
252
 
87
- sheet.rangeval("name", :default => "default_value")
253
+ sheet.namevalue("name", :default => "default_value")
88
254
 
89
255
  === Accessing a cell
90
256
 
@@ -106,7 +272,6 @@ or
106
272
 
107
273
  sheet.set_cellval(1,1,"new_value", :color => 42)
108
274
 
109
-
110
275
  === Accessing rows and columns
111
276
 
112
277
  The methods Sheet#each, Sheet#each_row and Sheet#each_column enable to access each cell, row and column, respectively.
@@ -139,8 +304,3 @@ Within a row or column range you can access a certain cell.
139
304
  row_range[1] # => first cell in row_range
140
305
  column_range[2] # => second cell in column_range
141
306
 
142
- === Naming a cell
143
-
144
- You can (re-) name a cell range.
145
-
146
- sheet.set_name(1,1,"name")