在c++builder中怎么将电脑里图片导入到word中的表格里
在c++builder中如何将电脑里图片导入到word中的表格里
word文档里只有一个表格,目前在c++builder中已经实现向表格中导入数据,但是有一项是图形,我是用Tchart控件画的,我已经把画的图保存在电脑里,但是不会把图导入表格中了,请教各路大神 !!
------解决方案--------------------
c++builder中已经实现向word表格中插入图片和数据:
word文档里只有一个表格,目前在c++builder中已经实现向表格中导入数据,但是有一项是图形,我是用Tchart控件画的,我已经把画的图保存在电脑里,但是不会把图导入表格中了,请教各路大神 !!
------解决方案--------------------
c++builder中已经实现向word表格中插入图片和数据:
try
{
/* AnsiString VehPic= ".\\Temp1.bmp";
AnsiString asDir=ExtractFilePath(ParamStr(0)),asSFile,asDFile;
AnsiString Content; */
Graphics::TBitmap *bmp;
Graphics::TBitmap *smallbmp;
asSFile = asDir+"\\doc\\lt.doc";
asDFile = asDir+"\\CheckReport.doc";
if(FileExists(asDFile)) DeleteFile(asDFile);
CopyFile(asSFile.c_str(),asDFile.c_str(),false);
//保存电子文档
Variant vWordApp;
Variant vDoc, vTable,vCell;
DWORD ErrCode;
HWND hPrevApp = FindWindow(NULL,"Microsoft Word");
if(!hPrevApp)
{ //if word not started
try
{
vWordApp=CreateOleObject("Word.Application");
}
catch(...)
{
MessageBox(Handle, "启动Word出错!", Application->Title.t_str(), MB_OK
------解决方案--------------------
MB_ICONERROR);
return;
}
}
else
vWordApp=GetActiveOleObject("Word.Application");
vWordApp.OlePropertySet("Visible", true);
WideString strDocName = asDFile;
vDoc = vWordApp.OlePropertyGet("Documents").OleFunction("Open", strDocName);
vTable=vWordApp.OlePropertyGet("ActiveDocument").OleFunction("Range").OlePropertyGet("Tables").OleFunction("Item", 2);
for(int i=0;i<PrintData.AxleGrNum;i++)
{
//RvProject->SetParam("AxleGrW"+IntToStr(i+1),PrintData.AxleGr[i].Weight);
if(i<5)
vCell=vTable.OleFunction("Cell",i+2,3);
else
vCell=vTable.OleFunction("Cell",i+2,6);
Content=PrintData.AxleGr[i].Weight;
vCell.OlePropertySet("Range",Content.c_str());
if(i<5)
vCell=vTable.OleFunction("Cell",i+2,2);
else
vCell=vTable.OleFunction("Cell",i+2,5);
switch(PrintData.AxleGr[i].Type)
{
case 1:
//RvProject->SetParam("AxleGrType"+IntToStr(i+1),"单轴单轮");
Content= "单轴单轮";
break;
case 2:
//RvProject->SetParam("AxleGrType"+IntToStr(i+1),"单轴双轮");
Content= "单轴双轮";
break;
case 5:
//RvProject->SetParam("AxleGrType"+IntToStr(i+1),"双联轴双轮");
Content= "双联轴双轮";
break;
case 7:
//RvProject->SetParam("AxleGrType"+IntToStr(i+1),"三联轴双轮");
Content= "三联轴双轮";
break;
}
vCell.OlePropertySet("Range",Content.c_str());
}
vCell=vTable.OleFunction("Cell",7,2);
Content=PrintData.Weight;
vCell.OlePropertySet("Range",Content.c_str());
vCell=vTable.OleFunction("Cell",7,4);
Content=PrintData.AxleNum;
vCell.OlePropertySet("Range",Content.c_str());
vCell=vTable.OleFunction("Cell",7,6);
Content=PrintData.OverLoad;
vCell.OlePropertySet("Range",Content.c_str());
vTable=vWordApp.OlePropertyGet("ActiveDocument").OleFunction("Range").OlePropertyGet("Tables").OleFunction("Item", 3);
vCell=vTable.OleFunction("Cell",1,2);
Content=Driver;
vCell.OlePropertySet("Range",Content.c_str());
vCell=vTable.OleFunction("Cell",1,4);
Content=VehPlate;
vCell.OlePropertySet("Range",Content.c_str());
vCell=vTable.OleFunction("Cell",3,2);
Content=VehOperator;
vCell.OlePropertySet("Range",Content.c_str());
vCell=vTable.OleFunction("Cell",4,4);
Content=FormatDateTime("YYYY'-'MM'-'DD' ' HH:NN:SS",PrintTime);
vCell.OlePropertySet("Range",Content.c_str());
try
{
AnsiString strPicFile;
strPicFile = asDir+"\\Temp1.jpg";
Variant vShape;
vTable=vWordApp.OlePropertyGet("ActiveDocument").OleFunction("Range").OlePropertyGet("Tables").OleFunction("Item", 1);
vCell=vTable.OleFunction("Cell",1,1);
vCell.OleFunction("select");
vShape =vWordApp.OlePropertyGet("Selection")
.OlePropertyGet("InlineShapes")
.OleFunction("AddPicture", strPicFile.c_str(),false,true);
}
catch(...)
{
//
}
vWordApp.OlePropertyGet("Documents").OleFunction("Save");
//vWordApp.OlePropertyGet("Documents").OleFunction("Printer");