Templating Word Documents in C#

Posted by NullGeo on Stack Overflow See other posts from Stack Overflow or by NullGeo
Published on 2013-11-06T21:31:07Z Indexed on 2013/11/06 21:53 UTC
Read the original article Hit count: 164

I was wondering if there is a library out there such that it could give me the ability to fill in word templates with custom values.

For example: Following could be the content of the Word Document

{Address}
{PhoneNumber}

Hello {Name}, How are you doing?

In C# I would like to do something like this to replace all the placeholders in the Word document:

using(WordDocument doc = WordDocument.Load("Mail.docx")){
      var person = new {Name = "John Smith", Address="42 Wallaby Way, Sydney", PhoneNumber="555-555-5555"};
      doc.Template(person);
      doc.Print();
}

The resulting document would look like this:

42 Wallaby Way, Sydney
555-555-5555

Hello John Smith, How are you doing?

Any libraries out there (preferably free) that let's me do this?

Edit: I am not asking you to find anything that let's me do this. If that was the case, I would do a Google search by myself. Honestly, all I am asking is "has anybody used a library in the past to do this exact thing."

© Stack Overflow or respective owner

Related posts about c#

Related posts about ms-word