robust_excel_ole 1.1 → 1.1.1
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.
- checksums.yaml +7 -0
- data/Changelog +26 -12
- data/README.rdoc +35 -27
- data/README_detail.rdoc +66 -50
- data/examples/edit_sheets/example_access_sheets_and_cells.rb +4 -4
- data/examples/edit_sheets/example_adding_sheets.rb +1 -1
- data/examples/edit_sheets/example_concating.rb +2 -2
- data/examples/edit_sheets/example_copying.rb +2 -2
- data/examples/edit_sheets/example_expanding.rb +2 -2
- data/examples/edit_sheets/example_naming.rb +2 -2
- data/examples/edit_sheets/example_saving.rb +4 -4
- data/examples/open_save_close/example_default_excel.rb +5 -5
- data/examples/open_save_close/example_force_excel.rb +4 -4
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +3 -3
- data/examples/open_save_close/example_if_obstructed_forget.rb +4 -4
- data/examples/open_save_close/example_if_obstructed_save.rb +3 -3
- data/examples/open_save_close/example_if_unsaved_accept.rb +3 -3
- data/examples/open_save_close/example_if_unsaved_forget.rb +3 -3
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +3 -3
- 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_reuse.rb +4 -4
- data/examples/open_save_close/example_simple.rb +1 -1
- data/examples/open_save_close/example_unobtrusively.rb +2 -2
- data/lib/reo_console.rb +1 -1
- data/lib/robust_excel_ole/book.rb +56 -23
- data/lib/robust_excel_ole/excel.rb +35 -25
- data/lib/robust_excel_ole/general.rb +1 -1
- data/lib/robust_excel_ole/sheet.rb +99 -66
- data/lib/robust_excel_ole/version.rb +1 -1
- data/reo.bat +1 -1
- data/spec/book_spec.rb +7 -1
- data/spec/book_specs/book_misc_spec.rb +0 -4
- data/spec/data/another_workbook.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +11 -17
- data/spec/sheet_spec.rb +11 -11
- metadata +38 -60
| @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            # -*- coding: utf-8 -*-
         | 
| 2 2 |  | 
| 3 3 | 
             
            require 'weakref'
         | 
| 4 | 
            +
            require 'Win32API'
         | 
| 4 5 |  | 
| 5 6 | 
             
            def ka 
         | 
| 6 7 | 
             
              Excel.kill_all
         | 
| @@ -381,10 +382,8 @@ module RobustExcelOle | |
| 381 382 | 
             
                  processes.select{ |p| p.name == "EXCEL.EXE"}.size
         | 
| 382 383 | 
             
                end
         | 
| 383 384 |  | 
| 384 | 
            -
                #  | 
| 385 | 
            -
                 | 
| 386 | 
            -
                #  not for Excel instances opened by the user)
         | 
| 387 | 
            -
                def self.excel_processes
         | 
| 385 | 
            +
                # returns all Excel objects for all Excel instances opened with RobustExcelOle,
         | 
| 386 | 
            +
                def self.known_excel_instances
         | 
| 388 387 | 
             
                  pid2excel = {}
         | 
| 389 388 | 
             
                  @@hwnd2excel.each do |hwnd,wr_excel|
         | 
| 390 389 | 
             
                    if wr_excel.weakref_alive?
         | 
| @@ -601,7 +600,7 @@ module RobustExcelOle | |
| 601 600 | 
             
                # @param [String]  name  the name of the range
         | 
| 602 601 | 
             
                # @param [Variant] value the contents of the range
         | 
| 603 602 | 
             
                def []= (name, value)
         | 
| 604 | 
            -
                  set_nameval(name,value)
         | 
| 603 | 
            +
                  set_nameval(name,value, :color => 42) # 42 - aqua-marin, 7-green
         | 
| 605 604 | 
             
                end
         | 
| 606 605 |  | 
| 607 606 | 
             
                # returns the contents of a range with given name
         | 
| @@ -611,17 +610,12 @@ module RobustExcelOle | |
| 611 610 | 
             
                # @param [Hash]   opts  the options
         | 
| 612 611 | 
             
                # @option opts [Variant] :default value (default: nil)
         | 
| 613 612 | 
             
                def nameval(name, opts = {:default => nil})
         | 
| 614 | 
            -
                   | 
| 615 | 
            -
             | 
| 616 | 
            -
             | 
| 617 | 
            -
                    return opts[:default] if opts[:default]
         | 
| 618 | 
            -
                    raise NameNotFound, "cannot find name #{name.inspect}"
         | 
| 619 | 
            -
                  end
         | 
| 620 | 
            -
                  begin
         | 
| 621 | 
            -
                    value = name_obj.RefersToRange.Value
         | 
| 613 | 
            +
                  name_obj = name_object(name)
         | 
| 614 | 
            +
                  value = begin
         | 
| 615 | 
            +
                    name_obj.RefersToRange.Value
         | 
| 622 616 | 
             
                  rescue  WIN32OLERuntimeError
         | 
| 623 617 | 
             
                    begin
         | 
| 624 | 
            -
                       | 
| 618 | 
            +
                      self.Evaluate(name_obj.Name)
         | 
| 625 619 | 
             
                    rescue WIN32OLERuntimeError
         | 
| 626 620 | 
             
                      return opts[:default] if opts[:default]
         | 
| 627 621 | 
             
                      raise RangeNotEvaluatable, "cannot evaluate range named #{name.inspect}"
         | 
| @@ -634,22 +628,36 @@ module RobustExcelOle | |
| 634 628 | 
             
                  return opts[:default] if (value.nil? && opts[:default])
         | 
| 635 629 | 
             
                  value      
         | 
| 636 630 | 
             
                end
         | 
| 637 | 
            -
             | 
| 631 | 
            +
             | 
| 638 632 | 
             
                # assigns a value to a range with given name
         | 
| 639 633 | 
             
                # @param [String]  name   the range name
         | 
| 640 634 | 
             
                # @param [Variant] value  the assigned value
         | 
| 641 | 
            -
                 | 
| 642 | 
            -
             | 
| 643 | 
            -
                    name_obj = self.Names.Item(name)
         | 
| 644 | 
            -
                  rescue WIN32OLERuntimeError
         | 
| 645 | 
            -
                    raise NameNotFound, "cannot find name #{name.inspect}"
         | 
| 646 | 
            -
                  end
         | 
| 635 | 
            +
                # @param [Hash]    opts :color [FixNum]  the color when setting the contents
         | 
| 636 | 
            +
                def set_nameval(name,value, opts = {:color => 0})
         | 
| 647 637 | 
             
                  begin
         | 
| 648 | 
            -
                     | 
| 638 | 
            +
                    cell = name_object(name).RefersToRange
         | 
| 639 | 
            +
                    cell.Interior.ColorIndex = opts[:color]
         | 
| 640 | 
            +
                    cell.Value = value
         | 
| 649 641 | 
             
                  rescue  WIN32OLERuntimeError
         | 
| 650 642 | 
             
                    raise RangeNotEvaluatable, "cannot assign value to range named #{name.inspect}"
         | 
| 651 643 | 
             
                  end
         | 
| 652 | 
            -
                end | 
| 644 | 
            +
                end
         | 
| 645 | 
            +
             | 
| 646 | 
            +
              private  
         | 
| 647 | 
            +
             | 
| 648 | 
            +
                def name_object(name)
         | 
| 649 | 
            +
                  begin
         | 
| 650 | 
            +
                    self.Parent.Names.Item(name)
         | 
| 651 | 
            +
                  rescue WIN32OLERuntimeError
         | 
| 652 | 
            +
                    begin
         | 
| 653 | 
            +
                      self.Names.Item(name)
         | 
| 654 | 
            +
                    rescue WIN32OLERuntimeError
         | 
| 655 | 
            +
                      raise NameNotFound, "name #{name.inspect}"
         | 
| 656 | 
            +
                    end
         | 
| 657 | 
            +
                  end
         | 
| 658 | 
            +
                end  
         | 
| 659 | 
            +
             | 
| 660 | 
            +
              public    
         | 
| 653 661 |  | 
| 654 662 | 
             
                # returns the contents of a range with a locally defined name
         | 
| 655 663 | 
             
                # evaluates the formula if the contents is a formula
         | 
| @@ -679,14 +687,16 @@ module RobustExcelOle | |
| 679 687 | 
             
                # assigns a value to a range given a locally defined name
         | 
| 680 688 | 
             
                # @param [String]  name   the range name
         | 
| 681 689 | 
             
                # @param [Variant] value  the assigned value
         | 
