Hi finnstone,
Expert shooksm has suggested above mentioned solution. It will load the excel on browser to download by user.
Regards,
---Pinal
Main Topics
Browse All Topicsi have a query output into a table on the web. how can i make this table exportable into excel, i want to have a link that says export to excel
heres the query
<cfquery name="view1" datasource="PR">
SELECT projects.projID, projects.projname, History.period, Sum(History.pmhrsused) AS SumOfpmhrsused, Sum(History.pm2hrsused) AS SumOfpm2hrsused, Sum(History.sehrsused1) AS SumOfsehrsused1, Sum(History.sehrsused2) AS SumOfsehrsused2, Sum(History.sehrsused3) AS SumOfsehrsused3, Sum(History.sehrsused4) AS SumOfsehrsused4, Sum(History.sehrsused5) AS SumOfsehrsused5, projects.pmsell, projects.pm2sell, projects.sesell1, projects.sesell2, projects.sesell3, projects.sesell4, projects.sesell5, projects.PMname, projects.PMname2, projects.SEname1, projects.SEname2, projects.SEname3, projects.SEname4, projects.SEname5
FROM History RIGHT JOIN projects ON History.projID = projects.projID
GROUP BY projects.projID, projects.projname, History.period, projects.pmsell, projects.pm2sell, projects.sesell1, projects.sesell2, projects.sesell3, projects.sesell4, projects.sesell5, projects.PMname, projects.PMname2, projects.SEname1, projects.SEname2, projects.SEname3, projects.SEname4, projects.SEname5;
</cfquery>
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
there is a custom tag created by Ali Taleb, which i've modified a little to allow ordering columns.
save this code under the \CFUSION\CustomTags directory, naming the file Query2Excel.cfm
<cfif Not IsDefined("Attributes.Quer
<cfoutput><div align="center"><b>Error! 'Query' attribute is required in your custom tag.</b></div></cfoutput>
<cfabort>
</cfif>
<cfset QueryName = "Caller." & #Attributes.Query#>
<cfset NumRows = Evaluate(QueryName & ".RecordCount")>
<cfparam name="Attributes.columnLis
<cfparam name="Attributes.Headers" default=#Evaluate(QueryNam
<cfif ListLen(Attributes.columnL
<cfoutput><div align="center"><b>Error! There are more query fields than the items in the 'Headers' list.</cfoutput>
<cfabort>
<cfelseif ListLen(Attributes.Headers
<cfoutput><div align="center"><b>Error! There are more values in the 'Headers' list than the fields returned by the query.</cfoutput>
<cfabort>
</cfif>
<cfparam name="Attributes.Alternate
<cfparam name="Attributes.Type" default="application/vnd.m
<cfset Counter = 1>
<cfloop query="#QueryName#">
<cfset TheValueList = "">
<cfloop list="#Attributes.columnLi
<cfset TheValue = #Trim(TheValue)#>
<cfset TheValue = #Evaluate(QueryName & "." & TheValue)#>
<cfset TheValue = Replace(TheValue, ",", "¦¦", "All")>
<cfset TheValueList = ListAppend(TheValueList,Th
<cfset temp = SetVariable("ValueList#Cou
</cfloop>
<cfset Counter = Counter + 1>
</cfloop>
<cfset AlternateColor = #Attributes.AlternateColor
<cfcontent type="#Attributes.Type#">
<cfset CharWidth = 10>
<table border="1">
<tr bgcolor="#C0C0C0"><cfloop list="#Attributes.Headers#
<cfset TheString = "#TheColTitle#"><cfset TheLength = Len(#TheString#) * #charwidth#>
<cfoutput><th width="#TheLength#"><b>#Th
</tr>
<cfset ColorList = "ffffff,#AlternateColor#">
<cfloop from="1" to="#NumRows#" index="n">
<cfif ColorList is "ffffff,#AlternateColor#">
<cfset ColorList = "#AlternateColor#,ffffff">
<cfelse>
<cfset ColorList = "ffffff,#AlternateColor#">
</cfif>
<cfloop list="#ColorList#" index="c">
<cfset CurrentColor = #ListGetAt(c,1)#>
</cfloop>
<cfset temp = SetVariable("CurrentList",
<cfset CurrentList = Replace(CurrentList, ",,", ", ,", "All")>
<cfset CurrentList = Replace(CurrentList, ",,", ", ,", "All")>
<cfoutput><tr bgcolor="#CurrentColor#"><
<cfloop list="#CurrentList#" index="TheColValue"><cfset
<cfset TheString = Replace(TheString, "¦¦", ",", "All")><cfoutput><td width="#TheLength#">#TheSt
</tr>
</cfloop>
</table>
then on your page you'll have:
<cfif isDefined('url.getxls')>
<cfoutput>
<!------------------------
this tag generates a well formed HTML table, which Excel can open as a workbook.
if you specify type=unknown, user will be prompted to save the file on local drive. then he can open it in Excel and save it as a regular workbook
if you don't specify the type, the browser itself will open the table in Excel format
--------------------------
<CF_Query2Excel
Query="view1"
columnList="projID,projNam
headers="Project ID,Project Name,ETC"
type="unknown"
>
<cfabort>
</cfoutput>
</cfif>
<html>
<body>
<a href="thisPage.cfm">Get Excel</a>
</body>
</html>
<cfheader name="content-disposition"
<cfcontent type="application/msexcel"
your text goes here
<td></td>
or...you can put that text in the table too...like
<cfheader name="content-disposition"
<cfcontent type="application/msexcel"
<td>your text goes here</td>
<td></td>
Or this is not what you asked...
Regards,
---Pinal
Business Accounts
Answer for Membership
by: pinaldavePosted on 2004-08-31 at 11:48:34ID: 11945332
Hi finnstone, re" name="qryAccessData"> value="inline;filename=Acc essToExcel Dump.xls"> > </td> </td> </td>
<cfquery datasource="MyDataSourceHe
SELECT Field1, Field2, FieldN
FROM AccessTable
</cfquery>
<cfheader name="content-disposition"
<cfcontent type="application/msexcel"
<table border="1">
<tr>
<th>Field1</th>
<th>Field2</th>
<th>FieldN</th>
</tr><cfoutput query="qryAccessData">
<tr>
<td>#qryAccessData.Field1#
<td>#qryAccessData.Field2#
<td>#qryAccessData.FieldN#
</tr></cfoutput>
</table>
Regards,
---Pinal