IXlCell.Value Property

Gets or sets a cell value.

Namespace: DevExpress.Export.Xl

Assembly: DevExpress.Printing.v20.1.Core.dll

Declaration

XlVariantValue Value { get; set; }
Property Value As XlVariantValue

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.

Examples

NOTE

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

// 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;
        }
    }
}
See Also