• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Trouble creating Excel File

Community Beginner ,
Oct 21, 2009 Oct 21, 2009

Copy link to clipboard

Copied

Hi

Here is the code I got and modified from the internet

<cfsetting enableCFOutputOnly="Yes">

<cfquery datasource="#dsn#" name="getInfo">
SELECT distinct route
  FROM empDB
  where route > 100 and route < 4999
  order by route asc
</cfquery>

<cfset tabChar = chr(9)>     
<cfset newLine = chr(13) & chr(10)>
<cfheader name="Content-Disposition" value="filename=pay1.xls">
<cfcontent type="application/msexcel">

<cfoutput>Street Number#tabChar#Street Name#newLine#</cfoutput>
<cfloop query="getFilms">
<cfoutput>#streetNumber##tabChar##streetName##newLine#</cfoutput>
</cfloop>

When I run the code, i get Error: "internet explorer cannot download math.cfm from www.brantnews.com"

anyone got any ideas why

Thanks

Craig

TOPICS
Advanced techniques

Views

943

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 21, 2009 Oct 21, 2009

Copy link to clipboard

Copied

Craig,

A couple of things to try:

1. Change the type attribute of the cfcontent tag to either 'application/unknown' and/or 'text/plain'

2. The downside is that you'd have to re-write a bit of code but check out Ben Nadel's POI CFC project I use this utility for all Excel files. Basically, you can easily create an Excel file, write it to the server and provide a download link. It's worked consistently for me across browsers and applications.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 21, 2009 Oct 21, 2009

Copy link to clipboard

Copied

If the template is named math.cfm, the problem might be that excel 2007 does not like excel content created this way.  There is a cfc out there that you can use to create actual excel files and this works a lot better.  To find it, google "coldfusion export to excel poi"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 21, 2009 Oct 21, 2009

Copy link to clipboard

Copied

Does the code run without error (save the Excel file to disk instead of delivering it to the browser for the purposes of testing) if you run it without the <cfheader> / <cfcontent> lines?

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 21, 2009 Oct 21, 2009

Copy link to clipboard

Copied

try:

<cfheader name="Content-Disposition" value="attachment; filename=yourfile.xls">

HTH

Melvin T.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 27, 2009 Oct 27, 2009

Copy link to clipboard

Copied

LATEST

Thanks alot everyone

I tried a few of the things and nothing by itsself worked but when I removed the cfcontent/cfheader I noticed a invalid field in one of the querys, once I removed that the process worked.

again, thanks alot.

Craig

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation