Solved

Cfspreadsheet to write to DOWNLOADS folder on loca PC

Posted on 2014-10-30
3
413 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
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 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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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