Skip to main content

IXlCell.Value Property

Gets or sets a cell value.

Namespace: DevExpress.Export.Xl

Assembly: DevExpress.Printing.v23.2.Core.dll

NuGet Package: DevExpress.Printing.Core

Declaration

XlVariantValue Value { get; set; }

Property Value

Type Description
XlVariantValue

An XlVariantValue object.

Remarks

A value contained in a cell is specified by the XlVariantValue object. The Value property provides the access to this object.

To set a cell value, you can assign the Value property to an object of the System.String, System.DateTime, System.Boolean or any numeric type (System.Int32, System.Double, etc.). To use an object of any type for specifying a cell value, use the XlVariantValue.FromObject method, which converts the passed object to XlVariantValue using the default converter.

If a cell does not contain any data, the Value property returns an empty value object (XlVariantValue.IsEmpty is true).

Use the IXlCell.SetFormula method overloads to assign a formula to a cell to calculate its value dynamically. See the How to: Create a Cell Formula example.

Example

Note

A complete sample project is available at https://github.com/DevExpress-Examples/excel-export-api-examples

// Create a worksheet.
using (IXlSheet sheet = document.CreateSheet()) {
    // Create the column A and set its width. 
    using (IXlColumn column = sheet.CreateColumn()) {
        column.WidthInPixels = 150;
    }

    // Create the first row.
    using (IXlRow row = sheet.CreateRow()) {

        // Create the cell A1 and set its value.
        using (IXlCell cell = row.CreateCell()) {
            cell.Value = "Numeric value:";
        }

        // Create the cell B1 and assign the numeric value to it.
        using (IXlCell cell = row.CreateCell()) {
            cell.Value = 123.45;
        }
    }

    // Create the second row.
    using (IXlRow row = sheet.CreateRow()) {

        // Create the cell A2 and set its value.
        using (IXlCell cell = row.CreateCell()) {
            cell.Value = "Text value:";
        }

        // Create the cell B2 and assign the text value to it.
        using (IXlCell cell = row.CreateCell()) {
            cell.Value = "abc";
        }
    }

    // Create the third row.
    using (IXlRow row = sheet.CreateRow()) {

        // Create the cell A3 and set its value.
        using (IXlCell cell = row.CreateCell()) {
            cell.Value = "Boolean value:";
        }

        // Create the cell B3 and assign the boolean value to it.
        using (IXlCell cell = row.CreateCell()) {
            cell.Value = true;
        }
    }

    // Create the fourth row.
    using (IXlRow row = sheet.CreateRow()) {

        // Create the cell A4 and set its value.
        using (IXlCell cell = row.CreateCell()) {
            cell.Value = "Error value:";
        }

        // Create the cell B4 and assign an error value to it.
        using (IXlCell cell = row.CreateCell()) {
            cell.Value = XlVariantValue.ErrorName;
        }
    }
}

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.

See Also