Articles in this section
Category / Section

How to customize cell value while exporting the DataGrid into Excel and PDF in Windows Phone?

5 mins read

In SfDataGrid, you can customize the cell value while exporting it into Excel and PDF by using CellsExportingEventHandler with ExcelExportingOptions and PdfExportingOptions class.

The cell value is displayed in SfDataGrid like below,

SFDataGrid View

Figure 1: SfDataGrid view

Excel Exporting:

The above cell value of IsClosed (GridCheckBoxColumn) column is customized while exporting to Excel like below,

C#:

var options = new ExcelExportingOptions();
 
// Assign the customized cellsExportingHandler to ExcelExportingOptions
options.CellsExportingEventHandler = cellsExportingHandler;
 
 
private void cellsExportingHandler(object sender, GridCellExcelExportingEventArgs 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 == "IsClosed")
    {
        //if the cell value is True, "Y" will be displayed else "N" will be displayed.
        if (e.CellValue.Equals(true))
            e.Range.Cells[0].Value = "Y";
        else
            e.Range.Cells[0].Value = "N";
        e.Handled = true;
    }
}

 

The cell value of IsClosed column has been customized in Exported Excel Sheet like below,

 

Table

Description automatically generated

Figure 2: Excel View

PDF Exporting:

The above cell value of IsClosed (GridCheckBoxColumn) column is customized while exporting to PDF like below,

C#:

var options = new PdfExportingOptions();
 
// Assign the customized cellsExportingHandler to PdfExportingOptions
options.CellsExportingEventHandler = cellsExportingEventHandler;
 
private void cellsExportingEventHandler(object sender, GridCellPdfExportingEventArgs e)
{
 
    // Based on the column mapping name and the cell type, we can change the cell values when exporting to PDF.
    if(e.CellType==ExportCellType.RecordCell&&e.ColumnName=="IsClosed")
    {
        //if the cell value is True, "Y" will be displayed else "N" will be displyed.
        if (e.CellValue.Equals("True"))
            e.CellValue= "Y";
        else
            e.CellValue = "N";               
    }
}

 

The cell value of IsClosed column has been customized in Exported PDF document like below,

PDF View

Figure 3: PDF View

 

Sample Links:

WPF

WinRT

WP

UWP

 

 

 

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