roo-rb/roo-xls

View on GitHub
lib/roo/xls/spreadsheet_extensions.rb

Summary

Maintainability
A
45 mins
Test Coverage
module Roo
  module Xls
    # patch for skipping blank rows in the case of
    # having a spreadsheet with 30,000 nil rows appended
    # to the actual data.  (it happens and your RAM will love me)
    module SpreadsheetEachSkipBlanks
      def each(skip = dimensions[0])
        blanks = 0
        skip.upto(dimensions[1] - 1) do |i|
          if row(i).any?
            Proc.new.call(row(i))
          else
            blanks += 1
            blanks < 20 ? next : return
          end
        end
      end
    end
  end
end

class Spreadsheet::Worksheet
  include Roo::Xls::SpreadsheetEachSkipBlanks
end