| 682 | 
            -
                 | 
| 690 | 
            +
                # @param [Hash]    opts :color [FixNum]  the color when setting the contents
         | 
| 691 | 
            +
                def set_rangeval(name,value, opts = {:color => 0})
         | 
| 683 692 | 
             
                  begin
         | 
| 684 693 | 
             
                    range = self.Range(name)
         | 
| 685 694 | 
             
                  rescue WIN32OLERuntimeError
         | 
| 686 695 | 
             
                    raise NameNotFound, "cannot find name #{name.inspect}"
         | 
| 687 696 | 
             
                  end
         | 
| 688 697 | 
             
                  begin
         | 
| 689 | 
            -
                    range. | 
| 698 | 
            +
                    range.Interior.ColorIndex = opts[:color]
         | 
| 699 | 
            +
                    range.Value = value        
         | 
| 690 700 | 
             
                  rescue  WIN32OLERuntimeError
         | 
| 691 701 | 
             
                    raise RangeNotEvaluatable, "cannot assign value to range named #{name.inspect} in #{self.name}"
         | 
| 692 702 | 
             
                  end
         | 
| @@ -113,7 +113,7 @@ module MethodHelpers | |
| 113 113 | 
             
              end
         | 
| 114 114 |  | 
| 115 115 | 
             
              def methods   # :nodoc: # 
         | 
| 116 | 
            -
                (super + ole_object.ole_methods.map{|m| m.to_s}).uniq.select{|m| m =~ /^(?!\_)/}.sort
         | 
| 116 | 
            +
                (super.map{|m| m.to_s} + ole_object.ole_methods.map{|m| m.to_s}).uniq.select{|m| m =~ /^(?!\_)/}.sort
         | 
| 117 117 | 
             
              end
         | 
| 118 118 |  | 
| 119 119 | 
             
            end
         | 
| @@ -48,7 +48,11 @@ module RobustExcelOle | |
| 48 48 | 
             
                    y, x = p1, p2
         | 
| 49 49 | 
             
                    yx = "#{y}_#{x}"
         | 
| 50 50 | 
             
                    @cells = { }
         | 
| 51 | 
            -
                     | 
| 51 | 
            +
                    begin
         | 
| 52 | 
            +
                      @cells[yx] = RobustExcelOle::Cell.new(@worksheet.Cells.Item(y, x))
         | 
| 53 | 
            +
                    rescue
         | 
| 54 | 
            +
                      raise RangeNotEvaluatable, "cannot read cell (#{p1.inspect},#{p2.inspect})"
         | 
| 55 | 
            +
                    end
         | 
| 52 56 | 
             
                  else
         | 
| 53 57 | 
             
                    name = p1
         | 
| 54 58 | 
             
                    begin
         | 
| @@ -68,11 +72,17 @@ module RobustExcelOle | |
| 68 72 | 
             
                def []= (p1, p2, p3 = :__not_provided)
         | 
| 69 73 | 
             
                  if p3 != :__not_provided
         | 
| 70 74 | 
             
                    y, x, value = p1, p2, p3
         | 
| 71 | 
            -
                     | 
| 75 | 
            +
                    begin
         | 
| 76 | 
            +
                      cell = @worksheet.Cells.Item(y, x)
         | 
| 77 | 
            +
                      cell.Value = value
         | 
| 78 | 
            +
                      cell.Interior.ColorIndex = 42 # aqua-marin, 4-green
         | 
| 79 | 
            +
                    rescue WIN32OLERuntimeError
         | 
| 80 | 
            +
                      raise RangeNotEvaluatable, "cannot assign value #{p3.inspect} to cell (#{p1.inspect},#{p2.inspect})"
         | 
| 81 | 
            +
                    end
         | 
| 72 82 | 
             
                  else
         | 
| 73 83 | 
             
                    name, value = p1, p2
         | 
| 74 84 | 
             
                    begin
         | 
| 75 | 
            -
                      set_nameval(name, value) 
         | 
| 85 | 
            +
                      set_nameval(name, value, :color => 42) # aqua-marin, 4-green
         | 
| 76 86 | 
             
                    rescue REOError
         | 
| 77 87 | 
             
                      begin
         | 
| 78 88 | 
             
                        workbook.set_nameval(name, value)
         | 
| @@ -83,52 +93,6 @@ module RobustExcelOle | |
| 83 93 | 
             
                  end
         | 
