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

Export to Excel with formatting and Annotations

3 Answers 103 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rami
Top achievements
Rank 1
Rami asked on 22 Apr 2011, 05:12 PM
Hi,

I'm using RadControls for Silverlight Q1 2011 and in the process of trying to export data in a Gridview to an excel file. I looked at the demo you have at http://demos.telerik.com/silverlight/#GridView/Exporting and noticed that you can only export to an xls format, what about Excel 2007's xlsx format?

Also, Can you add styling (coloring) to specific cells? What about annotations? Any examples would be fantastic. Thank you.

Rami

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 25 Apr 2011, 09:35 AM
Hi Rami,

The features requested are not supported by RadGridView out-of-the-box.
To achieve such behavior  the only way is to modify the output stream when exporting the content of RadGridView. 

You  can get access to this stream in the Exporting event.

All the best,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rami
Top achievements
Rank 1
answered on 25 Apr 2011, 04:07 PM
Thanks Pavel - do you have any examples on manipulating the output stream through the exporting event?

What about my question regarding exporting to Excel 2007 (.xlsx) format, is that possible in the current version? Thanks again.

Rami
0
Pavel Pavlov
Telerik team
answered on 25 Apr 2011, 04:25 PM
Hi Rami,

RadGridView does not support Excel2007 format. 
Regarding  styling  /coloring of specific cells - here is some code I took form the online example :
private void RadGridView1_ElementExporting(object sender, GridViewElementExportingEventArgs e)
       {
           if (e.Element == ExportElement.HeaderRow || e.Element == ExportElement.FooterRow
               || e.Element == ExportElement.GroupFooterRow)
           {
               e.Background = HeaderBackgroundPicker.SelectedColor;
               e.Foreground = HeaderForegroundPicker.SelectedColor;
               e.FontSize = 20;
               e.FontWeight = FontWeights.Bold;
           }
           else if (e.Element == ExportElement.Row)
           {
               e.Background = RowBackgroundPicker.SelectedColor;
               e.Foreground = RowForegroundPicker.SelectedColor;
           }
           else if (e.Element == ExportElement.Cell &&
               e.Value != null && e.Value.Equals("Chocolade"))
           {
               e.FontFamily = new FontFamily("Verdana");
               e.Background = Colors.LightGray;
               e.Foreground = Colors.Blue;
           }
           else if (e.Element == ExportElement.GroupHeaderRow)
           {
               e.FontFamily = new FontFamily("Verdana");
               e.Background = Colors.LightGray;
               e.Height = 30;
           }
           else if (e.Element == ExportElement.GroupHeaderCell &&
               e.Value != null && e.Value.Equals("Chocolade"))
           {
               e.Value = "MyNewValue";
           }
           else if (e.Element == ExportElement.GroupFooterCell)
           {
               GridViewDataColumn column = e.Context as GridViewDataColumn;
               QueryableCollectionViewGroup qcvGroup = e.Value as QueryableCollectionViewGroup;
               if (column != null && qcvGroup != null && column.AggregateFunctions.Count() > 0)
               {
                   e.Value = GetAggregates(qcvGroup, column);
               }
           }
       }
       private string GetAggregates(QueryableCollectionViewGroup group, GridViewDataColumn column)
       {
           List<string> aggregates = new List<string>();
           foreach (AggregateFunction f in column.AggregateFunctions)
           {
               foreach (AggregateResult r in group.AggregateResults)
               {
                   if (f.FunctionName == r.FunctionName && r.FormattedValue != null)
                   {
                       aggregates.Add(r.FormattedValue.ToString());
                   }
               }
           }
           return String.Join(",", aggregates.ToArray());
       }


All the best,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Rami
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Rami
Top achievements
Rank 1
Share this question
or