I saw an old post by you on a Kathleen's Weblog about how to prevent printing content control placeholder text. I have searched your blog and haven't found any information on that topic. Would you mind, providing some guidance on how to achieve this?
I ended up emptying the Content Control placeholder text in beforeprint event handler and reported it as a bug in Word that it prints the placeholder text. Actually thanks for reminding me, I need tocheck this in 2010 ;-)
Let me know if you need the code, I have it but not right here with me.
The code would be great. I tried to work through it, but no luck. I am starting with existing content controls and I've had problems with identifying the index/ID of the controls. Thanks for the help.
OK, I'll lookup the code, meanwhile I remember I was using the the Tag property of each control to store a unique ID and had a little helper method to find them by ID/Tag.
//Clearing a placeholder text: occ.SetPlaceholderText(null, null, "");
/// Find content control in document by Tag, note the CC's in Headers and Footer are in a seperate collection. private Word.ContentControl GetCC(string Tag) { foreach (Word.ContentControl cc in Application .ActiveDocument.ContentControls) { if (cc.Tag == Tag) { return cc; } }
return null; }
Although a loop like this looks expensive I have an Add-in/Template that uses this for 25+ controls in a doc and there's no performance problem at all.
8 comments:
Ed,
I saw an old post by you on a Kathleen's Weblog about how to prevent printing content control placeholder text. I have searched your blog and haven't found any information on that topic. Would you mind, providing some guidance on how to achieve this?
I ended up emptying the Content Control placeholder text in beforeprint event handler and reported it as a bug in Word that it prints the placeholder text.
Actually thanks for reminding me, I need tocheck this in 2010 ;-)
Let me know if you need the code, I have it but not right here with me.
Ed
The code would be great. I tried to work through it, but no luck. I am starting with existing content controls and I've had problems with identifying the index/ID of the controls. Thanks for the help.
gk
OK, I'll lookup the code, meanwhile I remember I was using the the Tag property of each control to store a unique ID and had a little helper method to find them by ID/Tag.
Ed
Hey Ed,
I'm having trouble with trying to obtain the tag of an existing content control. If you have that code, it would be helpful. Thanks again.
gk
Sorry it took a while, here is the code:
//Clearing content for a control:
CcControl.LockContentControl = false;
CcControl.LockContents = false;
CcControl.Range.Text = "";
//Clearing a placeholder text:
occ.SetPlaceholderText(null, null, "");
/// Find content control in document by Tag, note the CC's in Headers and Footer are in a seperate collection.
private Word.ContentControl GetCC(string Tag)
{
foreach (Word.ContentControl cc in Application
.ActiveDocument.ContentControls)
{
if (cc.Tag == Tag)
{
return cc;
}
}
return null;
}
Although a loop like this looks expensive I have an Add-in/Template that uses this for 25+ controls in a doc and there's no performance problem at all.
HTH,
Ed
Thanks, Ed. Here's hoping Microsoft realizes there is no value in printing an empty control and provides a fix sooner than later. Take care.
gk
Post a Comment