officefileapi-devexpress-dot-spreadsheet-dot-export-dot-datatableexporter-78e9635b.md
Occurs when an empty row is encountered during export and the DataTableExportOptions.SkipEmptyRows property is false.
Namespace : DevExpress.Spreadsheet.Export
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
public event ProcessEmptyRowEventHandler ProcessEmptyRow
Public Event ProcessEmptyRow As ProcessEmptyRowEventHandler
The ProcessEmptyRow event's data class is ProcessEmptyRowEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Action | Gets or sets an action to be performed when an empty row is encountered and the DataTableExporter.ProcessEmptyRow event occurs. |
| RowIndex | Obtains the index of an empty row. |
The event data class exposes the following methods:
| Method | Description |
|---|---|
| Initialize(Int32) | Initializes the object before passing it to a DataTableExporter.ProcessEmptyRow event handler. |
The ProcessEmptyRow event enables you to specify the action performed when the exporter processes an empty row.
using DevExpress.Spreadsheet;
using DevExpress.Spreadsheet.Export;
Worksheet worksheet = spreadsheetControl1.Document.Worksheets.ActiveWorksheet;
CellRange range = worksheet.Selection;
// Determine whether the first row in a range contains headers.
bool rangeHasHeaders = this.barCheckItemHasHeaders1.Checked;
// Determine whether an empty row must stop conversion.
bool stopOnEmptyRow = barCheckItemStopEmptyRow.Checked;
// Create a data table with column names obtained from the first row in a range if it has headers.
// 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, rangeHasHeaders);
// Create the exporter that obtains data from the specified range,
// skips the header row (if required) and populates the previously created data table.
DataTableExporter exporter = worksheet.CreateDataTableExporter(range, dataTable, rangeHasHeaders);
// Handle value conversion errors.
exporter.CellValueConversionError += (sender,args)=> {args.Action = DataTableExporterAction.Continue;};
if (stopOnEmptyRow) {
exporter.Options.SkipEmptyRows = false;
// Handle empty row.
exporter.ProcessEmptyRow += (sender, args) => { args.Action = DataTableExporterAction.Stop; };
}
// Perform the export.
exporter.Export();
Imports DevExpress.Spreadsheet
Imports DevExpress.Spreadsheet.Export
Dim worksheet As Worksheet = spreadsheetControl1.Document.Worksheets.ActiveWorksheet
Dim range As CellRange = worksheet.Selection
' Determine whether the first row in a range contains headers.
Dim rangeHasHeaders As Boolean = Me.barCheckItemHasHeaders1.Checked
' Determine whether an empty row must stop conversion.
Dim stopOnEmptyRow As Boolean = barCheckItemStopEmptyRow.Checked
' Create a data table with column names obtained from the first row in a range if it has headers.
' 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, rangeHasHeaders)
' Create the exporter that obtains data from the specified range,
' skips the header row (if required) and populates the previously created data table.
Dim exporter As DataTableExporter = worksheet.CreateDataTableExporter(range, dataTable, rangeHasHeaders)
' Handle value conversion errors.
AddHandler exporter.CellValueConversionError, Sub(sender,args) args.Action = DataTableExporterAction.Continue
If stopOnEmptyRow Then
exporter.Options.SkipEmptyRows = False
' Handle empty row.
AddHandler exporter.ProcessEmptyRow, Sub(sender, args) args.Action = DataTableExporterAction.Stop
End If
' Perform the export.
exporter.Export()
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ProcessEmptyRow 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#L84
// Handle empty row.
exporter.ProcessEmptyRow += (sender, args) => { args.Action = DataTableExporterAction.Stop; };
}
how-to-export-cell-range-to-a-datatable/VB/ExportToDataTableExample/Form1.vb#L81
' Handle empty row.
AddHandler exporter.ProcessEmptyRow, Sub(sender, args) args.Action = DataTableExporterAction.Stop
End If
See Also