Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CF & Word Tables (export list)

Status
Not open for further replies.

RikForgo

Programmer
Jul 31, 2002
59
0
0
US
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(&quot;URL.tidn_id&quot;) EQ False>

<CFLOCATION url=&quot;tid_entry.cfm&quot;>

<CFELSE>

<CFQUERY NAME=&quot;GetNeed&quot; DATASOURCE=&quot;attro-MySQL&quot;>
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=&quot;tid_year&quot; default=&quot;TID_YEAR&quot;>
<cfparam name=&quot;service&quot; default=&quot;SERVICE&quot;>
<cfparam name=&quot;tidn_id&quot; default=&quot;TIDN_ID&quot;>

<!--- Location of our RTF &quot;template&quot; document --->
<CFSET ThisFolder = GetDirectoryFromPath(GetCurrentTemplatePath())>
<CFSET TemplatePath = ThisFolder & &quot;need_list_template.rtf&quot;>

<!--- Read RTF template into variable called &quot;RTF&quot; --->
<CFFILE
ACTION=&quot;Read&quot;
FILE=&quot;#TemplatePath#&quot;
VARIABLE=&quot;RTF&quot;>

<!--- Replace &quot;placeholders&quot; with specific information --->
<CFSET TodaysDate = DateFormat(Now(), &quot;dddd, mmmm d, yyyy&quot;)>
<CFSET RTF = Replace(RTF, &quot;%CurrentDate%&quot;, TodaysDate)>
<CFSET RTF = Replace(RTF, &quot;%project_name%&quot;, GetNeed.project_name)>
<CFSET RTF = Replace(RTF, &quot;%project_name_header%&quot;, GetNeed.project_name)>
<CFSET RTF = Replace(RTF, &quot;%tid_year%&quot;, GetNeed.tid_year)>
<CFSET RTF = Replace(RTF, &quot;%service%&quot;, GetNeed.sservice)>


<!--- Suggest default filename for document --->
<CFHEADER NAME=&quot;Content-Disposition&quot; VALUE=&quot;filename=NeedOutput.doc&quot;>

<!--- Set the content-type so Word is invoked --->
<CFCONTENT TYPE=&quot;application/msword&quot;><CFOUTPUT>#RTF#</CFOUTPUT>

</CFIF>
 
Hi mates,

This is what I do to create an MS Word table:
Code:
<cfquery name=&quot;test&quot; datasource=&quot;DSP4B&quot;>
select * from mas00
</cfquery>
<CFFILE contentType=&quot;application/x-msword&quot; action=&quot;write&quot; file=&quot;d:\temp\temp2.doc&quot; output = '<table border=0 width=&quot;580&quot;><tr><th colspan=5 height=&quot;30&quot;>Table 1. Table Title, 2003</th></tr><tr><td colspan=5></td></tr></table>
<table border=1 style=&quot;border-color:silver&quot; width:&quot;580&quot; align=&quot;center&quot;>
<tr bgcolor=black style=&quot;color:white&quot;>
<th height=&quot;40&quot; colspan=2 rowspan=&quot;2&quot; style=&quot;border-color:silver;width:320&quot;>Province</th>
<th colspan=&quot;3&quot; style=&quot;border-color:silver&quot;>Number of</th>
</tr>
<tr bgcolor=black style=&quot;color:white&quot;>
<th align=right width=&quot;10&quot; style=&quot;border-color:silver&quot;>Household</th>
<th align=right width=&quot;10&quot; style=&quot;border-color:silver&quot;>Population</th>
<th align=right width=&quot;10&quot; style=&quot;border-color:silver&quot;>Voter</th></tr>
</tr>
<tr bgcolor=&quot;c0c0c0&quot;>
<th colspan=2 align=&quot;center&quot; style=&quot;font-size:10&quot;>(&nbsp;1&nbsp;)</th>
<th align=center style=&quot;font-size:10&quot;>(&nbsp;2&nbsp;)</th>
<th align=center style=&quot;font-size:10&quot;>(&nbsp;3&nbsp;)</th>
<th align=center style=&quot;font-size:10&quot;>(&nbsp;4&nbsp;)</th>
</tr>'>
<cfset totrt = 0><cfset totpd = 0><cfset totpl = 0>
<cfoutput query=&quot;test&quot;>
<CFFILE contentType=&quot;application/x-msword&quot; action=&quot;append&quot; file=&quot;d:\temp\temp2.doc&quot; addnewline=&quot;No&quot; output = '<tr BGCOLOR=&quot;#IIF(currentrow MOD 2, DE(&quot;eeffff&quot;),DE(&quot;ffffee&quot;))#&quot;><td align=center style=&quot;font-size:11&quot;>#kdprop#</td><td style=&quot;font-size:11&quot;>#areaname#</td><td align=&quot;right&quot; style=&quot;font-size:11&quot;>#Replace(NumberFormat(JRT),&quot;,&quot;,&quot;.&quot;,&quot;all&quot;)#</td><td align=&quot;right&quot; style=&quot;font-size:11&quot;>#Replace(NumberFormat(JPD),&quot;,&quot;,&quot;.&quot;,&quot;all&quot;)#</td><td align=&quot;right&quot; style=&quot;font-size:11&quot;>#Replace(NumberFormat(JPL),&quot;,&quot;,&quot;.&quot;,&quot;all&quot;)#</td></tr>'>
<cfset totrt = totrt + jrt><cfset totpd = totpd + jpd><cfset totpl = totpl + jpl>
</cfoutput>
<CFFILE contentType=&quot;application/x-msword&quot; action=&quot;append&quot; file=&quot;d:\temp\temp2.doc&quot; addnewline=&quot;No&quot; output = '<tr bgcolor=&quot;c0c0c0&quot;><th colspan=2 style=&quot;font-size:11&quot;>T o t a l</th><th align=right style=&quot;font-size:11&quot;>#Replace(NumberFormat(totrt),&quot;,&quot;,&quot;.&quot;,&quot;all&quot;)#</th><th align=right style=&quot;font-size:11&quot;>#Replace(NumberFormat(totpd),&quot;,&quot;,&quot;.&quot;,&quot;all&quot;)#</th><th align=right style=&quot;font-size:11&quot;>#Replace(NumberFormat(totpl),&quot;,&quot;,&quot;.&quot;,&quot;all&quot;)#</th></tr></table>'>

It doesn't look nice here. Just copy and paste to test it.

Hope this helps,
mansii
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top