Skip to main content

DataTableExporter.CellValueConversionError Event

Fires if an error occurs during conversion of a specific cell value to the value which should be stored in a data table.

Namespace: DevExpress.Spreadsheet.Export

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

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

public event CellValueConversionErrorEventHandler CellValueConversionError

Event Data

The CellValueConversionError event's data class is CellValueConversionErrorEventArgs. The following properties provide information specific to this event:

Property Description
Action Specifies the action performed after the DataTableExporter.CellValueConversionError event is handled.
Cell Identifies the cell containing the value that cannot be converted.
CellValue Gets the value that caused the error.
ConversionResult Gets an enumeration member that identifies the cause of the conversion error.
DataColumn Provides access to a column in a target DataTable that cannot be filled with data for the current row due to a conversion error.
DataTableValue Gets or sets a value contained in the target DataTable.

The event data class exposes the following methods:

Method Description
Initialize(Cell, CellValue, DataColumn, ConversionResult) Initializes the object before passing it to a DataTableExporter.CellValueConversionError event handler.

Remarks

The following code illustrates how to handle the CellValueConversionError event.

View Example

using DevExpress.Spreadsheet;
using DevExpress.Spreadsheet.Export;
            Worksheet worksheet = spreadsheetControl1.Document.Worksheets[0];
            CellRange range = worksheet.Tables[0].Range;

            // Create a data table with column names obtained from the first row in a range.
            // Column data types are obtained from cell value types of cells in the first data row of the worksheet range.
            DataTable dataTable = worksheet.CreateDataTable(range, true);

            // Create the exporter that obtains data from the specified range which has a header row and populates the previously created data table. 
            DataTableExporter exporter = worksheet.CreateDataTableExporter(range, dataTable, true);
            // Handle value conversion errors.
            exporter.CellValueConversionError += exporter_CellValueConversionError;

            // Specify exporter options.
            exporter.Options.ConvertEmptyCells = true;
            exporter.Options.DefaultCellValueToColumnTypeConverter.EmptyCellValue = 0;
            exporter.Options.DefaultCellValueToColumnTypeConverter.SkipErrorValues = barCheckItemSkipErrors.Checked;

            // Perform the export.
            exporter.Export();
        void exporter_CellValueConversionError(object sender, CellValueConversionErrorEventArgs e)
        {
            MessageBox.Show("Error in cell " + e.Cell.GetReferenceA1());
            e.DataTableValue = null;
            e.Action = DataTableExporterAction.Continue;
        }

The following code snippets (auto-collected from DevExpress Examples) contain references to the CellValueConversionError event.

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