Articles in this section

How to customize cell value while exporting the .NET MAUI DataGrid (SfDataGrid) into Excel and PDF?

To customize specific cell values during the export of a .NET MAUI DataGrid to Excel and PDF, you can use the DataGridPdfExportingController.CellExporting and DataGridExcelExportingController.CellExporting event.

Export to PDF:

The following code facilitates the customization of a cell value during the export of the SfDataGrid to PDF.

DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
pdfExport.CellExporting += PdfExport_CellExporting;

private void PdfExport_CellExporting(object? sender, DataGridCellPdfExportingEventArgs e)
{
   if (e.CellValue is string && e.CellValue == "Hannah Arakawa")
   {
       e.CellValue = "Guptill Martin";
   }
}
Export to Excel

The provided code allows for the customization of a cell value during the export of the SfDataGrid to Excel. Similar to PDF exporting.

DataGridExcelExportingController excelExport = new DataGridExcelExportingController();
excelExport.CellExporting += ExcelExport_CellExporting;

private void ExcelExport_CellExporting(object? sender, DataGridCellExcelExportingEventArgs e)
{
   if (e.CellValue is string && e.CellValue == "Phyllis Allen")
   {
       e.CellValue = "Guptill Martin";
   }
}

Download the complete sample from GitHub.

Conclusion

I hope you enjoyed learning how to customize cell value while exporting the .NET MAUI DataGrid (SfDataGrid) into Excel and PDF.

You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI components on the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to explore our .NET MAUI DataGrid and other .NET MAUI components.

Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac or feedback portal, or the feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied