robust_excel_ole 1.3 → 1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog +6 -0
  3. data/README.rdoc +1 -1
  4. data/docs/README_open.rdoc +1 -1
  5. data/docs/README_ranges.rdoc +60 -57
  6. data/docs/README_sheet.rdoc +1 -1
  7. data/examples/introducing_examples/example_introducing.rb +42 -0
  8. data/examples/introducing_examples/example_open.rb +49 -0
  9. data/examples/introducing_examples/example_range.rb +67 -0
  10. data/examples/{edit_sheets → modifying_sheets}/example_access_sheets_and_cells.rb +0 -0
  11. data/examples/{edit_sheets → modifying_sheets}/example_adding_sheets.rb +0 -0
  12. data/examples/{edit_sheets → modifying_sheets}/example_concating.rb +1 -1
  13. data/examples/{edit_sheets → modifying_sheets}/example_copying.rb +1 -1
  14. data/examples/{edit_sheets → modifying_sheets}/example_expanding.rb +1 -1
  15. data/examples/{edit_sheets → modifying_sheets}/example_naming.rb +1 -1
  16. data/examples/{edit_sheets → modifying_sheets}/example_ranges.rb +1 -1
  17. data/examples/{edit_sheets → modifying_sheets}/example_saving.rb +1 -1
  18. data/examples/open_save_close/example_control_to_excel.rb +2 -2
  19. data/examples/open_save_close/example_if_obstructed_save.rb +2 -2
  20. data/examples/open_save_close/example_if_unsaved_accept.rb +1 -1
  21. data/examples/open_save_close/example_if_unsaved_forget.rb +3 -3
  22. data/examples/open_save_close/example_if_unsaved_forget_more.rb +4 -4
  23. data/examples/open_save_close/example_read_only.rb +1 -1
  24. data/examples/open_save_close/example_rename_cells.rb +1 -1
  25. data/examples/open_save_close/example_simple.rb +1 -1
  26. data/examples/open_save_close/example_unobtrusively.rb +3 -3
  27. data/lib/robust_excel_ole.rb +2 -2
  28. data/lib/robust_excel_ole/bookstore.rb +1 -1
  29. data/lib/robust_excel_ole/cell.rb +15 -2
  30. data/lib/robust_excel_ole/excel.rb +14 -12
  31. data/lib/robust_excel_ole/general.rb +12 -0
  32. data/lib/robust_excel_ole/range.rb +37 -20
  33. data/lib/robust_excel_ole/reo_common.rb +63 -37
  34. data/lib/robust_excel_ole/version.rb +1 -1
  35. data/lib/robust_excel_ole/{book.rb → workbook.rb} +35 -33
  36. data/lib/robust_excel_ole/{sheet.rb → worksheet.rb} +22 -22
  37. data/spec/bookstore_spec.rb +38 -38
  38. data/spec/cell_spec.rb +10 -10
  39. data/spec/data/another_workbook.xls +0 -0
  40. data/spec/data/workbook.xls +0 -0
  41. data/spec/excel_spec.rb +113 -105
  42. data/spec/general_spec.rb +37 -5
  43. data/spec/range_spec.rb +34 -19
  44. data/spec/reo_common_spec.rb +58 -48
  45. data/spec/{book_spec.rb → workbook_spec.rb} +198 -198
  46. data/spec/workbook_specs/workbook_all_spec.rb +33 -0
  47. data/spec/{book_specs/book_close_spec.rb → workbook_specs/workbook_close_spec.rb} +10 -10
  48. data/spec/{book_specs/book_misc_spec.rb → workbook_specs/workbook_misc_spec.rb} +148 -128
  49. data/spec/{book_specs/book_open_spec.rb → workbook_specs/workbook_open_spec.rb} +427 -427
  50. data/spec/{book_specs/book_save_spec.rb → workbook_specs/workbook_save_spec.rb} +44 -44
  51. data/spec/{book_specs/book_sheet_spec.rb → workbook_specs/workbook_sheet_spec.rb} +19 -19
  52. data/spec/{book_specs/book_subclass_spec.rb → workbook_specs/workbook_subclass_spec.rb} +5 -6
  53. data/spec/{book_specs/book_unobtr_spec.rb → workbook_specs/workbook_unobtr_spec.rb} +339 -344
  54. data/spec/{sheet_spec.rb → worksheet_spec.rb} +85 -55
  55. metadata +25 -22
  56. data/spec/book_specs/book_all_spec.rb +0 -22
@@ -95,7 +95,7 @@ module RobustExcelOle
95
95
  class REOCommon
96
96
 
97
97
  def excel
98
- raise TypeREOError, "receiver instance is neither an Excel nor a Book"
98
+ raise TypeREOError, "receiver instance is neither an Excel nor a Workbook"
99
99
  end
100
100
 
101
101
  def own_methods
@@ -142,36 +142,53 @@ module RobustExcelOle
142
142
 
143
143
  attr_reader :rows
144
144
  attr_reader :columns
145
- attr_reader :a1_format
146
145
 
147
- def initialize(address_comp1, address_comp2 = __not_provided)
146
+ def initialize(address)
147
+ address = [address] unless address.is_a?(Array)
148
+ raise AddressInvalid, "more than two components" if address.size > 2
148
149
  begin
149
- if address_comp2 == __not_provided
150
- row_comp = address_comp1.gsub(/[0-9]/,'')
151
- column_comp = address_comp1.gsub(/[A-Z]/,'')
152
- if address_comp1 != column_comp+row_comp
153
- raise AddressInvalid, "address #{address_comp1.inspect} not in A1-format"
154
- end
155
- address_comp1, address_comp2 = column_comp, row_comp
150
+ if address.size == 1
151
+ comp1, comp2 = address[0].split(':')
152
+ address_comp1 = comp1.gsub(/[A-Z]/,'')
153
+ address_comp2 = comp1.gsub(/[0-9]/,'')
154
+ if comp1 != address_comp2+address_comp1
155
+ raise AddressInvalid, "address #{comp1.inspect} not in A1-format"
156
+ end
157
+ unless comp2.nil?
158
+ address_comp3 = comp2.gsub(/[A-Z]/,'')
159
+ address_comp4 = comp2.gsub(/[0-9]/,'')
160
+ if comp2 != address_comp4+address_comp3
161
+ raise AddressInvalid, "address #{comp2.inspect} not in A1-format"
162
+ end
163
+ address_comp1 = address_comp1..address_comp3
164
+ address_comp2 = address_comp2..address_comp4
165
+ end
166
+ else
167
+ address_comp1, address_comp2 = address
156
168
  end
157
- address_comp1 = address_comp1 .. address_comp1 unless address_comp1.is_a?(Range)
158
- address_comp2 = address_comp2 .. address_comp2 unless address_comp2.is_a?(Range)
159
- if address_comp1.min.is_a?(String)
160
- raise AddressInvalid, "address (#{address_comp1.inspect}, #{address_comp2.inspect}) not in A1-format" if address_comp2.min.is_a?(String)
161
- @columns = address_comp1
162
- @rows = address_comp2
163
- @a1_format = true
169
+ address_comp1 = address_comp1 .. address_comp1 unless address_comp1.is_a?(Object::Range)
170
+ address_comp2 = address_comp2 .. address_comp2 unless address_comp2.is_a?(Object::Range)
171
+ @rows = address_comp1.min.to_i .. address_comp1.max.to_i
172
+ if address_comp2.min.to_i == 0
173
+ raise AddressInvalid, "address (#{address_comp1.inspect}, #{address_comp2.inspect}) not in A1-format" if address_comp1.min.to_i == 0
174
+ @columns = str2num(address_comp2.min) .. str2num(address_comp2.max)
164
175
  else
165
- @columns = address_comp2
166
- @rows = address_comp1
167
- @a1_format = false
176
+ @columns = address_comp2.min.to_i .. address_comp2.max.to_i
168
177
  end
169
178
  rescue
170
- address_string = (address_comp2 == __not_provided) ?
171
- "#{address_comp1.inspect}" : "#{address_comp1.inspect}, #{address_comp2.inspect}"
172
- raise AddressInvalid, "address (#{address_string}) not in A1- or R1C1-format"
179
+ raise AddressInvalid, "address (#{address.inspect}) not in A1- or R1C1-format"
173
180
  end
174
181
  end
182
+
183
+ private
184
+
185
+ def str2num(str)
186
+ str = str.upcase
187
+ sum = 0
188
+ (1..str.length).each { |i| sum += (str[i-1].ord-64) * 26 ** (str.length - i) }
189
+ sum
190
+ end
191
+
175
192
  end
176
193
 
177
194
  class RangeOwners < REOCommon
@@ -196,8 +213,8 @@ module RobustExcelOle
196
213
  value = begin
197
214
  name_obj.RefersToRange.Value
198
215
  rescue WIN32OLERuntimeError
199
- sheet = if self.is_a?(Sheet) then self
200
- elsif self.is_a?(Book) then self.sheet(1)
216
+ sheet = if self.is_a?(Worksheet) then self
217
+ elsif self.is_a?(Workbook) then self.sheet(1)
201
218
  elsif self.is_a?(Excel) then self.workbook.sheet(1)
202
219
  end
203
220
  begin
@@ -240,7 +257,7 @@ module RobustExcelOle
240
257
  # @option opts [Symbol] :default the default value that is provided if no contents could be returned
241
258
  # @return [Variant] the contents of a range with given name
242
259
  def namevalue(name, opts = {:default => :__not_provided})
243
- return namevalue_glob(name, opts) if self.is_a?(Book)
260
+ return namevalue_glob(name, opts) if self.is_a?(Workbook)
244
261
  begin
245
262
  range = self.Range(name)
246
263
  rescue WIN32OLERuntimeError
@@ -267,7 +284,7 @@ module RobustExcelOle
267
284
  # @param [Hash] opts :color [FixNum] the color when setting the contents
268
285
  def set_namevalue(name, value, opts = {:color => 0})
269
286
  begin
270
- return set_namevalue_glob(name, value, opts) if self.is_a?(Book)
287
+ return set_namevalue_glob(name, value, opts) if self.is_a?(Workbook)
271
288
  range = self.Range(name)
272
289
  rescue WIN32OLERuntimeError
273
290
  raise NameNotFound, "name #{name.inspect} not in #{self.inspect}"
@@ -297,23 +314,32 @@ module RobustExcelOle
297
314
  set_namevalue(name, value, opts)
298
315
  end
299
316
 
317
+ # @params [String] name defined range name
318
+ # @returns [Range] a Range object
319
+ def name2range(name)
320
+ begin
321
+ RobustExcelOle::Range.new(name_object(name).RefersToRange)
322
+ rescue WIN32OLERuntimeError
323
+ raise RangeNotCreated, "range could not be created from the defined name"
324
+ end
325
+ end
326
+
300
327
  # adds a name referring to a range given by the row and column
301
328
  # @param [String] name the range name
302
- # @params [Fixnum,Range] row or range of the rows
303
- # @params [Fixnum,Range] column or range of columns
304
- def add_name(name, int_range1, int_range2)
305
- int_range1 = int_range1 .. int_range1 if int_range1.is_a?(Fixnum)
306
- int_range2 = int_range2 .. int_range2 if int_range2.is_a?(Fixnum)
307
- address = "Z" + int_range1.min.to_s + "S" + int_range2.min.to_s +
308
- ":Z" + int_range1.max.to_s + "S" + int_range2.max.to_s
329
+ # @params [Address] address of the range
330
+ def add_name(name, addr, addr_deprecated = :__not_provided)
331
+ addr = [addr,addr_deprecated] unless addr_deprecated == :__not_provided
332
+ address = Address.new(addr)
333
+ address_string = "Z" + address.rows.min.to_s + "S" + address.columns.min.to_s +
334
+ ":Z" + address.rows.max.to_s + "S" + address.columns.max.to_s
309
335
  begin
310
- self.Names.Add("Name" => name, "RefersToR1C1" => "=" + address)
336
+ self.Names.Add("Name" => name, "RefersToR1C1" => "=" + address_string)
311
337
  rescue WIN32OLERuntimeError => msg
312
338
  #trace "WIN32OLERuntimeError: #{msg.message}"
313
- raise RangeNotEvaluatable, "cannot add name #{name.inspect} to cell with row #{row.inspect} and column #{column.inspect}"
339
+ raise RangeNotEvaluatable, "cannot add name #{name.inspect} to range #{addr.inspect}"
314
340
  end
