Articles in this section

How to convert the WinForms DataGrid to Image?

WinForms DataGrid (SfDataGrid) can be exported into Excel and PDF files. It also possible to convert the exported excel file into Image without saving the excel file in system with the help of IWorksheet.ConvertToImage method.

using Syncfusion.WinForms.DataGridConverter;
using Syncfusion.XlsIO;
 
private void BtnExportExcel_Click(object sender, EventArgs e)
{
    var excelExportingOptions = new ExcelExportingOptions();
    var excelEngine = sfDataGrid.ExportToExcel(sfDataGrid.View, excelExportingOptions);
    IWorkbook workbook = excelEngine.Excel.Workbooks[0];
    IWorksheet sheet = workbook.Worksheets[0];
    sheet.UsedRangeIncludesFormatting = false;
    int lastRow = sheet.UsedRange.LastRow + 1;
    int lastColumn = sheet.UsedRange.LastColumn;
    System.Drawing.Image img = sheet.ConvertToImage(1, 1, lastRow, lastColumn, ImageType.Bitmap, null);
    img.Save("Sample.png", ImageFormat.Png);
    System.Diagnostics.Process.Start("Sample.png");
} 

Note:

The following assemblies are required for converting the DataGrid to excel and image.

  1. Syncfusion.Compression.Base
  2. Syncfusion.SfDataGridConverter.WinForms
  3. Syncfusion.XlsIO.Base

 

The following screenshot shows the converted DataGrid to Image.

Shows the converted SfDataGrid to Image


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)
Access denied
Access denied