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

Formatting Grid Data while exporting to excel

4 Answers 174 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ramyashree
Top achievements
Rank 1
Ramyashree asked on 31 Mar 2011, 10:37 AM
Hi ,

    I have a grid and i'm exporting the records of which to an excel sheet with the following code....
 private void Export()
        {
            try
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.DefaultExt = "xls";
                dialog.Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", "xls", "Excel");
                dialog.FilterIndex = 1;

                if (dialog.ShowDialog() == true)
                {
                    using (Stream stream = dialog.OpenFile())
                    {
                        GridViewExportOptions exportOptions = new GridViewExportOptions();
                        exportOptions.Format = ExportFormat.Html;

                        exportOptions.ShowColumnHeaders = true;
                        exportOptions.ShowGroupFooters = true;

                        radGridViewTaskStatus.Export(stream, exportOptions);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }


I have a column which displays color in it's cell template and I need to export it's hexadecimal code to the excel sheet.. 
The code of the grid is as follows,

<telerik:RadGridView   Name="radGridViewTaskStatus" telerik:StyleManager.Theme="Office_Blue"
                                AutoGenerateColumns="False" 
                                IsReadOnly="True"
                                RowHeight="17"
                                ShowColumnFooters="True"
                                FontSize="11"
                                FontFamily="Arial"
                                Margin="41,0,39,10"  Grid.Row="2"                                
                                VerticalAlignment="Top" 
                                AddingNewDataItem="radGridViewTaskStatus_AddingNewDataItem"
                                ItemsSource="{Binding}"                                   
                                FieldFilterEditorCreated="radGridViewTaskStatus_FieldFilterEditorCreated" 
                                SelectionChanged="radGridViewTaskStatus_SelectionChanged" DataLoaded="radGridViewTaskStatus_DataLoaded">
             <telerik:RadGridView.Columns>
                 <telerik:GridViewDataColumn Header="Status" Width="*" IsReadOnly="True" DataMemberBinding="{Binding Path=Status,Mode=TwoWay,Converter={StaticResource TrimConverter}}">
                     <telerik:GridViewDataColumn.AggregateFunctions>
                         <telerik:CountFunction Caption="Count: " />
                     </telerik:GridViewDataColumn.AggregateFunctions>
                 </telerik:GridViewDataColumn>
                 <telerik:GridViewDataColumn Header="Order"  DataMemberBinding="{Binding Path=Order,Mode=TwoWay,Converter={StaticResource TrimConverter}}" />
                 <telerik:GridViewCheckBoxColumn Header="Complete" DataMemberBinding="{Binding Path=Complete,Mode=TwoWay,Converter={StaticResource YesNoStringToBooleanConverter}}" EditTriggers="CellClick" AutoSelectOnEdit="True" />
                 <telerik:GridViewDataColumn Header="Colour" Width="100">
                     <telerik:GridViewColumn.CellTemplate >
                         <DataTemplate>
                             <StackPanel  Height="17"  Background="{Binding Path=Colour,Mode=TwoWay,Converter={StaticResource IntegerToColourConverter}}" Width="Auto">
                             </StackPanel>
                         </DataTemplate>
                     </telerik:GridViewColumn.CellTemplate>
                     <telerik:GridViewColumn.CellEditTemplate >
                         <DataTemplate>
                             <StackPanel  Background="{Binding Path=Colour,Mode=TwoWay,Converter={StaticResource IntegerToColourConverter}}" Width="Auto">
                                 <Button Width="Auto" Height="Auto" Content="..." Margin="2" Name="radBtnSetColor" Click="radBtnSetColor_Click" HorizontalAlignment="Right" ></Button>
                             </StackPanel>
                         </DataTemplate>
                     </telerik:GridViewColumn.CellEditTemplate>
                 </telerik:GridViewDataColumn>
             </telerik:RadGridView.Columns>
         </telerik:RadGridView>

But when I export to excel, the color is beign displayed as taskstatus1, taskstatus15 and so on..

    Is there any way to format this into a hexadecimal or an integer color code... ?

Thanks in Advance,
Ramya

4 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 05 Apr 2011, 02:18 PM
Hello Ramyashree,

The default behavior of our exporting mechanism, when colors are concerned, is to export colors' hexadecimal values as an exporting value. This can be reproduced with the attached project that I have prepared for you. You may try subscribing to the ElementExporting  event of RadGridView, in order to easily operate with the exported values. Could you please share with us the implementation of your business object that is being exported?

All the best,
Ivan Ivanov
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
Luis
Top achievements
Rank 1
answered on 21 Nov 2014, 08:01 PM
I'm export my grid with data how "may - 7801" when export it in the excel file appears may-01 and is a date. what i need to do for change the format the cell of excel from code? 
"may" is a name not a month
0
Dimitrina
Telerik team
answered on 24 Nov 2014, 08:20 AM
Hello,

You can check the Export String Value article on how to additionally format the value to be exported.

Let me know how this works for you.

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Luis
Top achievements
Rank 1
answered on 24 Nov 2014, 11:10 PM
thanks,  was very helpful!!
Tags
GridView
Asked by
Ramyashree
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Luis
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or