officefileapi-devexpress-dot-spreadsheet-dot-export-dot-datatableexporter-84ca8936.md
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.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
public event CellValueConversionErrorEventHandler CellValueConversionError
Public Event CellValueConversionError As CellValueConversionErrorEventHandler
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. |
The following code illustrates how to handle the CellValueConversionError event.
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;
}
Imports DevExpress.Spreadsheet
Imports DevExpress.Spreadsheet.Export
Dim worksheet As Worksheet = spreadsheetControl1.Document.Worksheets(0)
Dim range As CellRange = 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.
Dim dataTable As 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.
Dim exporter As DataTableExporter = worksheet.CreateDataTableExporter(range, dataTable, True)
' Handle value conversion errors.
AddHandler exporter.CellValueConversionError, AddressOf 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()
Private Sub exporter_CellValueConversionError(ByVal sender As Object, ByVal e As CellValueConversionErrorEventArgs)
MessageBox.Show("Error in cell " & e.Cell.GetReferenceA1())
e.DataTableValue = Nothing
e.Action = DataTableExporterAction.Continue
End Sub
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.
how-to-export-cell-range-to-a-datatable/CS/ExportToDataTableExample/Form1.cs#L55
// Handle value conversion errors.
exporter.CellValueConversionError += exporter_CellValueConversionError;
asp-net-mvc-grid-upload-and-display-excel-file/CS/UploadControlApplication/Models/HelperClass.cs#L18
DataTableExporter exporter = sheet.CreateDataTableExporter(range, table, false);
exporter.CellValueConversionError += exporter_CellValueConversionError;
exporter.Export();
asp-net-web-forms-grid-upload-and-display-excel-file/CS/Solution/Default.aspx.cs#L29
DataTableExporter exporter = sheet.CreateDataTableExporter(range, table, false);
exporter.CellValueConversionError += exporter_CellValueConversionError;
exporter.Export();
how-to-export-cell-range-to-a-datatable/VB/ExportToDataTableExample/Form1.vb#L54
' Handle value conversion errors.
AddHandler exporter.CellValueConversionError, AddressOf exporter_CellValueConversionError
' Perform the export.
Dim exporter As DataTableExporter = worksheet.CreateDataTableExporter(range, dataTable, True)
AddHandler exporter.CellValueConversionError, AddressOf exporter_CellValueConversionError
Dim myconverter As New MyConverter()
asp-net-mvc-grid-upload-and-display-excel-file/VB/UploadControlApplication/Models/HelperClass.vb#L13
Dim exporter As DataTableExporter = sheet.CreateDataTableExporter(range, table, False)
AddHandler exporter.CellValueConversionError, AddressOf exporter_CellValueConversionError
exporter.Export()
asp-net-web-forms-grid-upload-and-display-excel-file/VB/Solution/Default.aspx.vb#L35
Dim exporter As DataTableExporter = sheet.CreateDataTableExporter(range, table, False)
AddHandler exporter.CellValueConversionError, AddressOf exporter_CellValueConversionError
exporter.Export()
See Also