# Problem with downloading a generated Excel sheet

**URL:** <https://www.ruby-forum.com/t/problem-with-downloading-a-generated-excel-sheet/180997>\
**Category:** Rails\
**Created:** [January 3, 2010, 11:55am UTC](https://www.ruby-forum.com/t/problem-with-downloading-a-generated-excel-sheet/180997 "2010-01-03T11:55:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amabdelsalam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@amabdelsalam](https://www.ruby-forum.com/u/amabdelsalam)\
**Post date:** [January 3, 2010, 11:55am UTC](https://www.ruby-forum.com/t/problem-with-downloading-a-generated-excel-sheet/180997/1 "2010-01-03T11:55:49Z")

</div>

Hello,

I’m using the spreadsheet/excel gem to generate an excel sheet that I  
want user to be able to download it once it’s generated. Please take a  
look on the below code:

@contacts=Contact.find(:all)  
if @contacts.size\>0  
file="#{Date.today}\_Report.xls"

```
    workbook=Spreadsheet::Excel.new("#{RAILS_ROOT}/public/reports/#{file}")
    worksheet=workbook.add_worksheet("All Users on Database")
    worksheet.write(0, 0, "First Name")
    worksheet.write(0, 1, "Last Name")
    worksheet.write(0, 2, "Email")
    row = 2
    @contacts.each do |users|
      worksheet.write(row, 0, "#{users.first_name}")
      worksheet.write(row, 1, "#{users.last_name}")
      worksheet.write(row, 2, "#{users.email}")

      row += 1

    end

    workbook.close
    send_file "#{RAILS_ROOT}/public/reports/#{file}", :type =>

```

‘text/xl; charset=utf-8; header=present’, :disposition =\>  
‘attachement’,:filename=\>"#{file}"

The excel sheet is generated correctly, but the last line gives an error  
in the server, and no file is downloaded.

Here is the error:  
NoMethodError (undefined method `call’ for nil:NilClass):

I don’t know what is the nill class of the above line.

Can anyone help me?

---

<div class="post-metadata">

**Author:** ![amabdelsalam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@amabdelsalam](https://www.ruby-forum.com/u/amabdelsalam)\
**Post date:** [January 4, 2010, 1:49pm UTC](https://www.ruby-forum.com/t/problem-with-downloading-a-generated-excel-sheet/180997/2 "2010-01-04T13:49:56Z")

</div>

Thank you for your response, It helped me a lot.

---

<div class="post-metadata">

**Author:** ![amabdelsalam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@amabdelsalam](https://www.ruby-forum.com/u/amabdelsalam)\
**Post date:** [January 4, 2010, 10:34am UTC](https://www.ruby-forum.com/t/problem-with-downloading-a-generated-excel-sheet/180997/3 "2010-01-04T10:34:03Z")

</div>

Ahmed A. wrote:

> Hello,
> 
> I’m using the spreadsheet/excel gem to generate an excel sheet that I  
> want user to be able to download it once it’s generated. Please take a  
> look on the below code:

[snip]

> ```
> workbook.close
> send_file "#{RAILS_ROOT}/public/reports/#{file}", :type =>
> 
> ```
> 
> ‘text/xl; charset=utf-8; header=present’, :disposition =\>  
> ^^  
> This is a typo, should be ‘text/xls’?

> ‘attachement’,:filename=\>“#{file}”  
> ^^^^^^^^^^^  
> This is a typo, should be ‘attachment’

> The excel sheet is generated correctly, but the last line gives an error  
> in the server, and no file is downloaded.
> 
> Here is the error:  
> NoMethodError (undefined method `call’ for nil:NilClass):
> 
> I don’t know what is the nill class of the above line.

My guess is attachement.

> Can anyone help me?

HTH,  
gvb

–

You received this message because you are subscribed to the Google  
Groups “Ruby on Rails: Talk” group.  
To post to this group, send email to removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).
