Solved

Export CFDirectory result to Excel

Posted on 2010-08-25
4
450 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
Blue Coat API portal URL 2 181
Google Maps 7 82
Gulp not seeing Changes 4 92
Coldfusion / Railo 4 -  datetimeFormat problem 3 37
In this short web based tutorial, I wanted to show users how they can still use the powers of FrontPage in conjunction with Expression Web 3.  Even though Microsoft eliminated the use of Web components, we can still use them with FrontPage and edit …
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. 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 : Go t…

685 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