Solved

Cfspreadsheet to write to DOWNLOADS folder on loca PC

Posted on 2014-10-30
3
428 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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

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 …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 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