Solved

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

Posted on 2011-09-12
5
324 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

A Knowledge Base That Stays Up-to-Date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now