?
Solved

Cfspreadsheet to write to DOWNLOADS folder on loca PC

Posted on 2014-10-30
3
Medium Priority
?
467 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

770 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