If the column names are dynamic, you caould always do it in your query, if
the db supports it

<cfquery name="get_results" datasource="DSN">
        SELECT  Column1 AS (SELECT ColumnValue FROM Table WHERE ColumnName =
'Column1'),
                        Column2 AS (SELECT ColumnValue FROM Table WHERE ColumnName = 
'Column2'),
                        Column3 AS (SELECT ColumnValue FROM Table WHERE ColumnName = 
'Column3'),
                        Column4 AS (SELECT ColumnValue FROM Table WHERE ColumnName = 
'Column4'),
                        Column5 AS (SELECT ColumnValue FROM Table WHERE ColumnName = 
'Column5')
        FROM            answers
        WHERE   id = 1
</cfquery>

I think that will work

Otherwise you could use CF variables in your query like

<cfquery name="get_results" datasource="DSN">
        SELECT  Column1 AS #Column1#,
                        Column2 AS #Column2#,
                        Column3 AS #Column3#,
                        Column4 AS #Column4#,
                        Column5 AS #Column5#
        FROM            answers
        WHERE   id = 1
</cfquery>

Regards
Steve Onnis

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Jake A
Sent: Monday, January 19, 2004 11:39 AM
To: CFAussie Mailing List
Subject: [cfaussie] Cf to Excel - Change column names


Hi all,

I'm creating an Excel document from a database table which is working
fine,
although i was hoping to be able to dynamically change the column titles.

Here is the code:

<!---query to output all results in a excel spreadsheet--->
<cfquery name="get_results" datasource="DSN">
SELECT *
FROM answers
WHERE id = 1
</cfquery>

<html>
<head>
<title>Excel Output</title>

<cfheader name="Content-Disposition" value="attachment; Filename=Name.xls">

<CFCONTENT TYPE="application/vnd.ms-excel" RESET="Yes">
</head>

<body>

<cfoutput query="get_results">
<table border="1">
<tr>
<td>#id#</td<td>#Username#</td<td>#q1#</td>
</tr>
</table>
</cfoutput>
</html>

An example or the output on the excel doc:

A          B            C
-----------------------------
1       nametest     q1answer


The field values are being updated by the database. I was hoping to change
the field titles (a,b,c).

Any help or suggestions are appreciated!

Thanks

Jake

---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
http://www.mxdu.com/ + 24-25 February, 2004


---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
http://www.mxdu.com/ + 24-25 February, 2004

Reply via email to