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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3490200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:59:48  来源:igfitidea点击:

Insert an image on each row in an Excel Sheet with Delphi

delphiexcelexcel-vbadelphi-6vba

提问by Snackmoore

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.

我的 Delphi 6 程序需要在我的 Excel Sheet 的每一行上放置一个图像。我可以使用我从另一篇文章中读到的内容将图片插入到固定位置。

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?

上面的代码工作正常,但我在传递 PictureTop 和 PictureLeft 参数时遇到了麻烦,所以每行的第二列有不同的图像?

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

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

Please help.

请帮忙。

回答by SimaWB

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]

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