Skip to main content

SpreadsheetBuilder.Open(String, Func<Stream>) Method

Opens a document from a stream.

Namespace: DevExpress.AspNetCore.Spreadsheet

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

Declaration

public SpreadsheetBuilder Open(
    string documentId,
    Func<Stream> contentAccessorByStream
)

Parameters

Name Type Description
documentId String

A document identifier.

contentAccessorByStream Func<Stream>

A method delegate that obtains a stream.

Returns

Type Description
SpreadsheetBuilder

An object that can be used to further configure the Spreadsheet.

Remarks

This overload determines the document’s format automatically. Pass the document format to the Open(String, DocumentFormat, Func<Stream>) method to disable automatic detection and improve performance when you open a document. Refer to the following section for more information: Open a Document from a Stream.

The example below demonstrates how to open a document from a stream:

@model SpreadsheetDocumentContent

@(Html.DevExpress()
    .Spreadsheet("spreadsheet")
    .Open(@Model.DocumentId, @Model.ContentAccessorByStream)
)
public IActionResult Index() {
    Func<Stream> contentAccessorByStream = () => System.IO.File.Open("your-file-path", FileMode.Open);
    var model = new SpreadsheetDocumentContent(DocumentId1, contentAccessorByStream);
    return View(model);
}
public class SpreadsheetDocumentContent {
    public string DocumentId { get; set; }
    public Func<Stream> ContentAccessorByStream { get; set; }
    public DocumentFormat DocumentFormat { get; set; } = DocumentFormat.Xlsx;
    public SpreadsheetDocumentContent(string documentId, Stream contentAccessorByStream) {
        DocumentId = documentId;
        ContentAccessorByStream = contentAccessorByStream;
    }
}
See Also