315
341
  name
316
- end
342
+ end
317
343
 
318
344
  def set_name(name,row,column) # :deprecated :#
319
345
  add_name(name,row,column)
@@ -1,3 +1,3 @@
1
1
  module RobustExcelOle
2
- VERSION = "1.3"
2
+ VERSION = "1.4"
3
3
  end
@@ -4,7 +4,9 @@ require 'weakref'
4
4
 
5
5
  module RobustExcelOle
6
6
 
7
- class Book < RangeOwners
7
+ # see https://docs.microsoft.com/en-us/office/vba/api/excel.workbook#methods
8
+
9
+ class Workbook < RangeOwners
8
10
 
9
11
  attr_accessor :excel
10
12
  attr_accessor :ole_workbook
@@ -73,7 +75,7 @@ module RobustExcelOle
73
75
  # :visible true -> makes the workbook visible
74
76
  # :check_compatibility true -> check compatibility when saving
75
77
  # :update_links true -> user is being asked how to update links, false -> links are never updated
76
- # @return [Book] a representation of a workbook
78
+ # @return [Workbook] a representation of a workbook
77
79
  def open(file, opts={ }, &block)
78
80
  options = @options = process_options(opts)
79
81
  book = nil
@@ -111,12 +113,12 @@ module RobustExcelOle
111
113
  end
112
114
  end
113
115
 
114
- # creates a Book object by opening an Excel file given its filename workbook or
115
- # by lifting a Win32OLE object representing an Excel file
116
+ # creates a Workbook object by opening an Excel file given its filename workbook
117
+ # or by promoting a Win32OLE object representing an Excel file
116
118
  # @param [WIN32OLE] workbook a workbook
117
119
  # @param [Hash] opts the options
118
120
  # @option opts [Symbol] see above
119
- # @return [Book] a workbook
121
+ # @return [Workbook] a workbook
120
122
  def self.new(workbook, opts={ }, &block)
121
123
  opts = process_options(opts)
122
124
  if workbook && (workbook.is_a? WIN32OLE)
@@ -136,12 +138,12 @@ module RobustExcelOle
136
138
  end
137
139
  end
138
140
 
139
- # creates a new Book object, if a file name is given
140
- # Promotes the workbook to a Book object, if a win32ole-workbook is given
141
+ # creates a new Workbook object, if a file name is given
142
+ # Promotes the win32ole workbook to a Workbook object, if a win32ole-workbook is given
141
143
  # @param [Variant] file_or_workbook file name or workbook
142
144
  # @param [Hash] opts the options
143
145
  # @option opts [Symbol] see above
144
- # @return [Book] a workbook
146
+ # @return [Workbook] a workbook
145
147
  def initialize(file_or_workbook, options={ }, &block)
146
148
  #options = @options = self.class.process_options(options) if options.empty?
147
149
  if file_or_workbook.is_a? WIN32OLE
@@ -210,7 +212,7 @@ module RobustExcelOle
210
212
  opts
211
213
  end
212
214
 
213
- # returns an Excel object when given Excel, Book or Win32ole object representing a Workbook or an Excel
215
+ # returns an Excel object when given Excel, Workbook or Win32ole object representing a Workbook or an Excel
214
216
  def self.excel_of(object) # :nodoc: #
215
217
  if object.is_a? WIN32OLE
216
218
  case object.ole_obj_help.name
@@ -478,7 +480,7 @@ module RobustExcelOle
478
480
  # @option opts [Boolean] :rw_change_excel Excel instance in which the workbook with the new
479
481
  # write permissions shall be opened :current (default), :new or an Excel instance
480
482
  # @option opts [Boolean] :keep_open whether the workbook shall be kept open after unobtrusively opening
481
- # @return [Book] a workbook
483
+ # @return [Workbook] a workbook
482
484
  def self.unobtrusively(file, opts = { }, &block)
