مشاركة عبر


DocumentBase.SelectLinkedControls أسلوب

تقوم بإرجاع الجميع المحتويات عناصر التحكم في مستند التي تم ربطها إلى عقده XML المخصص المحدد.

مساحة الاسم:  Microsoft.Office.Tools.Word
التجميع:  Microsoft.Office.Tools.Word.v4.0.Utilities (في Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

بناء الجملة

'إقرار
Public Function SelectLinkedControls ( _
    node As CustomXMLNode _
) As ContentControls
public ContentControls SelectLinkedControls(
    CustomXMLNode node
)

المعلمات

  • node
    النوع: CustomXMLNode
    CustomXMLNodeالذي المحتوى عناصر التحكم المرتبطة.

القيمة المُرجعة

النوع: Microsoft.Office.Interop.Word.ContentControls
ContentControlsالمجموعة التي تحتوي على المحتوى عناصر التحكم تم ربطها إلى المعين المخصص XML عقدة.

أمثلة

يلي تعليمات برمجية في المثال إضافة ثلاثة عناصر تحكم المحتوى الخاصة بتنسيق النص العادي للمستند الحالي. المثال أيضا إضافة CustomXMLPartالذي يحتوي على بيانات الموظفين ويرتبط اثنان من المحتوى عناصر التحكم للعقد XML الموجودة CustomXMLPart. التالية، تعليمات برمجية يحصل على عناصر التحكم المرتبطة بعقدة اسم الموظف وتعرض صندوق رسالة الذي يظهر عدد عناصر التحكم المرتبطة بالعثور على وأخيراً تتكرر بين عناصر التحكم المرتبطة عرض العنوان لكل ربط عنصر التحكم. عند تشغيل هذه تعليمات برمجية، يجب يحصل عنصر تحكم مرتبط و يجب أن يكون عنوان الخاص به "اسم الموظف". إلى لاستخدام هذا المثال، قم بتشغيلها من ThisDocumentالفئة في مشروع المستوى مستند.

Private Sub LinkedControls()
    Me.Paragraphs.Last.Range.InsertParagraphAfter()
    Dim employeeName As Microsoft.Office.Tools.Word.PlainTextContentControl _
        = Me.Controls.AddPlainTextContentControl(Me.Paragraphs.Last.Range, _
        "employeeName")
    employeeName.Title = "Employee Name"
    Me.Paragraphs.Last.Range.InsertParagraphAfter()
    Dim employeeHireDate As  _
        Microsoft.Office.Tools.Word.PlainTextContentControl = _
        Me.Controls.AddPlainTextContentControl(Me.Paragraphs.Last.Range, _
        "employeeHireDate")
    employeeHireDate.Title = "Employee Hire Date"
    Me.Paragraphs.Last.Range.InsertParagraphAfter()
    Dim comments As Microsoft.Office.Tools.Word.PlainTextContentControl _
        = Me.Controls.AddPlainTextContentControl(Me.Paragraphs.Last.Range, _
        "comments")
    comments.Title = "Comments"

    Dim xmlString As String = _
        "<?xml version=""1.0"" encoding=""utf-8"" ?>" _
        + "<employees>" _
        + "<employee>" _
        + "<name>Karina Leal</name>" _
        + "<hireDate>1999-04-01</hireDate>" _
        + "</employee>" _
        + "</employees>"
    Dim employeeXMLPart As Office.CustomXMLPart = _
        Me.CustomXMLParts.Add(xmlString)

    employeeName.XMLMapping.SetMapping("/employees/employee/name")
    employeeHireDate.XMLMapping.SetMapping("/employees/employee/hireDate")

    Dim node As Office.CustomXMLNode = employeeXMLPart.SelectSingleNode( _
        "/employees[1]/employee[1]/name[1]")

    Dim linkedControls As Word.ContentControls = Me.SelectLinkedControls(node)

    MessageBox.Show("Number of controls linked to the " + node.XPath _
        + " node: " + linkedControls.Count.ToString())
    For Each linkedControl As Word.ContentControl In linkedControls
        MessageBox.Show("Linked control title: " + linkedControl.Title)
    Next
End Sub
private void LinkedControls()
{
    this.Paragraphs.Last.Range.InsertParagraphAfter();
    Microsoft.Office.Tools.Word.PlainTextContentControl employeeName = 
        this.Controls.AddPlainTextContentControl(this.Paragraphs.Last.Range, 
        "employeeName");
    employeeName.Title = "Employee Name";
    this.Paragraphs.Last.Range.InsertParagraphAfter();
    Microsoft.Office.Tools.Word.PlainTextContentControl employeeHireDate = 
        this.Controls.AddPlainTextContentControl(this.Paragraphs.Last.Range, 
        "employeeHireDate");
    employeeHireDate.Title = "Employee Hire Date";
    this.Paragraphs.Last.Range.InsertParagraphAfter();
    Microsoft.Office.Tools.Word.PlainTextContentControl comments =
        this.Controls.AddPlainTextContentControl(this.Paragraphs.Last.Range, 
        "comments");
    comments.Title = "Comments";

    string xmlString = 
        "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" 
        + "<employees>" 
        + "<employee>" 
        + "<name>Karina Leal</name>" 
        + "<hireDate>1999-04-01</hireDate>"             
        + "</employee>" 
        + "</employees>";
    Office.CustomXMLPart employeeXMLPart = 
        this.CustomXMLParts.Add(xmlString, missing);

    employeeName.XMLMapping.SetMapping(
        "/employees/employee/name", "", employeeXMLPart);
    employeeHireDate.XMLMapping.SetMapping(
        "/employees/employee/hireDate", "", employeeXMLPart);

    Office.CustomXMLNode node = employeeXMLPart.SelectSingleNode(
        "/employees[1]/employee[1]/name[1]");

    Word.ContentControls linkedControls = this.SelectLinkedControls(node);
    MessageBox.Show("Number of controls linked to the " + node.XPath 
                    + " node: " + linkedControls.Count.ToString());
    foreach (Word.ContentControl linkedControl in linkedControls)
    {
        MessageBox.Show("Linked control title: " + linkedControl.Title);
    }            
}

أمن NET Framework.

راجع أيضًَا

المرجع

DocumentBase الفئة

DocumentBase الأعضاء

Microsoft.Office.Tools.Word مساحة الاسم