Articles in this section
Category / Section

How to apply the conditional format for excel sheet exported from WPF DataGrid (SfDataGrid)?

WPF DataGrid (SfDataGrid) does not provide direct support to the conditional formatting while exporting from the grid to excel sheet. But you can achieve this by applying the conditional formatting to the exported worksheet.

C#:

private void OnExportClicked(object obj)
 {
     var grid = obj as SfDataGrid;
     var options = new ExcelExportingOptions();
     options.ExcelVersion = ExcelVersion.Excel2013;
     var excelEngine = grid.ExportToExcel(grid.View, options);
     var workBook = excelEngine.Excel.Workbooks[0];
     //Apply conditional format to worksheet
     IWorksheet worksheet = workBook.Worksheets[0];
     IConditionalFormats formats = worksheet["F2:F11"].ConditionalFormats;
     IConditionalFormat format = formats.AddCondition();
     format.FormatType = ExcelCFType.DataBar;
     IDataBar dataBar = format.DataBar;
     dataBar.BarColor = Color.Blue;
     workBook.SaveAs("Sample.xlsx");
 }

 

Conditional formatting for exported excel

View WPF DataGrid Formatting Demo in GitHub

UG link: https://help.syncfusion.com/wpf/datagrid/export-to-excel#customize-exported-workbook-and-worksheet

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