Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 348
  • Last Modified:

cfspreadsheet basics

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
cb_it
Asked:
cb_it
  • 3
1 Solution
 
_agx_Commented:
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
 
cb_itAuthor Commented:
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
 
_agx_Commented:
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
 
_agx_Commented:
(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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now