How to add an image to Excel while exporting the RadGridView in Winforms

2 posts, 0 answers
  1. Ori Tamuz
    Ori Tamuz avatar
    3 posts
    Member since:
    Aug 2009

    Posted 22 Jun 2012 Link to this post


    I am exporting RadGridView to Excel in Winforms.  
    In the resulting Excel sheet I need to add an image in the top left cell A1, and some text in cell A4.
    I have the code to add the text, but how can I insert an image?
    Here is the code from the _ExcelTableCreated event. 

    // example
            void exporter_ExcelTableCreated(object sender, ExcelTableCreatedEventArgs e)
                SingleStyleElement style = ((ExportToExcelML)sender).AddCustomExcelRow(e.ExcelTableElement, 50, "MY HEADER");
    // This is what I need:  
    // Image img = (Image)Properties.Resources.logo;
    // SingleStyleElement style = ((ExportToExcelML)sender).AddCustomExcelRow(e.ExcelTableElement, 50, img);

                style.FontStyle.Bold = true;
                style.FontStyle.Size = 18;
                style.InteriorStyle.Pattern = InteriorPatternType.Solid;
                style.AlignmentElement.HorizontalAlignment = HorizontalAlignmentType.Left;
                style.AlignmentElement.VerticalAlignment = VerticalAlignmentType.Center;

    //end of example

    Next, I need to turn on the AutoFilter for the Row 2, since my header row now moved down one row.   (Ctrl-shift-L shortcut in Excel turns on AutoFilter).   

    I found the thread about exporting to Excel with autofilter for ASP.NET, but did not locate an example for WinForms.
    Thank you in advance!
  2. Ivan Petrov
    Ivan Petrov avatar
    705 posts

    Posted 26 Jun 2012 Link to this post

    Hello Ori,

    Thank you for writing.

    Excel actually does not support inserting images into cells. You can see that if you insert an image into excel it will float over the cells and will not be inside any particular cell. Therefore there is no support in ExportToExcelML for exporting images.

    On your second questions, currently this is also a not supported feature, but we believe it will be a good addition to the existing functionality and I have added a feature request to our Public Issue Tracking System - PITS. You can track its progress and add your vote/comment to it on the following link - PITS Feature.

    I have also updated your Telerik points for the good suggestion.

    Do not hesitate to write back with any further questions.

    All the best,
    Ivan Petrov
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Back to Top