4 Replies Latest reply on May 22, 2017 11:29 PM by andrél93139241

    Open a xlsx file with Coldfusion 10

    andrél93139241 Level 1

      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>

        • 1. Re: Open a xlsx file with Coldfusion 10
          BKBK Adobe Community Professional & MVP

          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#"> 

          • 2. Re: Open a xlsx file with Coldfusion 10
            andrél93139241 Level 1

            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é

            • 3. Re: Open a xlsx file with Coldfusion 10
              BKBK Adobe Community Professional & MVP

              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.

              • 4. Re: Open a xlsx file with Coldfusion 10
                andrél93139241 Level 1

                Hello,

                Ok, Thank you for your answer.

                Best regards

                André