2014-03-19 36 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; 
     }   
    } 


}