First up you can't have cfml tags in the output attribute of cffile. If you
wanted to do something similar you could either build up a string or use
cfsavecontent:

<cfset str = "">
<cfset str = str & "Something">
<cfset str = str & "Something else">
<cfset str = str & "More stuff">

<cffile output="#str#">

or:

<cfsavecontent variable="str">
A bunch of code here, the output of which would be in the variable 'str'
</cfsavecontent>

<cffile output="#str#">

But that's an aside.

Are you sure you want to give the user a tab/return delimited file when the
data may have genuine tabs and returns in? How about XML? For example:

<data>
        <row>
                <columnNameOne>data here</columnNameOne>
                <columnNameTwo>data here</columnNameTwo>
                <columnNameThree>data here</columnNameThree>
                <columnNameFour>data here</columnNameFour>
        </row>
</data>

You can use XMLFormat() to escape certain characters and/or use CDATA
islands. I'm a little rusty on those at the moment but I'm sure there's a
good time to use them.

Here's some quick code:

<cfxml variable="xmlData">
        <cfloop query="getData">
                <data>
                        <row>
                                <cfloop list="#getData.ColumnList#" index="i">
                                        
<#i#>#XMLFormat(getData[i][getData.CurrentRow])#</#i#>
                                </cfloop>
                        </row>
                </data>
        </cfloop>
</cfxml>

<cffile action="WRITE" file="#tempfile#" output="#ToString(xmlData)#">

You still have a nested loop but you've lost the RegEx's,
Evaluate()/SetVariable() and you write to the file only once, which on the
face of it sounds faster but I don't have any proof.

Not exactly what you asked for but another idea for you to think about.


Ade


-----Original Message-----
From: Doug Hyde [mailto:[EMAIL PROTECTED]
Sent: 03 March 2005 01:28
To: CF-Talk
Subject: Questions on a dynamic tab delimited export and regular
expressions


Help please...

I am trying to create a little custom tag that allows someone to query a
database, and then (if they decide) have the results of the query sent to
them as a tab delimited file by email. The user can select any number of
fields. The data is in sql server, and some of it is in ntext columns, and
in some cases has tabs in it (commas won't work...more commas than tabs).

So, I have two challenges. First, because the user can select any of the
fields they want, I don't always know what the column names are ahead of
time. To resolve this for column headings in the export file, I created a
tab-delimited list based on query.columnlist. However, it gets tricky for
the actual data...I loop through the query, and append each value. What I
need to do is run a regular expression inside this loop...but I am not sure
how to (1) dynamically generate the variable from the query based on and (2)
run a regular expression on any ntext fields to remove returns.....here is
my code - throws an error at output in cffile (doesn't like the loop). The
loop works fine out of the cffile tag. Any thoughts?

<cfoutput query="getData">

<cffile
 action="append"
 file="#tempfile#"
 output="<cfloop list="#getData.columnList#" index="i">
                <cfif findnocase('mem',i)>
                        <cfset temp =
rereplace(setvariable(i,#evaluate('getData.'&i)#),replacethis,replacewith)&c
hr(9)>
                <cfelse>
                        <cfset temp = 
setvariable(i,#evaluate('getData.'&i)#)&chr(9)>
                </cfif>
                <cfoutput>#temp#</cfoutput>
        </cfloop>"
 addnewline="Yes">

</cfoutput>

Thanks.

D
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.5.7 - Release Date: 01/03/2005


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:197218
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to