Your search did not match any results.

Open a Byte Array

The ASP.NET Core Spreadsheet allows you to open and save documents to an external data storage. This demo demonstrates how to open and save a document as a byte array.

  • To open the document, pass a delegate that obtains the target byte array as a parameter to the Open method's overload.
  • To convert the document to the byte array, call the SaveCopy) method's overload and specify the document's format as a parameter.
Backend API
@model SpreadsheetDocumentContentFromBytes <div class="button-container"> <div id="button-save"></div> </div> <script type="text/javascript"> $("#button-save").dxButton({ icon: "save", type: "normal", text: "Save copy to byte array", onClick: function (e) { var spreadsheetState = spreadsheet.getSpreadsheetState(); $.ajax({ type: 'POST', url: '@Url.Action("SaveToBytes")', data: { spreadsheetState: spreadsheetState } }); } }); </script> @(Html.DevExpress() .Spreadsheet("spreadsheet") .Height("500px") .Width("100%") .ConfirmOnLosingChanges(confirm => confirm.Enabled(false)) .DocumentRequestHandlerUrl(Url.Action("DxDocumentRequest")) .Open(@Model.DocumentId, DocumentFormat.Xlsx, @Model.ContentAccessorByBytes) )
using System; using System.IO; using System.Linq; using System.Text; using DevExpress.AspNetCore.Spreadsheet; using DevExpress.Spreadsheet; using DevExpress.XtraSpreadsheet.Export; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; namespace AspNetCoreDemos.Spreadsheet { [Route("[action]")] public class SpreadsheetController : Controller { public ActionResult FromBytes() { string documentName = "SportResults"; string documentId = Path.Combine(DirectoryManagmentUtils.GetDocumentSampleFolderPath(HttpContext), documentName); Func<byte[]> contentAccessorByBytes = () => DocumentDatabaseMock.GetDocumentContentBytes(documentName); var viewmodel = new SpreadsheetDocumentContentFromBytes(documentId, contentAccessorByBytes); return View(viewmodel); } [HttpPost] public void SaveToBytes(SpreadsheetClientState spreadsheetState) { var spreadsheet = SpreadsheetRequestProcessor.GetSpreadsheetFromState(spreadsheetState); string documentId = spreadsheet.DocumentId; byte[] documentContent = spreadsheet.SaveCopy(DocumentFormat.Xlsx); DocumentDatabaseMock.SaveDocument(documentId, documentContent); } } }