C++ Builder

Moderators: Lundin
Number of threads: 509
Number of posts: 1146

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
C++ Builder and Word fields Posted by Luigino on 5 Jun 2009 at 9:18 AM
Hello everyone!!!

anyone tried to pass some data to fields of a word's document after connecting to it?...
If yes, how I would do?...

I created a word document saved as RTF where I put inside two REF fields related to two bookmarks ( ex. {REF FIRST_BOOKMARK} {REF SECOND_BOOKMARK}).
I connected to the document with:

WordDocument->ConnectTo(WordApplication->Documents->Open(filename));

at this point how I could pass the contents of two dataset fields I have to those word's document fields?

In the specific I tried a code like this:

WordApplication->Connect();
OleVariant filename = _PathDataBase + "\\document.doc";
WordDocument->ConnectTo(WordApplication->Documents->Open(filename));
WordDocument->OnClose = OnWordClose;
WordApplication->set_Visible(false);
OleVariant vBookmark;
if ( WordDocument->Bookmarks->Exists((wchar_t *)"FIRST_BOOKMARK") )
{
vBookmark = StringToOleStr("FIRST_BOOKMARK");
WordDocument->Bookmarks->Item(vBookmark)->Select();
AnsiString StringToReplace = _DataSetMemo->Fields->Fields[1]->AsString;
WordApplication->Selection->TypeText(StringToOleStr(StringToReplace));
}
WordApplication->set_Visible(true);
WordApplication->Activate();

but when I am checking if the bookmark exists it returns an error like:

(this->Exists(Name, (VARIANT_BOOL*)&prop)) Error: C0000005 (-1073741819) @ ....\include\vcl\Word_2k.h/9396
Press [Y]es to terminate, [N]o to continue and [C]ancel to Debug.

Did I have missed something?... or even did something wrong?...

Thanks in advance to all!!
Ciao,
Luigi
Report
Re: C++ Builder and Word fields Posted by Luigino on 8 Jun 2009 at 1:53 AM
Or even anyone knows a way to find soem text I could set up and replace with the right text?... Like if I put in word document this <fieldname=FIRST_BOOKMARK> and finding it from C++ code and replace the entire <> with something else I want to write for example a name?....

Thanks again
Ciao,
Luigi
Report
Re: C++ Builder and Word fields Posted by aliancemd on 12 Nov 2009 at 3:05 AM
Yes u can. But I don't really understand what u mean... U want to change a text into the file or what? If u want to work with the text of the file use Standart->Memo.
Report
Re: C++ Builder and Word fields Posted by aliancemd on 12 Nov 2009 at 3:12 AM
Yes u can. But I don't really understand what u mean... U want to change a text into the file or what? If u want to work with the text of the file use Standart->Memo.
Report
Re: C++ Builder and Word fields Posted by aliancemd on 12 Nov 2009 at 3:19 AM
Yes u can. But I don't really understand what u mean... U want to change a text into the file or what? If u want to work with the text of the file use Standart->Memo.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.