Exporting Custom Column

As of R1 2018 the GetCellContent method is no longer used for exporting a custom column content. Instead, the GetExportCellContent one of GridViewBoundColumnBase needs to be overriden. Check Example 2.

In order to automatically export a custom column, without handling some of the exporting events, it should implement the IExportableColumn interface. The interface exposes the following methods and properties:

  • GetCellContent: Gets the content of the cell. You can override it to return custom value.
  • DataFormatString: Gets or sets the string format applied to the column.
  • ExportedElementWidth: Gets the actual width of the column.

The GridViewBoundColumnBase class implements the interface so you can directly override the method.

Example 1: Overriden GetCellContent method

protected override object GetCellContent(object item)
{
    var columnProperty = item.GetType().GetProperty(this.DataMemberBinding.Path.Path);
    return string.Format("@ {0} @", columnProperty.GetValue(item, null) as string);
}

Example 2: Overriden GetExportCellContent method

protected override object GetExportCellContent(object item)
{
    var columnProperty = item.GetType().GetProperty(this.DataMemberBinding.Path.Path);
    return string.Format("@ {0} @", columnProperty.GetValue(item, null) as string);
}

The values from the exported column will appear in Excel as shown in Figure 1.

Figure 1: Exported Custom Column to Excel

exported custom column

See Also

In this article
Not finding the help you need? Improve this article