Skip to content

Commit 179dfc6

Browse files
committed
UG for MasterDetailsView exporting
1 parent 23d4e2b commit 179dfc6

File tree

6 files changed

+146
-2
lines changed

6 files changed

+146
-2
lines changed
57.8 KB
Loading
62 KB
Loading
75.8 KB
Loading
95.5 KB
Loading

MAUI/DataGrid/export-to-excel.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,4 +1051,78 @@ private void ExcelExport_RowExporting(object sender, DataGridRowExcelExportingEv
10511051
}
10521052
}
10531053
{% endhighlight %}
1054-
{% endtabs %}
1054+
{% endtabs %}
1055+
1056+
### Exporting DetailsView
1057+
1058+
By default, [DetailsViewDataGrid](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.DetailsViewDataGrid.html) will be exported to Excel. You can customize its exporting operation by using `DataGridChildExcelExportingEventArgs`.
1059+
1060+
## Excluding DetailsViewDataGrid while exporting
1061+
You can exclude particular DetailsViewDataGrid while exporting, by using the DataGridChildExcelExportingEventArgs and `DataGridChildExcelExportingEventArgs.Cancel`.
1062+
1063+
```csharp
1064+
private void Button_Clicked_1(object sender, EventArgs e)
1065+
{
1066+
DataGridExcelExportingController excelExport = new DataGridExcelExportingController();
1067+
DataGridExcelExportingOption option = new DataGridExcelExportingOption();
1068+
excelExport.DataGridChildExcelExporting += ExcelExport_DataGridChildExcelExporting;
1069+
option.CanExportDetailsView= true;
1070+
var excelEngine = excelExport.ExportToExcel(this.dataGrid, option);
1071+
var workbook = excelEngine.Excel.Workbooks[0];
1072+
MemoryStream stream = new MemoryStream();
1073+
workbook.SaveAs(stream);
1074+
workbook.Close();
1075+
excelEngine.Dispose();
1076+
string OutputFilename = "ExportFeature.xlsx";
1077+
SaveService saveService = new();
1078+
saveService.SaveAndView(OutputFilename, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", stream);
1079+
}
1080+
private void ExcelExport_DataGridChildExcelExporting(object? sender, DataGridChildExcelExportingEventArgs e)
1081+
{
1082+
var recordEntry = e.NodeEntry as RecordEntry;
1083+
1084+
if ((recordEntry?.Data as Orders)?.OrderID == 1002)
1085+
e.Cancel = true;
1086+
}
1087+
```
1088+
<img alt="Excluding specific DetailsView while exporting to Excel in DataGrid " src="Images\export-to-excel\maui-datagrid-detailsviewexporting.png" Width="404"/>
1089+
1090+
Here, `DetailsViewDataGrid` is not exported for the parent record having OrderID as 1002.
1091+
1092+
## Customizing DetailsViewDataGrid cells
1093+
Like parent DataGrid, You can customize the DetailsViewDataGrid cells also by using [DataGridCellExcelExportingEventArgs](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.Exporting.DataGridCellExcelExportingEventArgs.html).
1094+
1095+
```csharp
1096+
private void Button_Clicked_1(object sender, EventArgs e)
1097+
{
1098+
DataGridExcelExportingController excelExport = new DataGridExcelExportingController();
1099+
DataGridExcelExportingOption option = new DataGridExcelExportingOption();
1100+
excelExport.CellExporting += ExcelExport_CellExporting;
1101+
option.CanExportDetailsView= true;
1102+
var excelEngine = excelExport.ExportToExcel(this.dataGrid, option);
1103+
var workbook = excelEngine.Excel.Workbooks[0];
1104+
MemoryStream stream = new MemoryStream();
1105+
workbook.SaveAs(stream);
1106+
workbook.Close();
1107+
excelEngine.Dispose();
1108+
string OutputFilename = "ExportFeature.xlsx";
1109+
SaveService saveService = new();
1110+
saveService.SaveAndView(OutputFilename, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", stream);
1111+
}
1112+
1113+
private void ExcelExport_CellExporting(object? sender, DataGridCellExcelExportingEventArgs e)
1114+
{
1115+
if (e.DetailsViewDefinition == null && e.DetailsViewDefinition?.RelationalColumn != "OrdersList")
1116+
{
1117+
return;
1118+
}
1119+
1120+
if (e.ColumnName == "ProductID")
1121+
{
1122+
e.Range.CellStyle.Font.Size = 12;
1123+
e.Range.CellStyle.Font.Color = ExcelKnownColors.Blue;
1124+
e.Range.CellStyle.Font.FontName = "Segoe UI";
1125+
}
1126+
}
1127+
```
1128+
<img alt="Customizing DetailsViewDataGrid while exporting to Excel in DataGrid" src="Images/export-to-excel/maui-datagrid-customize-detailsview-excel.png" Width="404"/>

