Solved

Export CFDirectory result to Excel

Posted on 2010-08-25
4
451 Views
Last Modified: 2013-12-16
I want to obtain the files in a directory and export the result to excel.  I have the following code but all it does is display the results on the website.  An excel file containing the files in the dir is not created

Any ideas?
<HTML>
  <head>
    <title>>> </title>
  </head>
  <body>
    <cfcontent type="application/msexcel">
    <CFDIRECTORY action="LIST" directory="D:\Image" name="myimage">
    <cfheader name="Content-Disposition" value="filename=image.xls">
    <table>
      <tr>
	<th>my images</th>
      </tr>
      <cfoutput query="myimage">
      <TR>
        <cfif #name# neq 'index.cfm'>
          <TD>#name#</TD>
        </cfif>
      </TR>
      </cfoutput>
    </table>		
  </body>
</HTML>

Open in new window

0
Comment
Question by:CipherIS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:JohnHowlett
ID: 33525594
Try this (cfcontent at the top):

 <cfheader name="Content-Disposition" value="filename=image.xls">

    <cfcontent type="application/msexcel">
    <CFDIRECTORY action="LIST" directory="D:\Image" name="myimage">
    <table>
      <tr>
      <th>my images</th>
      </tr>
      <cfoutput query="myimage">
      <TR>
        <cfif name neq 'index.cfm'>
          <TD>#name#</TD>
        </cfif>
      </TR>
      </cfoutput>
    </table>



When you go to this page, you should be asked to open it in Excel.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 33526113
(no points please ...)

I suspect the cause is how the cfheader/cfcontent tags are ordered.  I believe you must list the header _first_, then cfcontent.  

     <cfheader name="Content-Disposition" value="filename=image.xls">
     <cfcontent type="application/msexcel">

>>   <cfcontent type="application/msexcel">
>>    <CFDIRECTORY action="LIST" directory="D:\Image" name="myimage">
>>    <cfheader name="Content-Disposition" value="filename=image.xls">

I noticed you've got the cfdirectory and header code mixed together.  MS Excel can sometimes be picky about how it parses html. So best to keep all display code (ie html) separate from everything else. I'd suggest running the cfdirectory first

     <!--- do any NON-display code first....--->
     <CFDIRECTORY action="LIST" directory="D:\Image" name="myimage">

 ... then generate the "excel" output in one shot.

     <!--- header code ....--->
     <cfheader name="Content-Disposition" value="filename=image.xls">
     <cfcontent type="application/vnd.ms-excel">
     <!--- file content ....--->
     <table>
      <tr>
      .... etc.....
      </TR>
    </table>            

0
 
LVL 1

Author Comment

by:CipherIS
ID: 33531320
Did not work.
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 33533759
>> <cfheader name="Content-Disposition" value="filename=image.xls">

The Content-Disposition value is missing the type. ie inline (display in browser) or attachment (prompt to download).  Also, if you have debugging enabled it can interfere with Excel.  So suppress it if needed.

The attached works correctly (condensed for brevity)

<!--- suppress any debugging output. it can interfere with excel --->
<cfsetting showdebugoutput="false">
      <CFDIRECTORY action="LIST" directory="D:\Image" name="myimage">
      <cfheader name="Content-Disposition" value="inline; filename=image.xls">
      <cfcontent type="application/vnd.msexcel">
      <table>
      <tr><th>my images</th></tr>
      <cfoutput query="myimage">
            <TR><cfif name neq 'index.cfm'><TD>#name#</TD></cfif></TR>
      </cfoutput>
      </table>
</cfsetting>
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php :…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question