483
485
  opts = {:if_closed => :current,
484
486
  :rw_change_excel => :current,
@@ -577,7 +579,7 @@ module RobustExcelOle
577
579
  # :close_if_saved -> closes the blocking workbook, if it is saved,
578
580
  # otherwise raises an exception
579
581
  # :discoloring states, whether colored ranges shall be discolored
580
- # @return [Book], the book itself, if successfully saved, raises an exception otherwise
582
+ # @return [Workbook], the book itself, if successfully saved, raises an exception otherwise
581
583
  def save_as(file, opts = { } )
582
584
  raise FileNameNotGiven, "filename is nil" if file.nil?
583
585
  raise ObjectNotAlive, "workbook is not alive" unless alive?
@@ -682,10 +684,10 @@ module RobustExcelOle
682
684
 
683
685
  # returns a sheet, if a sheet name or a number is given
684
686
  # @param [String] or [Number]
685
- # @returns [Sheet]
687
+ # @returns [Worksheet]
686
688
  def sheet(name)
687
689
  begin
688
- sheet_class.new(@ole_workbook.Worksheets.Item(name))
690
+ worksheet_class.new(@ole_workbook.Worksheets.Item(name))
689
691
  rescue WIN32OLERuntimeError => msg
690
692
  raise NameNotFound, "could not return a sheet with name #{name.inspect}"
691
693
  end
@@ -693,32 +695,32 @@ module RobustExcelOle
693
695
 
694
696
  def each
695
697
  @ole_workbook.Worksheets.each do |sheet|
696
- yield sheet_class.new(sheet)
698
+ yield worksheet_class.new(sheet)
697
699
  end
698
700
  end
699
701
 
700
702
  def each_with_index(offset = 0)
701
703
  i = offset
702
704
  @ole_workbook.Worksheets.each do |sheet|
703
- yield sheet_class.new(sheet), i
705
+ yield worksheet_class.new(sheet), i
704
706
  i += 1
705
707
  end
706
708
  end
707
709
 
708
710
  # copies a sheet to another position
709
711
  # default: copied sheet is appended
710
- # @param [Sheet] sheet a sheet that shall be copied
712
+ # @param [Worksheet] sheet a sheet that shall be copied
711
713
  # @param [Hash] opts the options
712
714
  # @option opts [Symbol] :as new name of the copied sheet
713
715
  # @option opts [Symbol] :before a sheet before which the sheet shall be inserted
714
716
  # @option opts [Symbol] :after a sheet after which the sheet shall be inserted
715
717
  # @raise NameAlreadyExists if the sheet name already exists
716
- # @return [Sheet] the copied sheet
718
+ # @return [Worksheet] the copied sheet
717
719
  def copy_sheet(sheet, opts = { })
718
720
  new_sheet_name = opts.delete(:as)
719
721
  after_or_before, base_sheet = opts.to_a.first || [:after, last_sheet]
720
722
  sheet.Copy({ after_or_before.to_s => base_sheet.ole_worksheet })
721
- new_sheet = sheet_class.new(@excel.Activesheet)
723
+ new_sheet = worksheet_class.new(@excel.Activesheet)
722
724
  new_sheet.name = new_sheet_name if new_sheet_name
723
725
  new_sheet
724
726
  end
@@ -730,24 +732,24 @@ module RobustExcelOle
730
732
  # @option opts [Symbol] :before a sheet before which the sheet shall be inserted
731
733
  # @option opts [Symbol] :after a sheet after which the sheet shall be inserted
732
734
  # @raise NameAlreadyExists if the sheet name already exists
733
- # @return [Sheet] the added sheet
735
+ # @return [Worksheet] the added sheet
734
736
  def add_empty_sheet(opts = { })
735
737
  new_sheet_name = opts.delete(:as)
736
738
  after_or_before, base_sheet = opts.to_a.first || [:after, last_sheet]
737
739
  @ole_workbook.Worksheets.Add({ after_or_before.to_s => base_sheet.ole_worksheet })
738
- new_sheet = sheet_class.new(@excel.Activesheet)
740
+ new_sheet = worksheet_class.new(@excel.Activesheet)
739
741
  new_sheet.name = new_sheet_name if new_sheet_name
740
742
  new_sheet
741
743
  end
742
744
 
743
745
  # copies a sheet to another position if a sheet is given, or adds an empty sheet
744
746
  # default: copied or empty sheet is appended, i.e. added behind the last sheet
745
- # @param [Sheet] sheet a sheet that shall be copied (optional)
747
+ # @param [Worksheet] sheet a sheet that shall be copied (optional)
746
748
  # @param [Hash] opts the options
747
749
  # @option opts [Symbol] :as new name of the copied or added sheet
748
750
  # @option opts [Symbol] :before a sheet before which the sheet shall be inserted
749
751
  # @option opts [Symbol] :after a sheet after which the sheet shall be inserted
750
- # @return [Sheet] the copied or added sheet
752
+ # @return [Worksheet] the copied or added sheet
751
753
  def add_or_copy_sheet(sheet = nil, opts = { })
752
754
  if sheet.is_a? Hash
753
755
  opts = sheet
@@ -762,11 +764,11 @@ module RobustExcelOle
762
764
  end
763
765
 
764
766
  def last_sheet
765
- sheet_class.new(@ole_workbook.Worksheets.Item(@ole_workbook.Worksheets.Count))
767
+ worksheet_class.new(@ole_workbook.Worksheets.Item(@ole_workbook.Worksheets.Count))
766
768
  end
767
769
 
768
770
  def first_sheet
769
- sheet_class.new(@ole_workbook.Worksheets.Item(1))
771
+ worksheet_class.new(@ole_workbook.Worksheets.Item(1))
770
772
  end
771
773
 
772
774
  # returns the value of a range
@@ -870,7 +872,7 @@ module RobustExcelOle
870
872
 
871
873
  # @return [Boolean] true, if the full book names and excel Instances are identical, false otherwise
872
874
  def == other_book
873
- other_book.is_a?(Book) &&
875
+ other_book.is_a?(Workbook) &&
874
876
  @excel == other_book.excel &&
875
877
  self.filename == other_book.filename
876
878
  end
@@ -892,7 +894,7 @@ module RobustExcelOle
892
894
  end
893
895
 
894
896
  def inspect # :nodoc: #
895
- "#<Book: " + "#{"not alive " unless alive?}" + "#{File.basename(self.filename) if alive?}" + " #{@ole_workbook} #{@excel}" + ">"
897
+ "#<Workbook: " + "#{"not alive " unless alive?}" + "#{File.basename(self.filename) if alive?}" + " #{@ole_workbook} #{@excel}" + ">"
896
898
  end
897
899
 
898
900
  def self.excel_class # :nodoc: #
@@ -905,12 +907,12 @@ module RobustExcelOle
905
907
  end
906
908
  end
907
909
 
908
- def self.sheet_class # :nodoc: #
909
- @sheet_class ||= begin
910
+ def self.worksheet_class # :nodoc: #
911
+ @worksheet_class ||= begin
910
912
  module_name = self.parent_name
911
- "#{module_name}::Sheet".constantize
913
+ "#{module_name}::Worksheet".constantize
912
914
  rescue NameError => e
913
- Sheet
915
+ Worksheet
914
916
  end
915
917
  end
916
918
 
@@ -918,8 +920,8 @@ module RobustExcelOle
918
920
  self.class.excel_class
919
921
  end
920
922
 
921
- def sheet_class # :nodoc: #
922
- self.class.sheet_class
923
+ def worksheet_class # :nodoc: #
924
+ self.class.worksheet_class
923
925
  end
924
926
 
925
927
  include MethodHelpers
@@ -946,6 +948,6 @@ module RobustExcelOle
946
948
 
947
949
  public
948
950
 
949
- Workbook = Book
951
+ Book = Workbook
950
952
 
951
953
  end
@@ -2,7 +2,9 @@
2
2
 
3
3
  module RobustExcelOle
4
4
 
5
- class Sheet < RangeOwners
5
+ # see https://docs.microsoft.com/en-us/office/vba/api/excel.worksheet#methods
6
+
7
+ class Worksheet < RangeOwners
6
8
 
7
9
  attr_reader :ole_worksheet
8
10
  attr_reader :workbook
@@ -18,7 +20,7 @@ module RobustExcelOle
18
20
  @end_row = last_row
19
21
  @end_column = last_column
20
22
  end
21
- @workbook = book_class.new(self.Parent)
23
+ @workbook = workbook_class.new(self.Parent)
22
24
  end
23
25
 
24
26
  # sheet name
@@ -103,7 +105,7 @@ module RobustExcelOle
103
105
  end
104
106
 
105
107
  # sets the value of a cell, if row, column and color of the cell are given
106
- # @params [Fixnum] x,y row and column
108
+ # @params [Integer] x,y row and column
107
109
  # @option opts [Symbol] :color the color of the cell when set
108
110
  def set_cellval(x,y,value, opts = {:color => 0})
109
111
  begin
@@ -117,19 +119,17 @@ module RobustExcelOle
117
119
  end
118
120
 
119
121
  # creates a range.
120
- # @params [Fixnum,Range] row or range of the rows
121
- # @params [Fixnum,Range] column or range of columns
122
- # row and column of the bottum right cell of a rectangur range
122
+ # @params [Address] address
123
123
  # @return [Range] a range
124
- def range(int_range1, int_range2)
125
- int_range1 = int_range1 .. int_range1 if int_range1.is_a?(Fixnum)
126
- int_range2 = int_range2 .. int_range2 if int_range2.is_a?(Fixnum)
124
+ def range(address, address2 = :__not_provided)
125
+ address = [address,address2] unless address2 == :__not_provided
126
+ address = Address.new(address)
127
127
  begin
128
128
  RobustExcelOle::Range.new(@ole_worksheet.Range(
129
- @ole_worksheet.Cells(int_range1.min, int_range2.min),
130
- @ole_worksheet.Cells(int_range1.max, int_range2.max)))
129
+ @ole_worksheet.Cells(address.rows.min, address.columns.min),
130
+ @ole_worksheet.Cells(address.rows.max, address.columns.max)))
131
131
  rescue WIN32OLERuntimeError
