Ruby script to load .xlsx files into a MySQL database
For starters, I'd break the script up into many more methods. If nothing else it'll avoid the "pyramid code" (all that nested indentation) you've got going on. But it should also make the code easier to understand, maintain and extend.

I'd also, as an overall approach, favor writing a file of INSERT statements, rather than inserting each row, one at a time. At least for testing, I'd highly recommend this. You can always read this file directly into mysql later. The point is that if, say, the first 2 rows get inserted fine, but the 3rd fails, you'll already have those first 2 row in the database, when you run the script again. And since the .xlsx files only get removed if everything works out, the same file may be imported several times - perhaps failing halfway several times - resulting in a bunch of doubled rows.

Speaking of files, I'd avoid completely removing the xlsx file once it's done. Probably better to move it or rename it, so you still have it, but it won't get read again. In general, just try to avoid destructive operations unless necessary.

Anyway, the code below is an attempt to break up your code. I haven't tried it, so don't just blindly run it or anything.

Moreover, I'm using RubyXL's get_table method here - I don't know if that's actually useful in your case. However, I imagine that the xlsx-files have a header row, since you always skip the first row. If those headers are sensical, you can use them to your advantage, and avoid the hard-coded (and opaque) column indices.

Some of the methods here have optional arguments that default to instance variables. I won't recommend that for production use; it's there for testing purposes. You can either make the arguments required, or you can remove the arguments, and rely on instance variables.

# Hash for translating xlsx columns to mysql columns
# The procs may not be necessary; get_table may handle conversion
COLUMN_TRANSLATIONS = {
  "Service"     =&gt; { column: "service",     proc: :to_s },
  "Impressions" =&gt; { column: "impressions", proc: :to_i },
  "Clicks"      =&gt; { column: "clicks",      proc: :to_i },
  "Cost"        =&gt; { column: "cost",        proc: :to_f },
  "Total"       =&gt; { column: "total",       proc: :to_f }
}.freeze

# Gets the relevant .xlsx-files
def xlsx_files(directory = @paid_adv_work_path)
  path = File.join(directory, "*(PPC)*.xlsx")
  files = Dir.glob(path)
  files.reject { |file| File.basename(file) =~ /^~/ }
end

# Use get_table to get structured data
def read_xlsx(file)
  workbook  = RubyXL::Parser.parse(file)
  worksheet = workbook.worksheets[0]
  worksheet.get_table(COLUMN_TRANSLATIONS.keys)[:table]
end

# Translate into a mysql-friendly format
def translate_table(table)
  table.map do |row|
    row.map do |column, value|
      lookup = COLUMN_TRANSLATIONS[name.to_s] # get_table uses symbol keys; we want strings
      value = value.send(lookup[:proc])
      [lookup[:column], value]
    end
  end
end

# Insert a row
def insert_rows(rows, connection = @db)
  columns = COLUMN_TRANSLATIONS.map { |name, info| info[:column] }
  rows.each do |row|
    columns = row.keys.join(", ")
    values  = row.values.map { |value| "'#{connection.escape(value)}'" }.join(", ")
    query = "INSERT INTO ppc (#{columns}) VALUES (#{values});"
    connection.query(query)
  end
end

# Put it together per-file
def import_xlsx_file(file, connection = @db)
  table = read_xlsx(file)
  rows  = translate_table(table)
  insert_rows(rows, connection)
end

# And all together now...
def import
  xlsx_files.each do |file|
    begin
      import_xlsx_file(file)
      # Handle file removal/renaming here
    rescue =&gt; e
      @log.info "Failed to import #{file}: #{e.message}"
    end
  end
end


An advantage of having the optional arguments is that you can swap out the database connection with a stand-in object, like:

class QueryLogger
  def initialize(logger)
    @logger = logger
  end

  def query(string)
    @logger.info(string)
  end
end


And try something like import_xlsx_file(some_file, QueryLogger.new(@log)) to log the queries instead of actually running them on the server.