robust_excel_ole 1.1.5 → 1.1.6
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 +2 -2
- data/docs/README_excel.rdoc +2 -3
- data/docs/README_open.rdoc +8 -12
- data/docs/README_ranges.rdoc +21 -9
- data/docs/README_sheet.rdoc +1 -1
- data/lib/robust_excel_ole/book.rb +3 -23
- data/lib/robust_excel_ole/excel.rb +2 -15
- data/lib/robust_excel_ole/reo_common.rb +11 -7
- data/lib/robust_excel_ole/sheet.rb +36 -15
- data/lib/robust_excel_ole/version.rb +1 -1
- data/robust_excel_ole.gemspec +1 -1
- data/spec/book_spec.rb +1 -1
- data/spec/book_specs/book_close_spec.rb +3 -3
- data/spec/book_specs/book_misc_spec.rb +25 -1
- data/spec/book_specs/book_open_spec.rb +299 -5
- data/spec/book_specs/book_sheet_spec.rb +1 -1
- data/spec/book_specs/book_unobtr_spec.rb +275 -35
- 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 +118 -5
- data/spec/helpers/key_sender.rb +2 -2
- data/spec/reo_common_spec.rb +0 -4
- data/spec/sheet_spec.rb +32 -0
- data/spec/spec_helper.rb +3 -0
- metadata +3 -21
- data/spec/ruby1.8.6_rspec2.14/book_spec.rb +0 -1421
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_all_spec.rb +0 -22
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_close_spec.rb +0 -252
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_misc_spec.rb +0 -1070
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_open_spec.rb +0 -1855
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_save_spec.rb +0 -514
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_sheet_spec.rb +0 -395
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_subclass_spec.rb +0 -51
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_unobtr_spec.rb +0 -1737
- data/spec/ruby1.8.6_rspec2.14/bookstore_spec.rb +0 -495
- data/spec/ruby1.8.6_rspec2.14/cell_spec.rb +0 -76
- data/spec/ruby1.8.6_rspec2.14/cygwin_spec.rb +0 -42
- data/spec/ruby1.8.6_rspec2.14/excel_spec.rb +0 -1820
- data/spec/ruby1.8.6_rspec2.14/general_spec.rb +0 -212
- data/spec/ruby1.8.6_rspec2.14/range_spec.rb +0 -131
- data/spec/ruby1.8.6_rspec2.14/reo_common_spec.rb +0 -130
- data/spec/ruby1.8.6_rspec2.14/sheet_spec.rb +0 -663
- data/spec/ruby1.8.6_rspec2.14/spec_helper.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb0b1d72f09a87508b2d3f42a909b76de9230232
|
4
|
+
data.tar.gz: 54e2a4230a0833cb672881a49da5e105b3b74895
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de86c09449b9bc6c93915ef14cb898077d6243bc19012ce002a81a5d6828f8c4cb5ffaee8ed7a75c1d7ae0f8e1ad77b92dbd5d194af44393714578c2149c5a11
|
7
|
+
data.tar.gz: b43dfe70f03b3197d09710eeccb72fc696ae425b65b8a3ffbe36a94b0b61ce0a03e91ceb2929631aa33f22648f90362e1623d818b54b0e2fe97a5a00c971f39e
|
data/Changelog
CHANGED
data/README.rdoc
CHANGED
@@ -203,7 +203,7 @@ Without the option +:default+, the workbook can be forced to be opened in the cu
|
|
203
203
|
|
204
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.
|
205
205
|
|
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.
|
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 (forgotten) before opening the workbook, e.g.
|
207
207
|
|
208
208
|
workbook = Workbook.open('workbook.xls', :if_unsaved => :accept)
|
209
209
|
|
@@ -264,7 +264,7 @@ or
|
|
264
264
|
|
265
265
|
sheet.row_range(1)[0].value # => "foo"
|
266
266
|
|
267
|
-
Then we modify it
|
267
|
+
Then we modify it.
|
268
268
|
|
269
269
|
sheet[1,1] = "hello"
|
270
270
|
|
data/docs/README_excel.rdoc
CHANGED
@@ -69,16 +69,15 @@ and turn DisplayAlerts off with
|
|
69
69
|
|
70
70
|
excel1.displayalerts = false
|
71
71
|
|
72
|
-
You can turn off
|
72
|
+
You can turn DisplayAlerts off or on within a block.
|
73
73
|
|
74
|
-
excel = Excel.create
|
75
74
|
excel.with_displayalerts false do
|
76
75
|
# do something
|
77
76
|
end
|
78
77
|
|
79
78
|
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
|
+
=== Setting Calculation mode
|
82
81
|
|
83
82
|
You can set the calculation mode of an Excel instance to manual or automatic.
|
84
83
|
|
data/docs/README_open.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= RobustExcelOle
|
2
2
|
|
3
|
-
=== Opening
|
3
|
+
=== Opening a workbook.
|
4
4
|
|
5
5
|
If you want to open a workbook, use
|
6
6
|
|
@@ -25,9 +25,9 @@ The options are the following:
|
|
25
25
|
|
26
26
|
+:visible+:: makes the workbook visible or invisible
|
27
27
|
|
28
|
-
+:if_unsaved+:: specify behaviour if the workbook was unsaved (default: +
|
28
|
+
+:if_unsaved+:: specify behaviour if the workbook was unsaved (default: +:raise+)
|
29
29
|
|
30
|
-
+:if_obstructed+:: specify behaviour if the workbook is blocked by another book (default: +
|
30
|
+
+:if_obstructed+:: specify behaviour if the workbook is blocked by another book (default: +:raise+)
|
31
31
|
|
32
32
|
+:read_only+:: open in read-only mode (default: +false+)
|
33
33
|
|
@@ -37,12 +37,7 @@ The options are the following:
|
|
37
37
|
|
38
38
|
+:if_absent+:: specify behaviour if the workbook with the given file name does not exist if the workbook does not exist (default: +create+)
|
39
39
|
|
40
|
-
You can use the following abbreviations:
|
41
|
-
|
42
|
-
+:f+:: +:force+
|
43
|
-
+:d+:: +:default+
|
44
|
-
+:e+:: +:excel+
|
45
|
-
+:v+:: +:visible+
|
40
|
+
You can use the following abbreviations: +:f+ for +:force+, +:d+ for +:default+, +:e+ for +:excel+, and +:v+ for +:visible+. Finally you can leave out the option +:force+ or +:f+.
|
46
41
|
|
47
42
|
The option +:excel+ :
|
48
43
|
|
@@ -100,7 +95,6 @@ For simplicity, you can also leave out the +:force+ option (but not the +:defaul
|
|
100
95
|
You can also specify an Excel instance
|
101
96
|
|
102
97
|
excel1 = Excel.create
|
103
|
-
# do something
|
104
98
|
Workbook.open('workbook.xls', :excel => excel1)
|
105
99
|
|
106
100
|
If you want to open the workbook and make its window visible, then use
|
@@ -156,8 +150,8 @@ Options are the following:
|
|
156
150
|
|
157
151
|
+: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
|
158
152
|
|
159
|
-
+:read_only+:: Whether the workbook shall be forced to be open in ReadOnly mode
|
160
|
-
+:writable+:: Whether changes in the workbook shall be saved
|
153
|
+
+:read_only+:: Whether the workbook shall be forced to be open in ReadOnly mode
|
154
|
+
+:writable+:: Whether changes in the workbook shall be saved
|
161
155
|
|
162
156
|
+:rw_change_excel+:: Excel instance in which the workbook with the
|
163
157
|
changed read-write permissions shall be opened
|
@@ -180,6 +174,8 @@ The methods +for_reading+ and +for_modifying+ indicate unobtrusively reading or
|
|
180
174
|
sheet[1,1] = "c"
|
181
175
|
end
|
182
176
|
|
177
|
+
Remark: The methods +unobtrusively+, +for_reading+ and +for_modifying+ work only for workbooks opened via RobustExcelOle. They do not connect to workbooks opened outside RobustExcelOle.
|
178
|
+
|
183
179
|
=== Retaining the saved-status
|
184
180
|
|
185
181
|
This method ensures keeping the save status of the workbook
|
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 Sheet, a Book or an Excel object representing a Worksheet, Workbook, or Application object 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, in VBA.
|
6
6
|
|
7
7
|
=== Reading and writing the contents of a named range in a workbook.
|
8
8
|
|
@@ -10,7 +10,7 @@ Assume you have opened a workbook:
|
|
10
10
|
|
11
11
|
book = Workbook.open('workbook.xls', :visible => true)
|
12
12
|
|
13
|
-
You can get the contents of a range with a defined name with help of the method [] or nameval
|
13
|
+
You can get the contents of a range with a defined name with help of the method [] or +nameval+.
|
14
14
|
|
15
15
|
book["name"]
|
16
16
|
=> "value"
|
@@ -20,7 +20,7 @@ or
|
|
20
20
|
book.nameval("name")
|
21
21
|
=> "value"
|
22
22
|
|
23
|
-
Using nameval
|
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.
|
24
24
|
|
25
25
|
book.namval("name", :default => "default_value")
|
26
26
|
|
@@ -32,11 +32,11 @@ or
|
|
32
32
|
|
33
33
|
book.set_nameval("name", "new_value")
|
34
34
|
|
35
|
-
The method []= colors the written cell. You can specify the color of a changed range via the method set_nameval
|
35
|
+
The method []= colors the written cell. You can specify the color of a changed range via the method +set_nameval+.
|
36
36
|
|
37
37
|
book.set_nameval("name", "new_value", :color => 4)
|
38
38
|
|
39
|
-
Similarly, the contents of a named range can be read and modified in a worksheet
|
39
|
+
Similarly, the contents of a named range can be read and modified in a worksheet
|
40
40
|
|
41
41
|
sheet = book.sheet(1)
|
42
42
|
|
@@ -45,7 +45,7 @@ Similarly, the contents of a named range can be read and modified in a worksheet
|
|
45
45
|
|
46
46
|
sheet["name"] = "new_value"
|
47
47
|
|
48
|
-
or an
|
48
|
+
or an Application object.
|
49
49
|
|
50
50
|
excel = book.excel
|
51
51
|
|
@@ -64,7 +64,7 @@ or
|
|
64
64
|
|
65
65
|
=== Reading and writing the contents of a range with a locally defined name
|
66
66
|
|
67
|
-
The contents of locally defined ranges can be read
|
67
|
+
The contents of locally defined ranges can be read by
|
68
68
|
|
69
69
|
sheet.rangeval("name")
|
70
70
|
=> "value"
|
@@ -74,7 +74,7 @@ or
|
|
74
74
|
excel.rangeval("name")
|
75
75
|
=> "value"
|
76
76
|
|
77
|
-
and be modified
|
77
|
+
and be modified by
|
78
78
|
|
79
79
|
sheet.set_rangeval("name", "value")
|
80
80
|
|
@@ -88,13 +88,25 @@ Similarly to nameval, you can provide a default value that is returned when ocur
|
|
88
88
|
|
89
89
|
=== Accessing a cell
|
90
90
|
|
91
|
-
You can read
|
91
|
+
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):
|
92
92
|
|
93
93
|
sheet[1,1].value
|
94
94
|
=> "foo
|
95
95
|
|
96
|
+
or
|
97
|
+
|
98
|
+
sheet.cellval(1,1)
|
99
|
+
=> "foo"
|
100
|
+
|
101
|
+
Similarly, you can write a cell.
|
102
|
+
|
96
103
|
sheet[1,1] = "new_value"
|
97
104
|
|
105
|
+
or
|
106
|
+
|
107
|
+
sheet.set_cellval(1,1,"new_value", :color => 42)
|
108
|
+
|
109
|
+
|
98
110
|
=== Accessing rows and columns
|
99
111
|
|
100
112
|
The methods Sheet#each, Sheet#each_row and Sheet#each_column enable to access each cell, row and column, respectively.
|
data/docs/README_sheet.rdoc
CHANGED
@@ -111,24 +111,6 @@ module RobustExcelOle
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
-
# here is what is different and works
|
115
|
-
=begin
|
116
|
-
if book
|
117
|
-
if (((not options[:force][:excel]) || (forced_excel == book.excel)) &&
|
118
|
-
(not (book.alive? && (not book.saved) && (not options[:if_unsaved] == :accept))))
|
119
|
-
book.options = options
|
120
|
-
book.ensure_excel(options) # unless book.excel.alive?
|
121
|
-
# if the ReadOnly status shall be changed, close and reopen it; save before, if it is writable
|
122
|
-
if book.alive? and (((not book.writable) and (not options[:read_only])) or
|
123
|
-
(book.writable and options[:read_only]))
|
124
|
-
book.save if book.writable
|
125
|
-
book.close(:if_unsaved => :forget)
|
126
|
-
end
|
127
|
-
# reopens the book
|
128
|
-
book.ensure_workbook(file,options) unless book.alive?
|
129
|
-
=end
|
130
|
-
|
131
|
-
|
132
114
|
# creates a Book object by opening an Excel file given its filename workbook or
|
133
115
|
# by lifting a Win32OLE object representing an Excel file
|
134
116
|
# @param [WIN32OLE] workbook a workbook
|
@@ -145,6 +127,8 @@ module RobustExcelOle
|
|
145
127
|
book.visible = opts[:force][:visible] unless opts[:force].nil? or opts[:force][:visible].nil?
|
146
128
|
book.excel.calculation = opts[:calculation] unless opts[:calculation].nil?
|
147
129
|
return book
|
130
|
+
else
|
131
|
+
super
|
148
132
|
end
|
149
133
|
end
|
150
134
|
else
|
@@ -158,7 +142,6 @@ module RobustExcelOle
|
|
158
142
|
# @param [Hash] opts the options
|
159
143
|
# @option opts [Symbol] see above
|
160
144
|
# @return [Book] a workbook
|
161
|
-
#def initialize(file_or_workbook, opts={ }, &block)
|
162
145
|
def initialize(file_or_workbook, options={ }, &block)
|
163
146
|
#options = @options = self.class.process_options(options) if options.empty?
|
164
147
|
if file_or_workbook.is_a? WIN32OLE
|
@@ -250,8 +233,6 @@ module RobustExcelOle
|
|
250
233
|
public
|
251
234
|
|
252
235
|
def ensure_excel(options) # :nodoc: #
|
253
|
-
#if (excel && @excel.alive? && (options[:force].nil? or options[:force][:excel].nil? or
|
254
|
-
# options[:force][:excel]==@excel))
|
255
236
|
if excel && @excel.alive?
|
256
237
|
@excel.created = false
|
257
238
|
return
|
@@ -487,6 +468,7 @@ module RobustExcelOle
|
|
487
468
|
|
488
469
|
# allows to read or modify a workbook such that its state remains unchanged
|
489
470
|
# state comprises: open, saved, writable, visible, calculation mode, check compatibility
|
471
|
+
# remarks: works only for workbooks opened with RobustExcelOle
|
490
472
|
# @param [String] file the file name
|
491
473
|
# @param [Hash] opts the options
|
492
474
|
# @option opts [Variant] :if_closed :current (default), :new or an Excel instance
|
@@ -496,7 +478,6 @@ module RobustExcelOle
|
|
496
478
|
# write permissions shall be opened :current (default), :new or an Excel instance
|
497
479
|
# @option opts [Boolean] :keep_open whether the workbook shall be kept open after unobtrusively opening
|
498
480
|
# @return [Book] a workbook
|
499
|
-
# state = [:open, :saved, :writable, :visible, :calculation, :check_compatibility]
|
500
481
|
def self.unobtrusively(file, opts = { }, &block)
|
501
482
|
opts = {:if_closed => :current,
|
502
483
|
:rw_change_excel => :current,
|
@@ -651,7 +632,6 @@ module RobustExcelOle
|
|
651
632
|
private
|
652
633
|
|
653
634
|
def discoloring
|
654
|
-
# self.each{|sheet| sheet.UsedRange.each{|cell| cell.Interior.ColorIndex = XlNone}}
|
655
635
|
@modified_cells.each{|cell| cell.Interior.ColorIndex = XlNone}
|
656
636
|
end
|
657
637
|
|
@@ -225,6 +225,8 @@ module RobustExcelOle
|
|
225
225
|
|
226
226
|
# closes all Excel instances
|
227
227
|
# @return [Fixnum,Fixnum] number of closed Excel instances, number of errors
|
228
|
+
# remark: the returned number of closed Excel instances is valid only for known Excel instances
|
229
|
+
# if there are unknown Excel instances (opened not via this class), then they are counted as 1
|
228
230
|
# @param [Hash] options the options
|
229
231
|
# @option options [Symbol] :if_unsaved :raise, :save, :forget, or :alert
|
230
232
|
# options:
|
@@ -589,21 +591,6 @@ module RobustExcelOle
|
|
589
591
|
end
|
590
592
|
end
|
591
593
|
|
592
|
-
=begin
|
593
|
-
# make all workbooks visible or invisible
|
594
|
-
def workbooks_visible= visible_value
|
595
|
-
begin
|
596
|
-
@ole_excel.Workbooks.each do |ole_wb|
|
597
|
-
workbook = Book.new(ole_wb)
|
598
|
-
workbook.visible = visible_value
|
599
|
-
end
|
600
|
-
rescue RuntimeError => msg
|
601
|
-
trace "RuntimeError: #{msg.message}"
|
602
|
-
raise ExcelDamaged, "Excel instance not alive or damaged" if msg.message =~ /failed to get Dispatch Interface/
|
603
|
-
end
|
604
|
-
end
|
605
|
-
=end
|
606
|
-
|
607
594
|
def focus
|
608
595
|
self.visible = true
|
609
596
|
#if not Windows10 then
|
@@ -8,7 +8,7 @@ File.delete REO_LOG_FILE rescue nil
|
|
8
8
|
|
9
9
|
module RobustExcelOle
|
10
10
|
|
11
|
-
class REOError < RuntimeError
|
11
|
+
class REOError < RuntimeError # :nodoc: #
|
12
12
|
end
|
13
13
|
|
14
14
|
class ExcelREOError < REOError # :nodoc: #
|
@@ -17,6 +17,9 @@ module RobustExcelOle
|
|
17
17
|
class WorkbookREOError < REOError # :nodoc: #
|
18
18
|
end
|
19
19
|
|
20
|
+
class SheetREOError < REOError # :nodoc: #
|
21
|
+
end
|
22
|
+
|
20
23
|
class FileREOError < REOError # :nodoc: #
|
21
24
|
end
|
22
25
|
|
@@ -176,7 +179,7 @@ module RobustExcelOle
|
|
176
179
|
begin
|
177
180
|
cell = name_object(name).RefersToRange
|
178
181
|
cell.Interior.ColorIndex = opts[:color]
|
179
|
-
workbook.modified_cells << cell unless cell_modified?(cell)
|
182
|
+
workbook.modified_cells << cell if workbook #unless cell_modified?(cell)
|
180
183
|
cell.Value = value
|
181
184
|
rescue WIN32OLERuntimeError
|
182
185
|
raise RangeNotEvaluatable, "cannot assign value to range named #{name.inspect} in #{self.inspect}"
|
@@ -192,6 +195,7 @@ module RobustExcelOle
|
|
192
195
|
# @option opts [Symbol] :default the default value that is provided if no contents could be returned
|
193
196
|
# @return [Variant] the contents of a range with given name
|
194
197
|
def rangeval(name, opts = {:default => :__not_provided})
|
198
|
+
return nameval(name, opts) if self.is_a?(Book)
|
195
199
|
begin
|
196
200
|
range = self.Range(name)
|
197
201
|
rescue WIN32OLERuntimeError
|
@@ -227,7 +231,7 @@ module RobustExcelOle
|
|
227
231
|
end
|
228
232
|
begin
|
229
233
|
range.Interior.ColorIndex = opts[:color]
|
230
|
-
workbook.modified_cells << range unless cell_modified?(range)
|
234
|
+
workbook.modified_cells << range if workbook #unless cell_modified?(range)
|
231
235
|
range.Value = value
|
232
236
|
rescue WIN32OLERuntimeError
|
233
237
|
raise RangeNotEvaluatable, "cannot assign value to range named #{name.inspect} in #{self.inspect}"
|
@@ -248,10 +252,10 @@ module RobustExcelOle
|
|
248
252
|
end
|
249
253
|
end
|
250
254
|
|
251
|
-
def cell_modified?(cell)
|
252
|
-
|
253
|
-
|
254
|
-
end
|
255
|
+
#def cell_modified?(cell)
|
256
|
+
# workbook.modified_cells.each{|c| return true if c.Name.Value == cell.Name.Value}
|
257
|
+
# false
|
258
|
+
#end
|
255
259
|
|
256
260
|
end
|
257
261
|
|
@@ -23,7 +23,11 @@ module RobustExcelOle
|
|
23
23
|
|
24
24
|
# returns name of the sheet
|
25
25
|
def name
|
26
|
-
|
26
|
+
begin
|
27
|
+
@ole_worksheet.Name
|
28
|
+
rescue
|
29
|
+
raise SheetREOError, "name #{name.inspect} could not be determined"
|
30
|
+
end
|
27
31
|
end
|
28
32
|
|
29
33
|
# name the sheet
|
@@ -40,17 +44,16 @@ module RobustExcelOle
|
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
|
-
# returns
|
44
|
-
# returns the value of a range if its name is given
|
47
|
+
# returns cell, if row and column are given
|
45
48
|
def [] p1, p2 = :__not_provided
|
46
49
|
if p2 != :__not_provided
|
47
|
-
|
48
|
-
|
50
|
+
x, y = p1, p2
|
51
|
+
xy = "#{x}_#{y}"
|
49
52
|
@cells = { }
|
50
53
|
begin
|
51
|
-
@cells[
|
54
|
+
@cells[xy] = RobustExcelOle::Cell.new(@ole_worksheet.Cells.Item(x, y))
|
52
55
|
rescue
|
53
|
-
raise RangeNotEvaluatable, "cannot read cell (#{
|
56
|
+
raise RangeNotEvaluatable, "cannot read cell (#{x.inspect},#{y.inspect})"
|
54
57
|
end
|
55
58
|
else
|
56
59
|
name = p1
|
@@ -66,14 +69,8 @@ module RobustExcelOle
|
|
66
69
|
# sets the value of a range if its name is given
|
67
70
|
def []= (p1, p2, p3 = :__not_provided)
|
68
71
|
if p3 != :__not_provided
|
69
|
-
|
70
|
-
|
71
|
-
cell = @ole_worksheet.Cells.Item(y, x)
|
72
|
-
cell.Value = value
|
73
|
-
cell.Interior.ColorIndex = 42 # aqua-marin, 4-green
|
74
|
-
rescue WIN32OLERuntimeError
|
75
|
-
raise RangeNotEvaluatable, "cannot assign value #{p3.inspect} to cell (#{p1.inspect},#{p2.inspect})"
|
76
|
-
end
|
72
|
+
x, y, value = p1, p2, p3
|
73
|
+
set_cellval(x,y,value)
|
77
74
|
else
|
78
75
|
name, value = p1, p2
|
79
76
|
begin
|
@@ -87,6 +84,30 @@ module RobustExcelOle
|
|
87
84
|
end
|
88
85
|
end
|
89
86
|
end
|
87
|
+
|
88
|
+
# returns the value of a cell, if row and column are given
|
89
|
+
def cellval(x,y)
|
90
|
+
xy = "#{x}_#{y}"
|
91
|
+
@cells = { }
|
92
|
+
begin
|
93
|
+
@cells[xy] = RobustExcelOle::Cell.new(@ole_worksheet.Cells.Item(x, y))
|
94
|
+
@cells[xy].Value
|
95
|
+
rescue
|
96
|
+
raise RangeNotEvaluatable, "cannot read cell (#{p1.inspect},#{p2.inspect})"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# sets the value of a cell, if row, column and color of the cell are given
|
101
|
+
def set_cellval(x,y,value, opts = {:color => 0})
|
102
|
+
begin
|
103
|
+
cell = @ole_worksheet.Cells.Item(x, y)
|
104
|
+
cell.Interior.ColorIndex = opts[:color] # 42 - aqua-marin, 4-green
|
105
|
+
@workbook.modified_cells << cell if @workbook
|
106
|
+
cell.Value = value
|
107
|
+
rescue WIN32OLERuntimeError
|
108
|
+
raise RangeNotEvaluatable, "cannot assign value #{value.inspect} to cell (#{y.inspect},#{x.inspect})"
|
109
|
+
end
|
110
|
+
end
|
90
111
|
|
91
112
|
# assigns a name to a range (a cell) given by an address
|
92
113
|
# @param [String] name the range name
|