退出时的Powerpoint问题 [英] Powerpoint issue when quitting

查看:113
本文介绍了退出时的Powerpoint问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些C#代码,可以打开一张Powerpoint幻灯片,刷新图形,然后退出.

I have some c# code which opens a Powerpoint slide, refreshes the graphs, and then quits.

这很好用,除非用户已经打开Powerpoint幻灯片,在这种情况下,一旦该exe运行,它将关闭其现有会话(丢失他们可能进行的任何更改!).

This works fine, unless the user already has a Powerpoint slide open, in which case it will close down their existing session (losing any changes they may have made!) once the exe has run.

所以,问题是,如果您在后台打开了PPT,请运行我的EXE,该EXE将运行以下代码(打开模板,刷新一些图形,保存并关闭),在应用程序退出时,它会处理变量ppApp,似乎关闭了所有正在运行的PPT.

So, the issue is if you have PPT’s open in the background, run my EXE which runs the below code (opening up a template, refreshing some graphs, saving and closing), upon application exit it disposes of the variable ppApp which seems to close down every running PPT.

如果我省略了ppApp.Quit(),甚至是这种情况;

This is even the case if I omit ppApp.Quit();

PowerPoint.Application ppApp = new PowerPoint.Application();                
PowerPoint.Presentation ppPres = ppApp.Presentations.Open(MITemplate, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);

//refresh graphs
foreach(PowerPoint.Slide sl in ppPres.Slides)
{
    foreach (PowerPoint.Shape sh in sl.Shapes)
    {

        if (sh.Type.Equals(Microsoft.Office.Core.MsoShapeType.msoLinkedOLEObject))
        {
            sh.LinkFormat.SourceFullName = XLTemplate + sh.LinkFormat.SourceFullName.Substring(sh.LinkFormat.SourceFullName.LastIndexOf("\\") + 1);
            sh.LinkFormat.Update();
        }
    }
}
ppPres.SaveAs(outputFilename);
ppPres.Close(); 
ppApp.Quit();

推荐答案

您可以检查打开了多少个其他演示文稿,并且只有在您的演示文稿是唯一的情况下才退出:

You could check how many other Presentations are open, and only quit if yours is the only one:

ppPres.SaveAs(outputFilename);

var presentations = ppApp.Presentations;

if (presentations.Count <= 1)
{
    ppPres.Close(); 
    ppApp.Quit();
}

这篇关于退出时的Powerpoint问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