Your search did not match any results.

Export

The ASP.NET Core Spreadsheet control allows you to download a spreadsheet as an HTML or XLSX file. Call the SaveCopy method's overload to save the document as a stream and then export it as an XLSX file. To download the document as an HTML file, call the ExportToHTML method and pass the exporting options as a parameter. The ExportToHTML method is available via the IWorkbook interface.

<div class="button-container"> <form id="formExport" method="post"> <input name="SpreadsheetWorkSessionId" type="hidden" value="" /> <div id="button-download-xlsx"></div> <div id="button-download-html"></div> </form> </div> <script type="text/javascript"> $(function () { $("#button-download-xlsx").dxButton({ icon: "download", type: "normal", text: "Download as Xlsx", onClick: function (e) { var spreadsheetState = spreadsheet.GetSpreadsheetState(); $("#formExport").attr('action', '@Url.Action("DownloadXlsx")'); $("input[name='SpreadsheetWorkSessionId']").val(spreadsheetState.SpreadsheetWorkSessionId); }, useSubmitBehavior: true }); $("#button-download-html").dxButton({ icon: "download", type: "normal", text: "Download as Html", onClick: function (e) { var spreadsheetState = spreadsheet.GetSpreadsheetState(); $("#formExport").attr('action', '@Url.Action("DownloadHtml")'); $("input[name='SpreadsheetWorkSessionId']").val(spreadsheetState.SpreadsheetWorkSessionId); }, useSubmitBehavior: true }); }); </script> @(Html.DevExpress() .Spreadsheet("spreadsheet") .Height("500px") .Width("100%") .ShowConfirmOnLosingChanges(false) .DocumentRequestHandlerUrl(Url.Action("DxDocumentRequest")) .Open((string)ViewData["DocumentPath"]) )
using DevExpress.AspNetCore; using DevExpress.Spreadsheet; using DevExpress.XtraSpreadsheet.Export; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.IO; using System.Text; namespace AspNetCoreDemos.Spreadsheet { [Route("[action]")] public class DemosController : Controller { public ActionResult Export() { ViewData["DocumentPath"] = DocumentPath; return View(); } public IActionResult DownloadXlsx(SpreadsheetClientState spreadsheetState) { var spreadsheet = SpreadsheetRequestProcessor.GetSpreadsheetFromState(spreadsheetState); MemoryStream stream = new MemoryStream(); spreadsheet.SaveCopy(stream, DocumentFormat.Xlsx); stream.Position = 0; return File(stream, XlsxContentType, "ProfitAndLoss.xlsx"); } public IActionResult DownloadHtml(SpreadsheetClientState spreadsheetState) { var spreadsheet = SpreadsheetRequestProcessor.GetSpreadsheetFromState(spreadsheetState); HtmlDocumentExporterOptions options = new HtmlDocumentExporterOptions(); options.CssPropertiesExportType = DevExpress.XtraSpreadsheet.Export.Html.CssPropertiesExportType.Style; options.Encoding = Encoding.UTF8; options.EmbedImages = true; options.SheetIndex = spreadsheet.Document.Worksheets.ActiveWorksheet.Index; MemoryStream stream = new MemoryStream(); spreadsheet.Document.ExportToHtml(stream, options); stream.Position = 0; return File(stream, "text/html", "ProfitAndLoss.html"); } } }