我正在为 Word 2010 编写 VSTO。我想检查 msoGroup 形状中的形状,但未能获得组中的形状。这是我的尝试:
public void TestGroupShapes_Action(Microsoft.Office.Core.IRibbonControl control)
{
Microsoft.Office.Interop.Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;
foreach(Microsoft.Office.Interop.Word.Shape shape in doc.Shapes)
{
if (shape.Type == Microsoft.Office.Core.MsoShapeType.msoGroup)
{
/*
// System.InvalidCastException:
// Cannot convert System.__ComObject to Microsoft.Office.Interop.Word.Shape”
foreach (Shape groupShape in shape.GroupItems)
{
Console.WriteLine(groupShape.Name);
}
*/
for(int i=0; i<shape.GroupItems.Count; i++)
{
// System.ArgumentException: Cannot use the index in the assembly.
Microsoft.Office.Interop.Word.Shape groupShape = shape.GroupItems[i];
Console.WriteLine(groupShape.Name);
}
}
}
}
如何解决问题?