Skip to content

Instantly share code, notes, and snippets.

@heaven
Created December 7, 2011 08:30
Show Gist options
  • Save heaven/1442001 to your computer and use it in GitHub Desktop.
Save heaven/1442001 to your computer and use it in GitHub Desktop.
def errors_report
return nil unless self.source.present?
# self.source — the paperclip attachment
book = Spreadsheet.open(self.source.path)
sheet = book.worksheet(0)
errors = self.import_errors.map { |e| e[:line] }
path = "tmp/#{self.source.original_filename}-errors.xls"
# debugger
# sheet.rows
# => []
# I need to remove all the rows which is not included in the errors array
sheet.each do |row|
# this block executing correctly
next if errors.include?(row.idx)
sheet.delete_row(row.idx)
end
return path if book.write(path)
# => got the same file as on input
nil
end
@zdavatz
Copy link

zdavatz commented Dec 16, 2011

Don't save the file back to the same file name if you edit an XLS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment