2014-03-19 37 views
1

我正在研究一个应用程序,它允许用户上传演示文稿,对其进行编辑,然后将最终输出作为另一个PowerPoint演示文稿下载。不稳定的办公室(Powerpoint)自动化

我有,我上传不同的表现非常不稳定的行为:(?不知道为什么)

  1. 有时改变图像模糊返回

  2. 有时不正确形状的ID,因此我无法合并已更改的工作与现有的PowerPoint形状。

    var shape = (PowerPoint.Shape)item; 
    var shapeid=shape.ID; //this is different from what interop has returned on first presentation read. 
    
  3. 动画没有得到正确复印(有时他们这样做有时他们不这样做)。

     newshape.AnimationSettings.EntryEffect = oldshape.AnimationSettings.EntryEffect; 
         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; 
    

我知道的一个事实,即服务器端自动化可能有不稳定的行为或死锁。然而,没有任何文件确切地说明对行为不稳定。
这些行为(上面两个)在同一类别中还是我在这里丢失了某些东西?我如何解决这些问题?

+3

“不稳定办公自动化”是同义反复:( –

+0

我想我们会需要更多地了解你的代码正在做什么来指出潜在的修复 –

+0

@JoelCoehoorn:感谢edit.as我已经提到过我遇到过很多不稳定的行为,我甚至会添加将动画从现有形状复制到 –

回答

-1

如果您仍然需要使用互操作,然后尝试释放COM对象和ocasionally杀的PowerPoint情况下,低于提到:

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; 
     }   
    } 


}