Articles in this section
Category / Section

How to export the Excel file with checkbox in WinForms DataGrid?

2 mins read

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;
    }
}

Shows export the excel file with checkbox in SfDataGrid


The following screenshot shows the exported excel file with a checkbox.

Shows exported filed with checkbox in SfDataGrid


Take a moment to peruse the WinForms DataGrid – Export to Excel documentation, where you can find about export to excel with code examples.

View sample in GitHub

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