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.v24.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
This example demonstrates how to use the CellRange.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");
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the SetValueFromText(String, Boolean) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.