获取包括所有形状对象的Excel范围

在VSTO(C#)项目中,我想要使用UsedRange,包括形状对象(如图片和图表)。

1.是否有一种方法来获得形状对象的UsedRange?

由于找不到这样的方法,我想用这个方法来计算边缘:

foreach (Excel.Shape shape in shapeObjects) { float shapeBottom = shape.Top + shape.Height; float shapeRight = shape.Left + shape.Width; if (maxBottom < shapeBottom) { maxBottom = shapeBottom; } if (maxRight < shapeRight) { maxRight = shapeRight; } } Excel.Range r = <XXX>(maxBottom, maxRight); 

所以现在我有问题从maxBottom和maxRight获取范围。

2.有没有办法通过给出宽度和高度来获得一个Range对象?

Shapes有一个BottomRightCell属性,它返回形状右下angular覆盖的单元格。 如果你遍历每个形状的属性,你应该能够收集最右边的列和最后一行你想要的范围。