| 84 94 | 
             
                end
         | 
| 85 95 |  | 
| 86 | 
            -
                def each
         | 
| 87 | 
            -
                  each_row do |row_range|
         | 
| 88 | 
            -
                    row_range.each do |cell|
         | 
| 89 | 
            -
                      yield cell
         | 
| 90 | 
            -
                    end
         | 
| 91 | 
            -
                  end
         | 
| 92 | 
            -
                end
         | 
| 93 | 
            -
             | 
| 94 | 
            -
                def each_row(offset = 0)
         | 
| 95 | 
            -
                  offset += 1
         | 
| 96 | 
            -
                  1.upto(@end_row) do |row|
         | 
| 97 | 
            -
                    next if row < offset
         | 
| 98 | 
            -
                    yield RobustExcelOle::Range.new(@worksheet.Range(@worksheet.Cells(row, 1), @worksheet.Cells(row, @end_column)))
         | 
| 99 | 
            -
                  end
         | 
| 100 | 
            -
                end
         | 
| 101 | 
            -
             | 
| 102 | 
            -
                def each_row_with_index(offset = 0)
         | 
| 103 | 
            -
                  each_row(offset) do |row_range|
         | 
| 104 | 
            -
                    yield RobustExcelOle::Range.new(row_range), (row_range.row - 1 - offset)
         | 
| 105 | 
            -
                  end
         | 
| 106 | 
            -
                end
         | 
| 107 | 
            -
             | 
| 108 | 
            -
                def each_column(offset = 0)
         | 
| 109 | 
            -
                  offset += 1
         | 
| 110 | 
            -
                  1.upto(@end_column) do |column|
         | 
| 111 | 
            -
                    next if column < offset
         | 
| 112 | 
            -
                    yield RobustExcelOle::Range.new(@worksheet.Range(@worksheet.Cells(1, column), @worksheet.Cells(@end_row, column)))
         | 
| 113 | 
            -
                  end
         | 
| 114 | 
            -
                end
         | 
| 115 | 
            -
             | 
| 116 | 
            -
                def each_column_with_index(offset = 0)
         | 
| 117 | 
            -
                  each_column(offset) do |column_range|
         | 
| 118 | 
            -
                    yield RobustExcelOle::Range.new(column_range), (column_range.column - 1 - offset)
         | 
| 119 | 
            -
                  end
         | 
| 120 | 
            -
                end
         | 
| 121 | 
            -
             | 
| 122 | 
            -
                def row_range(row, range = nil)
         | 
| 123 | 
            -
                  range ||= 1..@end_column
         | 
| 124 | 
            -
                  RobustExcelOle::Range.new(@worksheet.Range(@worksheet.Cells(row , range.min ), @worksheet.Cells(row , range.max )))
         | 
| 125 | 
            -
                end
         | 
| 126 | 
            -
             | 
| 127 | 
            -
                def col_range(col, range = nil)
         | 
| 128 | 
            -
                  range ||= 1..@end_row
         | 
| 129 | 
            -
                  RobustExcelOle::Range.new(@worksheet.Range(@worksheet.Cells(range.min , col ), @worksheet.Cells(range.max , col )))
         | 
| 130 | 
            -
                end
         | 
| 131 | 
            -
             | 
| 132 96 | 
             
                # returns the contents of a range
         | 
| 133 97 | 
             
                # evaluates the formula if the contents is a formula
         | 
| 134 98 | 
             
                # if no contents could be returned, then return default value, if provided, raise error otherwise
         | 
| @@ -136,17 +100,12 @@ module RobustExcelOle | |
| 136 100 | 
             
                # @param [Hash]   opts  the options
         | 
| 137 101 | 
             
                # @option opts [Variant] :default default value (default: nil)
         | 
| 138 102 | 
             
                def nameval(name, opts = {:default => nil})
         | 
| 139 | 
            -
                   | 
| 140 | 
            -
             | 
| 103 | 
            +
                  name_obj = name_object(name)
         | 
| 104 | 
            +
                  value = begin
         | 
| 105 | 
            +
                    name_obj.RefersToRange.Value
         | 
| 141 106 | 
             
                  rescue WIN32OLERuntimeError
         | 
| 142 | 
            -
                    return opts[:default] if opts[:default]
         | 
