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.
- Syncfusion.SfGridConverter.WPF
- Syncfusion.XlsIO.Base
Sample Link
https://www.syncfusion.com/downloads/support/directtrac/142582/ze/WPF-1819041975