Solved

Cfspreadsheet to write to DOWNLOADS folder on loca PC

Posted on 2014-10-30
3
391 Views
Last Modified: 2014-10-31
What is CFPREADSHEET syntax to have CF generate an Excel spreadsheet  on the local PC in folder DOWNLOADS ?
0
Comment
Question by:Errol Farro
  • 2
3 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 40414594
Depends on the source of the data and whether you need special formatting, but you can find a simple example in the docs. Just update the "fileName" path as needed.


<!--- get some sample data --->
<cfquery name="getCourses" datasource="cfdocexamples">
   SELECT CORNUMBER,DEPT_ID,COURSE_ID,CORNAME
   FROM COURSELIST
</cfquery>

<!--- Write the query to a file --->
<cfspreadsheet action="write"
    filename="c:\path\to\downloadsFolder\someFile.xls"
    query="getCourses"  
    sheetname="courses"
    overwrite="true">
0
 

Author Comment

by:Errol Farro
ID: 40414656
The CF runs on a server and is being access from a local PC.

When creating an Excel using <cfcontent type="application/msexcel"> <cfheader name="Content-Disposition" value="filename=Results.xls">, the Results.xls file is always created on the local PC in the Downloads directory.

How can I get the same behavior using CFPSREADsheet but without specifying filename="C:\Users\userName\Downloads" where userName is the user who has activated the CF application?
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 40414858
If your question is how to generate a download without saving it to a file on the server.  You could save it to a variable instead of a file:


Then return the binary:

... run query ...
<cfspreadsheet action="write"
    name="yourVariable"
    query="getCourses"  
    sheetname="courses"
    overwrite="true"> 

<cfheader name="Content-Disposition" value="filename=Results.xls">
<cfcontent type="application/msexcel" variable="#SpreadsheetReadBinary(yourVariable)#">

Open in new window


However, saving to a file isn't necessarily a bad thing. You could save it ram://  OR to a temp file on disk. Then use <cfcontent deletefile="true" ...> to automatically remove the file when the download is finished.

>The Results.xls file is always created on the local PC in the Downloads directory.

Not exactly.  Server side code can't save anything on a user's computer without their consent. The content is generated on the server, and the cfheader/cfcontent trigger a download/save prompt in the user's browser.  Ignoring the browser's temp directory, the file isn't saved on the user's computer until they click the "Save As" button in their browser. The fact that it may be saved to C:\Users\userName\Downloads is entirely dependent on browser settings.   ie That is the default for windows, but the path can be set to anything you want.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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