Link to home
Start Free TrialLog in
Avatar of Javier_Arroyo
Javier_Arroyo

asked on

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?
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
Can you show the code you're using to create this document?  
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

Avatar of Javier_Arroyo
Javier_Arroyo

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of SidFishes
SidFishes
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial