robust_excel_ole 1.3 → 1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +6 -0
- data/README.rdoc +1 -1
- data/docs/README_open.rdoc +1 -1
- data/docs/README_ranges.rdoc +60 -57
- data/docs/README_sheet.rdoc +1 -1
- data/examples/introducing_examples/example_introducing.rb +42 -0
- data/examples/introducing_examples/example_open.rb +49 -0
- data/examples/introducing_examples/example_range.rb +67 -0
- data/examples/{edit_sheets → modifying_sheets}/example_access_sheets_and_cells.rb +0 -0
- data/examples/{edit_sheets → modifying_sheets}/example_adding_sheets.rb +0 -0
- data/examples/{edit_sheets → modifying_sheets}/example_concating.rb +1 -1
- data/examples/{edit_sheets → modifying_sheets}/example_copying.rb +1 -1
- data/examples/{edit_sheets → modifying_sheets}/example_expanding.rb +1 -1
- data/examples/{edit_sheets → modifying_sheets}/example_naming.rb +1 -1
- data/examples/{edit_sheets → modifying_sheets}/example_ranges.rb +1 -1
- data/examples/{edit_sheets → modifying_sheets}/example_saving.rb +1 -1
- data/examples/open_save_close/example_control_to_excel.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 +1 -1
- data/examples/open_save_close/example_if_unsaved_forget.rb +3 -3
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +4 -4
- 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_simple.rb +1 -1
- data/examples/open_save_close/example_unobtrusively.rb +3 -3
- data/lib/robust_excel_ole.rb +2 -2
- data/lib/robust_excel_ole/bookstore.rb +1 -1
- data/lib/robust_excel_ole/cell.rb +15 -2
- data/lib/robust_excel_ole/excel.rb +14 -12
- data/lib/robust_excel_ole/general.rb +12 -0
- data/lib/robust_excel_ole/range.rb +37 -20
- data/lib/robust_excel_ole/reo_common.rb +63 -37
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/{book.rb → workbook.rb} +35 -33
- data/lib/robust_excel_ole/{sheet.rb → worksheet.rb} +22 -22
- data/spec/bookstore_spec.rb +38 -38
- data/spec/cell_spec.rb +10 -10
- data/spec/data/another_workbook.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +113 -105
- data/spec/general_spec.rb +37 -5
- data/spec/range_spec.rb +34 -19
- data/spec/reo_common_spec.rb +58 -48
- data/spec/{book_spec.rb → workbook_spec.rb} +198 -198
- data/spec/workbook_specs/workbook_all_spec.rb +33 -0
- data/spec/{book_specs/book_close_spec.rb → workbook_specs/workbook_close_spec.rb} +10 -10
- data/spec/{book_specs/book_misc_spec.rb → workbook_specs/workbook_misc_spec.rb} +148 -128
- data/spec/{book_specs/book_open_spec.rb → workbook_specs/workbook_open_spec.rb} +427 -427
- data/spec/{book_specs/book_save_spec.rb → workbook_specs/workbook_save_spec.rb} +44 -44
- data/spec/{book_specs/book_sheet_spec.rb → workbook_specs/workbook_sheet_spec.rb} +19 -19
- data/spec/{book_specs/book_subclass_spec.rb → workbook_specs/workbook_subclass_spec.rb} +5 -6
- data/spec/{book_specs/book_unobtr_spec.rb → workbook_specs/workbook_unobtr_spec.rb} +339 -344
- data/spec/{sheet_spec.rb → worksheet_spec.rb} +85 -55
- metadata +25 -22
- data/spec/book_specs/book_all_spec.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c82574a7d47691397738dc69d19c58a296e612f
|
4
|
+
data.tar.gz: 572d90add41cf354216f3cf9dcd2ca1260148b01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abd37e3a312f2c723fe9759b6e9f9ed5ce284e40e864c262afba3dbcf57ed5d9d59b17141b49f34d6c299f83eea0c337c33a93f960820dacb70273977272d946
|
7
|
+
data.tar.gz: 81d3dfad4b6720a208f7f236fa44ad18d32483df6dfb8550dda4756d5c492b5e86eb14415635b610375429009b2356a6f9a99a19b13c2f0f30026e4694ac599e
|
data/Changelog
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [1.4]
|
5
|
+
|
6
|
+
### Changed
|
7
|
+
- renamed Book to Workbook, Sheet to Worksheet
|
8
|
+
|
4
9
|
## [1.3.1]
|
5
10
|
|
6
11
|
### Added
|
7
12
|
- Book#open: option :excel => :reserved_new
|
13
|
+
- ReoCommon#name2range
|
8
14
|
|
9
15
|
## [1.2.2]
|
10
16
|
|
data/README.rdoc
CHANGED
@@ -253,7 +253,7 @@ For more details about processing worksheets see {README_sheet}[https://github.c
|
|
253
253
|
|
254
254
|
We can define a rectangular range by providing the top left and the bottum down cell.
|
255
255
|
|
256
|
-
sheet.range(1..3,1..4)
|
256
|
+
sheet.range([1..3,1..4])
|
257
257
|
|
258
258
|
We can read the first three cells of the first row
|
259
259
|
|
data/docs/README_open.rdoc
CHANGED
@@ -6,7 +6,7 @@ If you want to open a workbook, use
|
|
6
6
|
|
7
7
|
book = Workbook.open('spec/data/workbook.xls')
|
8
8
|
|
9
|
-
Once you have got an
|
9
|
+
Once you have got an Workbook object, you can apply all VBA methods that you would apply to a VBA Workbook object
|
10
10
|
(see https://docs.microsoft.com/en-us/office/vba/api/excel.workbook#methods).
|
11
11
|
For some common and complex tasks you can use the methods of RobustExcelOle.
|
12
12
|
|
data/docs/README_ranges.rdoc
CHANGED
@@ -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 workbooks. This can be done from a
|
5
|
+
RobustExcelOle enables to read and write the contents of ranges and cells in workbooks. This can be done from a Worksheet, a Workbook or an Excel object representing a Worksheet, Workbook, or Application object, respectively. You can use VBA methods or methods provided by RobustExcelOle.
|
6
6
|
|
7
7
|
=== Introducing Example
|
8
8
|
|
@@ -10,13 +10,21 @@ Suppose you have opened a workbook.
|
|
10
10
|
|
11
11
|
book = Workbook.open('spec/data/workbook.xls', :visible => true)
|
12
12
|
|
13
|
-
We
|
13
|
+
We access the first worksheet:
|
14
|
+
|
15
|
+
sheet = book.sheet(1)
|
16
|
+
|
17
|
+
Now 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
18
|
|
15
|
-
sheet.Range(sheet.Cells(1,
|
19
|
+
sheet.Range(sheet.Cells(1,2))
|
16
20
|
|
17
21
|
or using RobustExcelOle
|
18
22
|
|
19
|
-
range = sheet.range(1,
|
23
|
+
range = sheet.range([1,2])
|
24
|
+
|
25
|
+
or, using the A1-format,
|
26
|
+
|
27
|
+
range = sheet.range("B1")
|
20
28
|
|
21
29
|
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
30
|
|
@@ -24,24 +32,36 @@ Similarly you can access a rectangular range. Using VBA methods we provide the r
|
|
24
32
|
|
25
33
|
In RobustExcelOle we would supply the rows and columns as integer ranges.
|
26
34
|
|
27
|
-
range = sheet.range(1..3,1..4)
|
35
|
+
range = sheet.range([1..3,1..4])
|
36
|
+
|
37
|
+
or, using the A1-format
|
38
|
+
|
39
|
+
range = sheet.range([1..3,"A".."D"])
|
40
|
+
|
41
|
+
or
|
42
|
+
|
43
|
+
range = sheet.range(["A1:D3"])
|
28
44
|
|
29
45
|
You can read the values by
|
30
46
|
|
47
|
+
range.Value
|
48
|
+
|
49
|
+
or as flat array
|
50
|
+
|
31
51
|
range.values
|
32
52
|
|
33
53
|
Now we copy and paste a range. With help of VBA methods you would do
|
34
54
|
|
35
|
-
range.Copy(:destination => sheet.range(6,2).ole_range)
|
55
|
+
range.Copy(:destination => sheet.range([6,2]).ole_range)
|
36
56
|
|
37
57
|
or with help of RobustExcelOle
|
38
58
|
|
39
|
-
range.copy(6,2)
|
59
|
+
range.copy([6,2])
|
40
60
|
|
41
61
|
You can also copy a range into another worksheet in another workbook.
|
42
62
|
|
43
63
|
book2 = Workbook.open('spec/data/another_workbook.xls', :excel => :new, :visible => true)
|
44
|
-
range.copy(5,8,book2.sheet(3))
|
64
|
+
range.copy([5,8],book2.sheet(3))
|
45
65
|
|
46
66
|
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
67
|
|
@@ -49,7 +69,7 @@ Now we define a name that refers to a range consisting of only the first cell, i
|
|
49
69
|
|
50
70
|
RobustExcelOle provides the method +add_name+.
|
51
71
|
|
52
|
-
book.add_name("name",1,1)
|
72
|
+
book.add_name("name",[1,1])
|
53
73
|
|
54
74
|
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
75
|
|
@@ -57,25 +77,21 @@ We define a name of a rectangular range. With help of VBA methods this is done b
|
|
57
77
|
|
58
78
|
Using RobustExcelOle Defining a name referring to a rectangular range is done by providing the rows and columns as integer range.
|
59
79
|
|
60
|
-
book.add_name("name",1..2,3..4)
|
80
|
+
book.add_name("name",[1..2,3..4])
|
61
81
|
|
62
82
|
Now we can assign a value to that named range. With help of VBA methods this can be done by
|
63
83
|
|
64
|
-
book.Names.Item("name").RefersToRange.Value = "bar"
|
65
|
-
|
66
|
-
Using RobustExcelOle the assignment can be done by
|
84
|
+
book.Names.Item("name").RefersToRange.Value = [["foo", "bar"],[1.0, nil]]
|
67
85
|
|
68
|
-
|
69
|
-
|
70
|
-
Similarly, we can read the value of the range, using VBA methods
|
86
|
+
Now we can read value of that range.
|
71
87
|
|
72
|
-
book.Names.Item("
|
73
|
-
=> "bar"
|
88
|
+
book.Names.Item("rec_name").RefersToRange.Value
|
89
|
+
=> [["foo", "bar"],[1.0, nil]]
|
74
90
|
|
75
|
-
or
|
91
|
+
or
|
76
92
|
|
77
93
|
book["name"]
|
78
|
-
=> "bar"
|
94
|
+
=> [["foo", "bar"],[1.0, nil]]
|
79
95
|
|
80
96
|
Finally we can rename a range, and delete the name of a range. With help of VBA methods this can be achieved by
|
81
97
|
|
@@ -87,17 +103,13 @@ Using RobustExcelOle, we write
|
|
87
103
|
book.rename_range("name", "new_name")
|
88
104
|
book.delete_name("name")
|
89
105
|
|
90
|
-
Suppose you have a worksheet
|
91
|
-
|
92
|
-
sheet1 = book.sheet(1)
|
93
|
-
|
94
106
|
Now we can read the value of cell simply by providing the row and the column
|
95
107
|
|
96
108
|
sheet.Cells.Item(1,1).Value
|
97
109
|
|
98
110
|
or with RobustExcelOle
|
99
111
|
|
100
|
-
sheet[1,1].
|
112
|
+
sheet[1,1].Value
|
101
113
|
=> "foo
|
102
114
|
|
103
115
|
Similarly, you can write a cell.
|
@@ -108,67 +120,58 @@ or using RobustExcelOle
|
|
108
120
|
|
109
121
|
sheet[1,1] = "new_value"
|
110
122
|
|
111
|
-
|
112
|
-
|
113
|
-
book.Names.Add("Name" => "rec_name", "RefersToR1C1" => "=Z1S2:Z3S4")
|
114
|
-
|
115
|
-
and using RobustExcelOle
|
123
|
+
In the following some details are being summarized.
|
116
124
|
|
117
|
-
|
118
|
-
|
119
|
-
We assign values to the cells of that range
|
125
|
+
=== Accessing a range
|
120
126
|
|
121
|
-
|
122
|
-
[["foo", nil, "bar"], [nil, "foobar", nil], ["is", "nice", nil]]
|
127
|
+
You can access a range via its address or defined name. RobustExcelOle allows the R1C1- and the A1-format.
|
123
128
|
|
124
|
-
|
129
|
+
For example, you can access a range consisting of one cell by providing the row and and the column of a cell.
|
125
130
|
|
126
|
-
|
131
|
+
range = sheet.range([1,1])
|
127
132
|
|
128
|
-
|
133
|
+
Using the A1-format you write
|
129
134
|
|
130
|
-
|
131
|
-
=> [["workbook", "sheet1", nil], [nil, "foobaaa", nil], ["is", "nice", nil]]
|
135
|
+
range = sheet.range("A1")
|
132
136
|
|
133
|
-
|
137
|
+
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.
|
134
138
|
|
135
|
-
|
136
|
-
=> [["workbook", "sheet1", nil], [nil, "foobaaa", nil], ["is", "nice", nil]]
|
139
|
+
range = sheet.range([1..3,1..4])
|
137
140
|
|
138
|
-
|
141
|
+
or using the a1-format
|
139
142
|
|
140
|
-
|
143
|
+
range = sheet.range([1..3,"A".."D"])
|
141
144
|
|
142
|
-
|
145
|
+
or
|
143
146
|
|
144
|
-
range = sheet.range(
|
147
|
+
range = sheet.range("A1:D3")
|
145
148
|
|
146
|
-
You
|
149
|
+
You get the values of the range as flat array with help of
|
147
150
|
|
148
|
-
range
|
151
|
+
range.values
|
149
152
|
|
150
|
-
You
|
153
|
+
You can access a range via its defined name with
|
151
154
|
|
152
|
-
range.
|
155
|
+
range = sheet.name2range("name")
|
153
156
|
|
154
157
|
=== Copying a range
|
155
158
|
|
156
159
|
You can copy and paste a range.
|
157
160
|
|
158
|
-
range.copy(6,2)
|
161
|
+
range.copy([6,2])
|
159
162
|
|
160
163
|
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
164
|
|
162
165
|
book2 = Workbook.open('spec/data/another_workbook.xls', :excel => :new, :visible => true)
|
163
|
-
range.copy(5,8,book2.sheet(3))
|
166
|
+
range.copy([5,8],book2.sheet(3))
|
164
167
|
|
165
168
|
=== Naming a cell
|
166
169
|
|
167
170
|
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
171
|
|
169
|
-
book.add_name("name",1,1)
|
172
|
+
book.add_name("name",[1,1])
|
170
173
|
|
171
|
-
Most methods can be done for Workbook,
|
174
|
+
Most methods can be done for Workbook, Worksheet, and Excel objects.
|
172
175
|
|
173
176
|
=== Reading and writing the contents of a named range in a workbook.
|
174
177
|
|
@@ -256,7 +259,7 @@ Similarly to namevalue, you can provide a default value that is returned when oc
|
|
256
259
|
|
257
260
|
You can read a cell from a sheet object by providing the row and the column. For example, the following lines provide the value of the first cell (first row, first column):
|
258
261
|
|
259
|
-
sheet[1,1].
|
262
|
+
sheet[1,1].Value
|
260
263
|
=> "foo
|
261
264
|
|
262
265
|
or
|
@@ -274,7 +277,7 @@ or
|
|
274
277
|
|
275
278
|
=== Accessing rows and columns
|
276
279
|
|
277
|
-
The methods
|
280
|
+
The methods Worksheet#each, Worksheet#each_row and Worksheet#each_column enable to access each cell, row and column, respectively.
|
278
281
|
|
279
282
|
sheet.each do |cell|
|
280
283
|
# do something with cell
|
data/docs/README_sheet.rdoc
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
# introducing example
|
2
|
+
|
3
|
+
require File.expand_path('../../lib/robust_excel_ole', File.dirname(__FILE__))
|
4
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), '../../spec/helpers/create_temporary_dir')
|
5
|
+
require "fileutils"
|
6
|
+
|
7
|
+
include RobustExcelOle
|
8
|
+
|
9
|
+
dir = create_tmpdir
|
10
|
+
simple_file = dir + 'another_workbook.xls'
|
11
|
+
|
12
|
+
Excel.kill_all
|
13
|
+
|
14
|
+
# Let's open a workbook.
|
15
|
+
workbook = Workbook.open simple_file
|
16
|
+
# put name of the workbook
|
17
|
+
puts "name: #{workbook.Name}"
|
18
|
+
value = workbook['firstcell']
|
19
|
+
puts "value: #{value}"
|
20
|
+
# assigning a new value
|
21
|
+
workbook['firstcell'] = "new"
|
22
|
+
# saving the workbook
|
23
|
+
workbook.save
|
24
|
+
# closing the workbook
|
25
|
+
workbook.close
|
26
|
+
# reopening the workbook
|
27
|
+
workbook.reopen
|
28
|
+
# further operations
|
29
|
+
workbook['firstcell'] = "another_value"
|
30
|
+
# saved status of the workbook
|
31
|
+
puts "saved: #{workbook.Saved}"
|
32
|
+
# unobtrusively reading a workbook
|
33
|
+
Workbook.for_reading(simple_file) do |workbook|
|
34
|
+
puts "value of first cell: #{workbook['firstcell']}"
|
35
|
+
end
|
36
|
+
puts "saved: #{workbook.Saved}"
|
37
|
+
# unobtrusively modifying a workbook
|
38
|
+
Workbook.for_modifying(simple_file) do |workbook|
|
39
|
+
workbook['firstcell'] = "bar"
|
40
|
+
end
|
41
|
+
puts "saved: #{workbook.Saved}"
|
42
|
+
puts "value of first cell: #{workbook['firstcell']}"
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# introducing example example_open.rb
|
2
|
+
|
3
|
+
require File.expand_path('../../lib/robust_excel_ole', File.dirname(__FILE__))
|
4
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), '../../spec/helpers/create_temporary_dir')
|
5
|
+
require "fileutils"
|
6
|
+
|
7
|
+
include RobustExcelOle
|
8
|
+
|
9
|
+
dir = create_tmpdir
|
10
|
+
simple_file = dir + 'workbook.xls'
|
11
|
+
different_simple_file = dir + 'different_workbook.xls'
|
12
|
+
another_simple_file = dir + 'another_workbook.xls'
|
13
|
+
|
14
|
+
Excel.kill_all
|
15
|
+
|
16
|
+
# open a workbook
|
17
|
+
book = Workbook.open(simple_file)
|
18
|
+
puts "book: #{book}"
|
19
|
+
# open a workbook in a new Excel instance
|
20
|
+
book2 = Workbook.open(another_simple_file, :default => {:excel => :new})
|
21
|
+
puts "book2: #{book2}"
|
22
|
+
# open the workbook in a separate, reserved Excel instance.
|
23
|
+
book3 = Workbook.open(different_simple_file, :default => {:excel => :reserved_new})
|
24
|
+
puts "book3: #{book3}"
|
25
|
+
# open the workbook in a new Excel instance and make it visible
|
26
|
+
book4 = Workbook.open(simple_file, :force => {:excel => :new}, :visible => true)
|
27
|
+
puts "book4: #{book4}"
|
28
|
+
# open the workbook in a given Excel instance
|
29
|
+
excel1 = book.excel
|
30
|
+
book5 = Workbook.open(another_simple_file, :force => {:excel => excel1})
|
31
|
+
puts "book5: #{book5}"
|
32
|
+
# close a workbook
|
33
|
+
book.close
|
34
|
+
puts "close book -> book: #{book}"
|
35
|
+
# reopen the workbook
|
36
|
+
book6 = book.reopen
|
37
|
+
puts "reopened book: book6: #{book6}"
|
38
|
+
# unobtrusively opening a workbook
|
39
|
+
Workbook.unobtrusively(simple_file) do |book|
|
40
|
+
sheet = book.sheet(1)
|
41
|
+
sheet[1,1] = "c"
|
42
|
+
end
|
43
|
+
book6.close
|
44
|
+
book5.close
|
45
|
+
book4.close
|
46
|
+
book3.close
|
47
|
+
book2.close
|
48
|
+
Excel.close_all
|
49
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# introducing example example_range.rb
|
2
|
+
|
3
|
+
require File.expand_path('../../lib/robust_excel_ole', File.dirname(__FILE__))
|
4
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), '../../spec/helpers/create_temporary_dir')
|
5
|
+
require "fileutils"
|
6
|
+
|
7
|
+
include RobustExcelOle
|
8
|
+
|
9
|
+
dir = create_tmpdir
|
10
|
+
simple_file = dir + 'another_workbook.xls'
|
11
|
+
simple_file2 = dir + 'workbook.xls'
|
12
|
+
|
13
|
+
Excel.kill_all
|
14
|
+
|
15
|
+
# opening a workbook
|
16
|
+
book = Workbook.open(simple_file, :visible => true)
|
17
|
+
# accessing the 1st worksheet of this workbook
|
18
|
+
sheet = book.sheet(1)
|
19
|
+
# accessing a range consisting of one cell
|
20
|
+
range = sheet.range([1,2])
|
21
|
+
range2 = sheet.range("B1")
|
22
|
+
puts "range: #{range.Value}"
|
23
|
+
puts "range2: #{range2.Value}"
|
24
|
+
# the ranges are identical
|
25
|
+
# putting the values of the range
|
26
|
+
puts "range.values: #{range.values}"
|
27
|
+
# accessing a rectangular range given rows and columns
|
28
|
+
range3 = sheet.range([1..3,1..4])
|
29
|
+
range4 = sheet.range([1..3,"A".."D"])
|
30
|
+
# accessing the same range given the left top and the right bottum corner
|
31
|
+
range5 = sheet.range(["A1:D3"])
|
32
|
+
puts "range3: #{range3.Value}"
|
33
|
+
puts "range4: #{range4.Value}"
|
34
|
+
puts "range5: #{range5.Value}"
|
35
|
+
# the ranges are identival
|
36
|
+
# putting the values if the range
|
37
|
+
puts "range3.values: #{range3.values}"
|
38
|
+
# copying a range
|
39
|
+
range3.copy([6,2])
|
40
|
+
range6 = sheet.range([6..9,2..5])
|
41
|
+
puts "range3.Value: #{range3.Value}"
|
42
|
+
puts "range6.Value: #{range6.Value}"
|
43
|
+
# copying a range into another worksheet in another workbook of another Excel instance
|
44
|
+
book2 = Workbook.open(simple_file2, :excel => :new, :visible => true)
|
45
|
+
range3.copy([5,8], book2.sheet(3))
|
46
|
+
range7 = book2.sheet(3).range([5..8,8..11])
|
47
|
+
puts "range3.Value: #{range3.Value}"
|
48
|
+
puts "range7.Value: #{range7.Value}"
|
49
|
+
# adding a defined name referring to a range consisting of the first cell
|
50
|
+
book.add_name("name",[1,1])
|
51
|
+
# adding a defined name referring to a rectangular range
|
52
|
+
book.add_name("name",[1..2,3..4])
|
53
|
+
# assigning a value to that range
|
54
|
+
book["name"] = [["foo", "bar"],[1.0, nil]]
|
55
|
+
# reading the value of that range
|
56
|
+
value = book["name"]
|
57
|
+
puts "value: #{value}"
|
58
|
+
# renaming a range
|
59
|
+
book.rename_range("name", "new_name")
|
60
|
+
# deleting the name of a range
|
61
|
+
book.delete_name("new_name")
|
62
|
+
# reading the value of a cell
|
63
|
+
cell_value = sheet[1,1].Value
|
64
|
+
puts "cell_value: #{cell_value}"
|
65
|
+
# writing the value of a cell
|
66
|
+
sheet[1,1] = "bar"
|
67
|
+
Excel.close_all(:if_unsaved => :forget)
|