Skip to main content
Row

DataImportOptions.Converter Property

Gets or sets a converter for imported data.

Namespace: DevExpress.Spreadsheet

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

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

public IDataValueConverter Converter { get; set; }

Property Value

Type Description
IDataValueConverter

An object implementing the IDataValueConverter interface.

Remarks

The following example demonstrates using a custom converter in the WorksheetExtensions.Import method.

Example

View Example

List<TestObject> list = new List<TestObject>();
list.Add(new TestObject(1, "1", true));
list.Add(new TestObject(2, "2", false));
worksheet.Import(list, 0, 0, new DataSourceImportOptions() { Converter = new TestDataValueConverter() });
class TestDataValueConverter : DevExpress.Spreadsheet.IDataValueConverter
{
    public bool TryConvert(object value, int columnIndex, out DevExpress.Spreadsheet.CellValue result)
    {
        string strValue = value as string;
        if (strValue != null)
        {
            int str2int;
            bool success = Int32.TryParse(strValue, out str2int);
            result = success ? str2int : 0;
            return true;
        }
        Type valueType = value.GetType();
        if (valueType == typeof(int))
            result = (int)value;
        else
            result = null;
        return true;
    }
}
class TestObject
{
    public TestObject(int intValue, string value, bool boolValue)
    {
        this.intValue = intValue;
        this.Value = value;
        this.BoolValue = boolValue;

    }
    public int intValue;
    private int privateValue { get { return 123; } }
    public int IntValue { get { return intValue + privateValue - 123; } }
    public string Value { get; set; }
    public bool BoolValue { get; set; }
    public int this[int index] { get { return index; } }
}
See Also