ASPxSpreadsheet.Open(String, DocumentFormat, Func<Byte[]>) Method
Opens a document in the specified format from an array of bytes.
Namespace: DevExpress.Web.ASPxSpreadsheet
Assembly: DevExpress.Web.ASPxSpreadsheet.v24.2.dll
Declaration
public void Open(
string documentId,
DocumentFormat format,
Func<byte[]> contentAccessorByBytes
)
Parameters
Name | Type | Description |
---|---|---|
documentId | String | The document identifier. This value is assigned to the DocumentId property. |
format | DocumentFormat | The document format. |
contentAccessorByBytes | Func<Byte[]> | A method delegate to obtain a byte array from which to open the document. |
Remarks
Call this Open method to load a document from an array of bytes. Specify the documentId parameter to identify the document. If the specified value is not unique within all open documents, the method activates the previously loaded document with the same documentId and ignores the array of bytes.
C#
private void CustomDocumentOpening() {
var uniqueDocumentId = GetUniqueDocumentId();
// Open a document from a byte array
byte[] documentContentAsByteArray = GetByteArrayFromCustomDocumentStorage();
using (var stream = GetStreamFromCustomDocumentStorage()) {
ASPxSpreadsheet1.Open(uniqueDocumentId, DocumentFormat.Xlsx, () => documentContentAsByteArray);
}
}
private string GetUniqueDocumentId() {
throw new NotImplementedException();
// Obtain a previously saved DocumentId (for instance, from a database, if you have previously saved it there):
// return GetDocumentIdFromDatabase();
// or
// Create a new unique identifier:
// return Guid.NewGuid().ToString();
}
private byte[] GetByteArrayFromCustomDocumentStorage() {
throw new NotImplementedException();
// Provide your custom logic to obtain a document (for instance, from a database)
}
Note
We recommend that you do not use the LoadDocument method to open a document. When you call this method, the ASPxSpreadsheet does not receive information about the opened document and cannot work with it correctly.
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the Open(String, DocumentFormat, Func<Byte[]>) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.