Ask a Question related to Coldfusion - Getting Started, Design and Development.
-
Dave199 #1
creating rtf files
Hi
I'm following an example in a Macromedia textbook; it's designed to return obe
row whereas I want to return several rows. I can't get it to this even though
I've tried several variations of cfloop - I'd appreciate any advice!
Here's my code:
<cfquery name="q1" datasource="mysource">
select * from resources, month_lookup where
resources.month=month_lookup.month_num order by keyword1, keyword2, keyword3
</cfquery>
<cfset thisFolder = getDirectoryFromPath(getCurrentTemplatePath())>
<cfset templatePath = thisFolder & "resource.rtf">
<cffile action="read" file="#templatePath#" variable="rtf">
<cfset rtf= replace(rtf, "%keyword1%", q1.keyword1, "ALL")>
<cfset rtf= replace(rtf, "%keyword2%", q1.keyword2, "ALL")>
<cfset rtf= replace(rtf, "%keyword3%", q1.keyword3, "ALL")>
<cfset rtf= replace(rtf, "%contributor%", q1.contributor, "ALL")>
<cfset rtf= replace(rtf, "%month_name%", q1.month_name, "ALL")>
<cfset rtf= replace(rtf, "%year%", q1.year, "ALL")>
<cfset rtf= replace(rtf, "%information%", q1.information, "ALL")>
<cfheader name="Content-Disposition" value="filename=uklast92.doc">
<cfcontent type="application/msword"> <cfoutput>#rtf#</cfoutput>
Many thanks
Dave S
Dave199 Guest
-
Creating PDF files on a Mac G4 OS 9.
Why isn't it possible to create a PDF file on my Mac G4 OS 9 with Acrobat reader 4.05 installed? The File>Print window does not show the PDF option.... -
Creating ICO files???
Hello folks! This may be a little off tangent but basically I need to create an ICO file from a Freehand vector based artwork. I have both... -
Creating A5 files in PDF format
I use Ventura Publisher 5 to create files in A5 portrait format. I have Adobe Standard 6.0 installed as a printer but there is no A5 option. In... -
Creating SWF files using Director on XP
I have created a movie using Dierctor on XP. I want to be able to publish this so that a Solaris unix system can view the movie. Reading the manual... -
Creating PDF files in Unix
"Yves Leclerc" <yleclercNOSPAM@maysys.com> wrote in message news:<be4ks6$1bsu$1@news.securenet.net>... Check out www.sanface.com - Look for... -
mxstu #2
Re: creating rtf files
If your query returns more than one row, you could use <cfloop query="q1"
your current code in a cfloop, I think the first loop would replace all of the>...</cfloop> to loop through each row of the query. However, if you enclosed
"%keyword1%, etc..." strings and subsequent loops would probably do nothing,
because all of the replacements were already done. What are you trying to do?
mxstu Guest
-
Dave199 #3
Re: creating rtf files
Thanks for thr answer - I'm trying to return all the rows of the query, of
which there are several, into one rtf file. And my various cfloop efforts were
around the "%..%" lines. But I can't work out what else to do on this one.
Regards
Dave S
Dave199 Guest
-
BKBK #4
Re: creating rtf files
Does this do you?
<cfset original_rtf = rtf>
<cfset final_rtf = "">
<cfloop query="q1">
<cfset rtf= replace(rtf, "%keyword1%", q1.keyword1, "ALL")>
<cfset rtf= replace(rtf, "%keyword2%", q1.keyword2, "ALL")>
<cfset rtf= replace(rtf, "%keyword3%", q1.keyword3, "ALL")>
<cfset rtf= replace(rtf, "%contributor%", q1.contributor, "ALL")>
<cfset rtf= replace(rtf, "%month_name%", q1.month_name, "ALL")>
<cfset rtf= replace(rtf, "%year%", q1.year, "ALL")>
<cfset rtf= replace(rtf, "%information%", q1.information, "ALL")>
<!--- final modified rtf for the respective query row--->
<cfset final_rtf = final_rtf & rtf>
<!--- reset to oginal rtf before you begin replacements for new query row--->
<cfset rtf = original_rtf>
</cfloop>
<cfheader name="Content-Disposition" value="filename=uklast92.doc">
<cfcontent type="application/msword"> <cfoutput>#final_rtf#</cfoutput>
BKBK Guest
-
Dave199 #5
Re: creating rtf files
Yes thank you BKBK, that's spot on! Such a neat and simple solution, I must try to think more laterally and stopped getting bogged down.
Best wishes
Dave199 Guest
-
mxstu #6
Re: creating rtf files
Dave199,
Maybe it's just late, but as I said before, I don't see the purpose of the
loop. You are reading the entire contents of the file into the "rtf" variable.
In the first iteration of the query loop, your CFSET statements will replace
ALL of the words enclosed in percent signs.
<cfset rtf= replace(rtf, "%keyword1%", q1.keyword1, "ALL")>
... etc...
Since you are replacing ALL of the occurrences, there will be nothing to
replace after the first loop. Therefore subsequent iterations of the loop will
probably do nothing. So, am I missing something here?
mxstu Guest



Reply With Quote

