共用方式為


View.ExecuteAction 方法

根據檢視中選取的資料,針對表單基礎 XML 文件執行 Microsoft Office InfoPath 2003 編輯命令。

**命名空間:**Microsoft.Office.Interop.InfoPath
**組件:**Microsoft.Office.Interop.InfoPath (於 microsoft.office.interop.infopath.dll 中)

語法

'宣告
<DispIdAttribute(14)> _
Sub ExecuteAction ( _
    <InAttribute> bstrAction As String, _
    <InAttribute> <OptionalAttribute> varXmlToEdit As Object _
)
'用途
Dim instance As View
Dim bstrAction As String
Dim varXmlToEdit As Object

instance.ExecuteAction(bstrAction, varXmlToEdit)
[DispIdAttribute(14)] 
void ExecuteAction (
    [InAttribute] string bstrAction,
    [OptionalAttribute] [InAttribute] Object varXmlToEdit
)

參數

  • bstrAction
    要執行的編輯動作名稱。
  • varXmlToEdit
    要套用編輯動作的欄位或群組名稱;相當於表單定義檔案 (.xsf) 中 xmlToEdit 元素的名稱屬性值。

備註

ExecuteAction 方法可以用於根據檢視中選取的內容,對表單基礎 XML 文件以程式設計的方式執行內建 InfoPath 編輯動作。

執行的動作與在對等功能表或工具列按鈕上按一下時使用的動作相同。也就是說,.xsf 檔案中的按鈕元素具有對應 xmlToEditaction 屬性的動作。與使用按鈕時相同,動作將根據目前的選擇:它會在選取的內容上作用 (且當選取導致按鈕停用時,ExecuteAction 方法將不再有效)。

您可以先使用 SelectNodes 方法或 SelectText 方法設定選取範圍內容,然後呼叫 ExecuteAction 方法依該內容執行動作。

ExecuteAction 方法會因下列原因傳回錯誤:

  • bstrAction 參數未包含有效的編輯元件名稱。

  • varXmlToEdit 參數與檢視中定義的編輯元件不符。

  • 需要 varXmlToEdit 參數來執行特定的編輯動作。

  • 編輯動作不適用於選取的內容。

  • 下表列出可與 ExecuteAction 方法搭配使用的參數組合。

組合

描述

"Copy"

將選取的資料複製到剪貼簿。

"Paste"

將資料從剪貼簿複製到插入點。

"Cut"

移除選取的資料,並將資料複製到剪貼簿。

"Delete"

刪除選取的資料。

"xCollection::insert", "xmlToEdit"

會使用 xCollection 編輯元件,根據選取的內容插入資料。如果目前選取範圍在 xCollection 的容器 (由 .xsf 中的 xmlToEdit 元素指定) 中,則 fragmentToInsert 元素資料會新增至該容器中。

"xCollection::insertBefore", "xmlToEdit"

會使用 xCollection 編輯元件,在選取的內容之前插入資料。如果目前選取範圍在 xCollection 的項目 (由 .xsf 中的 xmlToEdit 元素指定) 中,則 fragmentToInsert 元素資料會在該項目之前插入。

"xCollection::insertAfter", "xmlToEdit"

會使用 xCollection 編輯元件在選取的內容之後插入資料。如果目前選取範圍在 xCollection 的項目 (由 .xsf 中的 xmlToEdit 元素指定) 中,則 fragmentToInsert 元素資料會在該項目之後插入。

"xCollection::remove", "xmlToEdit"

會使用 xCollection 編輯元件刪除已選取內容中的資料。如果目前選取範圍在 xCollection 的項目 (由 .xsf 中的 xmlToEdit 元素指定) 中,則會刪除該項目。

"xCollection::removeAll", "xmlToEdit"

會使用 xCollection 編輯元件,刪除已選取內容中所包含的全部資料。如果目前選取範圍在 xCollection 的容器 (由 .xsf 中的 xmlToEdit 元素指定) 中,則此動作會刪除該容器中的所有項目。

"xReplace::replace", "xmlToEdit"

會使用 xReplace 編輯元件取代選取的內容中的資料。如果目前選取範圍在 xReplace 的項目 (由 .xsf 中的 xmlToEdit 元素指定) 中,則 fragmentToInsert 元素資料會取代該項目。

"xOptional::insert", "xmlToEdit"

會使用 xOptional 編輯元件,根據選取的內容插入資料。如果目前選取範圍在 xOptional 的容器 (由 .xsf 中的 xmlToEdit 元素指定) 中,則 fragmentToInsert 元素資料會新增至該容器中。

"xOptional::remove", "xmlToEdit"

會使用 xOptional 編輯元件刪除已選取內容中的資料。如果目前選取範圍在 xOptional 的項目 (由 .xsf 中的 xmlToEdit 元素指定) 中,則會刪除該項目。

注意   在某些情況下,從檢視中按鈕的 OnClick 呼叫 ExecuteAction 方法可能會造成錯誤。這是因為按一下按鈕時,選取的內容會變更為該按鈕。在此情況下,最好使用自訂工作窗格、工具列或功能表上的按鈕 (或連結) 來呼叫 ExecuteAction 方法。

範例

在下列範例中,ViewObject 物件的 ExecuteAction 方法是用於刪除選取的資料,並將資料放在剪貼簿中:

thisXDocument.View.ExecuteAction("Cut", Type.Missing);

在下列範例中,使用 ExecuteAction 物件的 ViewObject 方法,根據所選內容使用 xCollection 編輯元件插入資料:

thisXDocument.View.ExecuteAction("xCollection::insert", "group1_1");

請參閱

參考

View 介面
View 成員
Microsoft.Office.Interop.InfoPath 命名空間