How can I put data in Word Documents???

G

Galo

I'm working in a Windows Project (using Visual Studio .Net 2003 with C#), 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
 
C

Cindy M.

Hi Galo,

A google search on the terms - bookmark C# - turns up the following

http://groups.google.ch/group/microsoft.public.office.developer.automation/brows
e_frm/thread/b1b7c83cb16d2e60/3e18f8c2f3b4422d?lnk=st&q=&rnum=1&hl=de#3e18f8c2f3
b4422d

which gives you the basic syntax.
I'm working in a Windows Project (using Visual Studio .Net 2003 with C#), 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????

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 :)
 
G

Galo

Thank you so much for you answer Cindy.

I wrote in my code those lines:
object objName = "bmkMyBookmark";
doc.Bookmarks.get_Item(ref objName).Range.Text = "some text";
But, when I was debbuging an error raised up.
It said something like this: (actually the message is in spanish, so I'm
trying to translate into english)
"The item of the set asked for doesn't exist
Microsoft Word
Microsoft.Office.Interop.Word.Bookmark get_Item(System.Object ByRef)
C:\Program Files\Microsoft Office\OFFICE11\3082\wdmain11.chm#25421"

I have to say that I'm not using Macros. I just selected the text where I
want to replace with the information from the database, and created at that
point the bookmark with the name 'bmkMyBookmark'.

Any idea of what's wrong???
Thank you for any answer you can give me and I appreciate a lot your time...
 
C

Cindy M.

Hi Galo,

Ah-ah, on re-reading I see VS 2003. I seem to recall seeing something about
the syntax being different for that version...

Take a look at the this thread
http://groups.google.ch/group/microsoft.public.office.developer.automation/bro
wse_frm/thread/622029abd0c200ec/f6c11a091c02fc17?lnk=st&q=&rnum=3&hl=de#f6c11a
091c02fc17

In there I see

Word.Range rng = ThisDocument.Bookmarks.Item(
ref oBookmarkName).Range;
rng.Text = newText;
I wrote in my code those lines:
object objName = "bmkMyBookmark";
doc.Bookmarks.get_Item(ref objName).Range.Text = "some text";
But, when I was debbuging an error raised up.
It said something like this: (actually the message is in spanish, so I'm
trying to translate into english)
"The item of the set asked for doesn't exist
Microsoft Word
Microsoft.Office.Interop.Word.Bookmark get_Item(System.Object ByRef)
C:\Program Files\Microsoft Office\OFFICE11\3082\wdmain11.chm#25421"

I have to say that I'm not using Macros. I just selected the text where I
want to replace with the information from the database, and created at that
point the bookmark with the name 'bmkMyBookmark'.

Any idea of what's wrong???

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 :)
 
C

Cindy M.

Hi Galo,
I solved already the problem and I posted the solution that I made at this
link:
http://www.microsoft.com/office/community/en-us/default.mspx?pg=6&guid=&sloc=en-us&d
g=microsoft.public.word.docmanagement&fltr=
Just so you know: the docmanagement newsgroup is targeted at end-users, not at
developers. Some people with object model knowledge pass through that group, but
it's not the optimal one to ask a programming question in :)

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