MAUI/DataGrid/export-to-pdf.md

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,4 +1144,74 @@ private void PdfExport_CellExporting(object sender, DataGridCellPdfExportingEven
11441144
{% endhighlight %}
11451145
{% endtabs %}
11461146

1147-
<img alt="Export DataGrid to PDF format with customized cell style" src="Images\export-to-pdf\maui-datagrid-style-based-on-column-name.png" width="689"/>
1147+
<img alt="Export DataGrid to PDF format with customized cell style" src="Images\export-to-pdf\maui-datagrid-style-based-on-column-name.png" width="689"/>
1148+
1149+
### Exporting DetailsView
1150+
1151+
By default, [DetailsViewDataGrid](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.DetailsViewDataGrid.html) will be exported to PDF. You can customize its exporting operation by using `DataGridChildPdfExportingEventArgs`.
1152+
1153+
## Excluding DetailsViewDataGrid while exporting
1154+
You can exclude particular DetailsViewDataGrid while exporting, by using the DataGridChildExcelExportingEventArgs and `DataGridChildPdfExportingEventArgs.Cancel`.
1155+
1156+
```csharp
1157+
private void Button_Clicked(object sender, EventArgs e)
1158+
{
1159+
MemoryStream stream = new MemoryStream();
1160+
DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
1161+
DataGridPdfExportingOption option = new DataGridPdfExportingOption();
1162+
pdfExport.DataGridChildPdfExporting += PdfExport_DataGridChildPdfExporting;
1163+
option.CanExportDetailsView = true;
1164+
var pdfDoc = pdfExport.ExportToPdf(this.dataGrid, option);
1165+
pdfDoc.Save(stream);
1166+
pdfDoc.Close(true);
1167+
SaveService saveService = new();
1168+
saveService.SaveAndView("ExportFeature.pdf", "application/pdf", stream);
1169+
}
1170+
1171+
private void PdfExport_DataGridChildPdfExporting(object? sender, DataGridChildPdfExportingEventArgs e)
1172+
{
1173+
var recordEntry = e.NodeEntry as RecordEntry;
1174+
1175+
if ((recordEntry?.Data as Orders)?.OrderID == 1002)
1176+
e.Cancel = true;
1177+
}
1178+
```
1179+
<img alt="Excluding specific DetailsView while exporting to Excel in DataGrid " src="Images\export-to-excel\maui-datagrid-detailsviewexporting.png" Width="404"/>
1180+
1181+
Here, `DetailsViewDataGrid` is not exported for the parent record having OrderID as 1002.
1182+
1183+
## Customizing DetailsViewDataGrid cells
1184+
Like parent DataGrid, you can customize the DetailsViewDataGrid cells also by using [DataGridCellPdfExportingEventArgs](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.Exporting.DataGridCellPdfExportingEventArgs.html).
1185+
1186+
```csharp
1187+
private void Button_Clicked_1(object sender, EventArgs e)
1188+
{
1189+
DataGridExcelExportingController excelExport = new DataGridExcelExportingController();
1190+
DataGridExcelExportingOption option = new DataGridExcelExportingOption();
1191+
excelExport.CellExporting += ExcelExport_CellExporting;
1192+
option.CanExportDetailsView= true;
1193+
var excelEngine = excelExport.ExportToExcel(this.dataGrid, option);
1194+
var workbook = excelEngine.Excel.Workbooks[0];
1195+
MemoryStream stream = new MemoryStream();
1196+
workbook.SaveAs(stream);
1197+
workbook.Close();
1198+
excelEngine.Dispose();
1199+
string OutputFilename = "ExportFeature.xlsx";
1200+
SaveService saveService = new();
1201+
saveService.SaveAndView(OutputFilename, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", stream);
1202+
}
1203+
1204+
private void ExcelExport_CellExporting(object? sender, DataGridCellExcelExportingEventArgs e)
1205+
{
1206+
if (e.ColumnName == "OrderID")
1207+
{
1208+
var cellStyle = new PdfGridCellStyle();
1209+
cellStyle.BackgroundBrush = PdfBrushes.Wheat;
1210+
cellStyle.Borders.All = new PdfPen(PdfBrushes.DarkGray, 0.2f);
1211+
e.PdfGridCell.Style = cellStyle;
1212+
}
1213+
}
1214+
```
1215+
<img alt="Customizing DetailsViewDataGrid while exporting to Excel in DataGrid" src="Images\export-to-pdf\maui-datagrid-customize-detailsview.png" Width="404"/>
1216+
1217+

0 commit comments

Comments
 (0)