【发布时间】:2015-01-12 07:23:08
【问题描述】:
问题:如何处理父PPT进程创建的子Excel窗口?
- 我将图表从 Excel 复制到 Power Point 2013
- 然后我用鼠标右键单击此图表并选择“编辑数据”
- 将出现紧凑的 Excel 弹出窗口,其中包含此图表的源数据
- 我关闭了这个窗口并且无法再次打开它,因为这个窗口的句柄似乎没有正确释放
如果Excel窗口中的某些数据发生变化,这是用于更新PPT图表的代码。
protected void UpdateSlide()
{
using (PresentationWrapper presentation = ParentSlide.Parent)
using (DocumentWindowWrapper window = presentation.Windows[0]) // !!! here is the place where Com oject is maintained but needs to be released
{
window.Activate();
}
}
这是不释放 Com 对象的包装器。
public class DocumentWindowWrapper : ComWrapper<ppt.DocumentWindow>, IWindow
{
DocumentWindowWrapper wrapper;
public static DocumentWindowWrapper CreateWrapper(ppt.DocumentWindow wrappedObject)
wrapper = new DocumentWindowWrapper(wrappedObject);
return wrapper;
}
public override void Dispose()
{
Marshal.ReleaseComObject(...); // !!! what should I put here to release this window?
base.Dispose();
}
}
这就是我说的窗口。
【问题讨论】:
-
正如 Yegor 所暗示的,
presentation.Windows[0]创建了两个 .NET 包装器(Windows和DocumentWindow)并且只发布了一个。也许这是你的问题?
标签: c# excel vsto powerpoint