How Can I put data in Word???

G

Guest

I'm working in a Windows Project (using Visual Studio .Net 2003), the goal
that I have to reach is to put data, (that is taked from database) and put
them in a Word document.

The problem that I have is that I'm NOT working with Visual Studio Tools For
Office, instead of that, I'm writing code.

A good example of what I'm trying to do is the following link:
http://www.codeproject.com/csharp/Simple_Ms_Word_Automation.asp

I'm working with templates, and in the template, I have putted bookmarks in
this way: Within Microsoft Word - Insert - Bookmark. Then I write a name for
the bookmark and finally clik on Insert.

After that, the goal that I want to have is to put the data in those
bookmarks....

Please can anyone tell me how can I solve this problem????

Thank you ver much for any answer...

Galo
 
J

Jezebel

To put data into the bookmark range, you use code like

MyDoc.Bookmarks("MyBookmark").Range = "MyText"

But simpler than using bookmarks is to use document properties or document
variables, and in the body of the document to use DocProperty or DocVariable
fields.
 
G

Guest

Thanks for your answer Jezebel!!!
But, is it possible you can give some code to have an idea how I can do
that???
Sorry for my inexperience but I know already how to put a DocVariable in a
Word Document, but in the C# code, how can assign the value from de database
to that DocVariable????
Please help me...
 
G

Guest

Hey guys.... I solve this problem.... =) And I want to share with
everyone.... hope helps to somebody sometime.....
Word = Microsoft.Office.Interop.Word
I used a variable of type Word.Application called applicationWord
Then I used this method:
applicationWord.ActiveDocument.Content.Find.Execute()

You can find a detailed page of the parameters that use de Find.Execute
method in this direction:
http://msdn2.microsoft.com/en-us/library/microsoft.office.interop.word.find.execute(VS.80).aspx

But the most importants are: the parameter FindText (the text looked at),
and the parameter ReplaceWith (in this case I used to put the data that I
brought from the DataBase).

So, in my word document, I don't used any bookmark or docvariable, just
write down in a template, let's say NameOfClient, and then replaced with the
real Name of the Client.

Anyway, this works fine in the body of the document, so if someone want to
replace any information in the header or the footer of the document, this
solution doesn't work.....

Maybe somebody around there may help to solve this part...

Thank you to all answer I received at this forum!!!
 

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