[英]Unable to case COM object of type
I'm getting a strange error when I'm trying to do a foreach
through shapes on a page using Word interop 当我尝试使用Word interop通过页面上的形状进行foreach
时遇到一个奇怪的错误
My code is as follows 我的代码如下
foreach (word.Shapes p in pages[3].Application.ActiveDocument.Shapes )
{
p.SelectAll();
}
The exception I get for some reason is this and I've no idea what I should do to fix this. 由于某种原因,我得到的例外是这个,我不知道该如何解决。
{"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))."} {“无法将类型'System .__ ComObject'的COM对象转换为接口类型'Microsoft.Office.Interop.Word.Shapes'。此操作失败,因为对IID为'{0002099F-0000”的接口的COM组件上的QueryInterface调用-0000-C000-000000000046}由于以下错误而失败:不支持此类接口(HRESULT的异常:0x80004002(E_NOINTERFACE))。“}
Shapes
是集合类型,但是要迭代形状,必须为每个对象使用Shape
作为类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.