IFormatDetectorService Interface
When implemented, allows you to detect the format of the document contained in the stream.
Namespace: DevExpress.XtraSpreadsheet.Services
Assembly: DevExpress.Spreadsheet.v24.2.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
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, XLSB, 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);
}