title: Iterate over an Excel workbook and index everything?
body: <p>This would be done in Ruby..I have provided what I have attempted thus far.</p>
  
  <p>I am curious as to if it is possible to iterate over an excel workbook (so it would be multiple sheets) and basically index/record where everything is located.  Lets say I have a workbook of 10 sheets.  I want it to grab the first sheet, record that sheets name, then move to the first cell and begin indexing(not sure if correct word) the data on that sheet.  It would record the cell location so for the first (1,A) and the data thats in it.  I am trying to output the data into a format as such like a CSV file or something:<img src="https://i.stack.imgur.com/q2EFp.png" alt="enter image description here">  </p>
  
  <p>Some code I have written that basically just iterates over every sheet and every cell in a workbook (removes whitespaces) and grabs its data and puts into a CSV...no sheet names or cell numbers present.  I am using the roo and csv gems:</p>
  
  <pre><code>require 'rubygems'
  require 'roo'
  
  #Classes Used
  class ArrayIterator
    def initialize(array)
      @array = array
      @index = 0
    end
  
    def has_next?
      @index &lt; @array.length
    end
  
    def item
      @array[@index]
    end
  
    def next_item
      value = @array[@index]
      @index += 1
      value
    end
  end
  
  #Open up files to compare
  w1 = Excelx.new ( "C:/Ruby/myworkbook.xlsx" )
  
  $values = Array.new
  i = 0.to_i
  # Continue until no worksheets left
  num_sheets = w1.sheets().size
  
  while  (i &lt; num_sheets)
        puts "i is currently : #{i}"
        puts "length of sheet array is : #{num_sheets}"
  
  #Grab first sheet of each workbook
    w1.default_sheet = w1.sheets[i]
   1.upto(w1.last_row) do | row |
      1.upto(w1.last_column) do | column |
          string = w1.cell(row, column).to_s
          if (string.strip.empty?) 
            puts "Whitespace!"
                  else
                    $values &lt;&lt; string
          end
      end
   end
     i = i + 1.to_i
  end  
  
  count = 0.to_i
  CSV.open('C:/Ruby/results.csv', "w") do |csv|   
   csv &lt;&lt; ['String']
  i = ArrayIterator.new($values)
     while i.has_next?
        csv &lt;&lt; [i.next_item]
        count += 1
       end
  end
  </code></pre>