This is a migrated thread and some comments may be shown as answers.

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

1 Answer 387 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ori Tamuz
Top achievements
Rank 1
Ori Tamuz asked on 22 Jun 2012, 09:15 PM
Hello,

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!

1 Answer, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 26 Jun 2012, 03:21 PM
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 >>
Tags
GridView
Asked by
Ori Tamuz
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Share this question
or