Export (0) Print
Expand All
Expand Minimize

NamedRange.Parse Method

Parses a range of data and breaks it into multiple cells.

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

Object Parse(
	Object ParseLine,
	Object Destination
)

Parameters

ParseLine
Type: System.Object

A string that contains left and right brackets to indicate where the cells should be split.

For example, "[xxx][xxx]" would insert the first three characters into the first column of the destination range, and it would insert the next three characters into the second column.

If this argument is omitted, Microsoft Office Excel guesses where to split the columns based on the spacing of the top left cell in the range. If you want to use a different range to guess the parse line, use a Microsoft.Office.Interop.Excel.Range object as the ParseLine argument. That range must be one of the cells that is being parsed. The ParseLine argument cannot be longer than 255 characters, including the brackets and spaces.

Destination
Type: System.Object

A Microsoft.Office.Interop.Excel.Range object that represents the upper-left corner of the destination range for the parsed data. If this argument is omitted, Excel parses in place.

Return Value

Type: System.Object

Distributes the contents of the NamedRange control to fill several adjacent columns. The NamedRange control can be no more than one column wide.

The following code example uses the Parse method to parse each group of digits in a set of telephone numbers from a NamedRange control named NamedRange1 into a new range of cells starting at cell D1.

This example is for a document-level customization.

private void ParsePhoneNumbers()
{
    this.Range["A1"].Value2 = "'5555550100'";
    this.Range["A2"].Value2 = "'2065550101'";
    this.Range["A3"].Value2 = "'4255550102'";
    this.Range["A4"].Value2 = "'4155550103'";
    this.Range["A5"].Value2 = "'5105550104'";

    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "A5"],
        "namedRange1");

    // Parse the phone numbers and insert them into  
    // the range starting at D1.
    namedRange1.Parse("[XXX][XXX][XXXX]",
        this.Range["D1"]);
}

Show:
© 2014 Microsoft