CellRange.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.v26.1.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
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
// Add data of different types to cells.
worksheet.Cells["B1"].SetValueFromText("28-Jul-20 5:43PM"); // DateTime
worksheet.Cells["B2"].SetValueFromText("3.1415926536"); // double
worksheet.Cells["B3"].SetValueFromText("Have a nice day!"); // string
worksheet.Cells["B4"].SetValueFromText("#REF!"); // error
worksheet.Cells["B5"].SetValueFromText("true"); // Boolean
worksheet.Cells["B6"].SetValueFromText("3.40282E+38"); // float
worksheet.Cells["B7"].SetValueFromText("2147483647"); // int32
worksheet.Cells["B8"].NumberFormat = "d-mmm-yy h:mm";
worksheet.Cells["B8"].SetValueFromText("28-Jul-20 5:43PM", true); // DateTime with a custom format
worksheet.Cells["B9"].SetValueFromText("=SQRT(25)"); // formula
See Also