Share via


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
)

매개 변수

반환 값

형식: Microsoft.Office.Interop.Word.ContentControls
문서에서 지정된 사용자 지정 XML 노드에 연결된 콘텐츠 컨트롤이 들어 있는 ContentControls 컬렉션입니다.

예제

다음 코드 예제에서는 현재 문서에 세 개의 일반 텍스트 콘텐츠 컨트롤을 추가합니다. 또한 직원 데이터가 들어 있는 CustomXMLPart를 추가하고 두 개의 콘텐츠 컨트롤을 CustomXMLPart의 XML 노드에 연결합니다. 그런 다음 직원 이름 노드에 연결된 컨트롤을 가져오고, 연결된 컨트롤의 수를 나타내는 메시지 상자를 표시하고, 마지막으로 연결된 컨트롤을 반복하여 연결된 각 컨트롤의 제목을 표시합니다. 이 코드를 실행할 때는 연결된 컨트롤을 하나 가져와야 하며 해당 컨트롤의 제목이 Employee Name이어야 합니다. 이 예제를 사용하려면 문서 수준 프로젝트 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 클래스

Microsoft.Office.Tools.Word 네임스페이스