Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-12
5
Medium Priority
?
344 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 2000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

916 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