string path = "output.xlsx"; grid1.ExportToXlsx([someParameters], path); [... Some more code...]
[EndOfFunction] ;
Sorry for the misunderstanding. It would be grand if you or somebody could be of assisstance in resolving the present matter. Thank you very much in advance for your feeeback.
Kind regards
Chris
Index.cshtml
@{
ViewBag.Title = "Home Page";
}
@using Syncfusion.EJ2
@Html.EJS().Button("exportexcel").Content("Export server side").IsPrimary(true).Render()
@(Html.EJS().Grid<EJ2Grid.Controllers.HomeController.Orders>("Grid").DataSource((IEnumerable<object>)ViewBag.data).AllowPaging(true).ToolbarClick("toolbarClick").
. . .
Toolbar(new List<string>() { "ExcelExport" }).AllowExcelExport(true).Render())
<form action="/Home/ExcelExport" method="post">
<input type="hidden" name="GridModel" id="hdnexcelexport" />
</form>
<script>
document.getElementById("exportexcel").addEventListener('click', function () {
var form = document.getElementsByTagName("form")[0];
form.submit();
});
function toolbarClick(args) {
var gridInstance = document.getElementById("Grid").ej2_instances[0];
if (args.item.text === 'Excel Export') {
gridInstance.excelExport();
}
}
</script>
|
Controller
public void ExcelExport(string GridModel)
{
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
IEnumerable DataSource = order;
//Import the data to worksheet
IList<Orders> reports = DataSource.AsQueryable().Cast<Orders>().ToList();
worksheet.ImportData(reports, 2, 1, true);
workbook.SaveAs("Excel.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.Open);
}
} |