Solved

Export CFDirectory result to Excel

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now