Back to Devexpress

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

aspnetcore-devexpress-dot-aspnetcore-dot-spreadsheet-dot-spreadsheetbuilder-dot-open-x28-system-dot-string-devexpress-dot-spreadsheet-dot-documentformat-system-dot-func-system-dot-byte-x29.md

latest3.3 KB
Original Source

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

Opens a document in the specified format from a byte array.

Namespace : DevExpress.AspNetCore.Spreadsheet

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

NuGet Package : DevExpress.AspNetCore.Spreadsheet

Declaration

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

Parameters

NameTypeDescription
documentIdString

A document identifier.

| | documentFormat | DocumentFormat |

A document format.

| | contentAccessorByBytes | Func<Byte[]> |

A method delegate that obtains a byte array.

|

Returns

TypeDescription
SpreadsheetBuilder

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

|

Remarks

This method overload allows you to disable automatic format detection and improve performance when the Spreadsheet opens a document. Call the Open(String, Func<Byte[]>) method to determine the document’s format automatically 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:

razor
@model SpreadsheetDocumentContent

@(Html.DevExpress()
    .Spreadsheet("spreadsheet")
    .Open(@Model.DocumentId, DocumentFormat.Xlsx, @Model.ContentAccessorByBytes)
)
csharp
public IActionResult Index() {
    byte[] byteArrayAccessor() => System.IO.File.ReadAllBytes("your-file-path");
    var model = new SpreadsheetDocumentContent("DocumentId1", byteArrayAccessor);
    return View(model);
}
csharp
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

SpreadsheetBuilder Class

SpreadsheetBuilder Members

DevExpress.AspNetCore.Spreadsheet Namespace