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

export to excel euro sign

1 Answer 72 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jonam
Top achievements
Rank 1
Jonam asked on 30 Aug 2011, 09:30 AM
I can get the grid to export an euro sign. I get the following export with the code beneath. I have version 2011 Q2 of telerik components.

Unit Price
€ 100,00
 


<UserControl x:Class="silverlightTest.MainPage"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
      
    <Grid x:Name="LayoutRoot" Background="White">
        <telerik:RadGridView ElementExporting="RadGridView1_ElementExporting" AutoExpandGroups="True" x:Name="RadGridView1" ItemsSource="{Binding RandomProducts}" ShowColumnFooters="True" ShowGroupFooters="True"
                             AutoGenerateColumns="False" IsReadOnly="True" CanUserFreezeColumns="False" CanUserResizeColumns="False" Margin="0,0,0,74">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Width="200" Header="Unit Price" TextAlignment="Right" DataMemberBinding="{Binding Value}" DataFormatString="{}{0:c}"/>
                      
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="26,259,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
    </Grid>
</UserControl>
  
  
code behind
  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
using Telerik.Windows.Controls;
using Telerik.Windows.Data;
  
namespace silverlightTest
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
  
            RadGridView1.ItemsSource = new List<MyObject>() { new MyObject() { Value = 100 } };
        }
  
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            string extension = "";
            ExportFormat format = ExportFormat.Html;
  
            string selectedItem = "Excel";
  
            switch (selectedItem)
            {
                case "Excel": extension = "xls";
                    format = ExportFormat.Html;
                    break;
                case "ExcelML": extension = "xml";
                    format = ExportFormat.ExcelML;
                    break;
                case "Word": extension = "doc";
                    format = ExportFormat.Html;
                    break;
                case "Csv": extension = "csv";
                    format = ExportFormat.Csv;
                    break;
            }
  
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.DefaultExt = extension;
            dialog.Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, selectedItem);
            dialog.FilterIndex = 1;
  
            if (dialog.ShowDialog() == true)
            {
                using (Stream stream = dialog.OpenFile())
                {
                    GridViewExportOptions exportOptions = new GridViewExportOptions();
                    exportOptions.Format = format;
                    exportOptions.ShowColumnFooters = true;
                    exportOptions.ShowColumnHeaders = true;
                    exportOptions.ShowGroupFooters = true;
  
                    RadGridView1.Export(stream, exportOptions);
                }
            }
        }
  
        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());
        }
  
    }
  
    public class MyObject
    {
        public decimal Value {get;set;}
    }
  
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Pavel Pavlov
Telerik team
answered on 03 Sep 2011, 08:25 AM
Hi Jonam,

I believe the issue may be solved by setting the  proper encoding via the GridViewExportOptions.Encoding property.

Regards,
Pavel Pavlov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
GridView
Asked by
Jonam
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Share this question
or