Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VB.NET Shapes.AddPicture与纵横比_Excel_Vb.net - Fatal编程技术网

Excel VB.NET Shapes.AddPicture与纵横比

Excel VB.NET Shapes.AddPicture与纵横比,excel,vb.net,Excel,Vb.net,我有一个用vB.NET编写的程序。我有一个问题,我正在“导出”一个excel文件,其中包含数据库中的一些数据。其中一个数据中有指向文件的链接。我想把这张图片(在链接中)放到excel中,在我找到它之前一切都很好。例如,宽的图像或高的图像(横向或纵向)。我正在使用以下代码将图像发布到excel文件: objWorkSheet.Shapes.AddPicture(linktofile, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Off

我有一个用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
放在代码中

如果使用高度和宽度的“-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

我希望这有帮助

如果使用高度和宽度的“-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

我希望这有帮助

如果要指定尺寸,则无法指定纵横比。。。尝试将高度和宽度设置为-1以保持大小。情况并非如此。我必须使图像更小(或等于)到285点的高度。。。到目前为止,我的解决方案是将图像的高度转换为点,并循环除以1,5,直到图像的高度不等于或小于285点。。。同样的aplies到它的高度(为了不丢失图像质量),然后将高度设置为285点,宽度设置为-1。这应该可以满足您的需要:)如果要指定尺寸,则无法指定纵横比。。。尝试将高度和宽度设置为-1以保持大小。情况并非如此。我必须使图像更小(或等于)到285点的高度。。。到目前为止,我的解决方案是将图像的高度转换为点,并循环除以1,5,直到图像的高度不等于或小于285点。。。同样的aplies到它的高度(为了不丢失图像质量),然后将高度设置为285点,宽度设置为-1。这应该可以满足您的需要:)