Back to Devexpress

Workbook.BeforeEncodingDetection Event

officefileapi-devexpress-dot-spreadsheet-dot-workbook-0def637d.md

latest2.8 KB
Original Source

Workbook.BeforeEncodingDetection Event

Occurs before detecting the encoding of the loaded CSV or TXT data.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Docs.v25.2.dll

NuGet Package : DevExpress.Document.Processor

Declaration

csharp
public event EventHandler<BeforeEncodingDetectionEventArgs> BeforeEncodingDetection
vb
Public Event BeforeEncodingDetection As EventHandler(Of BeforeEncodingDetectionEventArgs)

Event Data

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

PropertyDescription
EncodingGets or sets the document encoding.
HandledGets or sets whether the event is handled.
StreamObtains a stream with document data.

Remarks

The BeforeEncodingDetection event is raised when the spreadsheet attempts to detect encoding of the CSV or TXT text being imported. Handle this event to specify a custom encoding instead of the automatically detected encoding.

The event fires only if the TxtDocumentImporterOptions.AutoDetectEncoding or CsvDocumentImporterOptions.AutoDetectEncoding property is set to true.

The code sample below shows how to handle the event to specify the encoding:

csharp
private void Workbook_BeforeEncodingDetection(object? sender, BeforeEncodingDetectionEventArgs e)
{
    e.Encoding = Encoding.UTF8;
    e.Handled = true;
}
vb
Private Sub Workbook_BeforeEncodingDetection(ByVal sender As Object, ByVal e As BeforeEncodingDetectionEventArgs)
  e.Encoding = Encoding.UTF8
  e.Handled = True
End Sub

Implements

BeforeEncodingDetection

See Also

Workbook Class

Workbook Members

DevExpress.Spreadsheet Namespace