Skip to main content
Inspiring
May 19, 2017
Question

Open a xlsx file with Coldfusion 10

  • May 19, 2017
  • 3 replies
  • 4164 views

Good morning everybody,

I have a page containing a list of files (Excel in different format such as xls, xlsx and xlsm).

To open it, I use different content type: (see code below)

For the extension xls and xlsm, it work fine.

for xlsx, I receive the following error:

     "Excel cannot open the file 'xxx.xlsx' because the file format or file extension is not valid."

I already search on internet https://forums.adobe.com/message/8911025#8911025 and tried without effect.

I can open if I use the "cfcontent type='application/msexcel' " but I loose everything about Excel 2010.

There is anyone which can help me?

Thank you in advance for your support

Best regards

André

the code:

<cfset FileName  = Replace(request.getXlsFile.Uploaded_File_Name, ' ', '_',"All") >

<cfset extension = request.getXlsFile.template_ext >

<cfoutput>   

    <cfheader name="Cache-Control" value="private">

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

   

    <cfswitch expression="#extension#" >

        <!--- Excel format --->

        <cfcase value="xls">

            <cfcontent type="application/msexcel" reset="Yes" variable="#request.getXlsFile.Uploaded_XLS_File#">       

        </cfcase>

        <cfcase value="xlsx" >

            <cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" reset="Yes" variable="#request.getXlsFile.Uploaded_XLS_File#">       

        </cfcase>          

        <cfcase value="xlsm" >

            <cfcontent type="application/vnd.ms-excel.sheet.macroEnabled.12" reset="Yes" variable="#request.getXlsFile.Uploaded_XLS_File#">       

        </cfcase>

        <cfdefaultcase>

            <cfcontent type="application/msexcel" reset="Yes" variable="#request.getXlsFile.Uploaded_XLS_File#">

        </cfdefaultcase>

    </cfswitch>

</cfoutput>

<cfabort>

    This topic has been closed for replies.

    3 replies

    Inspiring
    May 23, 2017

    Hello,

    Ok, Thank you for your answer.

    Best regards

    André

    Inspiring
    May 22, 2017

    Hello,

    First of all, I would like to thanks for your support.

    Next, I tried your suggestion. Effectively, the document open. But I'm afraid that if the document have functions or configuration relative to Excel 2010, I will have problem !

    What do you think?

    Thanks

    Best regards

    André

    BKBK
    Community Expert
    Community Expert
    May 23, 2017

    andrél93139241  wrote

    Next, I tried your suggestion. Effectively, the document open.

    Is that the answer your original question? If so, then please mark the question as correctly answered before you move on to further questions. When you do so, you help others who have similar questions.

    But I'm afraid that if the document have functions or configuration relative to Excel 2010, I will have problem !

    What do you think?

    I expect no problems with Excel 2010 files. If you find any, bring it here and we shall look into it together, of course.

    BKBK
    Community Expert
    Community Expert
    May 21, 2017

    Some suggestions:

    1) Use application/vnd.ms-excel instead of application/msexcel for XLS.

    2) <cfheader name="Cache-Control" value="private"> and reset="Yes" seem to have no use. Remove them.

    3) The error message suggests that the content is not of type XLSX. Test with the file attribute instead, that is,

    <cfcontent type="application/vnd.ms-excel" file="#request.getXlsFile.Uploaded_XLS_File#"> 
    <cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" file="#request.getXlsFile.Uploaded_XLS_File#"> 

    <cfcontent type="application/vnd.ms-excel.sheet.macroEnabled.12" file="#request.getXlsFile.Uploaded_XLS_File#">