This example illustrates how to export the Excel file with checkbox in DataGrid.
WinForms DataGrid (SfDataGrid) does not provide the direct support to export the excel file with a checkbox. You can export the excel file with a checkbox by customizing the CellExporting event of the ExcelExportingOptions in DataGrid.
GridExcelExportingOptions.CellExporting += Options_CellExporting1;
private void Options_CellExporting1(object sender, Syncfusion.WinForms.DataGridConverter.Events.DataGridCellExcelExportingEventArgs e)
{
// Based on the column mapping name and the cell type, we can change the cell values while exporting to excel.
if (e.CellType == ExportCellType.RecordCell && e.ColumnName == "IsShipped")
{
//add the checkbox into excel sheet
var checkbox = e.Range.Worksheet.CheckBoxes.AddCheckBox(e.Range.Row, e.Range.Column, 20, 20);
//set the checked or unchecked state based on cell value
if (e.CellValue.ToString().ToLower() == "true")
checkbox.CheckState = ExcelCheckState.Checked;
else if (e.CellValue.ToString().ToLower() == "false")
checkbox.CheckState = ExcelCheckState.Unchecked;
//Created check box with cell link
checkbox.LinkedCell = e.Range.Worksheet[e.Range.AddressLocal];
e.Handled = true;
}
}
The following screenshot shows the exported excel file with a checkbox,
Take a moment to peruse the WinForms DataGrid – Export to Excel documentation, where you can find about export to excel with code examples.
Visual Studio 2015 and above versions