共用方式為


DocumentExtensions.GetVstoObject 方法

定義

多載

GetVstoObject(_Document, ApplicationFactory)

傳回 Document 主項目,其可擴充應用程式層級增益集中目前 Document 物件的功能。 將專案中的 Globals.Factory 物件傳遞給 factory 參數。

GetVstoObject(_Document, Factory)

傳回 Document 主項目,可擴充文件層級自訂中目前 Document 物件的功能。 將專案中的 Globals.Factory 物件傳遞給 factory 參數。

GetVstoObject(_Document, ApplicationFactory)

傳回 Document 主項目,其可擴充應用程式層級增益集中目前 Document 物件的功能。 將專案中的 Globals.Factory 物件傳遞給 factory 參數。

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Office::Tools::Word::Document ^ GetVstoObject(Microsoft::Office::Interop::Word::_Document ^ document, Microsoft::Office::Tools::Word::ApplicationFactory ^ factory);
public static Microsoft.Office.Tools.Word.Document GetVstoObject (this Microsoft.Office.Interop.Word._Document document, Microsoft.Office.Tools.Word.ApplicationFactory factory);
static member GetVstoObject : Microsoft.Office.Interop.Word._Document * Microsoft.Office.Tools.Word.ApplicationFactory -> Microsoft.Office.Tools.Word.Document
<Extension()>
Public Function GetVstoObject (document As _Document, factory As ApplicationFactory) As Document

參數

document
_Document

要擴充的原生文件物件。 請不要自行提供這個參數。 當您在 Word 文件上呼叫這個方法時,執行階段會提供這個參數。

factory
ApplicationFactory

提供應用程式層級增益集中特定功能之存取權的物件。 將 Globals.Factory 物件傳遞給這個參數。

傳回

可擴充目前 Document 物件之功能的主項目。

備註

在應用層級載入宏中,呼叫此方法以擴充在 Word 中開啟的任何檔。 如果尚未針對您呼叫這個方法的對象產生這類對象,Microsoft.Office.Interop.Word.Document這個方法就會產生新的Microsoft.Office.Tools.Word.Document主專案。 相同 Microsoft.Office.Interop.Word.Document 對象上這個方法的後續呼叫會傳回相同的 Microsoft.Office.Tools.Word.Document 實例。

提供這個方法,可讓您將目標從 .NET Framework 3.5 複位為 .NET Framework 4 或 .NET Framework 4.5 的 Office 專案回溯相容性。 在以 .NET Framework 4 或 .NET Framework 4.5 為目標的新專案中,您應該呼叫GetVstoObject項目中 物件所提供的 Globals.Factory 方法。

如需詳細資訊,請參閱 Extending Word Documents and Excel Workbooks in VSTO Add-ins at Run Time

注意

參數 document 的類型為 Microsoft.Office.Interop.Word._Document,這是 的 Microsoft.Office.Interop.Word.Document父介面。 因此,這個方法會擴充這兩種類型: Microsoft.Office.Interop.Word._DocumentMicrosoft.Office.Interop.Word.Document。 一般而言,當您參考 Word 檔案時,您會使用 Microsoft.Office.Interop.Word.Document

適用於

GetVstoObject(_Document, Factory)

傳回 Document 主項目,可擴充文件層級自訂中目前 Document 物件的功能。 將專案中的 Globals.Factory 物件傳遞給 factory 參數。

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Office::Tools::Word::Document ^ GetVstoObject(Microsoft::Office::Interop::Word::_Document ^ document, Microsoft::Office::Tools::Word::Factory ^ factory);
public static Microsoft.Office.Tools.Word.Document GetVstoObject (this Microsoft.Office.Interop.Word._Document document, Microsoft.Office.Tools.Word.Factory factory);
static member GetVstoObject : Microsoft.Office.Interop.Word._Document * Microsoft.Office.Tools.Word.Factory -> Microsoft.Office.Tools.Word.Document
<Extension()>
Public Function GetVstoObject (document As _Document, factory As Factory) As Document

參數

document
_Document

要擴充的原生文件物件。 請不要自行提供這個參數。 當您在 Word 文件上呼叫這個方法時,執行階段會提供這個參數。

factory
Factory

提供文件層級自訂中特定功能之存取權的物件。 將 Globals.Factory 物件傳遞給這個參數。

傳回

可擴充目前 Document 物件之功能的主項目。

備註

在文件層級自定義中,您可以呼叫這個方法來取得 Microsoft.Office.Tools.Word.Document 目前自定義中的主專案。 Microsoft.Office.Interop.Word.Document如果您呼叫這個方法的物件不是目前自訂中主項目的基礎物件Microsoft.Office.Tools.Word.Document,這個方法會傳null回 。

提供這個方法,可讓您將目標從 .NET Framework 3.5 複位為 .NET Framework 4 或 .NET Framework 4.5 的 Office 專案回溯相容性。 在以 .NET Framework 4 或 .NET Framework 4.5 為目標的新專案中,您應該呼叫GetVstoObject項目中 物件所提供的 Globals.Factory 方法。 如需詳細資訊,請參閱 Programming Document-Level Customizations

注意

參數 document 的類型為 Microsoft.Office.Interop.Word._Document,這是 的 Microsoft.Office.Interop.Word.Document父介面。 因此,這個方法會擴充這兩種類型: Microsoft.Office.Interop.Word._DocumentMicrosoft.Office.Interop.Word.Document。 一般而言,當您參考 Word 檔案時,您會使用 Microsoft.Office.Interop.Word.Document

適用於