| 143 | 
            -
                    raise NameNotFound, "name #{name.inspect} not in #{self.Name}"
         | 
| 144 | 
            -
                  end
         | 
| 145 | 
            -
                  begin
         | 
| 146 | 
            -
                    value = name_obj.RefersToRange.Value
         | 
| 147 | 
            -
                  rescue  WIN32OLERuntimeError
         | 
| 148 107 | 
             
                    begin
         | 
| 149 | 
            -
                       | 
| 108 | 
            +
                      self.Evaluate(name_obj.Name)
         | 
| 150 109 | 
             
                    rescue WIN32OLERuntimeError
         | 
| 151 110 | 
             
                      return opts[:default] if opts[:default]
         | 
| 152 111 | 
             
                      raise RangeNotEvaluatable, "cannot evaluate range named #{name.inspect} in #{self.Name}"
         | 
| @@ -163,19 +122,33 @@ module RobustExcelOle | |
| 163 122 | 
             
                # assigns a value to a range
         | 
| 164 123 | 
             
                # @param [String]  name   the name of a range
         | 
| 165 124 | 
             
                # @param [Variant] value  the assigned value
         | 
| 166 | 
            -
                 | 
| 125 | 
            +
                # @param [Hash]    opts :color [FixNum]  the color when setting the contents
         | 
| 126 | 
            +
                def set_nameval(name,value, opts = {:color => 0})
         | 
| 167 127 | 
             
                  begin
         | 
| 168 | 
            -
                     | 
| 169 | 
            -
             | 
| 170 | 
            -
                     | 
| 171 | 
            -
                  end
         | 
| 172 | 
            -
                  begin
         | 
| 173 | 
            -
                    name_obj.RefersToRange.Value = value
         | 
| 128 | 
            +
                    cell = name_object(name).RefersToRange        
         | 
| 129 | 
            +
                    cell.Interior.ColorIndex = opts[:color]
         | 
| 130 | 
            +
                    cell.Value = value
         | 
| 174 131 | 
             
                  rescue  WIN32OLERuntimeError
         | 
| 175 132 | 
             
                    raise RangeNotEvaluatable, "cannot assign value to range named #{name.inspect} in #{self.name}"
         | 
| 176 133 | 
             
                  end
         | 
| 177 134 | 
             
                end
         | 
| 178 135 |  | 
| 136 | 
            +
              private
         | 
| 137 | 
            +
             | 
| 138 | 
            +
                def name_object(name)
         | 
| 139 | 
            +
                  begin
         | 
| 140 | 
            +
                    self.Parent.Names.Item(name)
         | 
| 141 | 
            +
                  rescue WIN32OLERuntimeError
         | 
| 142 | 
            +
                    begin
         | 
| 143 | 
            +
                      self.Names.Item(name)
         | 
| 144 | 
            +
                    rescue WIN32OLERuntimeError
         | 
| 145 | 
            +
                      raise NameNotFound, "name #{name.inspect} not in #{self.name}"
         | 
| 146 | 
            +
                    end
         | 
| 147 | 
            +
                  end
         | 
| 148 | 
            +
                end
         | 
| 149 | 
            +
             | 
| 150 | 
            +
              public    
         | 
| 151 | 
            +
             | 
| 179 152 | 
             
                # returns the contents of a range with a locally defined name
         | 
| 180 153 | 
             
                # evaluates the formula if the contents is a formula
         | 
| 181 154 | 
             
                # if no contents could be returned, then return default value, if provided, raise error otherwise
         | 
| @@ -203,13 +176,15 @@ module RobustExcelOle | |
| 203 176 | 
             
                # assigns a value to a range given a locally defined name
         | 
| 204 177 | 
             
                # @param [String]  name   the name of a range
         | 
| 205 178 | 
             
                # @param [Variant] value  the assigned value
         | 
| 206 | 
            -
                 | 
| 179 | 
            +
                # @param [Hash]    opts :color [FixNum]  the color when setting the contents
         | 
| 180 | 
            +
                def set_rangeval(name,value, opts = {:color => 0})
         | 
| 207 181 | 
             
                  begin
         | 
| 208 182 | 
             
                    range = self.Range(name)
         | 
| 209 183 | 
             
                  rescue WIN32OLERuntimeError
         | 
| 210 184 | 
             
                    raise NameNotFound, "name #{name.inspect} not in #{self.name}"
         | 
