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

using ElementExporting event to customize the data while exporting to Excel.

1 Answer 65 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Srinivas
Top achievements
Rank 1
Srinivas asked on 25 Dec 2013, 09:18 PM

Hi ,
Am using a RadGridview control to populate my data and using the ElementExporting event to customize the data while exporting to Excel.

My customization need goes like, I want to add some metadata(some info the grid like report name, date generated, owner etc , at the top A1 cell ) to the grid data that is getting exporting . beneat that my actual grid data should be shown, and it should be sorted as my need.
I could able to append the metadata using the

grdRiskClarityReport.Export(stream,

new GridViewExportOptions()

{

Format=

ExportFormat.Html,

ShowColumnHeaders =

true,

ShowColumnFooters =

true,

ShowGroupFooters =

false,

});


and my event goes like this,

private void grdRiskClarityReport_ElementExported(object sender, GridViewElementExportedEventArgs e)

{

if (e.Element == ExportElement.HeaderCell && temp== 0)

{

// if (obj != null)

{

e.Writer.Write(

String.Format(@"<tr><td style=""background-color:#CCC;"" colspan=""{0}"">","dfdfd"));

e.Writer.Write(

String.Format(@"<b>Proposal Name:</b> {0} <br />", "dfdfd")); //need to input properdata

e.Writer.Write(

String.Format(@"<b>Proposal Status:</b> {0} <br />", "dfdfd"));

e.Writer.Write(

"</td></tr>");

temp = 1;

// using the restrict the metadata to the first cell

}

}

}



Could you please provide me a sample in wpf version that serves my need ?


Thanks in advance,
Srinivas J

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 30 Dec 2013, 02:48 PM
Hi Srinivas,

If you would like to add additional tags for the exported rows or cells, then you could edit the output stream after it has been exported. Please check the following code snippet for a reference:

if (dialog.ShowDialog() == true)
           {
               using (Stream stream = dialog.OpenFile())
               {
                   clubsGrid.Export(stream,
                    new GridViewExportOptions()
                    {
                        Format = ExportFormat.Html,
                        ShowColumnHeaders = true,
                        ShowColumnFooters = true,
                        ShowGroupFooters = false,
                    });
 
                   var reader = new StreamReader(stream);
                   stream.Position = 0;
                   
                   var text = reader.ReadToEnd();
                    
                   // change the text
                   var writer = new StreamWriter(stream);
                   writer.Write(text);
                   writer.Flush();
               }
           }


Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Srinivas
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Share this question
or