Board index » cppbuilder » Opening Word Document

Opening Word Document


2004-03-03 01:28:13 AM
cppbuilder4
Hi
I've just started to look at the COM server objects in C++ Builder 5
Professional. I found some sample code in the help file, but I've had to
modify it to even get it to compile. For now, I'd just like to open a Word
document by clicking on a button. I've placed a button and WordApplication
on a form, and have come up with the following code - don't laugh - I'm new
to all this:
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma link "Word_2K_SRVR"
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Button1Click(TObject *Sender)
{
String filename = "C:\\test.doc";
Variant FileName = filename.c_str();
WordApplication1->Documents->Open(FileName,
TNoParam(), TNoParam(), TNoParam(),
TNoParam(), TNoParam(), TNoParam(),
TNoParam(), TNoParam(), TNoParam(), TNoParam(), TNoParam() );
}
When I run it, I get an error message
'this->Open(FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument,
WritePasswordTemplate, Format, Encoding, Visible,
(Word_2k::WordDocumentPtr*)&prop)':Bad variable type. @
c:\.....\VCL\Word_2k.h/7034
I've looked at the Word2_k.h file, and I think I have the correct number of
parameters, etc. However, I don't really understand TVariant and
TNoParam().
I'd really appreciate some help with this.
Thanks in advance
David
 
 

Re:Opening Word Document

String filename = "C:\\test.doc";
WordApplication1->Documents->Open(OleVariant((WideString)(filename)));
would be enough ;)
You could use EmptyParam instead TNoParam().
Quote
Hi

I've just started to look at the COM server objects in C++ Builder 5
Professional. I found some sample code in the help file, but I've had to
modify it to even get it to compile. For now, I'd just like to open a Word
document by clicking on a button. I've placed a button and WordApplication
on a form, and have come up with the following code - don't laugh - I'm new
to all this:

#include <vcl.h>
... code ...

When I run it, I get an error message

'this->Open(FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument,
WritePasswordTemplate, Format, Encoding, Visible,
(Word_2k::WordDocumentPtr*)&prop)':Bad variable type. @
c:\.....\VCL\Word_2k.h/7034

I've looked at the Word2_k.h file, and I think I have the correct number of
parameters, etc. However, I don't really understand TVariant and
TNoParam().
--
RysiekLL
 

Re:Opening Word Document

Brilliant! Thanks very much. I still don't understand it, but I managed to
get the document to open and print. I thought it would open Word and
display the document within that, but it did everything in the background.
One of my customers has a requirement for some sort of document management
system, so I thought I'd see if BCB would be an option. It would have to
save documents based on client/case codes within the document, and provide
some sort of search facility. I'll have to mull it over. Maybe I could use
VB macros (I've not used those either...)
Thanks again
David
 

{smallsort}