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
  • 1871 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
    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
    August 30, 2024

    Please find the excel file.  Just open the excel file, you can see the prompt error/warning. If you click on Yes, it will load the records.  


    "Please find it" where? 

     

    And please respond to other questions I've asked in this thread and your earlier one with bkbk here. Help us help you. We don't work for Adobe but offer our time for free. 

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

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

    BKBK
    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
    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.