ufooar 0.1.1.140

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,65 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+
3
+ Version 3, 29 June 2007
4
+
5
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
6
+
7
+ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
8
+
9
+ This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
10
+ 0. Additional Definitions.
11
+
12
+ As used herein, �this License� refers to version 3 of the GNU Lesser General Public License, and the �GNU GPL� refers to version 3 of the GNU General Public License.
13
+
14
+ �The Library� refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
15
+
16
+ An �Application� is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
17
+
18
+ A �Combined Work� is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the �Linked Version�.
19
+
20
+ The �Minimal Corresponding Source� for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.
21
+
22
+ The �Corresponding Application Code� for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
23
+ 1. Exception to Section 3 of the GNU GPL.
24
+
25
+ You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
26
+ 2. Conveying Modified Versions.
27
+
28
+ If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:
29
+
30
+ * a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or
31
+ * b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
32
+
33
+ 3. Object Code Incorporating Material from Library Header Files.
34
+
35
+ The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:
36
+
37
+ * a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
38
+ * b) Accompany the object code with a copy of the GNU GPL and this license document.
39
+
40
+ 4. Combined Works.
41
+
42
+ You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:
43
+
44
+ * a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
45
+ * b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
46
+ * c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.
47
+ * d) Do one of the following:
48
+ o 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
49
+ o 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
50
+ * e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
51
+
52
+ 5. Combined Libraries.
53
+
54
+ You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:
55
+
56
+ * a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.
57
+ * b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
58
+
59
+ 6. Revised Versions of the GNU Lesser General Public License.
60
+
61
+ The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
62
+
63
+ Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License �or any later version� applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.
64
+
65
+ If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
@@ -0,0 +1,891 @@
1
+ # Filename: calc.rb
2
+ #
3
+ # Author:: Nathan Lane (mailto:nathamberlane@gmail.com)
4
+ # Copyright:: Copyright (c) 2007 Nathan Lane
5
+ # License:: GNU Lesser General Public License (http://www.gnu.org/licenses/lgpl.html)
6
+ #
7
+ # This program is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU General Public License
9
+ # as published by the Free Software Foundation; either version 2
10
+ # of the License, or (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
+ #
21
+ # Documentation for this library may be found at http://code.google.com/p/ufooar/
22
+
23
+ # This module contains the Calc classes used to automate OpenOffice.org
24
+ # via its UNO component.
25
+ # Author:: Nathan Lane
26
+ # Last Updated: 11/13/2007
27
+
28
+ require 'openoffice/document'
29
+
30
+ module OpenOffice
31
+
32
+ # This class contains methods used to manipulate sheets and spreadsheet documents.
33
+ # Author:: Nathan Lane
34
+ # Last Updated: 11/13/2007
35
+
36
+ class Calc
37
+
38
+ # This constant represents the difference between 0x00 and lowercase 'a' in the ASCII table
39
+ # Author:: Nathan Lane
40
+ # Last Updated: 11/13/2007
41
+
42
+ ASCIIDIFFERENCE = 97
43
+
44
+ attr_reader :spreadsheet, :file_uri, :file_args, :sheets, :current_sheet
45
+
46
+ # This method returns a Hidden Property object to be used in the args array when you want to
47
+ # load a spreadsheet but not have the window for OpenOffice.org be visible.
48
+ # Author:: Nathan Lane
49
+ # Last Updated: 11/13/2007
50
+
51
+ def self.HIDDEN
52
+ UNO.create_property_value "Hidden", true
53
+ end
54
+
55
+ # This constructor takes two arguments, file_path, which is a String and args, which is an
56
+ # Array. Args is not required to create a new spreadsheet, but you must specify a file path
57
+ # as a URI in the form file:///driveletter:/path/to/file.ods.
58
+ # Author:: Nathan Lane
59
+ # Last Updated: 11/13/2007
60
+
61
+ def initialize file_path = nil, file_args = []
62
+ @spreadsheet, @file_uri, @file_args = Document.create_document_instance :calc, file_path, file_args
63
+ @sheets = get_sheets_collection
64
+ @current_sheet = get_sheet_by_index 0
65
+ end # End: def initialize file_path = nil, file_args = []
66
+
67
+ # This method gets all of the sheets in a spreadsheet document.
68
+ # Author:: Nathan Lane
69
+ # Last Updated: 11/13/2007
70
+
71
+ def get_sheets_collection
72
+ @spreadsheet.Sheets
73
+ end # End: def load_sheets_collection
74
+
75
+ # This method returns the text name of the currently selected sheet.
76
+ # Author:: Nathan Lane
77
+ # Last Updated: 11/13/2007
78
+
79
+ def get_current_sheet_name
80
+ @spreadsheet.CurrentController.ActiveSheet.Name
81
+ end # End: def get_current_sheet_name
82
+
83
+ # This method selects the specified sheet and stores it in @current_sheet.
84
+ # Author:: Nathan Lane
85
+ # Last Updated: 11/13/2007
86
+ def select_sheet sheet
87
+ if sheet.class == String
88
+ @current_sheet = get_sheet_by_name sheet
89
+ elsif sheet.class == Fixnum
90
+ if sheet > 0
91
+ sheet = sheet - 1
92
+ end # End: if sheet > 0
93
+
94
+ @current_sheet = get_sheet_by_index sheet
95
+ elsif sheet.class == WIN32OLE
96
+ @current_sheet = sheet
97
+ end # End: if sheet.class == String
98
+
99
+ @spreadsheet.CurrentController.Select(@current_sheet)
100
+ end # End: def select_sheet sheet
101
+
102
+ # This method gets a single sheet object from a spreadsheet by its zero-based index.
103
+ # Author:: Nathan Lane
104
+ # Last Updated: 11/13/2007
105
+
106
+ def get_sheet_by_index sheet_index
107
+ if sheet_index.class == Fixnum
108
+ get_sheets_collection.getByIndex sheet_index
109
+ else
110
+ raise "Index must be numeric"
111
+ end # End: if sheet_index.class == Fixnum
112
+ end # End: def get_sheet_by_index sheet_index
113
+
114
+ # This method gets a sheet object by its name.
115
+ # Author:: Nathan Lane
116
+ # Last Updated: 11/13/2007
117
+
118
+ def get_sheet_by_name sheet_name
119
+ if sheet_name.class == String
120
+ get_sheets_collection.getByName sheet_name
121
+ else
122
+ raise "Sheet name must be a string"
123
+ end # End: if sheet_index.class == Fixnum
124
+ end # End: def get_sheet_by_name sheet_name
125
+
126
+ # This method gets a cell object by the sheet it's on (either name or index) and
127
+ # by its column, row location.
128
+ # Author:: Nathan Lane
129
+ # Last Updated: 11/13/2007
130
+
131
+ def get_cell_by_sheet column, row, sheet = @current_sheet
132
+ if column.class == String
133
+ column = parse_alpha_column_label column
134
+ end # End: if column.class == String
135
+
136
+ if sheet.class == Fixnum
137
+ get_sheet_by_index(sheet).getCellByPosition column, row
138
+ elsif sheet.class == String
139
+ get_sheet_by_name(sheet).getCellByPosition column, row
140
+ elsif sheet.class == WIN32OLE
141
+ sheet.getCellByPosition column, row
142
+ else
143
+ raise "Sheet must be either an index, a name, or an object"
144
+ end # End: if sheet.class == Fixnum
145
+ end # End: def get_cell_by_sheet sheet, column, row
146
+
147
+ # This method gets a cell object by its sheet (either name or index) and by
148
+ # its qualified name, for example A1
149
+ # Author:: Nathan Lane
150
+ # Last Updated: 11/13/2007
151
+
152
+ def get_cell_by_sheet_by_name cell_name, sheet = @current_sheet
153
+ cell_name_format = /^([Aa]+|[Bb]+|[Cc]+|[Dd]+|[Ee]+|[Ff]+|[Gg]+|[Hh]+|[Ii]+|[Jj]+|[Kk]+|[Ll]+|[Mm]+|[Nn]+|[Oo]+|[Pp]+|[Qq]+|[Rr]+|[Ss]+|[Tt]+|[Uu]+|[Vv]+|[Ww]+|[Xx]+|[Yy]+|[Zz]+)([\d]+)$/
154
+ if cell_name =~ cell_name_format
155
+ cell_column = cell_name.slice(/^([A-Za-z]+)/)
156
+ cell_row = (cell_name.slice(/([\d]+)$/).to_i - 1)
157
+ get_cell_by_sheet cell_column, cell_row, sheet
158
+ else
159
+ raise "OO notation was malformed, please use SheetName.CellName"
160
+ end # End: if cell_name =~ cell_name_format
161
+ end # End: def get_cell_by_sheet_by_name sheet, cell_name
162
+
163
+ # This method gets a cell object by OpenOffice cell notation, for example
164
+ # Sheet1.A1.
165
+ # Author:: Nathan Lane
166
+ # Last Updated: 11/13/2007
167
+
168
+ def get_cell_by_oo_notation oo_notation
169
+ oo_notation_format = /^[A-Za-z\d\s]+[.]{1}([Aa]+|[Bb]+|[Cc]+|[Dd]+|[Ee]+|[Ff]+|[Gg]+|[Hh]+|[Ii]+|[Jj]+|[Kk]+|[Ll]+|[Mm]+|[Nn]+|[Oo]+|[Pp]+|[Qq]+|[Rr]+|[Ss]+|[Tt]+|[Uu]+|[Vv]+|[Ww]+|[Xx]+|[Yy]+|[Zz]+)([\d]+)$/
170
+ if oo_notation =~ oo_notation_format
171
+ sheet_name = oo_notation.slice(/^[A-Za-z\d\s]+[.]{1}/)
172
+ sheet_name_length = sheet_name.length
173
+ sheet_name = sheet_name[0, (sheet_name_length - 1)]
174
+ cell_name = oo_notation.slice(/[.]{1}([Aa]+|[Bb]+|[Cc]+|[Dd]+|[Ee]+|[Ff]+|[Gg]+|[Hh]+|[Ii]+|[Jj]+|[Kk]+|[Ll]+|[Mm]+|[Nn]+|[Oo]+|[Pp]+|[Qq]+|[Rr]+|[Ss]+|[Tt]+|[Uu]+|[Vv]+|[Ww]+|[Xx]+|[Yy]+|[Zz]+)([\d]+)$/)
175
+ cell_name_length = cell_name.length
176
+ cell_name = cell_name[1, (cell_name_length - 1)]
177
+ get_cell_by_sheet_by_name sheet_name, cell_name
178
+ else
179
+ raise "OO notation was malformed, please use SheetName.CellName"
180
+ end # End: if oo_notation =~ oo_notation_format
181
+ end # End: def get_cell_by_oo_notation oo_notation
182
+
183
+ # This method returns an object of cells by reference by OpenOffice cell notation, for example
184
+ # Sheet1.A1:B5.
185
+ # Author:: Nathan Lane
186
+ # Last Updated: 11/13/2007
187
+
188
+ def get_cell_range_by_oo_notation oo_notation
189
+ oo_notation_format_sheet_style = /^([A-Za-z\d\s]+[.]{1}([Aa]+|[Bb]+|[Cc]+|[Dd]+|[Ee]+|[Ff]+|[Gg]+|[Hh]+|[Ii]+|[Jj]+|[Kk]+|[Ll]+|[Mm]+|[Nn]+|[Oo]+|[Pp]+|[Qq]+|[Rr]+|[Ss]+|[Tt]+|[Uu]+|[Vv]+|[Ww]+|[Xx]+|[Yy]+|[Zz]+)([\d]+)){1}[:]{1}([A-Za-z\d\s]+[.]{1}([Aa]+|[Bb]+|[Cc]+|[Dd]+|[Ee]+|[Ff]+|[Gg]+|[Hh]+|[Ii]+|[Jj]+|[Kk]+|[Ll]+|[Mm]+|[Nn]+|[Oo]+|[Pp]+|[Qq]+|[Rr]+|[Ss]+|[Tt]+|[Uu]+|[Vv]+|[Ww]+|[Xx]+|[Yy]+|[Zz]+)([\d]+)){1}$/
190
+ oo_notation_format_cell_style = /^([A-Za-z\d\s]+[.]{1}([Aa]+|[Bb]+|[Cc]+|[Dd]+|[Ee]+|[Ff]+|[Gg]+|[Hh]+|[Ii]+|[Jj]+|[Kk]+|[Ll]+|[Mm]+|[Nn]+|[Oo]+|[Pp]+|[Qq]+|[Rr]+|[Ss]+|[Tt]+|[Uu]+|[Vv]+|[Ww]+|[Xx]+|[Yy]+|[Zz]+)([\d]+)){1}[:]{1}(([Aa]+|[Bb]+|[Cc]+|[Dd]+|[Ee]+|[Ff]+|[Gg]+|[Hh]+|[Ii]+|[Jj]+|[Kk]+|[Ll]+|[Mm]+|[Nn]+|[Oo]+|[Pp]+|[Qq]+|[Rr]+|[Ss]+|[Tt]+|[Uu]+|[Vv]+|[Ww]+|[Xx]+|[Yy]+|[Zz]+)([\d]+)){1}$/
191
+ if oo_notation =~ oo_notation_format_sheet_style or oo_notation =~ oo_notation_format_cell_style
192
+ puts "TODO: develop get_cell_range_by_oo_notation"
193
+
194
+ else
195
+ raise "OO notation was malformed, please use SheetName.TopLeftCellName:SheetName.BottomRightCellName or SheetName.TopLeftCellName:BottomRightCellName"
196
+ end # End: if oo_notation =~ oo_notation_format_sheet_style or oo_notation =~ oo_notation_format_cell_style
197
+ end # End: def get_cell_range_by_oo_notation oo_notation
198
+
199
+ # This method returns an object of cells by reference by cell coordinates (all numeric), for
200
+ # example 0, 0, 4, 0.
201
+ # Author:: Nathan Lane
202
+ # Last Updated: 11/13/2007
203
+
204
+ def get_cell_range_by_sheet left, top, right, bottom, sheet = @current_sheet
205
+ if sheet.class == Fixnum
206
+ get_sheet_by_index(sheet).getCellRangeByPosition left, top, right, bottom
207
+ elsif sheet.class == String
208
+ get_sheet_by_name(sheet).getCellRangeByPosition left, top, right, bottom
209
+ elsif sheet.class == WIN32OLE
210
+ sheet.getCellByRangeByPosition left, top, right, bottom
211
+ else
212
+ raise "Sheet must be either an index, a name, or an object"
213
+ end # End: if sheet.class == Fixnum
214
+ end # End: def get_cell_range_by_sheet sheet, left, top, right, bottom
215
+
216
+ # This method returns an array of cells by reference by cell coordinates (all numeric), for
217
+ # example 0, 0, 4, 0.
218
+ # Author:: Nathan Lane
219
+ # Last Updated: 11/13/2007
220
+
221
+ def get_cell_range_by_sheet_as_array left, top, right, bottom, sheet = @current_sheet
222
+ cell_range
223
+
224
+ if sheet.class == Fixnum
225
+ cell_range = get_sheet_by_index(sheet).getCellRangeByPosition left, top, right, bottom
226
+ elsif sheet.class == String
227
+ cell_range = get_sheet_by_name(sheet).getCellRangeByPosition left, top, right, bottom
228
+ elsif sheet.class == WIN32OLE
229
+ cell_range = sheet.getCellByRangeByPosition left, top, right, bottom
230
+ else
231
+ raise "Sheet must be either an index, a name, or an object"
232
+ end # End: if sheet.class == Fixnum
233
+
234
+ cell_range_as_array = [] # Create an array
235
+
236
+ column_range, row_range = get_cell_range_dimensions cell_range
237
+ row_index = 0
238
+
239
+ while row_index < row_range
240
+ cell_range_as_array[row_index] = []
241
+ column_index = 0
242
+
243
+ while column_index < column_range
244
+ cell_range_as_array[row_index][column_index] = get_cell_formula_by_cell_range cell_range, column_index, row_index
245
+
246
+ column_index = column_index + 1
247
+ end # End: while column_index < column_range
248
+
249
+ row_index = row_index + 1
250
+ end # End: while row_index < row_range
251
+
252
+ return cell_range_as_array # Finally a 2-dimensional array
253
+ end # End: def get_cell_range_by_sheet_as_array sheet, left, top, right, bottom
254
+
255
+ # This method returns a cell object from a cell range object, based on a cell range object,
256
+ # column, and row.
257
+ # Author:: Nathan Lane
258
+ # Last Updated: 11/13/2007
259
+
260
+ def get_cell_by_cell_range cell_range, column, row
261
+ if column.class == String
262
+ column = parse_alpha_column_label column
263
+ end # End: if column.class == String
264
+
265
+ if cell_range.class == WIN32OLE
266
+ cell_range.getCellByPosition column, row
267
+ end # End: if cell_range.class == WIN32OLE
268
+ end # End: def get_cell_by_cell_range cell_range
269
+
270
+ # This method returns the number of columns in a cell range object.
271
+ # Author:: Nathan Lane
272
+ # Last Updated: 11/13/2007
273
+
274
+ def get_cell_range_columns_count cell_range
275
+ if cell_range.class == WIN32OLE
276
+ cell_range.Columns.Count
277
+ else
278
+ raise "Cell range must be an object"
279
+ end # End: if cell_range.class == WIN32OLE
280
+ end # End: def get_cell_range_columns_count cell_range
281
+
282
+ # This method returns the number of rows in a cell range object.
283
+ # Author:: Nathan Lane
284
+ # Last Updated: 11/13/2007
285
+
286
+ def get_cell_range_rows_count cell_range
287
+ if cell_range.class == WIN32OLE
288
+ cell_range.Rows.Count
289
+ else
290
+ raise "Cell range must be an object"
291
+ end # End: if cell_range.class == WIN32OLE
292
+ end # End: def get_cell_range_rows_count cell_range
293
+
294
+ # This method returns the dimensions of a cell range object as a two-element array.
295
+ # Author:: Nathan Lane
296
+ # Last Updated: 11/13/2007
297
+
298
+ def get_cell_range_dimensions cell_range
299
+ if cell_range.class == WIN32OLE
300
+ [ cell_range.Columns.Count, cell_range.Rows.Count ]
301
+ else
302
+ raise "Cell range must be an object"
303
+ end # End: if cell_range.class == WIN32OLE
304
+ end # End: def get_cell_range_dimensions cell_range
305
+
306
+ # This method returns the numeric value of a cell by sheet and column, row location.
307
+ # Author:: Nathan Lane
308
+ # Last Updated: 11/13/2007
309
+
310
+ def get_cell_value_by_sheet column, row, sheet = @current_sheet
311
+ if column.class == String
312
+ column = parse_alpha_column_label column
313
+ end # End: if column.class == String
314
+
315
+ get_cell_by_sheet(column, row, sheet).Value
316
+ end # End: def get_cell_value_by_sheet sheet, column, row
317
+
318
+ # This method returns the String value of a cell by sheet and column, row location.
319
+ # Author:: Nathan Lane
320
+ # Last Updated: 11/13/2007
321
+
322
+ def get_cell_string_by_sheet column, row, sheet = @current_sheet
323
+ if column.class == String
324
+ column = parse_alpha_column_label column
325
+ end # End: if column.class == String
326
+
327
+ get_cell_by_sheet(column, row, sheet).String
328
+ end # End: def get_cell_value_by_sheet sheet, column, row
329
+
330
+ # This method returns the formula value of a cell by sheet and column, row location.
331
+ # Author:: Nathan Lane
332
+ # Last Updated: 11/13/2007
333
+
334
+ def get_cell_formula_by_sheet column, row, sheet = @current_sheet
335
+ if column.class == String
336
+ column = parse_alpha_column_label column
337
+ end # End: if column.class == String
338
+
339
+ get_cell_by_sheet(column, row, sheet).Formula
340
+ end # End: def get_cell_number_by_sheet sheet, column, row
341
+
342
+ # This method returns the numeric value of a cell by cell range and column, row location.
343
+ # Author:: Nathan Lane
344
+ # Last Updated: 11/13/2007
345
+
346
+ def get_cell_value_by_cell_range cell_range, column, row
347
+ if column.class == String
348
+ column = parse_alpha_column_label column
349
+ end # End: if column.class == String
350
+
351
+ get_cell_by_cell_range(cell_range, column, row).Value
352
+ end # End: def get_cell_value_by_cell_range cell_range, column, row
353
+
354
+ # This method returns the String value of a cell by cell range and column, row location.
355
+ # Author:: Nathan Lane
356
+ # Last Updated: 11/13/2007
357
+
358
+ def get_cell_string_by_cell_range cell_range, column, row
359
+ if column.class == String
360
+ column = parse_alpha_column_label column
361
+ end # End: if column.class == String
362
+
363
+ get_cell_by_cell_range(cell_range, column, row).String
364
+ end # End: def get_cell_value_by_cell_range cell_range, column, row
365
+
366
+ # This method returns the formula value of a cell by cell range and column, row location.
367
+ # Author:: Nathan Lane
368
+ # Last Updated: 11/13/2007
369
+
370
+ def get_cell_formula_by_cell_range cell_range, column, row
371
+ if column.class == String
372
+ column = parse_alpha_column_label column
373
+ end # End: if column.class == String
374
+
375
+ get_cell_by_cell_range(cell_range, column, row).Formula
376
+ end # End: def get_cell_number_by_cell_range cell_range, column, row
377
+
378
+ # This method returns the numeric value of a cell by OpenOffice cell notation.
379
+ # Author:: Nathan Lane
380
+ # Last Updated: 11/13/2007
381
+
382
+ def get_cell_value_by_oo_notation oo_notation
383
+ oo_notation_format = /^[A-Za-z\d\s]+[.]{1}([Aa]+|[Bb]+|[Cc]+|[Dd]+|[Ee]+|[Ff]+|[Gg]+|[Hh]+|[Ii]+|[Jj]+|[Kk]+|[Ll]+|[Mm]+|[Nn]+|[Oo]+|[Pp]+|[Qq]+|[Rr]+|[Ss]+|[Tt]+|[Uu]+|[Vv]+|[Ww]+|[Xx]+|[Yy]+|[Zz]+)([\d]+)$/
384
+ if oo_notation =~ oo_notation_format
385
+ get_cell_by_oo_notation(oo_notation).Value
386
+ else
387
+ raise "OO notation was malformed, please use SheetName.CellName"
388
+ end # End: if oo_notation =~ oo_notation_format
389
+ end # End: def get_cell_value_by_oo_notation oo_notation
390
+
391
+ # This method returns the String value of a cell by OpenOffice cell notation.
392
+ # Author:: Nathan Lane
393
+ # Last Updated: 11/13/2007
394
+
395
+ def get_cell_string_by_oo_notation oo_notation
396
+ oo_notation_format = /^[A-Za-z\d\s]+[.]{1}([Aa]+|[Bb]+|[Cc]+|[Dd]+|[Ee]+|[Ff]+|[Gg]+|[Hh]+|[Ii]+|[Jj]+|[Kk]+|[Ll]+|[Mm]+|[Nn]+|[Oo]+|[Pp]+|[Qq]+|[Rr]+|[Ss]+|[Tt]+|[Uu]+|[Vv]+|[Ww]+|[Xx]+|[Yy]+|[Zz]+)([\d]+)$/
397
+ if oo_notation =~ oo_notation_format
398
+ get_cell_by_oo_notation(oo_notation).String
399
+ else
400
+ raise "OO notation was malformed, please use SheetName.CellName"
401
+ end # End: if oo_notation =~ oo_notation_format
402
+ end # End: def get_cell_value_by_oo_notation oo_notation
403
+
404
+ # This method returns the formula value of a cell by OpenOffice cell notation.
405
+ # Author:: Nathan Lane
406
+ # Last Updated: 11/13/2007
407
+
408
+ def get_cell_formula_by_oo_notation oo_notation
409
+ oo_notation_format = /^[A-Za-z\d\s]+[.]{1}([Aa]+|[Bb]+|[Cc]+|[Dd]+|[Ee]+|[Ff]+|[Gg]+|[Hh]+|[Ii]+|[Jj]+|[Kk]+|[Ll]+|[Mm]+|[Nn]+|[Oo]+|[Pp]+|[Qq]+|[Rr]+|[Ss]+|[Tt]+|[Uu]+|[Vv]+|[Ww]+|[Xx]+|[Yy]+|[Zz]+)([\d]+)$/
410
+ if oo_notation =~ oo_notation_format
411
+ get_cell_by_oo_notation(oo_notation).Formula
412
+ else
413
+ raise "OO notation was malformed, please use SheetName.CellName"
414
+ end # End: if oo_notation =~ oo_notation_format
415
+ end # End: def get_cell_number_by_oo_notation oo_notation
416
+
417
+ # This method returns the number of sheets in the spreadsheet document.
418
+ # Author:: Nathan Lane
419
+ # Last Updated: 11/13/2007
420
+
421
+ def get_sheet_count
422
+ get_sheets_collection.Count
423
+ end # End: def get_sheet_count
424
+
425
+ # This method is used by other methods to locate a column by its alphabetic label, for example
426
+ # A.
427
+ # Author:: Nathan Lane
428
+ # Last Updated: 11/13/2007
429
+
430
+ def parse_alpha_column_label alpha_column_label
431
+ if alpha_column_label.class == String
432
+ column_label_regex = /^([Aa]+|[Bb]+|[Cc]+|[Dd]+|[Ee]+|[Ff]+|[Gg]+|[Hh]+|[Ii]+|[Jj]+|[Kk]+|[Ll]+|[Mm]+|[Nn]+|[Oo]+|[Pp]+|[Qq]+|[Rr]+|[Ss]+|[Tt]+|[Uu]+|[Vv]+|[Ww]+|[Xx]+|[Yy]+|[Zz]+)$/
433
+ alpha_column_label.downcase!
434
+ if alpha_column_label =~ column_label_regex
435
+ index = 0
436
+ multiplyer = 1
437
+ column_index = 0
438
+
439
+ while index < alpha_column_label.length
440
+ column_index = column_index + (multiplyer * (alpha_column_label[index] - ASCIIDIFFERENCE))
441
+
442
+ index = index + 1
443
+ multiplyer = multiplyer * 26
444
+ end # End: while index < alpha_column_label.length
445
+
446
+ return column_index
447
+ else
448
+ raise "Column labels must only be alphabet characters and must be the same, like A or Aa"
449
+ end # End: if alpha_column_label =~ column_label_regex
450
+ end # End: if alpha_column_label.class == String
451
+ end # End: def parse_alpha_column_label alpha_column_label
452
+
453
+ # This method sets the numeric value of a cell by sheet and column, row location.
454
+ # Author:: Nathan Lane
455
+ # Last Updated: 11/13/2007
456
+
457
+ def set_cell_value_by_sheet column, row, value, sheet = @current_sheet
458
+ if column.class == String
459
+ column = parse_alpha_column_label column
460
+ end # End: if column.class == String
461
+
462
+ get_cell_by_sheet(column, row, sheet).Value = value
463
+ end # End: def set_cell_value_by_sheet sheet, column, row, value
464
+
465
+ # This method sets the String value of a cell by sheet and column, row location.
466
+ # Author:: Nathan Lane
467
+ # Last Updated: 11/13/2007
468
+
469
+ def set_cell_string_by_sheet column, row, string, sheet = @current_sheet
470
+ if column.class == String
471
+ column = parse_alpha_column_label column
472
+ end # End: if column.class == String
473
+
474
+ get_cell_by_sheet(column, row, sheet).String = string
475
+ end # End: def set_cell_value_by_sheet sheet, column, row, string
476
+
477
+ # This method sets the formula value of a cell by sheet and column, row location.
478
+ # Author:: Nathan Lane
479
+ # Last Updated: 11/13/2007
480
+
481
+ def set_cell_formula_by_sheet column, row, formula, sheet = @current_sheet
482
+ if column.class == String
483
+ column = parse_alpha_column_label column
484
+ end # End: if column.class == String
485
+
486
+ get_cell_by_sheet(column, row, sheet).Formula = formula
487
+ end # End: def set_cell_number_by_sheet sheet, column, row, formula
488
+
489
+ # This method sets the numeric value of a cell by cell range and column, row location.
490
+ # Author:: Nathan Lane
491
+ # Last Updated: 11/13/2007
492
+
493
+ def set_cell_value_by_cell_range cell_range, column, row, value
494
+ if column.class == String
495
+ column = parse_alpha_column_label column
496
+ end # End: if column.class == String
497
+
498
+ get_cell_by_cell_range(cell_range, column, row).Value = value
499
+ end # End: def set_cell_value_by_cell_range cell_range, column, row, value
500
+
501
+ # This method sets the String value of a cell by cell range and column, row location.
502
+ # Author:: Nathan Lane
503
+ # Last Updated: 11/13/2007
504
+
505
+ def set_cell_string_by_cell_range cell_range, column, row, string
506
+ if column.class == String
507
+ column = parse_alpha_column_label column
508
+ end # End: if column.class == String
509
+
510
+ get_cell_by_cell_range(cell_range, column, row).String = string
511
+ end # End: def set_cell_value_by_cell_range cell_range, column, row, string
512
+
513
+ # This method sets the formula value of a cell by cell range and column, row location.
514
+ # Author:: Nathan Lane
515
+ # Last Updated: 11/13/2007
516
+
517
+ def set_cell_formula_by_cell_range cell_range, column, row, formula
518
+ if column.class == String
519
+ column = parse_alpha_column_label column
520
+ end # End: if column.class == String
521
+
522
+ get_cell_by_cell_range(cell_range, column, row).Formula = formula
523
+ end # End: def set_cell_number_by_cell_range cell_range, column, row, formula
524
+
525
+ # This method sets the numeric value of a cell by OpenOffice cell notation and column, row
526
+ # location.
527
+ # Author:: Nathan Lane
528
+ # Last Updated: 11/13/2007
529
+
530
+ def set_cell_value_by_oo_notation oo_notation, value
531
+ oo_notation_format = /^[A-Za-z\d\s]+[.]{1}([Aa]+|[Bb]+|[Cc]+|[Dd]+|[Ee]+|[Ff]+|[Gg]+|[Hh]+|[Ii]+|[Jj]+|[Kk]+|[Ll]+|[Mm]+|[Nn]+|[Oo]+|[Pp]+|[Qq]+|[Rr]+|[Ss]+|[Tt]+|[Uu]+|[Vv]+|[Ww]+|[Xx]+|[Yy]+|[Zz]+)([\d]+)$/
532
+ if oo_notation =~ oo_notation_format
533
+ get_cell_by_oo_notation(oo_notation).Value = value
534
+ else
535
+ raise "OO notation was malformed, please use SheetName.CellName"
536
+ end # End: if oo_notation =~ oo_notation_format
537
+ end # End: def set_cell_value_by_oo_notation oo_notation, value
538
+
539
+ # This method sets the String value of a cell by OpenOffice cell notation and column, row
540
+ # location.
541
+ # Author:: Nathan Lane
542
+ # Last Updated: 11/13/2007
543
+
544
+ def set_cell_string_by_oo_notation oo_notation, string
545
+ oo_notation_format = /^[A-Za-z\d\s]+[.]{1}([Aa]+|[Bb]+|[Cc]+|[Dd]+|[Ee]+|[Ff]+|[Gg]+|[Hh]+|[Ii]+|[Jj]+|[Kk]+|[Ll]+|[Mm]+|[Nn]+|[Oo]+|[Pp]+|[Qq]+|[Rr]+|[Ss]+|[Tt]+|[Uu]+|[Vv]+|[Ww]+|[Xx]+|[Yy]+|[Zz]+)([\d]+)$/
546
+ if oo_notation =~ oo_notation_format
547
+ get_cell_by_oo_notation(oo_notation).String = string
548
+ else
549
+ raise "OO notation was malformed, please use SheetName.CellName"
550
+ end # End: if oo_notation =~ oo_notation_format
551
+ end # End: def set_cell_value_by_oo_notation oo_notation, string
552
+
553
+ # This method sets the formula value of a cell by OpenOffice cell notation and column, row
554
+ # location.
555
+ # Author:: Nathan Lane
556
+ # Last Updated: 11/13/2007
557
+
558
+ def set_cell_formula_by_oo_notation oo_notation, formula
559
+ oo_notation_format = /^[A-Za-z\d\s]+[.]{1}([Aa]+|[Bb]+|[Cc]+|[Dd]+|[Ee]+|[Ff]+|[Gg]+|[Hh]+|[Ii]+|[Jj]+|[Kk]+|[Ll]+|[Mm]+|[Nn]+|[Oo]+|[Pp]+|[Qq]+|[Rr]+|[Ss]+|[Tt]+|[Uu]+|[Vv]+|[Ww]+|[Xx]+|[Yy]+|[Zz]+)([\d]+)$/
560
+ if oo_notation =~ oo_notation_format
561
+ get_cell_by_oo_notation(oo_notation).Formula = formula
562
+ else
563
+ raise "OO notation was malformed, please use SheetName.CellName"
564
+ end # End: if oo_notation =~ oo_notation_format
565
+ end # End: def set_cell_number_by_oo_notation oo_notation, formula
566
+
567
+ # This method saves the current spreadsheet according to the URI you provide as the file path. The
568
+ # URI must be in the format file:///driveletter:/path/to/file.ods
569
+ # Author:: Nathan Lane
570
+ # Last Updated: 11/13/2007
571
+
572
+ def save file_path = nil, args = []
573
+ if file_path =~ /^(file:\/\/\/)[a-zA-Z]{1}[:]{1}[\/a-zA-Z\d\s._-]+(ods|xls|csv){1}$/
574
+ file_uri = file_path
575
+ file_args = args
576
+ @spreadsheet.storeAsURL file_uri, file_args
577
+ elsif file_path.nil? and !@file_uri.nil?
578
+ if @file_uri =~ /^[a-zA-Z]{1}[:]{1}[\/a-zA-Z\d\s._-]+(ods|xls|csv){1}$/
579
+ full_file_uri = "file:///" + @file_uri
580
+ else
581
+ full_file_uri = @file_uri
582
+ end # End: if @file_uri =~ /^[a-zA-Z]{1}[:]{1}[\/a-zA-Z\d\s._-]+(ods|xls|csv){1}$/
583
+
584
+ file_args = args
585
+ @spreadsheet.storeAsURL full_file_uri, file_args
586
+ else
587
+ raise "Malformed URI: only support for xls and ods files is currently available or file path not supplied"
588
+ end # End: if filepath =~ /^(file:\/\/\/)[a-zA-Z]{1}[:]{1}[\/a-zA-Z\d\s._-]+(ods|xls|csv){1}$/
589
+ end # End: def save file_path
590
+
591
+ # This method saves the current spreadshet in a different form according to what you provide as
592
+ # the format.
593
+ # Author:: Nathan Lane
594
+ # Last Updated: 11/13/2007
595
+
596
+ def save_as file_type = :ods, file_path = nil, args = []
597
+ case file_type
598
+ when :ods
599
+ args = args
600
+
601
+ # Fix the URI
602
+ if file_path.nil?
603
+ file_suffix = "ods"
604
+
605
+ if @file_uri["xls"] or @file_uri["csv"]
606
+ len = @file_uri.length - 1
607
+ @file_uri = @file_uri[0..(len - 3)] + file_suffix
608
+ end
609
+ else
610
+ file_suffix = "xls"
611
+
612
+ if file_path["ods"] or file_path["csv"]
613
+ len = @file_uri.length - 1
614
+ file_path = file_path[0..(len - 3)] + file_suffix
615
+ end
616
+ end # End: if file_path.nil?
617
+ when :excel97
618
+ excel_filter = UNO.create_property_value "FilterName", "MS Excel 97"
619
+ args = args + [ excel_filter ]
620
+
621
+ # Fix the URI
622
+ if file_path.nil?
623
+ file_suffix = "xls"
624
+
625
+ if @file_uri["ods"] or @file_uri["csv"]
626
+ len = @file_uri.length - 1
627
+ @file_uri = @file_uri[0..(len - 3)] + file_suffix
628
+ end
629
+ else
630
+ file_suffix = "xls"
631
+
632
+ if file_path["ods"] or file_path["csv"]
633
+ len = @file_uri.length - 1
634
+ file_path = file_path[0..(len - 3)] + file_suffix
635
+ end
636
+ end # End: if file_path.nil?
637
+ when :csv
638
+ csv_filter = UNO.create_property_value "FilterName", "Text - txt - csv (StarCalc)"
639
+ args = args + [ csv_filter ]
640
+ else
641
+ raise "Unsupported file type only :ods, :excel97, and :csv are supported"
642
+ end # End: case file_type
643
+
644
+ save file_path, args
645
+ end # End: def save_as file_path, args = [], file_type = :ods
646
+
647
+ # This method closes the current spreadsheet.
648
+ # Author:: Nathan Lane
649
+ # Last Updated: 11/13/2007
650
+
651
+ def close
652
+ @spreadsheet.close(0)
653
+ @spreadsheet
654
+ end # End: def close
655
+
656
+ # This method gets the formula and returns a String of a cell in a sheet by the cell's column and
657
+ # row. Fixnum variants of Sheet, Column, and Row must be the 1-based, so Sheet1 would be index 1,
658
+ # column A would be column 1, and row 11 would be row 11.
659
+ # Author:: Nathan Lane
660
+ # Last Updated: 11/13/2007
661
+
662
+ def get_cell_contents column, row, sheet = @current_sheet
663
+ if sheet.class == Fixnum
664
+ # Decrement the sheet if it's greater than zero
665
+ if sheet > 0
666
+ sheet = sheet - 1
667
+ end # End: if sheet > 0
668
+
669
+ if column.class == Fixnum
670
+ # Decrement the column if it's greater than zero
671
+ if column > 0
672
+ column = column - 1
673
+ end # End: if column > 0
674
+
675
+ if row.class == Fixnum
676
+ # Decrement the row if it's greater than zero
677
+ if row > 0
678
+ row = row - 1
679
+ end # End: if row > 0
680
+
681
+ get_cell_formula_by_sheet column, row, sheet
682
+ else
683
+ raise "row must be a numeric value"
684
+ end
685
+ elsif column.class == String
686
+ # Need to parse the string column label to a Fixnum
687
+ col = parse_alpha_column_label column
688
+
689
+ if row.class == Fixnum
690
+ # Decrement the row if it's greater than zero
691
+ if row > 0
692
+ row = row - 1
693
+ end # End: if row > 0
694
+
695
+ get_cell_formula_by_sheet column, row, sheet
696
+ else
697
+ raise "row must be a numeric value"
698
+ end
699
+ else
700
+ raise "column must be either a numeric or alphabetic value"
701
+ end
702
+ elsif sheet.class == String or sheet.class == WIN32OLE
703
+ if column.class == Fixnum
704
+ # Decrement the column if it's greater than zero
705
+ if column > 0
706
+ column = column - 1
707
+ end # End: if column > 0
708
+
709
+ if row.class == Fixnum
710
+ # Decrement the row if it's greater than zero
711
+ if row > 0
712
+ row = row - 1
713
+ end # End: if row > 0
714
+
715
+ get_cell_formula_by_sheet column, row, sheet
716
+ else
717
+ raise "row must be a numeric value"
718
+ end
719
+ elsif column.class == String
720
+ # Need to parse the string column label to a Fixnum
721
+ col = parse_alpha_column_label column
722
+
723
+ if row.class == Fixnum
724
+ # Decrement the row if it's greater than zero
725
+ if row > 0
726
+ row = row - 1
727
+ end # End: if row > 0
728
+
729
+ get_cell_formula_by_sheet column, row, sheet
730
+ else
731
+ raise "row must be a numeric value"
732
+ end
733
+ else
734
+ raise "column must be either a numeric or alphabetic value"
735
+ end
736
+ else
737
+ raise "sheet must be either the numeric index or the name of the sheet"
738
+ end # End: if (sheet.class == Fixnum or sheet.class == String) and (column.class == Fixnum or column.class == String) and row.class == Fixnum
739
+ end # End: def get_cell_contents sheet, column, row
740
+
741
+ # This method sets the formula of a cell in a sheet by the cell's column and row. Fixnum variants
742
+ # of Sheet, Column, and Row must be the 1-based, so Sheet1 would be index 1, column A would be
743
+ # column 1, and row 11 would be row 11.
744
+ # Author:: Nathan Lane
745
+ # Last Updated: 11/13/2007
746
+
747
+ def set_cell_contents column, row, value, sheet = @current_sheet
748
+ if sheet.class == Fixnum
749
+ # Decrement the sheet if it's greater than zero
750
+ if sheet > 0
751
+ sheet = sheet - 1
752
+ end # End: if sheet > 0
753
+
754
+ if column.class == Fixnum
755
+ # Decrement the column if it's greater than zero
756
+ if column > 0
757
+ column = column - 1
758
+ end # End: if column > 0
759
+
760
+ if row.class == Fixnum
761
+ # Decrement the row if it's greater than zero
762
+ if row > 0
763
+ row = row - 1
764
+ end # End: if row > 0
765
+
766
+ set_cell_formula_by_sheet column, row, value, sheet
767
+ else
768
+ raise "row must be a numeric value"
769
+ end
770
+ elsif column.class == String
771
+ # Need to parse the string column label to a Fixnum
772
+ col = parse_alpha_column_label column
773
+
774
+ if row.class == Fixnum
775
+ # Decrement the row if it's greater than zero
776
+ if row > 0
777
+ row = row - 1
778
+ end # End: if row > 0
779
+
780
+ set_cell_formula_by_sheet column, row, value, sheet
781
+ else
782
+ raise "row must be a numeric value"
783
+ end
784
+ else
785
+ raise "column must be either a numeric or alphabetic value"
786
+ end
787
+ elsif sheet.class == String or sheet.class == WIN32OLE
788
+ if column.class == Fixnum
789
+ # Decrement the column if it's greater than zero
790
+ if column > 0
791
+ column = column - 1
792
+ end # End: if column > 0
793
+
794
+ if row.class == Fixnum
795
+ # Decrement the row if it's greater than zero
796
+ if row > 0
797
+ row = row - 1
798
+ end # End: if row > 0
799
+
800
+ set_cell_formula_by_sheet column, row, value, sheet
801
+ else
802
+ raise "row must be a numeric value"
803
+ end # End: if row.class == Fixnum
804
+ elsif column.class == String
805
+ # Need to parse the string column label to a Fixnum
806
+ col = parse_alpha_column_label column
807
+
808
+ if row.class == Fixnum
809
+ # Decrement the row if it's greater than zero
810
+ if row > 0
811
+ row = row - 1
812
+ end # End: if row > 0
813
+
814
+ set_cell_formula_by_sheet column, row, value, sheet
815
+ else
816
+ raise "row must be a numeric value"
817
+ end # End: if row.class == Fixnum
818
+ else
819
+ raise "column must be either a numeric or alphabetic value"
820
+ end # End: if column.class == Fixnum
821
+ else
822
+ raise "sheet must be either the numeric index or the name of the sheet"
823
+ end # End: if (sheet.class == Fixnum or sheet.class == String) and (column.class == Fixnum or column.class == String) and row.class == Fixnum
824
+ end # End: def set_cell_contents sheet, column, row, value
825
+
826
+ # This method returns an array of string based on the criteria given. Sheets by index are 1-based.
827
+ # Author:: Nathan Lane
828
+ # Last Updated: 11/13/2007
829
+
830
+ def get_cell_range_contents column1, row1, column2, row2, sheet = @current_sheet
831
+ left = -1
832
+ top = -1
833
+ right = -1
834
+ bottom = -1
835
+
836
+ if sheet.class == Fixnum
837
+ if sheet > 0
838
+ sheet = sheet - 1
839
+ end # End: if sheet > 0
840
+ end # End: if sheet.class == Fixnum
841
+
842
+ if column1.class == String
843
+ left = parse_alpha_column_label column1
844
+ elsif column1.class == Fixnum
845
+ if column1 > 0
846
+ left = column1 - 1
847
+ else
848
+ left = column1
849
+ end # End: if column1 > 0
850
+ end # End: if column1.class == String
851
+
852
+ if row1.class == String
853
+ raise "row1 must be numeric"
854
+ elsif row1.class == Fixnum
855
+ if row1 > 0
856
+ top = row1 - 1
857
+ else
858
+ top = row1
859
+ end # End: if row1 > 0
860
+ else
861
+ raise "row1 must be numeric"
862
+ end # End: if row1.class == String
863
+
864
+ if column2.class == String
865
+ right = parse_alpha_column_label column2
866
+ elsif column2.class == Fixnum
867
+ if column2 > 0
868
+ right = column2 - 1
869
+ else
870
+ right = column2
871
+ end # End: if column2 > 0
872
+ end # End: if column2.class == String
873
+
874
+ if row2.class == String
875
+ raise "row2 must be numeric"
876
+ elsif row2.class == Fixnum
877
+ if row2 > 0
878
+ bottom = row2 - 1
879
+ else
880
+ bottom = row2
881
+ end # End: if row1 > 0
882
+ else
883
+ raise "row2 must be numeric"
884
+ end # End: if row2.class == String
885
+
886
+ get_cell_range_by_sheet_as_array left, top, right, bottom, sheet
887
+ end # End: def get_cell_range_contents sheet, column1, row1, column2, row2
888
+
889
+ end # End: class Calc
890
+
891
+ end # End: module OpenOffice