无法转换类型的 COM 对象
Unable to case COM object of type
当我尝试使用 Word 互操作 foreach
通过页面上的形状执行
时,我遇到了一个奇怪的错误
我的代码如下
foreach (word.Shapes p in pages[3].Application.ActiveDocument.Shapes )
{
p.SelectAll();
}
由于某种原因我得到的异常是这个,我不知道我应该做什么来解决这个问题。
{"Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Word.Shapes'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{0002099F-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."}
Shapes
是集合类型,但为了迭代形状,您必须使用 Shape
作为每个对象的类型。
当我尝试使用 Word 互操作 foreach
通过页面上的形状执行
我的代码如下
foreach (word.Shapes p in pages[3].Application.ActiveDocument.Shapes )
{
p.SelectAll();
}
由于某种原因我得到的异常是这个,我不知道我应该做什么来解决这个问题。
{"Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Word.Shapes'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{0002099F-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."}
Shapes
是集合类型,但为了迭代形状,您必须使用 Shape
作为每个对象的类型。