Your search did not match any results.

Export And Printing

The ASP.NET Core Spreadsheet control allows you to download workbook content in different formats.

Call the SaveCopy) method's overload to save the document in supported formats (in this demo: XLSX format). You can open the saved file using the Spreadsheet control.

To export the document to an HTML or PDF file, call the ExportToHTML or ExportToPdf method respectively, and pass the export options as a parameter. Note that you cannot open the exported file using the Spreadsheet control.

The Spreadsheet’s ribbon provides the Print item that allows end-users to print workbook content. Call the client-side print method to invoke the print dialog programmatically.

<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> <div id="button-print"></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 }); $("#button-print").dxButton({ icon: "print", type: "normal", text: "Print document", onClick: function(e) { spreadsheet.print("_blank"); } }); }); </script> @(Html.DevExpress() .Spreadsheet("spreadsheet") .Height("500px") .Width("100%") .ConfirmOnLosingChanges(confirm => confirm.Enabled(false)) .DocumentRequestHandlerUrl(Url.Action("DxDocumentRequest")) .Open((string)ViewData["DocumentPath"]) )
using DevExpress.AspNetCore.Spreadsheet; using DevExpress.Spreadsheet; using DevExpress.XtraSpreadsheet.Export; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using System; using System.IO; using System.Linq; 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"); } } }