在Delphi中将图像插入Excel工作表 [英] Inserting images to an Excel sheet in Delphi

查看:438
本文介绍了在Delphi中将图像插入Excel工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个问题,我有一个应用程序,需要在其中添加图像。我试过了:

I have a question here, I have an application and I need to add images to it. I have tried:

Sheet.Shapes.AddPicture(G_V.Prog_Dir+'pic.BMP',false,true, 190, 10+(15*rowcount), 100, 100 );

它工作得很好,但我不想提供参数,我想插入图片指定(和参数)单元格,因为我需要将图片添加到页面的最后一列;这个excel需要打印,我必须提到。所以我尝试了:

it works just fine, but I don't want to give parameters, I want to insert pictures to specified (and parametric) cells because I need to add picture to the last column of the page; this excel needs to be printed I must mention that. So I tried:

Sheet.Range['E'+inttostr(rowcount),'E'+inttostr(rowcount)].Select;
Sheet.Pictures.Insert(G_V.Prog_Dir+'pic.BMP');

乍一看看起来还可以,但是我认为这段代码将图像链接到了工作表上。例如,我将创建的Excel发送到另一台计算机,但看不到这些图像(我不记得确切的错误),当我搜索它时,发现接收计算机的图像需要在正确的路径上。作为此问题的解决方案,建议使用 Sheet.Shapes.AddPicture,但正如我之前所说的
,这里需要另一个解决方案。

It looks OK at first sight, however I think this code links images to the sheet. For example, I send the created Excel to another computer and these images cannot be seen (I don't recall the exact error) and when I searched it, I found out that receiving computer needs to have images at the exact path. As a solution to this, "Sheet.Shapes.AddPicture" recommended but as I stated before, I need another solution here.

我没看到有人遇到这种问题,希望有人帮助我。

I didn't see anybody experiencing this kind of problem, I hope someone helps me out.

推荐答案

您可以使用此代码导入图片。如果将此参数与AddPicture函数一起使用,则不需要确切的路径。

You can use this code to import picture. You do not need exact path if you use AddPicture function with this parameters. it copies photo and paste it to excel.

   Set p = ActiveSheet.Shapes.AddPicture(FileName:=PictureFileName,_
   linktofile:=msoFalse, savewithdocument:=msoCTrue, _ 
   left:=TargetCell.Left, Top:=TargetCell.Top, Width:=-1,_
   Height:=TargetCell.Height)

这篇关于在Delphi中将图像插入Excel工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