Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with cfcontent to Excel 1

Status
Not open for further replies.

LarrySteele

Programmer
May 18, 2004
318
US
I've created a number of cfm pages that create .xls files using the cfcontent and cfheader tags. Right now I'm having difficulty troubleshooting a page generation problem as long as I do not include the aforementioned tags. As soon as I add the tags, I get a new blank page. No error, no data, no spreadsheet. I haven't a clue how to proceed troubleshooting this since there's nothing to see but a white page.

The tags that I'm using are:
[tt]<cfheader name="Content-Disposition" value="inline; filename=mgr_detail.xls">
<cfcontent type="application/msexcel">[/tt]

Any assistance on how to troubleshoot this would be most appreciated.

- Larry
 
Thanks for the suggestion. Yes, I tried that last night and there was no difference. This page had been working for a few months, and other pages that are coded in the same manner work just fine. This is the only ~Excel~ cfm page that's not working.
 
Thanks again for your suggestion.

I wish that were the case. No, the page renders correctly when I comment out the cfcontent and cfheader tags. The data comes across just fine and the cells are being populated/formatted the way they're supposed to be. Suffice to say, this has proven very frustrating.

Here's my latest test page:
[tt]<cfheader name="Content-Disposition" value="inline; filename=mgr_detail.xls">
<cfcontent type="application/msexcel">

<table>
<tr>
<td>hello</td>
<td>world</td>
</tr>
</table>[/tt]
This page renders white and does not ask if I want to save/open as Excel. However, if I comment out the cfheader and cfcontent, then the table appears as expected.
 
to get rid of the page being white, please remove the html. so,

<cfheader name="Content-Disposition" value="inline; filename=mgr_detail.xls">
<cfcontent type="application/msexcel">
<cfoutput>
hello world
</cfoutput>

 
I use cfsavecontent in this manner:

Code:
<cfsavecontent variable="report">
   ...Generate Table...
</cfsavecontent>

<cfoutput>
   <cfset dtStamp = DateFormat(NOW(), "MMDDYYYY")>
   <cfset tmStamp = TimeFormat(NOW(), "hmmtt")>
   <cfset Stamp = "#dtStamp#_#tmStamp#">
   <cfset filename = "#Trim(Session.OpenRecordRequest.UserID)#"&"#Trim(DateFormat(NOW(),"YYYYMMDD"))#"&".xls">
   <cffile action="write" file = "C:\OpenRecords\#filename#" output="#report#">
   <cfheader name="Content-Disposition" VALUE="attachment; filename=#Replace(filename,' 1','')#">
   <cfcontent type="Application/vnd.ms-excel" file="C:\OpenRecords\#filename#" deletefile="yes">
</cfoutput>

Hope this helps.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
FALCONSEYE, thanks again. I gave it a go, and no change.

Lyndon, thanks for the suggestion. However, not many want to save the spreadsheet, they just want the option to save it. Others only want to open the page in Excel so they can manipulate the output, and the close without saving when they're done.

 
The method I proposed deletes it from the server as soon as the client get the file dialog.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Lyndon,

Very well, I decided to give yours a go.

It took a bit to recognize what parts of your example needed to be modified to work in my project, but I gave it a go and it did work. Of course, the tech in me wants to understand why the method that has worked for so many months, and continue to works on so many other pages, suddenly doesn't work. The idea that it's a bizarre quirk with no rationale explanation is always most unsettling.

Thank you for finding a work around. At least my client will be happy.

- Larry
 
I accidently found the cause of the problem - keyword usage.

Something's changed recently on our server configuration and I'm still investigating the change. Anyway, one of the effects of the change is that CF is much more sensative to keyword usage. I had originally named my query "DETAILS." I tried changing the query to "qrydetails" and suddenly the page renders the spreadsheet just fine. I'm baffled why this one change would cause one rendering type to work and cause another type to fail. Your solution worked with a query name of DETAILS.

Just bizarre!
 
Phooey, no sooner than I post than it stops working - and stopped working in both versions. I kept attempting to reopen the page in both versions and finally one opened and then they all opened just fine - regardless of what I named the query. In short, the code in the page was never the problem, because it's rendering in Excel just like it used to.

I feel an ulcer coming on [banghead]
 
Maybe this will help, maybe not. I noticed you use inline instead of attachment. I have always used attachment?

I have also had problems when there is a SPACE in the filename, so I replace spaces with _ for the cfheader filename

I always do this:

<!--- set the content-disposition and filename for the download in the http header --->
<cfheader name="Content-disposition" value="attachment;filename=YOURFILENAME">

<!--- cfcontent gets the file and sends the http info --->
<cfcontent file="FULLPATH&FILENAME" type="MIME" deletefile="No">

It always works for me?


Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
Thanks Kevin. I had also tried attachment rather than inline, even though inline always works for me. There was not difference, attachment resulted in the same blank white page. Yes, you're right about spaces in names, that's why I didn't have a space in my file name, but used an underscore instead.

Just as spontaneously as this problem appeared, it disappeared. So far, it's been working as it always had before. The cause? We'll never know.
 
LarryS, are you using a hosting service or your own server? I was wondering if you are getting stuck waiting on a download or maybe the server has had changes that interfere with your file open task. Does a file ever get created on the server? Can you ftp it to your desktop and open it?

I'm just guessing here as I'm very interested in what is causing your problems. I have dozens of requirements for .xls file creation and many more are in our design plans....

FYI - I use CF 5.0 & Access 2000 on our in-house W2K server.


Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Lyndon,

The server is on our intranet. We're using ColdFusion MX 6.1 that's running on a Windows 2003 box. We're going against DB2 for z/OS and MySQL 4 that's on another Windows 2003 box.

I checked last week with the server folks, and they said the last configuration change was at the beginning of the month when they applied security patches to Windows.

I only have about a couple of dozen pages on this site that are exportable to xls. This is the only page that I've had any problem with.

Larry
 
Your configuration is so much different than mine that I'll just monitor this thread, I'm out of ideas.

Good luck.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Lyndon,

Thanks for your ideas. I think we'll call this case closed. I just checked the page again and it's working just like all the other export pages on the site. I really hate errors that magically disappear!

- Larry
 
I always expect their untimely return.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
The problem is probably that the CF code generates an error. You won't be able to see this unless you generate the output to your browser and look at the bottom of the page. When CF error is fixed it works fine!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top