删除图像时,同时删除使用Excel互操作删除的行。

huangapple go评论122阅读模式
英文:

Delete images along with deleting rows with Excel interop

问题

我的Excel文档包含在行上的图像。
我正在使用EntireRow.Delete(Microsoft.Office.Interop.Excel.XlDirection.xlUp);删除各种行。
是否有一种方法也可以删除这些行上的图像?(现在它们向下移动)最好只删除在该行中心的图像,以防止删除略微偏离的图像。
我搜索了一下,但我担心我想要的可能不可能实现。
非常欢迎任何建议或解决方法,谢谢!

英文:

My excel document contain images on the rows.
I am deleting various rows with EntireRow.Delete(Microsoft.Office.Interop.Excel.XlDirection.xlUp);
Is there a way to also delete the images on those rows? (now they shifting down) Preferably only images whos center is in that row to prevent deleting images that were placed a little off.

I searched around a bit but I'm afraid what I want may not be possible.
Any advice or workaround is very welcome, thanks!

答案1

得分: 1

你已经注意到了图像浮在工作表上方。

我不熟悉Interop,所以我会展示VBA代码,你仍然需要翻译它。

你可以找到行的边界:

top = EntireRow.Top
bottom = EntireRow.Top + EntireRow.Height

然后你需要循环遍历形状以找出哪些在行内:

sheet = EntireRow.Parent ' 如果你已经有了工作表对象,就使用它。

For Each shape In sheet.Shapes
    mid_shp = shape.Top + shape.Height/2
    If mid_shp > top And mid_shp < bottom Then
       shape.Delete
    End If
Next
英文:

You already noticed that images float above the worksheet.

I am not familiar with Interop, then I will show the VBA code and you still need to translate it.

You can find the bounds of the row with:

top = EntireRow.Top
bottom = EntireRow.Top + EntireRow.Height

Then you need to loop over the shapes to find which ones are inside the row:

sheet = EntireRow.Parent &#39; if you have the sheet already, use it.

For Each shape In sheet.Shapes
    mid_shp = shape.Top + shape.Height/2
    If mid_shp &gt; top And mid_shp &lt; bottom Then
       shape.Delete
    End If
Next

huangapple
  • 本文由 发表于 2023年6月29日 19:43:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76580703.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定