Skip to main content
Participating Frequently
November 6, 2008
Answered

CFContent -- excel problem

  • November 6, 2008
  • 9 replies
  • 1934 views
Hello Everyone,
I am new to Coldfusion. I am trying to use the CFcontent tag to try to create an excel spreadsheet when a users clicks on a link. However, when I use the cfoutput tag, the excel window comes up to save, or open, but the file name suffix is .cfm instead of .xls. If I remove the cfoutput tags, the file suffix is .xls, but instead of listing the values, I get the field name in all cells -- ex. #hhkey# -- it does not replace the field name with the value. Could anyone assist me? Attached is the code:

    This topic has been closed for replies.
    Correct answer BKBK
    Sunmoonstars, what do you get when you use <cfoutput query="get_g_confirm">, but leave out the cfheader and cfcontent tags? Is it the table you expect?





    9 replies

    Inspiring
    November 13, 2008
    > [i/]It might be good to have a <cfcontent reset="true">
    > in there somewhere too.
    >
    > It is in there.

    Duh. Sorry.

    --
    Adam
    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    November 11, 2008
    Sunmoonstars, what do you get when you use <cfoutput query="get_g_confirm">, but leave out the cfheader and cfcontent tags? Is it the table you expect?





    Participating Frequently
    November 13, 2008
    to BKBK --- Thanks!! -- I commented out the cfheader and cfcontent -- there was an error -- one field name was spelled incorrectly!! Once I fixed that and put the cfheader and cfcontent back in, it worked!!!! My blonde hair is definitely natural!! DUH !!!

    Thanks
    BKBK
    Community Expert
    Community Expert
    November 11, 2008
    Adam Cameron wrote:
    It might be good to have a <cfcontent reset="true">
    in there somewhere too.


    It is in there.

    BKBK
    Community Expert
    Community Expert
    November 11, 2008
    Strange. Needs looking into. For the time being, use

    <cfoutput>
    <cfloop query="get_g_confirm">
    <!--- table --->
    </cfloop>
    </cfoutput>


    Participating Frequently
    November 11, 2008
    I tried that already too. I still get the same results as in cfoutput query ---- cfoutout makes it not an .xls; however, cfloop does not get the data!!!

    I don't know what else to try!!

    November 9, 2008
    Is anyone else having this problem? A few weeks ago, my Excel Output templates started having problems...they now only work ONE TIME. If you try an Excel output a second time (without closing your browser and starting it up again), you get an error which crashes your web browser (same with IE7 and FireFox 3). You have to press CTRL-ALT-DEL to bring up Task Manager, and END TASK on the download. Then you get another error, which references "hung app", and have to END TASK again on the browser, then start it up again. It's as if you are allowed ONE EXCEL OUTPUT PER BROWSER SESSION. Very strange.

    Error message references file: officeav.dll, which I found in folder:
    c:\Program Files\Norton AntiVirus.

    Using CF7. I've had Excel "buttons" for years on my web reports, and have only had these 2 tags in my templates (don't need all the other stuff mentioned above), which I place directly after the </CFQUERY> tag:

    <CFHEADER NAME="Content-Disposition" VALUE="attachment; filename=Excess_Bag_Details.xls">
    <CFCONTENT type="application/vnd.ms-excel">

    I've tried adding all the options mentioned above, that some of you are using. Still get same problem. In CFHEADER, I prefer using "attachment" vs. "inline" because it's easier for my users to save results in an Excel file. But when I tried switching to "inline", the problem went away. But would prefer to find a solution, than switch to "inline."

    Just wondering if anyone else is having the same problem? If you use "attachment", can you run repeated Excel output templates in same browser session, without having above problems? Or would appreciate any thoughts or advice. Thank you.

    Gary

    Participating Frequently
    November 10, 2008
    Ok -- I am the original poster -- I started with only cfcontent and cfheader. I added the other stuff per suggestions from other people. With or without cfsetting and the other added stuff, I get the same results!!! For now, I am exporting the data from SQL when the user request it. However, I would like to find out a solution!!!!

    Any other suggestions?
    BKBK
    Community Expert
    Community Expert
    November 10, 2008
    Sunmoonstars wrote:
    Ok -- I am the original poster -- I started with only cfcontent and cfheader. I added the other stuff per suggestions from other people. With or without cfsetting and the other added stuff, I get the same results!!!

    It should work. Just to be sure, did you indeed run the following code?

    BKBK
    Community Expert
    Community Expert
    November 7, 2008
    You should apply Kronin555's suggestion and you should remove the cfsetting tag. It disables the table and th tags!

    Participating Frequently
    November 7, 2008
    Good catch, BKBK. I skipped over that <cfsetting...> tag.
    Participating Frequently
    November 7, 2008
    Everything in your code is fine, except your cfheader line. Change it to:
    <cfheader name="Content-Disposition" value="inline; filename=TGSYC.xls">

    Note the "inline; " in the value.

    Also, I'm pretty sure HTTP Headers are case sensitive, so make sure you use "Content-Disposition" and not "content-disposition".
    Participating Frequently
    November 7, 2008
    Thanks!! --- I am trying several different responses -- I will let everyone know if any suggestions work
    November 7, 2008
    I inherited some code that does exactly what you are doing. The only difference I see is that my code has the following you may want to try: