XmlDataQuery Method

WorksheetBase.XmlDataQuery Method (String, Object, Object)

 

Gets a Range object that represents the cells mapped to a particular XPath. Gets null if the specified XPath has not been mapped to the worksheet, or if the mapped range is empty.

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

public Range XmlDataQuery(
	string xPath,
	object selectionNamespaces,
	object map
)

Parameters

xPath
Type: System.String

The XPath to query for.

selectionNamespaces
Type: System.Object

A space-delimited string that contains the namespaces referenced in the XPath parameter. A run-time error is generated if one of the specified namespaces cannot be resolved.

map
Type: System.Object

An XmlMap. Specify an XML map if you want to query for the XPath within a specific map.

Return Value

Type: Microsoft.Office.Interop.Excel.Range

A Range object that represents the cells mapped to a particular XPath; null if the specified XPath has not been mapped to the worksheet, or if the mapped range is empty.

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.

If the XPath exists within a column in an XML list, the Range object returned does not include the header row or the Insert row.

For information on optional parameters, see Optional Parameters in Office Solutions.

The following code example uses the XmlDataQuery method to get the Range of cells mapped to a particular XPath.

This example is for a document-level customization.

private void WorksheetQueryXmlData()
{
    string path = "/order/customer/address";
    string namespaces = "xmlns=http://www.contoso.com/orders";

    Excel.Range range1 = this.XmlDataQuery(path, namespaces);

    if (range1 == null)
    {
        MessageBox.Show("The specified XPath: '" + path + 
            "' has not been mapped to the worksheet, or the mapped " +
            "range is empty.");
    }
}
Return to top
Show:
© 2016 Microsoft