Adding line to a template word document with C#

G

Gidi

Hello,

I've a C# windows application that open a word document (a ready template),
and I've a list of customers. I know how to open the document and how to type
a line into it, but i can't find how to write the line in a specific location.

for example, my doucment looks like this:

date: 12/27/2006
Title: BLA BLA BLA BLA
For:
customer_name

BLA
BLA
BLA

what i want to do, is to change the customer name for each customer i have
and then print this doucment, my question is how can it be done?

Thanks,
Gidi.
 
C

Cindy M.

Hi Gidi,

Traditionally, one uses bookmarks for this.

Select the customer name, then Insert/Bookmark. Type in a name for the bookmark
(like txtCustomer). The code (VBA) then looks like this
doc.Bookmarks("txtCustomer").Range.Text = "the customer name"

C# is a bit more complicated. Off the top of my head:
object objName = "txtCustomer";
doc.Bookmarks.get_Item(ref objName).Range.Text = "the customer name";
I've a C# windows application that open a word document (a ready template),
and I've a list of customers. I know how to open the document and how to type
a line into it, but i can't find how to write the line in a specific location.

for example, my doucment looks like this:

date: 12/27/2006
Title: BLA BLA BLA BLA
For:
customer_name

BLA
BLA
BLA

what i want to do, is to change the customer name for each customer i have
and then print this doucment, my question is how can it be done?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top