Skip to main content

IFormatDetectorService.DetectFormat(Stream) Method

Determines the format of the document contained in a stream.

Namespace: DevExpress.XtraSpreadsheet.Services

Assembly: DevExpress.Spreadsheet.v24.2.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

DocumentFormat DetectFormat(
    Stream stream
)

Parameters

Name Type Description
stream Stream

A Stream object that is the stream containing the document.

Returns

Type Description
DocumentFormat

A DocumentFormat enumeration value specifying the document format.

Remarks

The target stream should meet the following requirements:

  • It should not be empty;
  • Its CanSeek property should return true.

The following formats can be detected.

  • XLSX, XLSB, XLSM, XLTX, XLTM;
  • XLS,XLT;
  • CSV,TXT (only if loaded from a FileStream instance).

Important

The format of encrypted XLSX/XLSM/XLTX/XLTM file cannot be detected (the DetectFormat method returns DocumentFormat.Undefined).

If the DetectFormat method fails to detect the format, it returns DocumentFormat.Undefined.

Example

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