Skip to content

Commit 7855a6d

Browse files
Merge pull request #3541 from syncfusion-content/Export_DetailsView
976266-Prepare UG documentation for MasterDetailsView DataGrid Exporting in .net MAUI.
2 parents b58210e + bb9dc79 commit 7855a6d

8 files changed

+191
-6
lines changed
57.8 KB
Loading
62 KB
Loading
95.5 KB
Loading
35.9 KB
Loading
39.3 KB
Loading
35.7 KB
Loading

MAUI/DataGrid/export-to-excel.md

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ To export the SfDataGrid to an Excel file, the following NuGet package should be
2626
</table>
2727

2828
## Save Service class in portable project.
29-
Add the new class file with name as SaveService to the Project and add below code in it. This is the helper class used to save and view the excell file in Windows, Android, IOS and MAC devices.
29+
Add the new class file with name as SaveService to the Project and add below code in it. This is the helper class used to save and view the excel file in Windows, Android, iOS and MAC devices.
3030

3131
{% tabs %}
3232
{% highlight c# %}
@@ -228,9 +228,9 @@ Add the following code to the AndroidManifest.xml file located under Properties
228228
{% endhighlight %}
229229
{% endtabs %}
230230

231-
### Save and View the Excel document in IOS
231+
### Save and View the Excel document in iOS
232232

233-
Add the new class file with name SaveIOS file under Platforms -> IOS directory to save and view the Excell document in the IOS device and use the below code in it.
233+
Add the new class file with name SaveIOS file under Platforms -> iOS directory to save and view the Excel document in the iOS device and use the below code in it.
234234

235235
{% tabs %}
236236
{% highlight c# %}
@@ -356,7 +356,7 @@ namespace GettingStarted
356356

357357
### Save and View the Excel document in MacCatalyst
358358

359-
Add the new class file with name SaveMAC file under Platforms -> MacCatylyst directory to save and view the Excel document in the MAC Device and use the below code in it.
359+
Add the new class file with name SaveMAC file under Platforms -> MacCatalyst directory to save and view the Excel document in the MAC Device and use the below code in it.
360360

361361
{% tabs %}
362362
{% highlight c# %}
@@ -1051,4 +1051,81 @@ 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 not be exported to Excel. You can export `DetailsViewDataGrid` by setting `CanExportDetailsView` property as true. You can customize its exporting operation by using `DataGridChildExcelExportingEventArgs`.
1059+
1060+
## Excluding DetailsViewDataGrid while exporting
1061+
1062+
You can exclude particular DetailsViewDataGrid while exporting by using the `DataGridChildExcelExportingEventArgs.Cancel` property.
1063+
1064+
```csharp
1065+
private void Button_Clicked_1(object sender, EventArgs e)
1066+
{
1067+
DataGridExcelExportingController excelExport = new DataGridExcelExportingController();
1068+
DataGridExcelExportingOption option = new DataGridExcelExportingOption();
1069+
excelExport.DataGridChildExcelExporting += ExcelExport_DataGridChildExcelExporting;
1070+
option.CanExportDetailsView= true;
1071+
var excelEngine = excelExport.ExportToExcel(this.dataGrid, option);
1072+
var workbook = excelEngine.Excel.Workbooks[0];
1073+
MemoryStream stream = new MemoryStream();
1074+
workbook.SaveAs(stream);
1075+
workbook.Close();
1076+
excelEngine.Dispose();
1077+
string OutputFilename = "ExportFeature.xlsx";
1078+
SaveService saveService = new();
1079+
saveService.SaveAndView(OutputFilename, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", stream);
1080+
}
1081+
1082+
private void ExcelExport_DataGridChildExcelExporting(object? sender, DataGridChildExcelExportingEventArgs e)
1083+
{
1084+
var recordEntry = e.NodeEntry as RecordEntry;
1085+
1086+
if ((recordEntry?.Data as Orders)?.OrderID == 1002)
1087+
e.Cancel = true;
1088+
}
1089+
```
1090+
<img alt="Excluding specific DetailsView while exporting to Excel in DataGrid " src="Images\export-to-excel\maui-datagrid-detailsviewexporting.png" Width="404"/>
1091+
1092+
Here, `DetailsViewDataGrid` is not exported for the parent record having OrderID as 1002.
1093+
1094+
## Customizing DetailsViewDataGrid cells
1095+
1096+
Similar to the parent DataGrid, you can also customize the cells of the DetailsViewDataGrid using the [DataGridCellExcelExportingEventArgs](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.Exporting.DataGridCellExcelExportingEventArgs.html). By utilizing the `DataGridCellExcelExportingEventArgs.DetailsViewDefinition` property, you can identify the specific DetailsViewDataGrid and make your customizations.
1097+
1098+
```csharp
1099+
private void Button_Clicked_1(object sender, EventArgs e)
1100+
{
1101+
DataGridExcelExportingController excelExport = new DataGridExcelExportingController();
1102+
DataGridExcelExportingOption option = new DataGridExcelExportingOption();
1103+
excelExport.CellExporting += ExcelExport_CellExporting;
1104+
option.CanExportDetailsView= true;
1105+
var excelEngine = excelExport.ExportToExcel(this.dataGrid, option);
1106+
var workbook = excelEngine.Excel.Workbooks[0];
1107+
MemoryStream stream = new MemoryStream();
1108+
workbook.SaveAs(stream);
1109+
workbook.Close();
1110+
excelEngine.Dispose();
1111+
string OutputFilename = "ExportFeature.xlsx";
1112+
SaveService saveService = new();
1113+
saveService.SaveAndView(OutputFilename, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", stream);
1114+
}
1115+
1116+
private void ExcelExport_CellExporting(object? sender, DataGridCellExcelExportingEventArgs e)
1117+
{
1118+
if (e.DetailsViewDefinition == null && e.DetailsViewDefinition?.RelationalColumn != "OrdersList")
1119+
{
1120+
return;
1121+
}
1122+
1123+
if (e.ColumnName == "OrderID")
1124+
{
1125+
e.Range.CellStyle.Font.Size = 12;
1126+
e.Range.CellStyle.Font.Color = ExcelKnownColors.Blue;
1127+
e.Range.CellStyle.Font.FontName = "Segoe UI";
1128+
}
1129+
}
1130+
```
1131+
<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: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,4 +1144,112 @@ 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 not be exported to PDF. You can export `DetailsViewDataGrid` by setting `CanExportDetailsView` property as true.
1152+
1153+
```csharp
1154+
MemoryStream stream = new MemoryStream();
1155+
DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
1156+
DataGridPdfExportingOption option = new DataGridPdfExportingOption();
1157+
option.CanExportDetailsView = true;
1158+
var pdfDoc = pdfExport.ExportToPdf(this.dataGrid, option);
1159+
pdfDoc.Save(stream);
1160+
pdfDoc.Close(true);
1161+
SaveService saveService = new();
1162+
saveService.SaveAndView("ExportFeature.pdf", "application/pdf", stream);
1163+
```
1164+
<img src="Images/export-to-pdf/maui-datagrid-exportdetailsview.png" alt="Maui DataGrid displays Nested dataGrid exported to PDF" width="404"/>
1165+
1166+
By default, only expanded DetailsViewDataGrids will be exported to the PDF document. If you want to export all the DetailsViewDataGrids, you need to set `CanExportAllDetails` to true.
1167+
1168+
```csharp
1169+
MemoryStream stream = new MemoryStream();
1170+
DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
1171+
DataGridPdfExportingOption option = new DataGridPdfExportingOption();
1172+
option.CanExportDetailsView = true;
1173+
option.CanExportAllDetails = true;
1174+
var pdfDoc = pdfExport.ExportToPdf(this.dataGrid, option);
1175+
pdfDoc.Save(stream);
1176+
pdfDoc.Close(true);
1177+
SaveService saveService = new();
1178+
saveService.SaveAndView("ExportFeature.pdf", "application/pdf", stream);
1179+
```
1180+
<img src="Images\export-to-pdf\maui-datagrid-exportalldetails.png" alt="Nested dataGrid exported to PDF" width="404"/>
1181+
1182+
Here, first record only expanded in SfDataGrid. But all the DetailsViewDataGrid’s are shown in exported PDF document.
1183+
1184+
You can customize its exporting operation by using `DataGridChildPdfExportingEventArgs`.
1185+
1186+
N> While exporting DetailsViewDataGrid, `CanFitAllColumnInOnePage` is set to true internally as horizontal pagination is not supported for DetailsViewDataGrid.
1187+
1188+
## Excluding DetailsViewDataGrid while exporting
1189+
1190+
You can exclude particular DetailsViewDataGrid while exporting, by using the `DataGridChildPdfExportingEventArgs.Cancel`.
1191+
1192+
```csharp
1193+
private void Button_Clicked(object sender, EventArgs e)
1194+
{
1195+
MemoryStream stream = new MemoryStream();
1196+
DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
1197+
DataGridPdfExportingOption option = new DataGridPdfExportingOption();
1198+
pdfExport.DataGridChildPdfExporting += PdfExport_DataGridChildPdfExporting;
1199+
option.CanExportDetailsView = true;
1200+
var pdfDoc = pdfExport.ExportToPdf(this.dataGrid, option);
1201+
pdfDoc.Save(stream);
1202+
pdfDoc.Close(true);
1203+
SaveService saveService = new();
1204+
saveService.SaveAndView("ExportFeature.pdf", "application/pdf", stream);
1205+
}
1206+
1207+
private void PdfExport_DataGridChildPdfExporting(object? sender, DataGridChildPdfExportingEventArgs e)
1208+
{
1209+
var recordEntry = e.NodeEntry as RecordEntry;
1210+
1211+
if ((recordEntry?.Data as Orders)?.OrderID == 1002)
1212+
e.Cancel = true;
1213+
}
1214+
```
1215+
<img alt="Excluding specific DetailsView while exporting to PDF in DataGrid " src="Images/export-to-pdf/maui-datagrid-excluderows.png" Width="404"/>
1216+
1217+
Here, `DetailsViewDataGrid` is not exported for the parent record having OrderID as 1002.
1218+
1219+
## Customizing DetailsViewDataGrid cells
1220+
1221+
Similar to the parent DataGrid, you can also customize the cells of the DetailsViewDataGrid by using the DataGridCellPdfExportingEventArgs. By utilizing the `DataGridCellPdfExportingEventArgs.DetailsViewDefinition` property, you can identify the specific DetailsViewDataGrid and customize it accordingly.
1222+
1223+
```csharp
1224+
private void Button_Clicked_1(object sender, EventArgs e)
1225+
{
1226+
MemoryStream stream = new MemoryStream();
1227+
DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
1228+
DataGridPdfExportingOption option = new DataGridPdfExportingOption();
1229+
pdfExport.DataGridChildPdfExporting += PdfExport_DataGridChildPdfExporting;
1230+
pdfExport.CellExporting += PdfExport_CellExporting;
1231+
option.CanExportDetailsView = true;
1232+
var pdfDoc = pdfExport.ExportToPdf(this.dataGrid, option);
1233+
pdfDoc.Save(stream);
1234+
pdfDoc.Close(true);
1235+
SaveService saveService = new();
1236+
saveService.SaveAndView("ExportFeature.pdf", "application/pdf", stream);
1237+
}
1238+
1239+
private void PdfExport_CellExporting(object? sender, DataGridCellPdfExportingEventArgs e)
1240+
{
1241+
if (e.DetailsViewDefinition == null && e.DetailsViewDefinition?.RelationalColumn != "OrdersList")
1242+
{
1243+
return;
1244+
}
1245+
1246+
if (e.ColumnName == "OrderID")
1247+
{
1248+
var cellStyle = new PdfGridCellStyle();
1249+
cellStyle.BackgroundBrush = PdfBrushes.Wheat;
1250+
cellStyle.Borders.All = new PdfPen(PdfBrushes.DarkGray, 0.2f);
1251+
e.PdfGridCell.Style = cellStyle;
1252+
}
1253+
}
1254+
```
1255+
<img alt="Customizing DetailsViewDataGrid while exporting to PDF in DataGrid" src="Images/export-to-pdf/maui-datagrid-customize-detailsview.png" Width="404"/>

0 commit comments

Comments
 (0)