This works for me

<cfheader name="Content-Disposition" value="attachment;
filename=ExportToXLS.xls">
<cfcontent type="application/msexcel" file="{absolute path to file}"
deletefile="Yes">

Pascal

> -----Original Message-----
> From: cf coder [mailto:[EMAIL PROTECTED]
> Sent: dinsdag 27 januari 2004 12:27
> To: CF-Talk
> Subject: CFFILE/CFCONTENT question.. Please help
>
> Hello Everybody,
>
> I have this form with a a drop-down box and a submit button.
> The drop down box displays a list of departments and has a
> onChange event, that calls a _javascript_ function that reloads
> the page. ColdFusion reads the querystring, passes it in a
> cfquery select statement and displays the usernames and
> fullnames associated with the dept from a sql table.
>
> I have been asked to also add a submit button which would
> take the results returned from the query and export it to a
> xls spreadsheet.
> I have added the code, for some reason when it is submitted,
> the File Download windows dialog box displays the wrong information
>
> File Name : Displays the name of the coldfusion file which
> contains this code, when I want it to display the file name
> given in the cffile FILE attribute.
> File Type : empty, when I want it to display MSExcel
>
> Here is my code. Somebody please show me how to get round
> this problem.
>
> report.cfm
>
> <cfparam name="url.dept" default="">
> <script language="_javascript_" type="text/_javascript_">
> function setDept() {
> if (document.the_form.deptselect.selectedIndex != 0) {
>    
> myindex=document.the_form.deptselect.selectedIndex;
>     
> location=document.the_form.deptselect.options[myindex].value;
>     return true;
> }
> else
> {
> location.href="" an option";
> return true;
> }
> }
> function setFlag(){
> document.the_form.flag.value=1;
> return true;
> }
> </script>
>
> <table align="left" border="0">
> <form name="the_form" action=""> > method="post">
> <tr>
>   <td align="left" nowrap>
> <select name="deptselect" > > <option value="" selected>-----select a
> department----</option>
> <option value="report.cfm?dept=Finance" <cfif
> url.dept EQ "Finance">selected</cfif>>Finance</option>
> <option value="report.cfm?dept=HR" <cfif
> url.dept EQ "HR">selected</cfif>>HR</option>
> <option value="report.cfm?dept=Mgmt" <cfif
> url.dept EQ "Mgmt">selected</cfif>>Mgmt</option>
> </select>
> <cfif url.dept eq "">
>   </td>
> </tr>
> <cfelseif url.dept neq "">
> <input type="hidden" name="flag" value="0">
> <input type="Submit" name="submit" value="Export to
> Spreadsheet" setFlag();">
>   </td>
> </tr>
> </cfif>
>   </form>
>
> <cfquery name="getDetails" datasource="mydsn">
>   select firstlastname, useremail from userdetails
> where area like '%#url.dept#%'
>     </cfquery>
>     
> <tr vAlign="top">
> <th vAlign="bottom" width="50%" bgColor="#444444"
> class="arttext">
> <font color="#FFFFFF">Username</font>
> </th>
> <th vAlign="bottom" width="50%" bgColor="#444444"
> class="arttext">
> <font color="#FFFFFF">Email</font>
> </th>
>    </tr>
>   
>    <cfoutput query="getDetails">
>    <tr>
> <td vAlign="bottom" width="50%" bgColor="E4E4E4"
> class="arttext">
> #firstlastname#
> </td>
> <td vAlign="bottom" width="50%" bgColor="E4E4E4"
> class="arttext">
> #useremail#
> </td>
>    </tr>
>    <cfif IsDefined("form.flag")>
>    <cfif form.flag EQ "1">
> <CFSET QUOTE = Chr(127)>
> <CFSET log_string = QUOTE & firstlastname & QUOTE & ","
> & QUOTE & useremail & QUOTE>
> <cfset log_string =
> Replace(log_string,"#chr(34)#","#chr(34)##chr(34)#","All")>
> <cfset log_string =
> Replace(log_string,"#chr(127)#","#chr(34)#","All")>
>
> <CFFILE ACTION=""> > FILE="\ExportToXLS.xls"
> ADDNEWLINE="Yes"
> OUTPUT="#log_string#">
> </cfif>
> </cfif>
>   </cfoutput>
>   
>   <cfif IsDefined("form.flag")>
>    <cfif form.flag EQ "1">
>    <CFHEADER NAME="Content-Type"
> VALUE="application/msexcel">
> <CFHEADER NAME="Content-Disposition" VALUE="inline;
> filename=\ExportToXLS.xls">
> <CFCONTENT TYPE="application/msexcel"
> FILE="\ExportToXLS.xls" deletefile="Yes">
>    </cfif>
>   </cfif>
> </table>
>   
> Best Regards,
> cfcoder
>
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free web site building tool. Try it!
> http://webhosting.yahoo.com/ps/sb/
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to