| 211 185 | 
             
                  end
         | 
| 212 186 | 
             
                  begin
         | 
| 187 | 
            +
                    range.Interior.ColorIndex = opts[:color]
         | 
| 213 188 | 
             
                    range.Value = value
         | 
| 214 189 | 
             
                  rescue  WIN32OLERuntimeError
         | 
| 215 190 | 
             
                    raise RangeNotEvaluatable, "cannot assign value to range named #{name.inspect} in #{self.name}"
         | 
| @@ -235,6 +210,64 @@ module RobustExcelOle | |
| 235 210 | 
             
                  end
         | 
| 236 211 | 
             
                end
         | 
| 237 212 |  | 
| 213 | 
            +
             | 
| 214 | 
            +
                def each
         | 
| 215 | 
            +
                  each_row do |row_range|
         | 
| 216 | 
            +
                    row_range.each do |cell|
         | 
| 217 | 
            +
                      yield cell
         | 
| 218 | 
            +
                    end
         | 
| 219 | 
            +
                  end
         | 
| 220 | 
            +
                end
         | 
| 221 | 
            +
             | 
| 222 | 
            +
                def each_with_index(offset = 0)
         | 
| 223 | 
            +
                  i = offset
         | 
| 224 | 
            +
                  each_row do |row_range|
         | 
| 225 | 
            +
                    row_range.each do |cell|          
         | 
| 226 | 
            +
                      yield cell, i
         | 
| 227 | 
            +
                      i+=1
         | 
| 228 | 
            +
                    end
         | 
| 229 | 
            +
                  end
         | 
| 230 | 
            +
                end
         | 
| 231 | 
            +
             | 
| 232 | 
            +
                def each_row(offset = 0)
         | 
| 233 | 
            +
                  offset += 1
         | 
| 234 | 
            +
                  1.upto(@end_row) do |row|
         | 
| 235 | 
            +
                    next if row < offset
         | 
| 236 | 
            +
                    yield RobustExcelOle::Range.new(@worksheet.Range(@worksheet.Cells(row, 1), @worksheet.Cells(row, @end_column)))
         | 
| 237 | 
            +
                  end
         | 
| 238 | 
            +
                end
         | 
| 239 | 
            +
             | 
| 240 | 
            +
                def each_row_with_index(offset = 0)
         | 
| 241 | 
            +
                  each_row(offset) do |row_range|
         | 
| 242 | 
            +
                    yield RobustExcelOle::Range.new(row_range), (row_range.row - 1 - offset)
         | 
| 243 | 
            +
                  end
         | 
| 244 | 
            +
                end
         | 
| 245 | 
            +
             | 
| 246 | 
            +
                def each_column(offset = 0)
         | 
| 247 | 
            +
                  offset += 1
         | 
| 248 | 
            +
                  1.upto(@end_column) do |column|
         | 
| 249 | 
            +
                    next if column < offset
         | 
| 250 | 
            +
                    yield RobustExcelOle::Range.new(@worksheet.Range(@worksheet.Cells(1, column), @worksheet.Cells(@end_row, column)))
         | 
| 251 | 
            +
                  end
         | 
| 252 | 
            +
                end
         | 
| 253 | 
            +
             | 
| 254 | 
            +
                def each_column_with_index(offset = 0)
         | 
| 255 | 
            +
                  each_column(offset) do |column_range|
         | 
| 256 | 
            +
                    yield RobustExcelOle::Range.new(column_range), (column_range.column - 1 - offset)
         | 
| 257 | 
            +
                  end
         | 
| 258 | 
            +
                end
         | 
| 259 | 
            +
             | 
| 260 | 
            +
                def row_range(row, range = nil)
         | 
| 261 | 
            +
                  range ||= 1..@end_column
         | 
| 262 | 
            +
                  RobustExcelOle::Range.new(@worksheet.Range(@worksheet.Cells(row , range.min ), @worksheet.Cells(row , range.max )))
         | 
| 263 | 
            +
                end
         | 
| 264 | 
            +
             | 
| 265 | 
            +
                def col_range(col, range = nil)
         | 
| 266 | 
            +
                  range ||= 1..@end_row
         | 
| 267 | 
            +
                  RobustExcelOle::Range.new(@worksheet.Range(@worksheet.Cells(range.min , col ), @worksheet.Cells(range.max , col )))
         | 
