def xl_to_csv(infile, outfile)
    filepath = File.expand_path(infile)
    puts "xl_to_csv: #{infile} => #{outfile}" if verbose?

    unless File.exists?(filepath)
      puts "Unable to find file."
      puts "  #{filepath}"
      return
    end

    #   Open an Excel file
    xl_app.open_workbook filepath

    # Build a list of work sheets to dump to file.
    sheets_in_file = []

    sheet_saved_count = 0

    xl_app.worksheet_names.each do |sheetname|
      if( sheetname.match(/CQDS/) || sheetname.match(/PLK/) )
        sheets_in_file << sheetname
        puts "Converting sheet #{sheetname}" if verbose?
        sheet_saved_count += 1
      end
    end

    if (1 > sheet_saved_count)
      puts "*** No sheets labeled 'PLK' or 'CQDS' ***"
      puts "Verify #{infile} is formatted correctly."
      # Close Excel
      xl_app.close_workbook
      return
    end

    # Write sheet data to file.
    File.open(outfile, "w") do |f|
      data = xl_app.worksheet_data(sheets_in_file[0])
      for row in data
        row_data = []
        for a_cell in row
          row_data << process_cell_value(a_cell)
        end

        contains_data = false

        # Determine if the row contains any data.
        for cell in row_data
          if(cell.match(/[^,\r\n]+/))
            contains_data = true
          end
        end

        # Insert an empty line if the row contains no data.
        if(true == contains_data)
          f << row_data.join(",")
          f << "\n"

          if(true == verbose?)
            puts "#{row_data}"
          end

        else
          f << "\n"

          if(true == verbose?)
            puts "\n"
          end
        end
      end
    end

    # Strip empty data from end of lines
    clean_csv(outfile)

    # Close Excel
    xl_app.close_workbook
  end
def xl_to_csv(infile, outfile)
    filepath = File.expand_path(infile)
    puts "xl_to_csv: #{infile} => #{outfile}" if verbose?

    unless File.exists?(filepath)
      puts "Unable to find file."
      puts "  #{filepath}"
      return
    end

    #   Open an Excel file
    xl_app.open_workbook filepath

    # Build a list of work sheets to dump to file.
    sheets_in_file = []

    sheet_saved_count = 0

    xl_app.worksheet_names.each do |sheetname|
      if( sheetname.match(/CQDS/) || sheetname.match(/PLK/) )
        sheets_in_file << sheetname
        puts "Converting sheet #{sheetname}" if verbose?
        sheet_saved_count += 1
      end
    end

    if (1 > sheet_saved_count)
      puts "*** No sheets labeled 'PLK' or 'CQDS' ***"
      puts "Verify #{infile} is formatted correctly."
      # Close Excel
      xl_app.close_workbook
      return
    end

    # Write sheet data to file.
    File.open(outfile, "w") do |f|
      data = xl_app.worksheet_data(sheets_in_file[0])
      for row in data
        row_data = []
        for a_cell in row
          row_data << process_cell_value(a_cell)
        end

        contains_data = false

        # Determine if the row contains any data.
        for cell in row_data
          if(cell.match(/[^,\r\n]+/))
            contains_data = true
          end
        end

        # Insert an empty line if the row contains no data.
        if(true == contains_data)
          f << row_data.join(",")
          f << "\n"

          if(true == verbose?)
            puts "#{row_data}"
          end

        else
          f << "\n"

          if(true == verbose?)
            puts "\n"
          end
        end
      end
    end

    # Strip empty data from end of lines
    clean_csv(outfile)

    # Close Excel
    xl_app.close_workbook
  end
Convert the 1st sheet in an xls(x) file to a csv file.