Created
December 7, 2011 08:30
-
-
Save heaven/1442001 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't save the file back to the same file name if you edit an XLS.