Solved

how to create a excel/csv file on the fly?

Posted on 2004-03-31
6
1,287 Views
Last Modified: 2013-12-24
Hello, I did my search around here and find Shooksm's code.

<cfheader name="content-disposition" value="attachment;filename=#Left(CreateUUID(), 8)#.html">
<cfcontent type="application/octet-stream">
<html>
     <head>
     <title>Your Custom Query</title>
</head>
<body>
<cfoutput>
<table border="1" width="100%"><cfloop index="i" from="0" to="95" step="5">
     <tr>
          <td>#i+1#</td>
          <td>#i+2#</td>
          <td>#i+3#</td>
          <td>#i+4#</td>
          <td>#i+5#</td>
     </tr></cfloop>
</table>
</cfoutput>
</body>
</html>


But after I copied and pasted into a blank cfm file, when I call it from browser. it returns the table in the browser though I was expecting a download box pop up?

I am using CF4.5 by the way, could that be the reason?

Also it seems the <cfsavecontent> is introduced in 5.0. What should I do to get the equvilent?

I am trying to develop a page to show a table report and if clients want, they can click a button/link to download it into excel. I hope there is a way I don't need to write the report twice.

Thanks,
lyrix
0
Comment
Question by:lyrix1999
  • 3
  • 2
6 Comments
 
LVL 35

Accepted Solution

by:
mrichmon earned 125 total points
ID: 10727314
Try this :

<cfcontent type="application/msexcel">

instead of octet-stream
0
 

Author Comment

by:lyrix1999
ID: 10727432
Great! It works!

Do you happen to know the answer to the other question? How do I use something else in 4.5 for <cfsavecontent> so I don't need to write twice or the server won't need to run twice for the online report and downloadable report?

Thanks,
lyrix
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10727549
Unfortunately I am not familiar with CF 4.5 so I am not sure what would work in place of <cfsavecontent>
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 9

Assisted Solution

by:shooksm
shooksm earned 125 total points
ID: 10728027
On 4.5, I would suggest you break out the portion of your code into three files.  The first file is the one that builds the table.  The second file is used to display the report to the browser and the third is the file used to download to excel.

ReportTable.cfm would contain the following:

<cfoutput>
<table border="1" width="100%"><cfloop index="i" from="0" to="95" step="5">
     <tr>
          <td>#i+1#</td>
          <td>#i+2#</td>
          <td>#i+3#</td>
          <td>#i+4#</td>
          <td>#i+5#</td>
     </tr></cfloop>
</table>
</cfoutput>

ShowReport.cfm would look like this:

<html>
     <head>
          <title>Your Custom Query</title>
     </head>
<body>
<h3>You custom sites template stuff starts here</h3>
<cfinclude template="ReportTable.cfm">
<p><a href="DownloadReport.cfm">Download to excel</a></p>
<h4>custom site template ends here</h3>
</body>
</html>

Then in your DownloadReport:

<cfheader name="content-disposition" value="attachment;filename=#Left(CreateUUID(), 8)#.xls">
<cfcontent type="application/msexcel">
<html>
     <head>
          <title>Your Custom Query</title>
     </head>
<body>
<cfinclude template="ReportTable.cfm">
</body>
</html>

This will allow your to write your report once but show is as html or download it as excel.  Hope this helps
0
 

Author Comment

by:lyrix1999
ID: 10728113
Hi, Shooksm, thanks for your kind help. I don't know how to split the points otherwise I must give  you some. Even though I just figure out a way around it, your method is also cool.
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10728143
I will request that a moderator split the points between us.
0

Featured Post

New My Cloud Pro Series - organize everything!

With space to keep virtually everything, the My Cloud Pro Series offers your team the network storage to edit, save and share production files from anywhere with an internet connection. Compatible with both Mac and PC, you're able to protect your content regardless of OS.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Server specifications for web hosting 7 90
SCCM vs Windows server 5 76
Change local server setting in php 6 82
Intranet and Kerberos Authentication (not sharepoint!) 8 117
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now