Skip to main content
Inspiring
February 16, 2011
Question

CFCONTENT Excel - Firefox errors

  • February 16, 2011
  • 1 reply
  • 1820 views

When I use <cfcontent type="application/vnd.ms-excel"> tag it works great on Internet Explorer.

But when I use Firefox it doesnt

It does NOT name the file correctly (It doesnt have the xls extension) therefore it doesnt make the file association with the excel program.

and my users dont know to rename and add the extension.

Is there anything I can do about this?

    This topic has been closed for replies.

    1 reply

    Inspiring
    February 16, 2011

    As per my response to your other similar post: CFCONTENT doesn't change the name of the returned file, it just sets the MIME type of the response.  If you want to change the name of the file being delivered you need to do so by changing the appropriate HTTP header, using CFHEADER.

    This is all in the documentation, btw.  It's a good first port-of-call when having difficulties with CF tags etc:

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7c82.html

    --

    Adam

    orangexception
    Participating Frequently
    February 17, 2011

    I second Adam.  Set the file extension to .xls (in cfheader).

    I'm surprised that you got IE to download with <cfcontent type="application/vnd.ms-excel">.  This gave me problems last time I tested.

    Typically I use code like this for Excel files:

    <!--- I set request.isIE in onRequestStart() in application.cfc --->

    <cfset request.isIE = false />

    <cfif cgi.http_user_agent contains "MSIE">

         <cfset request.isIE = true />

    </cfif>

    <cfheader name="Content-Disposition" value="attachment; filename=#FileName#.xls">

    <cfif request.isIE>

         <cfcontent file="#StorageDir##FileName#" deletefile="true" type="application/unknown">

    <cfelse>

         <cfcontent file="#StorageDir##FileName#" deletefile="true" type="application/vnd.ms-excel">

    </cfif>