使用 Delphi 在 Excel 工作表的每一行插入图像

发布于 2024-09-14 03:35:40 字数 740 浏览 5 评论 0原文

我的 Delphi 6 程序需要在 Excel 工作表的每一行上放置一个图像。 我可以将图片插入到固定位置,其中包含我从另一篇文章中读到的内容。

procedure insertImages(ActiveSheet: OleVariant; ImageFilePath: String; ImageHeight, PictureTop, PictureLeft: Integer);
var
  Picture: OleVariant;
begin
    try
       Picture := ActiveSheet.Pictures.Insert(ImageFilePath);
       Picture.Width := ImageHeight * Picture.Width /Picture.Height;
       Picture.Height := ImageHeight;
       Picture.ShapeRange.Left := PictureLeft;
       Picture.ShapeRange.Top := PictureTop;
       Picture.Placement := xlMove;
    except
    end; //try
end; //insertImages;

上面的代码工作正常,但我在传递 PictureTop 和 PictureLeft 参数时遇到问题,因此每行的第二列上有不同的图像?

如何获取特定单元格的顶部和左侧值? 或者有更好的方法来做到这一点吗?

请帮忙。

My Delphi 6 program need to place an image on each row of my of Excel Sheet.
I could insert a picture to a fixed position with something I read from another post.

procedure insertImages(ActiveSheet: OleVariant; ImageFilePath: String; ImageHeight, PictureTop, PictureLeft: Integer);
var
  Picture: OleVariant;
begin
    try
       Picture := ActiveSheet.Pictures.Insert(ImageFilePath);
       Picture.Width := ImageHeight * Picture.Width /Picture.Height;
       Picture.Height := ImageHeight;
       Picture.ShapeRange.Left := PictureLeft;
       Picture.ShapeRange.Top := PictureTop;
       Picture.Placement := xlMove;
    except
    end; //try
end; //insertImages;

The above code works fine, but I having trouble passing the PictureTop and PictureLeft parameter to make it so there is different image on the 2nd column of each row?

How can I get the Top and Left value for a specific cell?
Or is there a better way to do this?

Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余罪 2024-09-21 03:35:40

例如,如果您使用;

ActiveSheet.Cells[2, 2].Select;
ActiveSheet.Pictures.Insert(ImageFileName);

那么图片的顶部等于 Cell[2, 2] 的顶部,图片的左侧等于 Cell[2, 2] 的左侧

For example If you use;

ActiveSheet.Cells[2, 2].Select;
ActiveSheet.Pictures.Insert(ImageFileName);

then your picture's top equals top of Cell[2, 2] and picture's left equals left of Cell[2, 2]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文