gpt4 book ai didi

excel - 从excel导出时如何去除图像的边框?

转载 作者:行者123 更新时间:2023-12-04 22:28:15 35 4
gpt4 key购买 nike

这是我的代码从 excel 导出图像到文件

For Each oShape In ActiveSheet.Shapes
strImageName = oShape.TopLeftCell.Row & "_" & oShape.TopLeftCell.Column
If oShape.Type = msoPicture Then
oShape.Select
'Picture format initialization
Selection.ShapeRange.PictureFormat.Contrast = 0.5: Selection.ShapeRange.PictureFormat.Brightness = 0.5: Selection.ShapeRange.PictureFormat.ColorType = msoPictureAutomatic: Selection.ShapeRange.PictureFormat.TransparentBackground = msoFalse: Selection.ShapeRange.Fill.Visible = msoFalse: Selection.ShapeRange.Line.Visible = msoFalse: Selection.ShapeRange.Rotation = 0#: Selection.ShapeRange.PictureFormat.CropLeft = 0#: Selection.ShapeRange.PictureFormat.CropRight = 0#: Selection.ShapeRange.PictureFormat.CropTop = 0#: Selection.ShapeRange.PictureFormat.CropBottom = 0#: Selection.ShapeRange.ScaleHeight 1#, msoTrue, msoScaleFromTopLeft: Selection.ShapeRange.ScaleWidth 1#, msoTrue, msoScaleFromTopLeft
'/Picture format initialization
Application.Selection.CopyPicture
Set oDia = ActiveSheet.ChartObjects.Add(0, 0, oShape.Width, oShape.Height)
Set oChartArea = oDia.Chart
oDia.Activate
With oChartArea
.ChartArea.Select
.Paste
.Export ("D:\images\" & strImageName & ".jpg")
End With
oDia.Delete 'oChartArea.Delete
End If
Next

原始图像不存在边框,但在结果文件中存在图像边框过大:

enter image description here

从excel导出时如何保留原始图像?

最佳答案

边框位于您将图像放入以进行导出的图表上,而不是图像本身。所以:

    Set oChartArea = oDia.Chart
'No need to Activate the ChartObject
With oChartArea
.ChartArea.Format.Line.Visible = msoFalse 'No Outline
.ChartArea.Format.Fill.Visible = msoFalse 'No Background
.ChartArea.Paste 'No need to use Select
.Export ("D:\images\" & strImageName & ".jpg")
End With
oDia.Delete

你可以通过运行 ActiveSheet.ChartObjects.Add 0, 0, 100, 100 更清楚地看到这一点。在即时窗口中(在 VBE 中为 Ctrl+G)并观察 ChartObject 上的默认设置 - 包括轮廓。

关于excel - 从excel导出时如何去除图像的边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55651406/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com