132
- raise RangeNotCreated, "cannot create range (#{int_range1.inspect},#{int_range2.inspect})"
132
+ raise RangeNotCreated, "cannot create range #{address.inspect}"
133
133
  end
134
134
  end
135
135
 
@@ -161,7 +161,7 @@ module RobustExcelOle
161
161
 
162
162
  def each_row_with_index(offset = 0)
163
163
  each_row(offset) do |row_range|
164
- yield RobustExcelOle::Range.new(row_range), (row_range.row - 1 - offset)
164
+ yield RobustExcelOle::Range.new(row_range), (row_range.Row - 1 - offset)
165
165
  end
166
166
  end
167
167
 
@@ -175,7 +175,7 @@ module RobustExcelOle
175
175
 
176
176
  def each_column_with_index(offset = 0)
177
177
  each_column(offset) do |column_range|
178
- yield RobustExcelOle::Range.new(column_range), (column_range.column - 1 - offset)
178
+ yield RobustExcelOle::Range.new(column_range), (column_range.Column - 1 - offset)
179
179
  end
180
180
  end
181
181
 
@@ -190,21 +190,21 @@ module RobustExcelOle
190
190
  end
191
191
 
192
192
 
193
- def self.book_class # :nodoc: #
194
- @book_class ||= begin
193
+ def self.workbook_class # :nodoc: #
194
+ @workbook_class ||= begin
195
195
  module_name = self.parent_name
196
- "#{module_name}::Book".constantize
196
+ "#{module_name}::Workbook".constantize
197
197
  rescue NameError => e
198
- book
198
+ Workbook
199
199
  end
200
200
  end
201
201
 
202
- def book_class # :nodoc: #
203
- self.class.book_class
202
+ def workbook_class # :nodoc: #
203
+ self.class.workbook_class
204
204
  end
205
205
 
206
206
  def to_s # :nodoc: #
207
- "#<Sheet: " + "#{"not alive " unless @workbook.alive?}" + "#{name}" + " #{File.basename(@workbook.stored_filename)} >"
207
+ "#<Worksheet: " + "#{"not alive " unless @workbook.alive?}" + "#{name}" + " #{File.basename(@workbook.stored_filename)} >"
208
208
  end
209
209
 
210
210
  def inspect # :nodoc: #
@@ -247,7 +247,7 @@ module RobustExcelOle
247
247
 
248
248
  public
249
249
 
250
- Worksheet = Sheet
250
+ Sheet = Worksheet
251
251
 
252
252
  end
253
253