Solved

cfspreadsheet basics

Posted on 2013-06-07
4
328 Views
Last Modified: 2013-06-08
Just getting back into CF after a long layoff of about 10 years!

Trying out the cfspreadsheet tag. I have a query, and I am able to get the xls file to be saved on my server - I just want a prompt displayed for the user to either open or save the file - can this be done with cfspreadsheet??

Thanks for any help!
0
Comment
Question by:cb_it
  • 3
4 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 39229124
No. cfspreadsheet only generates the file. Use cfcontent/cfheader to return it to the browser.

IIRC, there is one small nuisance w/cfspreadsheet. "query" and "name" are mutually exclusive, meaning you must save it to disk first.  Use a unique file name (to avoid clashes w/other downloads) -  something like createUUID() should work:

<cfset filePath = "c:\desired\path\to\#CreateUUID()#.xls">
<cfspreadsheet action="write" query="yourQuery" fileName="#filePath#">

Open in new window


then display it with cfcontent/cfheader. Use the "delete" attribute so the temp file will be removed automatically after the download (or shortly thereafter).

<cfheader name="Content-Disposition" value="attachment; filename=whateverNameYouWant.xls" >
<cfcontent type="application/vnd.msexcel" file="#filePath#" delete="true" >

Open in new window


EDIT If you use the spreadsheet functions, instead of the tag, you do not need to save it to a file. You can save it to a variable instead. Works better with small spreadsheets.

<cfset theSheet = SpreadSheetNew()>
... add query data ...
<cfheader name="Content-Disposition" value="attachment; filename=whateverNameYouWant.xls" >
<cfcontent type="application/vnd.msexcel" file="#SpreadSheetReadBinary(theSheet)#" >

Open in new window

0
 

Author Comment

by:cb_it
ID: 39229829
Working perfectly, thanks. I wish the Adobe documentation was a little better, or gave more examples. I'm sure opening/saving the actual file is used quite a bit. Thanks again for the help.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39229856
That's a common problem w/documentation.  It's too focused on explaining the single tag or function. Not enough common usage examples that show how to tie different things together.  I understand why ... it's involved. Takes a lot of time to put together good examples. (Nothing worse than a bad or broken example). Still .. would be nice to see more of them.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39231740
(For the archives) Typo correction. The 2nd example should be:

<cfset theSheet = SpreadSheetNew()>
... add query data to sheet ...
<cfheader name="Content-Disposition" value="attachment; filename=someName.xls" >
<cfcontent type="application/vnd.msexcel" variable="#SpreadSheetReadBinary(theSheet)#" >
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…
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 …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

785 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