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

[Solved] Format Grouped Header in Excel Export

2 Answers 198 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 10 Feb 2010, 09:13 PM
I can format the items using the following code:
 protected void RadGrid1_ExcelExportCellFormatting(object source, ExcelExportCellFormattingEventArgs e)  
    {  
        GridDataItem item = e.Cell.Parent as GridDataItem;  
 
        item.Style["background-color"] = "#ffffff";  
        item.Style["font-size"] = "11px";  
        item.Style["font-family"] = "Verdana";  

How do I format the footer and my grouped headers?

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 11 Feb 2010, 09:23 AM
Hello Mike,

You can format GridGroupHeaderItem and GridFooterItem on ItemCreated:
bool isExport = false;
protected void Button2_Click(object sender, EventArgs e)
{
    isExport = true;
    RadGrid1.MasterTableView.ExportToExcel();
}
 
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (isExport)
    {
        if (e.Item is GridGroupHeaderItem)
            e.Item.Style["background-color"] = "gray";
        if (e.Item is GridFooterItem)
            e.Item.Style["background-color"] = "green";
    }
}

Best regards,
Daniel
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Mike
Top achievements
Rank 1
answered on 11 Feb 2010, 03:44 PM

I ended up using this

 protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridHeaderItem)  
        {  
            GridHeaderItem headerItem = e.Item as GridHeaderItem;  
            headerItem.Style["width"] = "20px";  
            headerItem.Style["background-color"] = "#ffffff";  
            headerItem.Style["font-size"] = "11px";  
            headerItem.Style["font-family"] = "Verdana";  
        }  
        if(e.Item is GridFooterItem)  
        {  
            GridFooterItem footerItem = e.Item as GridFooterItem;  
            footerItem.Style["width"] = "20px";  
            footerItem.Style["background-color"] = "#ffffff";  
            footerItem.Style["font-size"] = "11px";  
            footerItem.Style["font-family"] = "Verdana";  
            footerItem.Style["text-align"] = "right";  
        }  
        if (e.Item is GridGroupHeaderItem)  
        {  
            GridGroupHeaderItem groupedItem = e.Item as GridGroupHeaderItem;  
            groupedItem.Style["width"] = "20px";  
            groupedItem.Style["background-color"] = "#ffffff";  
            groupedItem.Style["font-size"] = "11px";  
            groupedItem.Style["font-family"] = "Verdana";  
            groupedItem.Style["text-align"] = "right";  
            groupedItem.Style["display"] = "none";  
        }  
        if (e.Item is GridGroupFooterItem)  
        {  
            GridGroupFooterItem groupedItem = e.Item as GridGroupFooterItem;  
            groupedItem.Style["width"] = "20px";  
            groupedItem.Style["background-color"] = "#efefef";  
            groupedItem.Style["font-size"] = "11px";  
            groupedItem.Style["font-family"] = "Verdana";  
            groupedItem.Style["text-align"] = "right";  
        }      
    } 
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Mike
Top achievements
Rank 1
Share this question
or