Home > Back-end >  BCB ole how to operate the replace some words in the word templates?
BCB ole how to operate the replace some words in the word templates?

Time:10-23

Is a a word templates, to get some data from the database, replacing a few places in the word templates, batch generated word document?

~ demon elder brother for help

CodePudding user response:

For reference only
 
Void __fastcall TfmSearch: : btExportWordClick (TObject * Sender)
{
Try
{
If (edTollID - & gt; The Text!="" & amp; & EdTollDate - & gt; The Text!="")
{
AnsiString asDir;
AnsiString asSFile=fmMain - & gt; G_asWorkPath + \ \ "doc \ \ lt doc";
AnsiString asDFile="d: \ " + edTollID - & gt; The Text + "doc";
Used by CopyFile (asSFile c_str (), asDFile c_str (), false);

//save the electronic document
The Variant vWordApp;
The Variant vDoc vTable, vCell;
DWORD ErrCode;
HWND hPrevApp=FindWindow (NULL, "Microsoft Word");

if(! HPrevApp)
{//if word not started
Try
{
VWordApp=CreateOleObject (" Word. Application ");
}
The catch (... )
{
//MessageBox (Handle, "to start the Word error!" Application - & gt; The Title. The c_str (), MB_OK | MB_ICONERROR);
return;
}
}
The else
VWordApp=GetActiveOleObject (" Word. Application ");

VWordApp. OlePropertySet (" Visible ", true);
WideString strDocName=asDFile;
VDoc.=vWordApp OlePropertyGet (" Documents "). OleFunction (" Open ", strDocName);
VTable=vWordApp. OlePropertyGet (" ActiveDocument "). The OleFunction (" Range "). OlePropertyGet (" Tables "). OleFunction (" Item ", 1);

VCell=vTable. OleFunction (" Cell ", 1, 2);
AnsiString Content=edTollID - & gt; The Text;//FormatDateTime (" yyyymmdd ", fmMain - & gt; DtDOCDate);
VCell. OlePropertySet (" Range ", content. c_str ());

VCell=vTable. OleFunction (" Cell ", 1, 4);
The Content=edTollDate - & gt; The Text;//fmMain - & gt; AsDOCVehType;
VCell. OlePropertySet (" Range ", content. c_str ());

VCell=vTable. OleFunction (" Cell ", 1, 6);
The Content=edLicPlate - & gt; The Text;//fmMain - & gt; AsDOCLic;
VCell. OlePropertySet (" Range ", content. c_str ());

VCell=vTable. OleFunction (" Cell ", 1, 8);
The Content=edVehType - & gt; The Text;//fmMain - & gt; AsDOCOpTicket;
VCell. OlePropertySet (" Range ", content. c_str ());



VCell=vTable. OleFunction (" Cell ", 2, 2);
The Content=edEPLAZAName - & gt; The Text;
VCell. OlePropertySet (" Range ", content. c_str ());

VCell=vTable. OleFunction (" Cell ", 2, 4);
The Content=edOperatorName - & gt; The Text;
VCell. OlePropertySet (" Range ", content. c_str ());

VCell=vTable. OleFunction (" Cell ", 2, 6);
The Content=edTollPay - & gt; The Text;
VCell. OlePropertySet (" Range ", content. c_str ());

VCell=vTable. OleFunction (" Cell ", 2, 8);
The Content=edCarWeight - & gt; The Text;
VCell. OlePropertySet (" Range ", content. c_str ());

VCell=vTable. OleFunction (" Cell ", 3, 2);
The Content=edOverloadPer - & gt; The Text;
VCell. OlePropertySet (" Range ", content. c_str ());

VCell=vTable. OleFunction (" Cell ", 3, 4);
The Content=edGoodsName - & gt; The Text;//fmMain - & gt; AsDOCGoodsName;
If (edMixGoodsName - & gt; The Text. The Trim ()!="")
Content +="+" + edMixGoodsName - & gt; The Text. The Trim ();
VCell. OlePropertySet (" Range ", content. c_str ());

VCell=vTable. OleFunction (" Cell ", 3, 6);
The Content=edDensity - & gt; The Text;
VCell. OlePropertySet (" Range ", content. c_str ());

VCell=vTable. OleFunction (" Cell ", 3, 8);
The Content=edCheckName - & gt; The Text;
VCell. OlePropertySet (" Range ", content. c_str ());

AnsiString strPicFile;

AsDir="d:";
String picFileName;
Try
{
PicFileName=asDir + "\ \ pictures on front. Jpeg";
ImgFront - & gt; Picture - & gt; SaveToFile (picFileName);
PicFileName=asDir + \ \ "at the top of the photo. Jpeg";
ImgTop - & gt; Picture - & gt; SaveToFile (picFileName);
PicFileName=asDir + "\ \ panoramic photos. Jpeg";
ImgTotal - & gt; Picture - & gt; SaveToFile (picFileName);
PicFileName=asDir + "\ \ left back photos. Jpeg";
ImgLeft - & gt; Picture - & gt; SaveToFile (picFileName);
PicFileName=asDir + "\ \ back right photo. Jpeg";
ImgRight - & gt; Picture - & gt; SaveToFile (picFileName);
PicFileName=asDir + "\ \ goods photos. Jpeg";
ImgCheck - & gt; Picture - & gt; SaveToFile (picFileName);
ExportDVfile ();//export video
}
The catch (... )
{
//
}
Try
{
StrPicFile=asDir + "\ \ pictures on front. Jpeg";

The Variant vShape;
VTable=vWordApp. OlePropertyGet (" ActiveDocument "). The OleFunction (" Range "). OlePropertyGet (" Tables "). OleFunction (" Item ", 2);
VCell=vTable. OleFunction (" Cell ", 1, 1);
VCell. OleFunction (" select ");
VShape=vWordApp. OlePropertyGet (" Selection ")
. OlePropertyGet (" InlineShapes ")
OleFunction (" AddPicture strPicFile. C_str (), false, true);

StrPicFile=asDir + \ \ "at the top of the photo. Jpeg";
VTable=vWordApp. OlePropertyGet (" ActiveDocument "). The OleFunction (" Range "). OlePropertyGet (" Tables "). OleFunction (" Item ", 2);
VCell=vTable. OleFunction (" Cell ", 1, 2);
VCell. OleFunction (" select ");
VShape=vWordApp. OlePropertyGet (" Selection ")
. OlePropertyGet (" InlineShapes ")
OleFunction (" AddPicture strPicFile. C_str (), false, true);

StrPicFile=asDir + "\ \ panoramic photos. Jpeg";
VTable=vWordApp. OlePropertyGet (" ActiveDocument "). The OleFunction (" Range "). OlePropertyGet (" Tables "). OleFunction (" Item ", 2);
VCell=vTable. OleFunction (" Cell ", 1, 3);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related