| 268 | 
            +
                end
         | 
| 269 | 
            +
             | 
| 270 | 
            +
             | 
| 238 271 | 
             
                def self.book_class   # :nodoc: #
         | 
| 239 272 | 
             
                  @book_class ||= begin
         | 
| 240 273 | 
             
                    module_name = self.parent_name
         | 
    
        data/reo.bat
    CHANGED
    
    
    
        data/spec/book_spec.rb
    CHANGED
    
    | @@ -654,7 +654,7 @@ describe Book do | |
| 654 654 | 
             
                      @excel1.close
         | 
| 655 655 | 
             
                      @excel2.close 
         | 
| 656 656 | 
             
                    rescue ExcelError => msg
         | 
| 657 | 
            -
                      puts "ExcelError: #{msg.message}" if msg.message =~ /Excel instance not alive or damaged/
         | 
| 657 | 
            +
                      # puts "ExcelError: #{msg.message}" if msg.message =~ /Excel instance not alive or damaged/
         | 
| 658 658 | 
             
                    end
         | 
| 659 659 | 
             
                  end
         | 
| 660 660 |  | 
| @@ -1345,6 +1345,12 @@ describe Book do | |
| 1345 1345 | 
             
                      sheet.should be_kind_of Sheet
         | 
| 1346 1346 | 
             
                    end
         | 
| 1347 1347 | 
             
                  end
         | 
| 1348 | 
            +
             | 
| 1349 | 
            +
                  it 'with each_with_index' do
         | 
| 1350 | 
            +
                    @book.each_with_index do |sheet,i|
         | 
| 1351 | 
            +
                      sheet.should be_kind_of Sheet
         | 
| 1352 | 
            +
                    end
         | 
| 1353 | 
            +
                  end
         | 
| 1348 1354 | 
             
                end
         | 
| 1349 1355 |  | 
| 1350 1356 | 
             
                describe "with retain_saved" do
         | 
| @@ -654,10 +654,6 @@ describe Book do | |
| 654 654 | 
             
                  @book1["named_formula"].should == 4      
         | 
| 655 655 | 
             
                end
         | 
| 656 656 |  | 
| 657 | 
            -
                it "should return default value if name not defined" do
         | 
| 658 | 
            -
                  @book1.nameval("foo", :default => 2).should == 2
         | 
| 659 | 
            -
                end
         | 
| 660 | 
            -
             | 
| 661 657 | 
             
                it "should raise an error if name not defined" do
         | 
