Back to Devexpress

ICellValueToColumnTypeConverter Interface

officefileapi-devexpress-dot-spreadsheet-dot-export-534de80a.md

latest3.6 KB
Original Source

ICellValueToColumnTypeConverter Interface

Base interface implemented by converters which are used by the DataTableExporter.

Namespace : DevExpress.Spreadsheet.Export

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
public interface ICellValueToColumnTypeConverter
vb
Public Interface ICellValueToColumnTypeConverter

The following members return ICellValueToColumnTypeConverter objects:

Example

View Example

csharp
class MyConverter : ICellValueToColumnTypeConverter
{
    public bool SkipErrorValues { get; set; }
    public CellValue EmptyCellValue { get; set; }

    public ConversionResult Convert(Cell readOnlyCell, CellValue cellValue, Type dataColumnType, out object result)
    {
        result = DBNull.Value;
        ConversionResult converted = ConversionResult.Success;
        if (cellValue.IsEmpty)
        {
            result = EmptyCellValue;
            return converted;
        }
        if (cellValue.IsError)
        {
            // You can return an error, subsequently the exporter throws an exception if the CellValueConversionError event is unhandled.
            //return SkipErrorValues ? ConversionResult.Success : ConversionResult.Error;
            result = "N/A";
            return ConversionResult.Success;
        }
        result = String.Format("{0:MMMM-yyyy}", cellValue.DateTimeValue);
        return converted;
    }
}
vb
Friend Class MyConverter
    Implements ICellValueToColumnTypeConverter

    Public Property SkipErrorValues() As Boolean
    Public Property EmptyCellValue() As CellValue Implements ICellValueToColumnTypeConverter.EmptyCellValue

    Public Function Convert(ByVal readOnlyCell As Cell, ByVal cellValue As CellValue, ByVal dataColumnType As Type,  ByRef result As Object) As ConversionResult Implements ICellValueToColumnTypeConverter.Convert
        result = DBNull.Value
        Dim converted As ConversionResult = ConversionResult.Success
        If cellValue.IsEmpty Then
            result = EmptyCellValue
            Return converted
        End If
        If cellValue.IsError Then
            ' You can return an error, subsequently the exporter throws an exception if the CellValueConversionError event is unhandled.
            'return SkipErrorValues ? ConversionResult.Success : ConversionResult.Error;
            result = "N/A"
            Return ConversionResult.Success
        End If
        result = String.Format("{0:MMMM-yyyy}", cellValue.DateTimeValue)
        Return converted
    End Function
End Class

See Also

ICellValueToColumnTypeConverter Members

DevExpress.Spreadsheet.Export Namespace