- Home
- Forum
- ASP.NET Core
- Export to Excel - Additional Parameters
Export to Excel - Additional Parameters
Hi,
I would like the end user to be able to pick the theme when exporting to excel. My grid has child data, I would also like the end user to be able to choose if the export should include the child data or not.
Is there a way I can pass information to the ExportToExcel method in the controller?
For example, the part of the ExportToExcel method would have something like this:
GridExcelExport excelExp = new GridExcelExport();
excelExp.Theme = userSuppliedString;
excelExp.IncludeChildGrid = userSuppliedBool;
I found this knowledge base article:
https://www.syncfusion.com/kb/5440/how-to-pass-additional-parameter-to-server-while-exporting
However, it is from 2015 and only for ASP.Net MVC. Is there an ASP.Net Core way of doing it?
Thanks,
Chris
SIGN IN To post a reply.
3 Replies
VN
Vignesh Natarajan
Syncfusion Team
June 25, 2018 11:47 AM UTC
Hi Chris,
Thanks for using Syncfusion products.
Yes, It can be implemented in ASP.NET Core. Kindly refer the below code snippet
|
<input type="text" id="count" />
<ej-grid id="Grid" datasource=ViewBag.parent toolbar-click="OnToolbarClick" allow-paging="true"
export-to-excel-action="HierarchyExportToExcel"
export-to-pdf-action="HierarchyExportToPdf"
export-to-word-action="HierarchyExportToWord">
. . . . .
</ej-grid>
<script>
function OnToolbarClick(args) {
if (args.itemName.indexOf("Export") > -1) {
this.model["recordCount"] = $("#count").val();
}
}
</script>
C#
public bool RecordCount { get; set; }
. . . . .
public ActionResult HierarchyExportToExcel(string GridModel)
{
ExcelExport exp = new ExcelExport();
var DataSource = emp;
GridProperties gridProp = ConvertGridModel(GridModel);
gridProp.ChildGrid.DataSource = _context.Orders.Take(100).ToList();
GridExcelExport excelExp = new GridExcelExport();
excelExp.FileName = "Export.xlsx"; excelExp.Excelversion = ExcelVersion.Excel2010;
excelExp.Theme = "flat-saffron";
excelExp.IncludeChildGrid = RecordCount;
return exp.Export(gridProp, DataSource, excelExp);
}
. . . . .
private GridProperties ConvertGridModel(string gridProperty)
{
GridProperties gridProp = new GridProperties();
var div = JsonConvert.DeserializeObject<Dictionary<string, object>>(gridProperty);
RecordCount = Convert.ToBoolean(div["recordCount"]);
gridProp = JsonConvert.DeserializeObject<GridProperties>(gridProperty);
return gridProp;
} |
Refer the below screenshot for the output
- In the View page
|
|
- Value in server side
|
|
Please get back if you have further queries.
Regards,
Vignesh Natarajan
CH
Chris
June 25, 2018 08:12 PM UTC
That worked perfectly.
Thank you.
Chris
SE
Sathyanarayanamoorthy Eswararao
Syncfusion Team
June 26, 2018 12:31 PM UTC
Hi Chris,
We are happy to hear that your issue has been resolved.
If you need any further assistance please get back to us.
Regards,
Sathyanarayanamoorthy
Sathyanarayanamoorthy
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
CH Chris
- Jun 22, 2018 09:03 PM UTC
- Jun 26, 2018 12:31 PM UTC