Answer:
The Template columns can be exported to excel by enabling the IncludeTemplateColumn of ExcelExportProperties. The template values cannot be directly exported into the excel cells so the ExcelQueryCellInfoEvent will be used to customize the values of template columns in excel export. Here is the code snippet for your reference,
<SfGrid ID="Grid" @ref="_sfGrid" DataSource="@Orders"
TValue="OrderResult">
<GridEvents ExcelQueryCellInfoEvent="ExcelQueryCellInfoHandler" OnToolbarClick="ToolbarClick" TValue="OrderResult" />
<GridColumns>
. . . .
GridColumns>
SfGrid>
@code{
public void ExcelQueryCellInfoHandler(ExcelQueryCellInfoEventArgs
args)
{
if (args.Column.Field
== "OrderCode")
{
args.Cell.Value = 'X' + args.Data.OrderCode;
}
}
private async Task
ToolbarClick(Syncfusion.Blazor.Navigations.ClickEventArgs args) {
if (args.Item.Id
== "Grid_excelexport") {
ExcelExportProperties exportProperties = new ExcelExportProperties();
exportProperties.IncludeTemplateColumn = true;
await _sfGrid.ExcelExport(exportProperties);
}
}
}
|
Documentation: https://blazor.syncfusion.com/documentation/datagrid/excel-exporting/