Solved

Cfspreadsheet to write to DOWNLOADS folder on loca PC

Posted on 2014-10-30
3
327 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_
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
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 …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now