View Full Version : Generating Word Documents through C# Application


chandra
02-15-2006, 02:30 AM
Hi all,

Does anyone know how to generate collection of word documents through a .NET
C# application?
The documents have the same template (.dot). The C# application should put
some data at the bookmarks in the template.


Thanks in advance

Cindy M -WordMVP-
02-15-2006, 05:23 PM
Hi =?Utf-8?B?Y2hhbmRyYQ==?=,

> Does anyone know how to generate collection of word documents through a .NET
> C# application?
> The documents have the same template (.dot). The C# application should put
> some data at the bookmarks in the template.
>
Sure, I've been there, done that. Where are you stuck? You need
the Document.Add method (with all those Ref object nasty parameters).
Roughly:
Word.Document doc = wdApp.Documents.Add(list of params);

Then you can address the bookmarks by name, or loop through them. Roughly:
object bkmName = "Name";
Word.Bookmark bkm = doc.Bookmarks.get_item(ref bkmName);
bkm.Range.Text = "Data that goes in the bookmark";

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)