Articles in this section
Category / Section

How to convert the SfDataGrid to Image?

1 min read

The 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.UI.Xaml.Grid.Converter;
using Syncfusion.XlsIO;
private void ConvertToImage_Click(object sender, RoutedEventArgs e)
{
    var excelExportingOptions = new ExcelExportingOptions();
    ExcelEngine 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 SfDataGrid to excel and image.

  1. Syncfusion.SfGridConverter.WPF
  2. Syncfusion.XlsIO.Base

 

 

Sample Link

https://www.syncfusion.com/downloads/support/directtrac/142582/ze/WPF-1819041975

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