Direct downloading a xls file without writing it to the directory by Spreadsheet gem

You can send it to the browser without saving it as a local file at all as follows

spreadsheet = StringIO.new 
book.write spreadsheet 
send_data spreadsheet.string, :filename => "yourfile.xls", :type =>  "application/vnd.ms-excel"

You could try this code

book.write "data.xls"

send_file "/path/to/data.xls", :type => "application/vnd.ms-excel", :filename => "data.xls", :stream => false

# and then delete the file

File.delete("path/to/data.xls")

Passing :stream => false to send_file will instruct Rails to copy the entire file into memory before streaming, so using File.delete immediately after send_file would be fine since send_file returns immediately without waiting for the download to complete. Having said that, with very large files you may see some memory bottle necks depending on the amount of memory available.

HTH