Solved

Export CFDirectory result to Excel

Posted on 2010-08-25
4
449 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
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
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…

860 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