DataImportOptions.Converter Property
Gets or sets a converter for imported data.
Namespace: DevExpress.Spreadsheet
Assembly:
DevExpress.Spreadsheet.v24.2.Core.dll
NuGet Package:
DevExpress.Spreadsheet.Core
Declaration
public IDataValueConverter Converter { get; set; }
Public Property Converter As IDataValueConverter
Property Value
The following example demonstrates using a custom converter in the WorksheetExtensions.Import method.
Example
View Example
Friend Class TestDataValueConverter
Implements DevExpress.Spreadsheet.IDataValueConverter
Public Function TryConvert(ByVal value As Object, ByVal columnIndex As Integer, <System.Runtime.InteropServices.Out()> ByRef result As DevExpress.Spreadsheet.CellValue) As Boolean Implements DevExpress.Spreadsheet.IDataValueConverter.TryConvert
Dim strValue As String = TryCast(value, String)
If strValue IsNot Nothing Then
Dim str2int As Integer = Nothing
Dim success As Boolean = Int32.TryParse(strValue, str2int)
result = If(success, str2int, 0)
Return True
End If
Dim valueType As Type = value.GetType()
If valueType Is GetType(Integer) Then
result = DirectCast(value, Integer)
Else
result = Nothing
End If
Return True
End Function
End Class
Friend Class TestObject
Public Sub New(ByVal intValue As Integer, ByVal value As String, ByVal boolValue As Boolean)
Me.intValue_Renamed = intValue
Me.Value = value
Me.BoolValue = boolValue
End Sub
Public intValue_Renamed As Integer
Private ReadOnly Property privateValue() As Integer
Get
Return 123
End Get
End Property
Public ReadOnly Property IntValue() As Integer
Get
Return intValue_Renamed + privateValue - 123
End Get
End Property
Public Property Value() As String
Public Property BoolValue() As Boolean
Default Public ReadOnly Property Item(ByVal index As Integer) As Integer
Get
Return index
End Get
End Property
End Class
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