Customize Row and Column Headers
Giving your data meaningful names helps you better understand it. For example, if your document contains a column with the first names of your employees, the column name A does not necessarily help you understand the meaning of the data contained in that column. For the same reason, you probably are likely to have one header row in the document that will store the names of your columns. But when a user scrolls down, the content of the header row would be hidden and the user would not see the names.
It will be useful if you can set the column heading name when the first row is not visible as shown in the image below.
Change the Row and Column Headings
Each worksheet has a property called RenderNameConverter, which provides a mechanism for changing the row and column headings for UI purposes, including the PDF export. All you need to do is create a custom name converter and assign an instance of it to the RenderNameConverter property. The converter class must inherit from HeaderNameRenderingConverterBase.
Example 1 shows a simple implementation for the converter class used for creating the snapshots above.
Example 1: Create a custom name converter
public class CustomNameConverter : HeaderNameRenderingConverterBase
{
protected override string ConvertColumnIndexToNameOverride(HeaderNameRenderingConverterContext context, int columnIndex)
{
if (columnIndex == 0)
{
return "First Name";
}
return base.ConvertColumnIndexToNameOverride(context, columnIndex);
}
}
Public Class CustomNameConverter
Inherits HeaderNameRenderingConverterBase
Protected Overrides Function ConvertColumnIndexToNameOverride(ByVal context As HeaderNameRenderingConverterContext, ByVal columnIndex As Integer) As String
If columnIndex = 0 Then
Return "First Name"
End If
Return MyBase.ConvertColumnIndexToNameOverride(context, columnIndex)
End Function
End Class
After implementing your custom name converter you need to instantiate it and assign it to the worksheet RenderNameConverter property. Example 2 sets a new instance of the CustomNameConverter created in Example 1 to a RadSpreadsheet's worksheet.
this.radSpreadsheet.SpreadsheetElement.Workbook.Worksheets[0].HeaderNameRenderingConverter = new CustomNameConverter();
Me.radSpreadsheet.SpreadsheetElement.Workbook.Worksheets(0).HeaderNameRenderingConverter = New CustomNameConverter()
That's it. The column heading is changed.