New to Telerik UI for WinFormsStart a free 30-day trial

SpreadStreamExportRenderer

Updated over 6 months ago

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.

C#
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.");
        }
    }
}

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.

C#
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.");
        }
    }
}

The WorkbookCreated event

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

See Also