A:可借助word的"Word.Application"接口的功能,对图片进行旋转后导出,具体实现可参考下面给出的案例:
第一步:封装旋转图片并导出到word的功能
function AddPictureToWord(picpath,wordpath,left,top,width,height,rotate);
begin
{
通过com对象,在指定excel里导入图片
picpath:图片路径
wordpath:打开或新建word路径
left,top:图片插入位置
width,height:图片宽高;保留原图片宽高,设置为-1
rotate:图片旋转角度
}
//创建com对象
GetOleObject("Word.Application",0,Obj);
//打开或新建word
app:=Obj.documents.Open(wordpath);
if not ifobj(app) then
begin
ifnewdoc:=1;
app:=Obj.Documents.Add;
end
//添加图片,设置图片位置和大小
sh:=obj.selection.InlineShapes.AddPicture(picpath);
//选中图片
num:=app.InlineShapes.Count;
shape:=app.InlineShapes(num).ConvertToShape;
//图片旋转
shape.IncrementRotation(rotate);
//图片位置
Shape.Top := top;
Shape.Left := left;
if width>0 then Shape.Width := width;
if Height>0 then Shape.Height := height;
//保存word
if ifnewdoc then
app.saveas(wordpath);
else
app.save();
//关闭word
app.close();
end
第二步:调用上面的模型,实现对指定图形的旋转并导出到指定word的操作
Function PicToWordDemo();
Begin
picpath:='D:\\DemoTest\\klineTest01.jpg';//图片
wordpath:="D:\\DemoTest\\test.docx";//word文件
return rdo2 AddPictureToWord(picpath,wordpath,100,100,100,100,90);
end;
返回结果展示: