Hello CF gurus,
I'm using Ben Forta's example of an RTF export, and it's working very nicely. I have a link set to a page which reads query results into an RTF template.
I have been asked now create a list page that shows all the records found by a particular query, and read them into an RTF table. I think I need to use a CF List Loop to do this, but where I'm having trouble is how do I incorporate the loop in the RTF template?
I understand how to get data from a single record into the RTf template, but how do I loop multiple records into the RTF?
If it helps, here's the file I use to set the contents of the single-record template.
------------------------------------------------
need_list_rtf.cfm
------------------------------------------------
<!--- If no TIDN_ID passed, redirect to search page. --->
<CFIF IsDefined("URL.tidn_id"
EQ False>
<CFLOCATION url="tid_entry.cfm">
<CFELSE>
<CFQUERY NAME="GetNeed" DATASOURCE="attro-MySQL">
SELECT tidn_id,
project_name,
tid_year,
tid_admin.service AS SService
FROM tidn, tid_admin
WHERE tidn.admin_id = tid_admin.admin_id
AND
tidn_id=#URL.tidn_id#
</CFQUERY>
<cfparam name="tid_year" default="TID_YEAR">
<cfparam name="service" default="SERVICE">
<cfparam name="tidn_id" default="TIDN_ID">
<!--- Location of our RTF "template" document --->
<CFSET ThisFolder = GetDirectoryFromPath(GetCurrentTemplatePath())>
<CFSET TemplatePath = ThisFolder & "need_list_template.rtf">
<!--- Read RTF template into variable called "RTF" --->
<CFFILE
ACTION="Read"
FILE="#TemplatePath#"
VARIABLE="RTF">
<!--- Replace "placeholders" with specific information --->
<CFSET TodaysDate = DateFormat(Now(), "dddd, mmmm d, yyyy"
>
<CFSET RTF = Replace(RTF, "%CurrentDate%", TodaysDate)>
<CFSET RTF = Replace(RTF, "%project_name%", GetNeed.project_name)>
<CFSET RTF = Replace(RTF, "%project_name_header%", GetNeed.project_name)>
<CFSET RTF = Replace(RTF, "%tid_year%", GetNeed.tid_year)>
<CFSET RTF = Replace(RTF, "%service%", GetNeed.sservice)>
<!--- Suggest default filename for document --->
<CFHEADER NAME="Content-Disposition" VALUE="filename=NeedOutput.doc">
<!--- Set the content-type so Word is invoked --->
<CFCONTENT TYPE="application/msword"><CFOUTPUT>#RTF#</CFOUTPUT>
</CFIF>
I'm using Ben Forta's example of an RTF export, and it's working very nicely. I have a link set to a page which reads query results into an RTF template.
I have been asked now create a list page that shows all the records found by a particular query, and read them into an RTF table. I think I need to use a CF List Loop to do this, but where I'm having trouble is how do I incorporate the loop in the RTF template?
I understand how to get data from a single record into the RTf template, but how do I loop multiple records into the RTF?
If it helps, here's the file I use to set the contents of the single-record template.
------------------------------------------------
need_list_rtf.cfm
------------------------------------------------
<!--- If no TIDN_ID passed, redirect to search page. --->
<CFIF IsDefined("URL.tidn_id"
<CFLOCATION url="tid_entry.cfm">
<CFELSE>
<CFQUERY NAME="GetNeed" DATASOURCE="attro-MySQL">
SELECT tidn_id,
project_name,
tid_year,
tid_admin.service AS SService
FROM tidn, tid_admin
WHERE tidn.admin_id = tid_admin.admin_id
AND
tidn_id=#URL.tidn_id#
</CFQUERY>
<cfparam name="tid_year" default="TID_YEAR">
<cfparam name="service" default="SERVICE">
<cfparam name="tidn_id" default="TIDN_ID">
<!--- Location of our RTF "template" document --->
<CFSET ThisFolder = GetDirectoryFromPath(GetCurrentTemplatePath())>
<CFSET TemplatePath = ThisFolder & "need_list_template.rtf">
<!--- Read RTF template into variable called "RTF" --->
<CFFILE
ACTION="Read"
FILE="#TemplatePath#"
VARIABLE="RTF">
<!--- Replace "placeholders" with specific information --->
<CFSET TodaysDate = DateFormat(Now(), "dddd, mmmm d, yyyy"
<CFSET RTF = Replace(RTF, "%CurrentDate%", TodaysDate)>
<CFSET RTF = Replace(RTF, "%project_name%", GetNeed.project_name)>
<CFSET RTF = Replace(RTF, "%project_name_header%", GetNeed.project_name)>
<CFSET RTF = Replace(RTF, "%tid_year%", GetNeed.tid_year)>
<CFSET RTF = Replace(RTF, "%service%", GetNeed.sservice)>
<!--- Suggest default filename for document --->
<CFHEADER NAME="Content-Disposition" VALUE="filename=NeedOutput.doc">
<!--- Set the content-type so Word is invoked --->
<CFCONTENT TYPE="application/msword"><CFOUTPUT>#RTF#</CFOUTPUT>
</CFIF>