Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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....
    2. 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...
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default Re: creating rtf files

    If your query returns more than one row, you could use <cfloop query="q1"
    >...</cfloop> to loop through each row of the query. However, if you enclosed
    your current code in a cfloop, I think the first loop would replace all of the
    "%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

  4. #3

    Default 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

  5. #4

    Default 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

  6. #5

    Default 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

  7. #6

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139