首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不稳定办公室(Powerpoint)自动化

不稳定办公室(Powerpoint)自动化
EN

Stack Overflow用户
提问于 2014-03-19 13:55:59
回答 1查看 330关注 0票数 1

我正在开发一个应用程序,允许用户上传演示文稿,编辑演示文稿,然后将最终输出作为另一个PowerPoint演示文稿下载。

对于上传的不同演示文稿,我有非常不稳定的行为:

  1. 有时改变的图像是模糊的(不确定为什么?)
  2. 有时会返回不正确的形状ids,因此我无法将更改后的工作与现有的PowerPoint形状合并。 var shape = (PowerPoint.Shape)item;var shapeid=shape.ID;//这与interop在第一次演示文稿读取时返回的内容不同。
  3. 动画没有被正确地复制(有时它们复制,有时它们没有)。 newshape.AnimationSettings.AdvanceMode=oldshape.AnimationSettings.AdvanceMode;newshape.AnimationSettings.AdvanceTime=oldshape.AnimationSettings.AdvanceTime;newshape.AnimationSettings.AfterEffect=oldshape.AnimationSettings.AfterEffect;newshape.AnimationSettings.Animate=oldshape.AnimationSettings.Animate;newshape.AnimationSettings.AnimateBackground = oldshape.AnimationSettings.AnimateBackground;newshape.AnimationSettings.TextLevelEffect = PowerPoint.PpTextLevelEffect.ppAnimateByAllLevels;newshape.AnimationSettings.AnimateTextInReverse=oldshape.AnimationSettings.AnimateTextInReverse;

我知道服务器端自动化可能具有不稳定的行为或死锁。然而,没有任何文件确切地记录了行为的不稳定性。

这些行为(以上两种行为)是否属于同一类别,还是我在这里遗漏了什么?我怎样才能解决这些问题?

EN

回答 1

Stack Overflow用户

发布于 2017-12-05 16:42:42

如果您仍然需要使用Interop,那么试着释放COM对象,然后按以下所述定位终止PowerPoint实例:

代码语言:javascript
复制
public static class PowerPointInterOp
{
    static PowerPoint.Application powerPointApp = null;
    static Object oMissing = System.Reflection.Missing.Value;
    static Object oTrue = true;
    static Object oFalse = false;
    static Object oCopies = 1;

    public static void InitializeInstance()
    {
        if (powerPointApp == null)
        {
            powerPointApp = new PowerPoint.ApplicationClass();

        }           
    }

    public static void KillInstances()
    {
        try
        {
            Process[] processes = Process.GetProcessesByName("POWERPNT");
            foreach(Process process in processes)
            {
                process.Kill();
            }
        }
        catch(Exception)
        {

        }
    }

    public static void CloseInstance()
    {
        if (powerPointApp != null)
        {
            powerPointApp.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(powerPointApp);
            powerPointApp = null;
        }
    }

    public static PowerPoint.Presentation OpenDocument(string documentPath)
    {
        InitializeInstance();

        PowerPoint.Presentation powerPointDoc = powerPointApp.Presentations.Open(documentPath, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);

        return powerPointDoc;
    }

    public static void CloseDocument(PowerPoint.Presentation powerPointDoc)
    {
        if (powerPointDoc != null)
        {
            powerPointDoc.Close();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(powerPointDoc);
            powerPointDoc = null;
        }           
    }


}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22508145

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档