Skip to content

Instantly share code, notes, and snippets.

@airspeed
Last active December 16, 2015 19:08
Show Gist options
  • Save airspeed/5482437 to your computer and use it in GitHub Desktop.
Save airspeed/5482437 to your computer and use it in GitHub Desktop.
Durchläuft eine XSLX Datei mit roo.
def perform(timestamp, settings)
Dir.glob(Pathname.new(settings["in"]).join(settings["format"]).to_s).each do |filename|
xlsx_name = Pathname.new(settings["in"]).join("#{File.basename(filename, ".*")}.xlsx").to_s
FileUtils.mv(filename, xlsx_name)
xls = Roo::Spreadsheet.open(xlsx_name)
sh = xls.sheet(0)
CSV.open(filename, "w", {:col_sep => "\t"}) do |csv|
(0..sh.last_row).each do |rn|
row = sh.row(rn)
next if (/\d{4}-\d{2}-\d{2}|Beleg.+/).match(row[0].to_s).nil?
csv << row
end
end
end
Clixxie::FileManagement::FileLocker.new(Dir.glob(Pathname.new(settings["in"]).join("#{File.basename(settings["format"], ".*")}.xlsx").to_s), timestamp).lock
rescue
Rails.logger.error(e.inspect)
ExceptionNotifier::Notifier.background_exception_notification(e, :data => {:settings => settings}).deliver
Clixxie::FileManagement::FileLocker.new(Dir.glob(Pathname.new(settings["in"]).join("#{File.basename(settings["format"], ".*")}.xlsx").to_s), timestamp).lock
Clixxie::FileManagement::FileLocker.new(Dir.glob(Pathname.new(settings["in"]).join(settings["format"]).to_s), timestamp).lock
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment