Back to Devexpress

IFormatDetectorService.DetectFormat(Stream) Method

officefileapi-devexpress-dot-xtraspreadsheet-dot-services-dot-iformatdetectorservice-dot-detectformat-x28-system-dot-io-dot-stream-x29.md

latest3.0 KB
Original Source

IFormatDetectorService.DetectFormat(Stream) Method

Determines the format of the document contained in a stream.

Namespace : DevExpress.XtraSpreadsheet.Services

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
DocumentFormat DetectFormat(
    Stream stream
)
vb
Function DetectFormat(
    stream As Stream
) As DocumentFormat

Parameters

NameTypeDescription
streamStream

A Stream object that is the stream containing the document.

|

Returns

TypeDescription
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

csharp
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("DXSpreadsheet.SampleDocument.xlsx"))
 {
    DocumentFormat format = spreadsheet.GetService<IFormatDetectorService>().DetectFormat(stream);
    spreadsheet.LoadDocument(stream, format);
 }
vb
Using stream As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("DXSpreadsheet.SampleDocument.xlsx")
   Dim format As DocumentFormat = spreadsheet.GetService(Of IFormatDetectorService)().DetectFormat(stream)
     spreadsheet.LoadDocument(stream, format)
   End Using

See Also

IFormatDetectorService Interface

IFormatDetectorService Members

DevExpress.XtraSpreadsheet.Services Namespace