Skip to main content

SpreadsheetBuilder.Open(String, Func<Byte[]>) Method

Opens a document from an array of bytes.

Namespace: DevExpress.AspNetCore.Spreadsheet

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

Declaration

public SpreadsheetBuilder Open(
    string documentId,
    Func<byte[]> contentAccessorByBytes
)

Parameters

Name Type Description
documentId String

A document identifier.

contentAccessorByBytes Func<Byte[]>

A method delegate that obtains the byte array.

Returns

Type Description
SpreadsheetBuilder

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

Remarks

This method determines the document’s format automatically. Pass the document format to the Open(String, DocumentFormat, Func<Byte[]>) method overload 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 Byte Array.

The example below demonstrates how to open a document from a byte array:

@model SpreadsheetDocumentContent

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