New to Telerik UI for WinForms? Download free 30-day trial

SpreadStreamExportRenderer

This class exposes methods and events needed to export using the SpreadStreamExport.

The WorksheetCreated event

Occurs when a new worksheet is created. It is suitable to set the columns width, add rows at the document begging, or insert cells before the firs column.

If this event is used the columns width would not be taken from the grid and you may want to explicitly set it.

Adding a Header Row.

private void Renderer_WorksheetCreated(object sender, SpreadStreamWorksheetEventArgs e)
{
    SpreadStreamExportRenderer exportRenderer = sender as SpreadStreamExportRenderer;
    exportRenderer.CreateRow();
    exportRenderer.SetRowHeight(50, true);
    for (int i = 0; i < this.radGridView1.Columns.Count; i++)
    {
        SpreadCellFormat format = new SpreadCellFormat()
        {
            Fill = SpreadPatternFill.CreateSolidFill(new SpreadColor(200, 200, 200))
        };
        exportRenderer.CreateCell();
        exportRenderer.ApplyCellFormat(format);
        if (this.radGridView1.Columns.Count / 2 == i)
        {
            exportRenderer.SetCellValue("This is HEADER row.");
        }
    }
}

Private Sub Renderer_WorksheetCreated(ByVal sender As Object, ByVal e As SpreadStreamWorksheetEventArgs)
    Dim exportRenderer As SpreadStreamExportRenderer = TryCast(sender, SpreadStreamExportRenderer)
    exportRenderer.CreateRow()
    exportRenderer.SetRowHeight(50, True)
    For i As Integer = 0 To Me.radGridView1.Columns.Count - 1
        Dim format As New SpreadCellFormat() With {.Fill = SpreadPatternFill.CreateSolidFill(New SpreadColor(200, 200, 200))}
        exportRenderer.CreateCell()
        exportRenderer.ApplyCellFormat(format)
        If Me.radGridView1.Columns.Count \ 2 = i Then
            exportRenderer.SetCellValue("This is HEADER row.")
        End If
    Next i
End Sub

The WorksheetExporting event

Occurs when a worksheet is about to be exported. This is suitable place to add rows at the end of the document.

Adding a Footer row.

private void Renderer_WorksheetExporting(object sender, SpreadStreamWorksheetEventArgs e)
{
    SpreadStreamExportRenderer exportRenderer = sender as SpreadStreamExportRenderer;
    exportRenderer.CreateRow();
    exportRenderer.SetRowHeight(50, true);
    for (int i = 0; i < this.radGridView1.Columns.Count; i++)
    {
        SpreadCellFormat format = new SpreadCellFormat()
        {
            Fill = SpreadPatternFill.CreateSolidFill(new SpreadColor(200, 200, 200))
        };
        exportRenderer.CreateCell();
        exportRenderer.ApplyCellFormat(format);
        if (this.radGridView1.Columns.Count / 2 == i)
        {
            exportRenderer.SetCellValue("This is FOOTER row.");
        }
    }
}

Private Sub Renderer_WorksheetExporting(ByVal sender As Object, ByVal e As SpreadStreamWorksheetEventArgs)
    Dim exportRenderer As SpreadStreamExportRenderer = TryCast(sender, SpreadStreamExportRenderer)
    exportRenderer.CreateRow()
    exportRenderer.SetRowHeight(50, True)
    For i As Integer = 0 To Me.radGridView1.Columns.Count - 1
        Dim format As New SpreadCellFormat() With {.Fill = SpreadPatternFill.CreateSolidFill(New SpreadColor(200, 200, 200))}
        exportRenderer.CreateCell()
        exportRenderer.ApplyCellFormat(format)
        If Me.radGridView1.Columns.Count \ 2 = i Then
            exportRenderer.SetCellValue("This is FOOTER row.")
        End If
    Next i
End Sub

The WorkbookCreated event

This is suitable place to add and/or modify Excel cell styles. Detailed information is available here: CellStyles

See Also

In this article