本文為機器翻譯文章。如需檢視英文版,請選取 [原文] 核取方塊。您也可以將滑鼠指標移到文字上,即可在快顯視窗顯示英文原文。
譯文
原文

ApplicationFactory.GetVstoObject 方法 (_Document)

 

傳回擴充指定原生文件物件之功能的 Microsoft.Office.Tools.Word.Document 主項目。

命名空間:   Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word (於 Microsoft.Office.Tools.Word.dll)

Document GetVstoObject(
	_Document document
)

參數

document
Type: Microsoft.Office.Interop.Word._Document

要擴充的原生文件物件。 雖然此參數的類型是 Microsoft.Office.Interop.Word._Document,但您通常會傳遞 Microsoft.Office.Interop.Word.Document 物件給此方法。

傳回值

Type: Microsoft.Office.Tools.Word.Document

擴充原生文件物件之功能的主項目。

Call this method in an application-level add-in to customize any document that is open in Word. This method generates a new T:Microsoft.Office.Tools.Word.Document object if no such object has already been generated. Subsequent calls to this method return the cached instance of the existing T:Microsoft.Office.Tools.Word.Document object. For more information, see Extending Word Documents and Excel Workbooks in VSTO Add-ins at Run Time.

System_CAPS_note注意

The document parameter is of type T:Microsoft.Office.Interop.Word._Document, which is the parent interface of T:Microsoft.Office.Interop.Word.Document. Therefore, this method can accept objects of both types: T:Microsoft.Office.Interop.Word._Document and T:Microsoft.Office.Interop.Word.Document. Typically, when you reference a Word document, you use a T:Microsoft.Office.Interop.Word.Document.

The following code example creates a T:Microsoft.Office.Tools.Word.Document host item for the active Word document. The example then adds a T:Microsoft.Office.Tools.Word.PlainTextContentControl to the document. To use this code, run it from the ThisAddIn class in a Word add-in project that targets the net_v40_short or the net_v45.

Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);

vstoDoc.Paragraphs.Last.Range.InsertParagraphAfter();
PlainTextContentControl myPlainTextControl =
    vstoDoc.Controls.AddPlainTextContentControl(
    vstoDoc.Paragraphs.Last.Range,
    "myPlainTextControl");
myPlainTextControl.PlaceholderText = "Insert first name";
回到頁首
顯示: