I am exporting a Telerik winforms grid to excel, which works fine. One of the fields I'm exporting is a Checkbox called 'USPerson'. The text of the USPerson field on export shows as true/false. I want to change this to YES/NO in the exported file.
Note: I'm able to do this when the grid is displayed by setting up an event to CellFormatting for the grid and doing this:
e.CellElement.Text = ((bool) e.CellElement.RowInfo.Cells["USPerson"].Value) ? "YES" : "NO";
How would I do this when exporting to an excel file?
Another way to introduce changes to cells - both appearance and in value is the CellFormatting event. Here is how to achieve what you need with it:
void exporter_CellFormatting(object sender, Telerik.WinControls.Export.CellFormattingEventArgs e)
{
if (e.GridColumnIndex == 2 && e.GridRowIndex >-1)
{
string newValue = (bool)e.GridCellInfo.Value ? "YES" : "NO";
Telerik.Windows.Documents.Spreadsheet.Model.CellSelection excelCell = (Telerik.Windows.Documents.Spreadsheet.Model.CellSelection)e.CellSelection;
excelCell.SetValue(newValue);
}
}