英文:
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 ' if you have the sheet already, use it.
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论