Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bcb and winword

Status
Not open for further replies.

drfb

Programmer
Jul 5, 2002
23
Dear All,
I would like to create a winword page with some information included in a database. Searching on the web I find only few commands:
V = CreateOleObject("Word.Basic");
V.Exec(Procedure("AppShow"));
V.Exec(Procedure("FileNew") << "Normal");
V.Exec(Procedure("FontSize") << 24);
V.Exec(Procedure("FileSaveAs")<<Table1Nome->Value);
V.Exec(Procedure("AppClose"));


could somene help me ?

ciao,
francesco
 
I've not used Winword so I may have to do some looking around.



James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
I'm using this for fill a doc (and save or print):


void __fastcall TfClientes::bCbvClick(TObject *Sender)
{
String sFic = xAp.cPB + "\\CARTBV_" + DigitLg(lsLg->Text) + ".doc";

if (MiraFile(sFic)) {
AvisaW(this, "Generando e impriendo carta ...");
CreaDOC(sFic, 1);
AvisaW(this, "");
} else
SBox("No se encuentra plantilla: " + sFic);

}
//---------------------------------------------------------------------------

void __fastcall TfClientes::CreaDOC(String cF, int nM)
{
Variant vWord, vDocumentos, vDocumento, vSeleccion, vBuscar;

//--- Abre Word
vWord = CreateOleObject("Word.Application");

//--- Abre el documento que usaremos como plantilla
vDocumentos = vWord.OlePropertyGet("Documents" );
// Documento // Confirmar conversiones
vDocumento = vDocumentos.OleFunction("Open", cF.c_str(), false, true, false, "" );
// Modo de solo lectura, // Añadir a ficheros recientes // Clave del documento
cF = IntToStr(xCF.nFd) + ".doc";
// al final. - vWord.OlePropertySet("Visible", true);

//--- Selecciona todo el documento para reemplazar
vSeleccion = vWord.OlePropertyGet("Selection");
//--- esto inserta texto- en word: Insertar/Marcador...
//vSeleccion.OleProcedure("Goto", -1, VT_EMPTY, VT_EMPTY, "nomape");
//vSeleccion.OleProcedure("TypeText", Une2Cd(xCF.cN, xCF.cA).c_str());
//vSeleccion.OleProcedure("Goto", -1, VT_EMPTY, VT_EMPTY, "direc");
//vSeleccion.OleProcedure("TypeText", xCF.c3.c_str());
//vSeleccion.OleProcedure("Goto", -1, VT_EMPTY, VT_EMPTY, "cppobl");
//vSeleccion.OleProcedure("TypeText", Une2Cd(xCF.c4, xCF.c5).c_str());
//vSeleccion.OleProcedure("Goto", -1, VT_EMPTY, VT_EMPTY, "prov");
//vSeleccion.OleProcedure("TypeText", xCF.c6.c_str());
//vSeleccion.OleProcedure("Goto", -1, VT_EMPTY, VT_EMPTY, "pais");
//vSeleccion.OleProcedure("TypeText", xCF.c7.c_str());
//-------------------------------------------------
vSeleccion.OlePropertyGet("Range").OleProcedure("SetRange", 0, 0);
vBuscar = vSeleccion.OlePropertyGet("Find");
vBuscar.OleProcedure("ClearFormatting");
vBuscar.OlePropertyGet("Replacement").OleProcedure("ClearFormatting");
if (nM>0) {
vBuscar.OleProcedure("Execute", "{nmapel}",
VT_EMPTY, VT_EMPTY, VT_EMPTY, VT_EMPTY, VT_EMPTY,
true, VT_EMPTY, VT_EMPTY, Une2Cd(xCF.cN, xCF.cA).c_str(), 2);
vBuscar.OleProcedure("Execute", "{direc}",
VT_EMPTY,VT_EMPTY, VT_EMPTY, VT_EMPTY, VT_EMPTY,
true, VT_EMPTY, VT_EMPTY, xCF.c3.c_str(), 2);
vBuscar.OleProcedure("Execute", "{cppobl}",
VT_EMPTY,VT_EMPTY, VT_EMPTY, VT_EMPTY, VT_EMPTY,
true, VT_EMPTY, VT_EMPTY, Une2Cd(xCF.c4, xCF.c5).c_str(), 2);
vBuscar.OleProcedure("Execute", "{provi}",
VT_EMPTY,VT_EMPTY, VT_EMPTY, VT_EMPTY, VT_EMPTY,
true, VT_EMPTY, VT_EMPTY, xCF.c6.c_str(), 2);
vBuscar.OleProcedure("Execute", "{pais}",
VT_EMPTY,VT_EMPTY, VT_EMPTY, VT_EMPTY, VT_EMPTY,
true, VT_EMPTY, VT_EMPTY, xCF.c7.c_str(), 2);
// ----- ^^^ --- ok para sustituir

//--- salvamos automaticamente si procede y cerramos Word
cF = xAp.cPB + "\\CtBv" + cF;
vDocumento_OleProcedure( "SaveAs", cF.c_str() );
vDocumento_OleProcedure("PrintOut");
while (vWord.OlePropertyGet("BackgroundPrintingStatus")>0) {
::Sleep(390);
//Application->ProcessMessages();
}
//vWord.OlePropertySet("Visible", true); //aqui lo vemos para imprimir
}
else { //--- para email
vBuscar.OleProcedure("Execute", "{trat}",
VT_EMPTY, VT_EMPTY, VT_EMPTY, VT_EMPTY, VT_EMPTY,
true, VT_EMPTY, VT_EMPTY, xTr->Text.c_str(), 2);

vBuscar.OleProcedure("Execute", "{nmapel}",
VT_EMPTY, VT_EMPTY, VT_EMPTY, VT_EMPTY, VT_EMPTY,
true, VT_EMPTY, VT_EMPTY, Une2Cd(xCF.cN, xCF.cA).c_str(), 2);

xCl.cCF = xAp.cPB + "\\EInf" + cF; // para enganchar...
vDocumento_OleProcedure( "SaveAs", xCl.cCF.c_str() );
}

//cerramos todo.
vDocumento_OleProcedure("Close", 0xFFFFFFFF);
vWord.OleProcedure( "Quit" );

vWord = vDocumentos = vDocumento = vSeleccion = vBuscar = Unassigned;
Application->ProcessMessages();
}
//---------------------------------------------------------------------------
 
thanks for your message.
i should insert a button inside a form and onclick event insert the code line
----------------------------------
String sFic = xAp.cPB + "\\CARTBV_" + DigitLg(lsLg->Text) + ".doc";

if (MiraFile(sFic)) {
AvisaW(this, "Generando e impriendo carta ...");
CreaDOC(sFic, 1);
AvisaW(this, "");
} else
SBox("No se encuentra plantilla: " + sFic);
-------------------------------
I have done it but the compiler shows me the following code error undefined symbol 'xAp'
I must include something in the form?
thanks again
francesco
 
Sorry for my late.

All that are string, int,... of my own (i.e. path, number).
Change to you need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top