| 662 658 | 
             
                  expect {
         | 
| 663 659 | 
             
                    @book1.nameval("foo")
         | 
| Binary file | 
    
        data/spec/data/workbook.xls
    CHANGED
    
    | Binary file | 
    
        data/spec/excel_spec.rb
    CHANGED
    
    | @@ -1556,33 +1556,31 @@ module RobustExcelOle | |
| 1556 1556 |  | 
| 1557 1557 | 
             
                end
         | 
| 1558 1558 |  | 
| 1559 | 
            -
                describe " | 
| 1559 | 
            +
                describe "known_excel_instances" do
         | 
| 1560 1560 |  | 
| 1561 1561 | 
             
                  it "should return empty list" do
         | 
| 1562 | 
            -
                    Excel. | 
| 1562 | 
            +
                    Excel.known_excel_instances.should be_empty
         | 
| 1563 1563 | 
             
                  end
         | 
| 1564 1564 |  | 
| 1565 1565 | 
             
                  it "should return list of one Excel process" do
         | 
| 1566 1566 | 
             
                    excel = Excel.new
         | 
| 1567 | 
            -
                    Excel. | 
| 1567 | 
            +
                    Excel.known_excel_instances.should == [excel]
         | 
| 1568 1568 | 
             
                    excel.close
         | 
| 1569 1569 | 
             
                  end
         | 
| 1570 1570 |  | 
| 1571 1571 | 
             
                  it "should return list of two Excel processes" do
         | 
| 1572 1572 | 
             
                    excel1 = Excel.create
         | 
| 1573 1573 | 
             
                    excel2 = Excel.create
         | 
| 1574 | 
            -
                    Excel. | 
| 1574 | 
            +
                    Excel.known_excel_instances.should == [excel1,excel2]
         | 
| 1575 1575 | 
             
                  end
         | 
| 1576 1576 |  | 
| 1577 1577 | 
             
                  it "should return list of two Excel processes" do
         | 
| 1578 1578 | 
             
                    excel1 = Excel.new
         | 
| 1579 1579 | 
             
                    excel2 = Excel.current
         | 
| 1580 1580 | 
             
                    excel3 = Excel.create
         | 
| 1581 | 
            -
                    Excel. | 
| 1581 | 
            +
                    Excel.known_excel_instances.should == [excel1,excel3]
         | 
| 1582 1582 | 
             
                  end
         | 
| 1583 1583 |  | 
| 1584 | 
            -
             | 
| 1585 | 
            -
             | 
| 1586 1584 | 
             
                end
         | 
| 1587 1585 |  | 
| 1588 1586 | 
             
                context "with hwnd and hwnd2excel" do
         | 
| @@ -1724,10 +1722,6 @@ module RobustExcelOle | |
| 1724 1722 | 
             
                    @excel1["firstcell"].should == "foo"
         | 
| 1725 1723 | 
             
                  end        
         | 
| 1726 1724 |  | 
| 1727 | 
            -
                  it "should return default value if name not defined and default value is given" do
         | 
| 1728 | 
            -
                    @excel1.nameval("foo", :default => 2).should == 2
         | 
| 1729 | 
            -
                  end
         | 
| 1730 | 
            -
             | 
| 1731 1725 | 
             
                  it "should evaluate a formula" do
         | 
| 1732 1726 | 
             
                    @excel1.nameval("named_formula").should == 4
         | 
| 1733 1727 | 
             
                    @excel1["named_formula"].should == 4
         | 
| @@ -1736,18 +1730,18 @@ module RobustExcelOle | |
| 1736 1730 | 
             
                  it "should raise an error if name not defined" do
         | 
| 1737 1731 | 
             
                    expect {
         | 
| 1738 1732 | 
             
                      @excel1.nameval("foo")
         | 
| 1739 | 
            -
                    }.to raise_error(NameNotFound, / | 
| 1733 | 
            +
                    }.to raise_error(NameNotFound, /name "foo"/)
         | 
| 1740 1734 | 
             
                    expect {
         | 
| 1741 1735 | 
             
                    @excel1["foo"]
         | 
| 1742 | 
            -
                    }.to raise_error(NameNotFound, / | 
| 1736 | 
            +
                    }.to raise_error(NameNotFound, /name "foo"/)
         | 
| 1743 1737 | 
             
                    expect {
         | 
| 1744 1738 | 
             
                      excel2 = Excel.create
         | 
| 1745 1739 | 
             
                      excel2.nameval("one")
         | 
| 1746 | 
            -
                    }.to raise_error(NameNotFound, / | 
| 1740 | 
            +
                    }.to raise_error(NameNotFound, /name "one"/)
         | 
| 1747 1741 | 
             
                    expect {
         | 
| 1748 1742 | 
             
                      excel3 = Excel.create(:visible => true)
         | 
| 1749 1743 | 
             
                      excel3["one"]
         | 
| 1750 | 
            -
                    }.to raise_error(NameNotFound, / | 
| 1744 | 
            +
                    }.to raise_error(NameNotFound, /name "one"/)
         | 
| 1751 1745 | 
             
                  end
         | 
| 1752 1746 |  | 
| 1753 1747 | 
             
                  it "should set a range to a value" do
         | 
| @@ -1761,10 +1755,10 @@ module RobustExcelOle | |
| 1761 1755 | 
             
                  it "should raise an error if name cannot be evaluated" do
         | 
| 1762 1756 | 
             
                    expect{
         | 
| 1763 1757 | 
             
                      @excel1.set_nameval("foo", 1)
         | 
| 1764 | 
            -
                      }.to raise_error(NameNotFound, / | 
| 1758 | 
            +
                      }.to raise_error(NameNotFound, /name "foo"/)
         | 
| 1765 1759 | 
             
                    expect{
         | 
| 1766 1760 | 
             
                      @excel1["foo"] = 1
         | 
| 1767 | 
            -
                      }.to raise_error(NameNotFound, / | 
| 1761 | 
            +
                      }.to raise_error(NameNotFound, /name "foo"/)
         | 
| 1768 1762 | 
             
                  end
         | 
| 1769 1763 | 
             
                end
         | 
| 1770 1764 |  |