HOW TO:從文件移除 Managed 程式碼擴充 (2003 系統)

更新:2007 年 11 月

適用於

本主題中的資訊僅適用於指定的 Visual Studio Tools for Office 專案和 Microsoft Office 版本。

專案類型

  • 文件層級專案

Microsoft Office 版本

  • Microsoft Office 2003

如需詳細資訊,請參閱依應用程式和專案類型提供的功能

您可以程式設計方式從參與 Microsoft Office 2003 文件層級自訂的文件或活頁簿中移除 Visual Studio Tools for Office 自訂組件。使用者將可以繼續開啟文件並檢視其內容,但是任何您加入文件中的自訂使用者介面 (UI) 將不會出現,而您的程式碼也將無法執行。當您移除組件時,可以選擇將快取資料留在文件中,或是將它移除:

  • 如果要保留快取資料,請清除內嵌在文件中的應用程式資訊清單。如果 ASP.NET 頁面或伺服器應用程式稍後還會讀取快取資料,您就可以保留這些資料。

  • 如果您不再需要快取資料,請同時清除應用程式資訊清單和快取資料。

Visual Studio Tools for Office Runtime 包含物件模型,可讓您以程式設計的方式執行上述動作。

清除內嵌的應用程式資訊清單

使用 ServerDocument 類別 (Class) 只會清除內嵌的應用程式資訊清單。您必須將使用 ServerDocument 類別的程式碼放置在新的專案 (而非您的 Visual Studio Tools for Office 方案) 中,例如,主控台應用程式 (Console Application) 或 Windows Form 專案中。

若要清除內嵌的應用程式資訊清單

  1. 建立新的專案,例如主控台應用程式或 Windows Form 專案。

  2. 將 Microsoft.VisualStudio.Tools.Applications.Runtime.dll 組件的參考加入專案中。

  3. 將下列 Imports 或 using 陳述式加入至程式碼檔的最上方。

    Imports Microsoft.VisualStudio.Tools.Applications.Runtime
    
    using Microsoft.VisualStudio.Tools.Applications.Runtime;
    
  4. 建立 ServerDocument 的執行個體,然後傳入方案文件。呼叫 AppManifest 屬性的 Clear 方法。

    Dim sd As ServerDocument = Nothing
    Try
        sd = New ServerDocument("C:\Documents\SolutionDocument.doc")
        sd.AppManifest.Clear()
    
    ServerDocument sd = null;
    try 
    {
        sd = new ServerDocument(@"C:\Documents\SolutionDocument.doc");
        sd.AppManifest.Clear();
    
  5. 儲存變更並關閉文件。

        sd.Save()
    
    Finally
        If Not sd Is Nothing Then
            sd.Close()
        End If
    End Try
    
        sd.Save();
    }
    finally
    {
        if (sd != null)
        {
            sd.Close();
        }
    }
    

清除內嵌的應用程式資訊清單和快取資料

您可以使用其中一種 RemoveCustomization 方法,同時從文件清除內嵌的應用程式資訊清單和快取資料:

注意事項:

Document.RemoveCustomizationWorkbook.RemoveCustomization 方法也會從文件中移除 Runtime Storage Control。如需 Runtime Storage Control 的詳細資訊,請參閱 Runtime Storage Control 概觀

若要從用戶端電腦上開啟的文件清除內嵌的應用程式資訊清單和快取資料

若要從關閉的文件或伺服器上的文件清除內嵌的應用程式資訊清單和快取資料

  1. 建立新的專案,例如主控台應用程式或 Windows Form 專案。

  2. 將 Microsoft.VisualStudio.Tools.Applications.Runtime.dll 組件的參考加入專案中。

  3. 將下列 Imports 或 using 陳述式加入至程式碼檔的最上方。

    Imports Microsoft.VisualStudio.Tools.Applications.Runtime
    
    using Microsoft.VisualStudio.Tools.Applications.Runtime;
    
  4. 呼叫 ServerDocument 類別的靜態 RemoveCustomization 方法,然後指定參數的方案文件路徑。

    If (ServerDocument.IsCustomized("C:\Documents\SolutionDocument.doc")) Then
    
        ServerDocument.RemoveCustomization("C:\Documents\SolutionDocument.doc")
    End If
    
    if (ServerDocument.IsCustomized(@"C:\Documents\SolutionDocument.doc"))
    {
        ServerDocument.RemoveCustomization(@"C:\Documents\SolutionDocument.doc");
    }
    

請參閱

工作

HOW TO:撰寫使用 ServerDocument 類別兩個版本的程式碼

HOW TO:將 Managed 程式碼擴充附加至文件 (2003 系統)

HOW TO:從文件移除 Managed 程式碼擴充 (2007 系統)

HOW TO:將 Managed 程式碼擴充附加至文件 (2007 系統)

概念

使用 ServerDocument 類別管理伺服器上的文件

快取資料

Office 方案中的應用程式和部署資訊清單