Formatting Grid Data while exporting to excel

5 posts, 0 answers
  1. Ramyashree
    Ramyashree avatar
    29 posts
    Member since:
    Jan 2011

    Posted 31 Mar 2011 Link to this post

    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
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 05 Apr 2011 Link to this post

    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
  3. DevCraft banner
  4. Luis
    Luis avatar
    29 posts
    Member since:
    Dec 2013

    Posted 21 Nov 2014 Link to this post

    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
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 24 Nov 2014 Link to this post

    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.

     
  6. Luis
    Luis avatar
    29 posts
    Member since:
    Dec 2013

    Posted 24 Nov 2014 in reply to Dimitrina Link to this post

    thanks,  was very helpful!!
Back to Top
DevCraft banner