0

I'm trying to create a word template with place holders (content controls), I then want to replace the text within these place holders using Open XML but I can't do it.

So within word I've entered Design Mode and added a Rich Text Box content control. Then using the properties I've set the Title/Tag to textBuildingName for example.

So I now want to change the text of that place holder from my C# code using Open XML. However I don't really know how to reference the place holder in code. So all I have so far is this:

using (WordprocessingDocument doc = WordprocessingDocument.Open(docPath, true))
{
    //What do I do here to get the content control by name
    //so I can do something like this:
    //textBuildingName.Text="This is my replacement text from my application";
}

Any advice on this would be greatly received, I can't find any good tutorials on the web.

I'm using Visual Studio 2012 and Word 2013

Sun
  • 4,458
  • 14
  • 66
  • 108
  • Can you post the sol. you used to solve this issue? In answer i can see a toll that list all Content Controls only , i cant see any C# code which do the conversion like explained in question – Sebastian Aug 17 '15 at 05:30

1 Answers1

1

I use Word 2007, but this might also work for newer versions (word 2010 works as well): I use the content control toolkit which is a easy way of connecting your rich text boxes with the correct xml tags.

http://dbe.codeplex.com/

Hope this helps