我有一个用vB.NET编写的程序,我有一个问题,我正在用一些数据库的数据“导出”一个excel文件。其中一个数据在其中有一个文件链接。我想把这个图片(在链接)到excel,所有的工作,直到我有。例如,宽的图像,或高的图像(风景或肖像)。我使用此代码将图像发送到excel文件:
objWorkSheet.Shapes.AddPicture(linktofile, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, Left:=10, Top:=419, Height:=285, Width:=510)所以问题是如何将AspectRatio := True放到代码中.
发布于 2018-09-04 13:31:34
如果您使用"-1“对高度和宽度使用”-1“导入图像及其原始尺寸,则可以选择它,并设置高度或宽度并保持高宽比。
例如:
With ActiveSheet.Shapes.AddPicture(Filename:=Filename, linktofile:=msoFalse, savewithdocument:=msoCTrue, Left:=0, Top:=0, Width:=-1, Height:=-1).Select
End With
Set theShape = Selection.ShapeRange.Item(1)
With theShape
.LockAspectRatio = msoTrue 'can be set to msoFalse if you don't need to lock aspect ratio
'.Width = 50
.Height = 50
End With我希望这能帮上忙!
https://stackoverflow.com/questions/49857922
复制相似问题