Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

IFormatDetectorService Interface

Allows detecting the format of a document contained in a stream.

Namespace: DevExpress.XtraSpreadsheet.Services

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

Declaration

public interface IFormatDetectorService

Remarks

The built-in IFormatDetectorService service implementation detects the format of the document loaded from a stream using the SpreadsheetControl.DocumentSource property or one of the LoadDocument method overloads.

The table below lists all formats the service can detect and gives information about elements which are used to indicate the format.

Format Detected by
XLSX, XLSM, XLTX, XLTM Inner zip archive signature and the contents of the [Content_Types].xml file.
XLS, XLT (including Excel 97 - Excel 2003 (BIFF8) and 5.0/95(BIFF5) Binary file formats) Compound File Binary signature and the Workbook or Book stream availability in the CFB file.
CSV, TXT (only if loaded from a FileStream instance) Document file extension.

Important

The format of an encrypted XLSX/XLSM/XLTX/XLTM file cannot be detected (the DocumentFormat.Undefined value is returned).

If the IFormatDetectorService instance fails to detect the format, an InvalidFormatException exception is thrown.

You can implement your own format detector and register it as a service to use in your application.

Example

using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("DXSpreadsheet.SampleDocument.xlsx"))
 {
    DocumentFormat format = spreadsheet.GetService<IFormatDetectorService>().DetectFormat(stream);
    spreadsheet.LoadDocument(stream, format);
 }
See Also