Skip to main content
All docs
V19.1
.NET Framework 4.5.2+
Row

Range.SetValueFromText(String, Boolean) Method

Parses the supplied string and creates a cell value to assign it to the cells in the current range.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v19.1.Core.dll

Declaration

void SetValueFromText(
    string value,
    bool preserveNumberFormat
)

Parameters

Name Type Description
value String

A string to parse.

preserveNumberFormat Boolean

True, to apply the number format which the cell contains; otherwise, false.

Remarks

The SetValueFromText method calls the default worksheet parser which is normally used to parse the input of the cell editor. If the preserveNumberFormat parameter is true, the cell number format is preserved after the method assigns the cell value. If the parameter is false, the cell number format is set to the default number format for the value type assigned to the cell.

Example

This example demonstrates how to use the Range.SetValueFromText method to parse the specified string and add data of different types to worksheet cells. To retain the Formatting.NumberFormat of the current cell, when calling the method, set the second parameter to true.

For details on how to access an individual cell or range of cells, refer to the How to: Access a Cell in a Worksheet or How to: Access a Range of Cells document.

// Add data of different types to cells.
worksheet.Cells["B1"].SetValueFromText("27-Jul-16 5:43PM");
worksheet.Cells["B2"].SetValueFromText("3.1415926536");
worksheet.Cells["B3"].SetValueFromText("Have a nice day!");
worksheet.Cells["B4"].SetValueFromText("#REF!");
worksheet.Cells["B5"].SetValueFromText("true");
worksheet.Cells["B6"].SetValueFromText("3.40282E+38");
worksheet.Cells["B7"].SetValueFromText("2147483647");
worksheet.Cells["B8"].NumberFormat = "###.###";
worksheet.Cells["B8"].SetValueFromText("27-Jul-16 5:43PM", true);
worksheet.Cells["B9"].SetValueFromText("=SQRT(25)");

// Fill all cells in the range with 10.
worksheet.Range["C11:F11"].SetValueFromText("=B1");
See Also