[英]Exception trying to load powerpoint presentation
I have a program that I need c# to load a powerpoint presentation. 我有一个需要c#加载PowerPoint演示文稿的程序。 when I do the following it throws an exception
当我执行以下操作时,它将引发异常
[System.Runtime.InteropServices.COMException] = {"Presentation (unknown member) : Object does not exist."} [System.Runtime.InteropServices.COMException] = {“演示文稿(未知成员):对象不存在。”}
It happens on pres.SlideShowWindow.View.First()
. 它发生在
pres.SlideShowWindow.View.First()
。 I also tried pres.SlideShowWindow.Activate()
before this but then got the exception on activate. 在此之前,我还尝试过
pres.SlideShowWindow.Activate()
,但是在激活时遇到了异常。 At the Run line the powerpoint flashes on the screen for just a second and I can make out the slide before it leaves. 在“运行”行中,PowerPoint在屏幕上闪烁仅一秒钟,我可以在幻灯片离开之前对其进行识别。 What am I doing wrong?
我究竟做错了什么?
try
{
app = new Microsoft.Office.Interop.PowerPoint.Application();
app.SlideShowNextSlide += new Microsoft.Office.Interop.PowerPoint.EApplication_SlideShowNextSlideEventHandler(app_SlideShowNextSlide);
pres = app.Presentations.Open(filename,
Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue,Microsoft.Office.Core.MsoTriState.msoFalse);
pres.SlideShowSettings.Run();
pres.SlideShowWindow.View.First();
}
catch (Exception f)
{
MessageBox.Show(f.Message);
}
It turns out 原来
app.SlideShowNextSlide += new Microsoft.Office.Interop.PowerPoint.EApplication_SlideShowNextSlideEventHandler(app_SlideShowNextSlide);
was being fired even on pres.SlideShowWindow.View.First();
甚至在
pres.SlideShowWindow.View.First();
上被解雇了 which was unexpected. 这是出乎意料的。 I was hoping it only fired on
pres.SlideShowWindow.View.Next();
我希望它只在
pres.SlideShowWindow.View.Next();
上pres.SlideShowWindow.View.Next();
but that was not the case. 但事实并非如此。 Because of logic in
app_SlideShowNextSlide()
the slideshow was closed before it got to the first slide thus causing the Exception. 由于
app_SlideShowNextSlide()
的逻辑,幻灯片在到达第一张幻灯片之前已关闭,从而导致异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.