• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

Word merge -- merging "html" text into a variable

I have a need to merge html formatted text into a word merge variable in addition to non html text into otehr variables, the non html text works fine, the issue I am trying to resolve is in the html formatted text where I would like to merge formatted text into my word document and have it show the format. See here http://www.arroyoc.com/mergedformatted.pdf for an example, everything above the html marked up text is no problem, the issue is the "body" and how to get that to format properly.  Is there any way to do this?
0
Javier_Arroyo
Asked:
Javier_Arroyo
1 Solution
 
GrahamSkanRetiredCommented:
Mail merge, if that's what you are using, does not merge formatted text.

To get HTML with its formatting applied into a Word document, it would have to be pasted.
0
 
gdemariaCommented:
Can you show the code you're using to create this document?  
0
 
SidFishesCommented:
Why use word at all. Use CF to create your doc files. Create a master doc in word, Create placeholders and then use replace...see the comments in the code below
<!--- this is a query simulator. In real life you would get the info from a datasource query --->

<cfset TempQry= querynew("")>
<cfset queryaddcolumn  (TempQry, "fname", "CF_SQL_varchar", ListToArray("Bill,Bob,Jane,John,Frank,Cindy"))>
<cfset queryaddcolumn  (TempQry, "lname", "CF_SQL_varchar", ListToArray("Smith,Jones,Foo,Bar,Miller,Cran"))>
<cfset queryaddcolumn  (TempQry, "address", "cf_sql_varchar", ListToArray("123 test st, 12 Foo Place, 321 Bar Harbour, 1229 CFML ave, 154 Anywhere, 999 somewhere"))> 

<!--- Create a nmaster doc and save it as htm. Open it in your cfml editor  --->


<!--- cut everything in the body tag and paste it into a savecontent variable named body--->
<cfsavecontent variable="body"> <!---  --->
<p class=MsoNormal>This is a really <b style='mso-bidi-font-weight:normal'>interesting
</b><i style='mso-bidi-font-style:normal'>example of </i>mail merge using <span
class=SpellE><span style='font-size:22.0pt;mso-bidi-font-size:11.0pt;
line-height:115%'>Coldfusion</span></span><span style='font-size:22.0pt;
mso-bidi-font-size:11.0pt;line-height:115%'>. </span><span style='font-size:
16.0pt;mso-bidi-font-size:11.0pt;line-height:115%'>I h</span><span
style='font-size:10.0pt;mso-bidi-font-size:11.0pt;line-height:115%'>op</span><span
style='font-size:16.0pt;mso-bidi-font-size:11.0pt;line-height:115%'>e you, </span>{fname} like<span
style='font-size:16.0pt;mso-bidi-font-size:11.0pt;line-height:115%'> it.</span></p>
</cfsavecontent>

<!--- the rest of the htm file is the skeleton of your doc --->

<cfsavecontent variable="myDoc">
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 14">
<meta name=Originator content="Microsoft Word 14">
<link rel=File-List href="address_files/filelist.xml">

<!--- i've cut out all the mso style info to post but you should leave it intact --->

</head>
<body lang=EN-US style='tab-interval:.5in'>
<div class=WordSection1>
	{address}
	Dear {name}
	{body}
	Sincerely,
	Bill Smith
</div>
</body>
</html>

</cfsavecontent>

<cfloop query="tempQry">
	<!--- replace any variables we want in the body text --->
<cfset body = replacenocase(body,"{fname}",tempqry.fname)> 
<!--- create the doc --->
<cfsavecontent variable="myOutput">
<cfset mydoc = replacenocase(mydoc,"{address}",tempqry.address)>
<cfset mydoc = replacenocase(mydoc,"{name}",tempqry.fname & " " & tempqry.lname)>
<cfset mydoc = replacenocase(mydoc,"{body}",body)>
</cfsavecontent>
<!--- write the doc to the file system (or email or whatever) --->
<cffile action="write" file="c:\temp\doc_#tempqry.lname#.doc" output="#mydoc#" >


</cfloop>

Open in new window

0
 
Javier_ArroyoAuthor Commented:
SidFishes --- would this paginate  and print within the "printable" area correctly? i.e. look at my link here:

http://www.arroyoc.com/mergedformatted.pdf

This is what we need to output i.e. the "pleadning paper" background, page xx of xx on bottom, data valus in header and of course the "body" which as you can see has html markup but using word mailmerge through DCOM I can't get to format correctly.
0
 
SidFishesCommented:
oops had my loops in the wrong place - also attached the output
<cfset TempQry= querynew("")>
<cfset queryaddcolumn  (TempQry, "fname", "CF_SQL_varchar", ListToArray("Bill,Bob,Jane,John,Frank,Cindy"))>
<cfset queryaddcolumn  (TempQry, "lname", "CF_SQL_varchar", ListToArray("Smith,Jones,Foo,Bar,Miller,Cran"))>
<cfset queryaddcolumn  (TempQry, "address", "cf_sql_varchar", ListToArray("123 test st, 12 Foo Place, 321 Bar Harbour, 1229 CFML ave, 154 Anywhere, 999 somewhere"))> 

<!--- Create a nmaster doc and save it as htm. Open it in your cfml editor  --->








<cfloop query="tempQry">
<!--- cut everything in the body tag and paste it into a savecontent variable named body--->
<cfsavecontent variable="body"> <!---  --->
<p class=MsoNormal>This is a really <b style='mso-bidi-font-weight:normal'>interesting
</b><i style='mso-bidi-font-style:normal'>example of </i>mail merge using <span
class=SpellE><span style='font-size:22.0pt;mso-bidi-font-size:11.0pt;
line-height:115%'>Coldfusion</span></span><span style='font-size:22.0pt;
mso-bidi-font-size:11.0pt;line-height:115%'>. </span><span style='font-size:
16.0pt;mso-bidi-font-size:11.0pt;line-height:115%'>I h</span><span
style='font-size:10.0pt;mso-bidi-font-size:11.0pt;line-height:115%'>op</span><span
style='font-size:16.0pt;mso-bidi-font-size:11.0pt;line-height:115%'>e you, </span>{fname} like<span
style='font-size:16.0pt;mso-bidi-font-size:11.0pt;line-height:115%'> it.</span></p>
</cfsavecontent>
	
<cfsavecontent variable="myDoc">
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 14">
<meta name=Originator content="Microsoft Word 14">
<link rel=File-List href="address_files/filelist.xml">
<!--- i've cut out all the mso style info to post but you should leave it intact --->
</head>
<body lang=EN-US style='tab-interval:.5in'>
<div class=WordSection1>
	<div style="font-weight:bold;margin-bottom:50px;">{address}</div>
	Dear {name}<br>
	{body}
	Sincerely,
	Bill Smith
</div>
</body>
</html>
</cfsavecontent>
<cfset body = replace(body,"{fname}",tempqry.fname)> 
<!--- create the doc --->
<cfsavecontent variable="myOutput">
	<!--- replace any variables we want in the body text --->

<cfset mydoc = replace(mydoc,"{address}",tempqry.address)>
<cfset mydoc = replace(mydoc,"{name}",tempqry.fname & " " & tempqry.lname)>
<cfset mydoc = replace(mydoc,"{body}",body)>
</cfsavecontent>
<!--- write the doc to the file system (or email or whatever) --->
<cffile action="write" file="c:\temp\doc_#tempqry.lname#.doc" output="#mydoc#" >


</cfloop>

Open in new window

new-1.JPG
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now