Solved

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

Posted on 2011-09-12
5
329 Views
Last Modified: 2012-05-12
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
Comment
Question by:Javier_Arroyo
5 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36526467
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
 
LVL 39

Expert Comment

by:gdemaria
ID: 36529285
Can you show the code you're using to create this document?  
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 36529829
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
 

Author Comment

by:Javier_Arroyo
ID: 36529874
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
 
LVL 36

Accepted Solution

by:
SidFishes earned 500 total points
ID: 36529935
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question