Back to Devexpress

CellRange.Value Property

officefileapi-devexpress-dot-spreadsheet-dot-cellrange-f4609e42.md

latest10.4 KB
Original Source

CellRange.Value Property

Gets or sets a cell value.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
CellValue Value { get; set; }
vb
Property Value As CellValue

Property Value

TypeDescription
CellValue

A cell value.

|

Remarks

A CellValue object specifies a value contained in a cell. Use the Value property to specify or obtain a cell value.

You can set the Value property to an object of the String, DateTime, Boolean or numeric type (Int32, Double, etc.). See the Cell Data Types topic for details on cell values and their types.

Note

You cannot assign a Decimal value to a cell via the CellRange.Value property. Use the CellRange.SetValue or CellValue.FromObject method instead.

The CellRange.SetValue method allows you to assign an object of any type to a cell value. It uses the default converter to convert the specified object to a CellValue and assigns it to a cell. To use a custom converter, use the CellValue.FromObject method. See the How to: Convert Objects to Cell Values and Cell Values to Objects example.

You can also use a formula to calculate a cell value dynamically.

If a cell has no data, the Value property returns an empty value object (CellValue.IsEmpty is true ).

Example

This example demonstrates how to use the CellRange.Value property to add data of different types to worksheet cells.

Enclose your code in the Workbook.BeginUpdate - Workbook.EndUpdate method calls to improve performance when you edit multiple cells in a document.

View Example

csharp
// Add data of different types to cells.
worksheet.Cells["B1"].Value = DateTime.Now;
worksheet.Cells["B2"].Value = Math.PI;
worksheet.Cells["B3"].Value = "Have a nice day!";
worksheet.Cells["B4"].Value = CellValue.ErrorReference;
worksheet.Cells["B5"].Value = true;
worksheet.Cells["B6"].Value = float.MaxValue;
worksheet.Cells["B7"].Value = 'a';
worksheet.Cells["B8"].Value = Int32.MaxValue;

// Fill all cells in the range with 10.
worksheet.Range["B10:E10"].Value = 10;
vb
' Add data of different types to cells.
worksheet.Cells("B1").Value = Date.Now
worksheet.Cells("B2").Value = Math.PI
worksheet.Cells("B3").Value = "Have a nice day!"
worksheet.Cells("B4").Value = CellValue.ErrorReference
worksheet.Cells("B5").Value = True
worksheet.Cells("B6").Value = Single.MaxValue
worksheet.Cells("B7").Value = "a"c
worksheet.Cells("B8").Value = Int32.MaxValue

' Fill all cells in the range with 10.
worksheet.Range("B10:E10").Value = 10

The following code snippets (auto-collected from DevExpress Examples) contain references to the Value property.

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.

spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/SpreadsheetActions/ExportActions.cs#L19

csharp
{
    workbook.Worksheets[0].Cells["D8"].Value = "This document is exported to the PDF format.";

winforms-spreadsheetcontrol-api-part1/CS/SpreadsheetControl/SpreadsheetActions/ImportExportActions.cs#L12

csharp
static void ExportToPdf(IWorkbook workbook) {
    workbook.Worksheets[0].Cells["D8"].Value = "This document is exported to the PDF format.";

wpf-spreadsheetcontrol-api-part-1/CS/SpreadsheetControl_WPF_API/SpreadsheetActions/ImportExportActions.cs#L13

csharp
static void ExportToPdf(IWorkbook workbook) {
    workbook.Worksheets[0].Cells["D8"].Value = "This document is exported to the PDF format.";

wpf-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_WPF_API_Part02/SpreadsheetActions/CustomXmlPartActions.cs#L16

csharp
#region #StoreCustomXmlPart
workbook.Worksheets[0].Cells["A1"].Value = "Custom Xml Test";

winforms-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_API_Part02/SpreadsheetActions/DocumentPropertiesActions.cs#L24

csharp
CellRange header = worksheet.Range["B2:C2"];
header[0].Value = "Property Name";
header[1].Value = "Value";

spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/SpreadsheetActions/ExportActions.vb#L16

vb
Private Sub ExportToPdf(ByVal workbook As Workbook)
            workbook.Worksheets(0).Cells("D8").Value = "This document is exported to the PDF format."
#Region "#ExportToPdf"

winforms-spreadsheetcontrol-api-part1/VB/SpreadsheetControl/SpreadsheetActions/ImportExportActions.vb#L16

vb
Private Shared Sub ExportToPdf(ByVal workbook As IWorkbook)
    workbook.Worksheets(0).Cells("D8").Value = "This document is exported to the PDF format."

wpf-spreadsheetcontrol-api-part-1/VB/SpreadsheetControl_WPF_API/SpreadsheetActions/ImportExportActions.vb#L16

vb
Private Shared Sub ExportToPdf(ByVal workbook As IWorkbook)
    workbook.Worksheets(0).Cells("D8").Value = "This document is exported to the PDF format."

winforms-spreadsheetcontrol-api-part-2/VB/SpreadsheetControl_API_Part02/SpreadsheetActions/DocumentPropertiesActions.vb#L20

vb
Dim header As CellRange = worksheet.Range("B2:C2")
header(0).Value = "Property Name"
header(1).Value = "Value"

wpf-spreadsheetcontrol-api-part-2/VB/SpreadsheetControl_WPF_API_Part02/SpreadsheetActions/DocumentPropertiesActions.vb#L20

vb
Dim header As CellRange = worksheet.Range("B2:C2")
header(0).Value = "Property Name"
header(1).Value = "Value"

See Also

SetValue(Object)

FromObject

ToObject

Cell Data Types

How to: Convert Objects to Cell Values and Cell Values to Objects

CellRange Interface

CellRange Members

DevExpress.Spreadsheet Namespace