Share via


NamedRange.XPath Property

Gets an XPath that represents the Xpath of the element mapped to the NamedRange control.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Syntax

'Declaration
ReadOnly Property XPath As XPath
XPath XPath { get; }

Property Value

Type: Microsoft.Office.Interop.Excel.XPath
An XPath that represents the Xpath of the element mapped to the NamedRange control.

Remarks

XML features, except for saving files in the XML Spreadsheet format, are available only in Microsoft Office Professional Edition 2003 and Microsoft Office Excel 2003.

Examples

The following code example maps an XmlMap to the current workbook, and then sets the XPath property of a NamedRange to an XPath defined in the XmlMap. This example assumes that an Excel Schema Definition file named Customers.xsd that contains the XPath definition "/ns1:Customer/ns1:LastName" exists at the root of the C directory.

This example is for a document-level customization.

Private Sub UseXPath()
        Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
            = Me.Controls.AddNamedRange(Me.Range("A1"), _
            "namedRange1")

        Dim xmlMap1 As Excel.XmlMap = _
            Globals.ThisWorkbook.XmlMaps.Add("C:\Customers.xsd", _
            "Customer")

        namedRange1.XPath.SetValue(xmlMap1, _
            "/ns1:Customer/ns1:LastName", , False)

        MessageBox.Show("The XPath of the NamedRange is: " & _
            namedRange1.XPath.Value)
    End Sub
private void UseXPath()
{
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1"],
        "namedRange1");

    Excel.XmlMap xmlMap1 = Globals.ThisWorkbook.XmlMaps.Add(
        @"C:\Customers.xsd", "Customer");

    namedRange1.XPath.SetValue(xmlMap1,
        "/ns1:Customer/ns1:LastName", false);

    MessageBox.Show("The XPath of the NamedRange is: " +
        namedRange1.XPath.Value);
}

.NET Framework Security

See Also

Reference

NamedRange Interface

Microsoft.Office.Tools.Excel Namespace