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

Export To Excel Problem

10 Answers 356 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Anto (DLL Version : 2008.3.1314.35) asked on 01 Apr 2009, 10:55 AM
Hi All

I have a radgrid with first name, middle name, last name and date of Birth

All the data is taken from the table to grid

Then I have Two button Export to Excel,Export to pdf

While I click this button, the datas are shown in the excel sheet.

But The column Date of Birth appears with some numbers ex: 38843.00

While I click Export to pdf this it shows the correct date.

-Anto 

10 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 01 Apr 2009, 11:09 AM
Hello Anto,

You can set the appropriate style on OnExcelExportCellFormatting event which is raised when RadGrid is exported to Excel (before the resulting document is rendered on the client). This event can be used for applying formatting to a cell. For instance adding numeric format to cell’s value by adding mso-number-format style attributes.
protected void RadGrid1_ExcelExportCellFormatting(object source, ExcelExportCellFormattingEventArgs e) 
   if (e.FormattedColumn.UniqueName == "OrderDate"
       e.Cell.Style["mso-number-format"] = @"d\-mmm\-yyyy"
   if (e.FormattedColumn.UniqueName == "Freight"
   { 
       e.Cell.Style["color"] = "red"
       e.Cell.Style["mso-number-format"] = @"0\.000"
   } 
   if (e.FormattedColumn.UniqueName == "CustomerID"
      e.Cell.HorizontalAlign = HorizontalAlign.Center; 
}  

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 01 Apr 2009, 12:51 PM
Hi Daniel

where should i give this RadGrid1_ExcelExportCellFormatting in the .aspx page

-Anto
0
Accepted
Daniel
Telerik team
answered on 01 Apr 2009, 04:51 PM
Hello Anto,

Simple code-snippet, illustrating how to wire the depicted event is shown below:
<telerik:RadGrid  
    ID="RadGrid1"  
    runat="server"  
    OnExcelExportCellFormatting="RadGrid1_ExcelExportCellFormatting" 
    .... 


Kind regards,
Daniel
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 02 Apr 2009, 06:02 AM
Hi Daniel

Thank you

-Anto
0
Nataly
Top achievements
Rank 1
answered on 29 Jul 2009, 03:23 PM
Hello, telerik!

I have some problem, connected with this grid. An event "ExcelExportCellFormatting" isn't raised when the grid is in process of exporting to excel.How can I call this event other way?
0
Mike
Top achievements
Rank 1
answered on 05 May 2010, 04:44 PM
How can I access the GridGroupFooterItem in the RadGrid1_ExcelExportCellFormatting?  I can only access 

 

GridDataItem item = e.Cell.Parent as GridDataItem;

 

0
Daniel
Telerik team
answered on 05 May 2010, 05:27 PM
Hello Mike,

ExcelExportCellFormatting event fires for GridDataItems only. If you want to apply custom formatting to non-data items, you should use ItemCreated/ItemDataBound events.

For more information, please examine the Using ItemCreated/ItemDataBound section in the following help topic:
Word/Excel export (HTML-based)

I hope this helps.

Regards,
Daniel
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
Mike
Top achievements
Rank 1
answered on 05 May 2010, 05:34 PM
I'm trying this and it's highlighting the whole footer row.  I only want to format one column with the unique name of "Price.

I think that I need to access an e.Cell at the GridGroupFooterItem but "e" will put me in the DataItem
protected void RadGrid1_ExcelExportCellFormatting(object source, ExcelExportCellFormattingEventArgs e)  
    {  
        GridDataItem item = e.Cell.Parent as GridDataItem;  
        item.Style["background-color"] = "white";  
        foreach (GridGroupFooterItem itemb in RadGrid1.MasterTableView.GetItems(GridItemType.GroupFooter))  
        {    
            if (e.FormattedColumn.UniqueName == "Price")  
            {  
                itemb.Style["mso-number-format"] = @"$0.0000";  
                itemb.Style["background-color"] = "#efefef";  
            }  
        }  
    } 
0
Daniel
Telerik team
answered on 06 May 2010, 05:25 PM
Hello Mike,

Please try the following approach:
protected void RadGrid1_ItemDataBound(object source, GridItemEventArgs  e)
{
    if (e.Item is GridGroupFooterItem && isExport)
    {
        TableCell cell = (e.Item as GridGroupFooterItem)["Price"];
        cell.Style["mso-number-format"] = @"$0.0000";
        cell.Style["background-color"] = "#efefef";
    }
}

Regards,
Daniel
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
Mike
Top achievements
Rank 1
answered on 06 May 2010, 06:49 PM
EXXXXXXXXXXXXXCEEEEEEEEEELLLLLLLLLLEEEEEEEEEENT!

Thank you!  That did it!
Tags
Grid
Asked by
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Nataly
Top achievements
Rank 1
Mike
Top achievements
Rank 1
Share this question
or