Skip to main content
Known Participant
August 30, 2024
Question

Error while exporting to excel - File format and extension doesn't match

  • August 30, 2024
  • 2 replies
  • 1900 views

Hi,

I have the below code to generate output to excel.  But when i open the excel after downloading, it shows that "file format and extension doesn't match".  Please refer the screenshot and generated excel attached.

<cfheader name="content-disposition" VALUE="attachment; filename=sitereport.xls">
<cfset type="application/msexcel">

 

Is it because it is .xls file and I am opening in office 365 enterprise (where the extension should be .xlsx)?  Attached the excel file also for reference.

 

regards,

Sunil

    This topic has been closed for replies.

    2 replies

    Charlie Arehart
    Community Expert
    Community Expert
    August 30, 2024

    While you've attached the screenshot, I'm not seeing the xls, at least on mobile. I also don't see it in your follow-up message where you seem to have realized you'd not attached it. Bkbk, are you seeing it?

     

    In any case, I have some questions:

    1. How did you create the xls file? If in cfml, using what tag(s)? Or was it created outside of cfml? 
    2. Is this process one that worked previously? If so, what changed?
    3. What cf version and update are you on? You can view this via the variable, server.coldfusion.productversion
    /Charlie (troubleshooter, carehart. org)
    Known Participant
    August 30, 2024

    I am not able to attach the excel file.  I renamed to .txt but still it failed in upload.

     

    1. The excel file is created outside and saved in the same folder.  While running the code (code pasted in the first thread), it output the file in browser.  
    2. No change, it was giving the same issue (prompt alert)
    3. cf version = 2018,0,19,330149
    Charlie Arehart
    Community Expert
    Community Expert
    August 30, 2024

    Still not clear. Did the code ever work for any excel file? Does it work for some and not others? Did it work for some cf version before your cf2018 update 19?

     

    Also, even if you can't upload the file in this forum, you could put it on something like Dropbox, Google drive, one drive, or otherwise and give us the link. It may make it easier for us to come up with a solution, if it's at all possible for that file. 

     

    Finally, as you may know, cf2018 is no longer updated since July 2023. If the cost of licensing cf2023 is an issue (because the 50% upgrade discount is only for those on cf2021), note that there's a special offer for a few more weeks where those on cf2018, cf2016, or earlier can buy a cf license at a 25% discount. More at https://www.carehart.org/blog/2024/7/8/limited_time_upgrade_discount_to_CF2023_from_older_releases

    /Charlie (troubleshooter, carehart. org)
    Known Participant
    August 30, 2024

    Attached the excel file. Remove .txt from the file name.

    BKBK
    Community Expert
    Community Expert
    August 30, 2024

    The value application/msexcel is incorrect. The correct MIME types for Excel are:

    • application/vnd.ms-excel (for XLS)
    • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (for XLSX)
    BKBK
    Community Expert
    Community Expert
    August 30, 2024

    Example:

     

    <cfheader name="Content-Disposition" value="attachment; filename=MySales.xls">
    <cfcontent type="application/vnd.ms-excel">
    
    <table border="1">
    	<tr><td>Month</td><td>Quantity</td><td>$ Sales</td></tr>
    	<tr><td>January</td><td>80</td><td >245</td></tr>
    	<tr><td>February</td><td>100</td><td>699</td></tr>
    	<tr><td>March</td><td>230</td><td >2036</td></tr>
    	<tr><td>Total</td><td>=Sum(B2..B4)</td><td>=Sum(C2..C4)</td></tr>
    </table>

    You may then ignore Microsoft Office's prompt that the file you are trying to open is in a format different from the specified file extension.