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

Grid Group Export to Excel Coloring

4 Answers 211 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dustin Dodson
Top achievements
Rank 1
Dustin Dodson asked on 21 Dec 2010, 03:31 PM
I need to know how to set the background color of a group header cell to something other than white.

here is the back end code that I have tried.

Attempt 1
protected void RadGrid1_ExcelExportCellFormatting(object source, ExcelExportCellFormattingEventArgs e)
{
    GridDataItem item = e.Cell.Parent as GridDataItem;
    if(item.ItemType == GridItemType.GroupHeader)
        item.Style["background-color"] = "#FFFF00";
}


Attempt 2... which did not work either. I have Group: as my header text... I guess I was hoping that it would grab that info...
protected void RadGrid1_ExcelExportCellFormatting(object source, ExcelExportCellFormattingEventArgs e)
{
    GridDataItem item = e.Cell.Parent as GridDataItem;
    if (e.Cell.Text.Contains("Group:"))
        item.Style["background-color"] = "#FFFF00";
}

I am exporting using ExcelHTML.

Thanks,

Dustin

4 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 21 Dec 2010, 03:55 PM
Hello Dustin,

Have you checked out this help article on how to handle ExcelML formatting?

http://www.telerik.com/help/aspnet-ajax/grid-excelml-export.html

You need to handle the ExcelMLRowCreated event, for setting Group styles.
0
Dustin Dodson
Top achievements
Rank 1
answered on 21 Dec 2010, 03:57 PM
Will this work for ExcelHTML though? I have read through the Excel/Word HTML style export settings, but have not found anything in particular about how to address/find cells that are from a group... Maybe I need to address the whole row instead of the cell??

Thanks,

Dustin
0
Dustin Dodson
Top achievements
Rank 1
answered on 22 Dec 2010, 02:59 PM
OK I have changed it over to ExcelMLExport, but I still have don't have the desired results.

I have groups that are setup on the client side, they don't even show up on the grid that I am exploring.

I have tried going through the:

protected void rgvHealthInspRpt_ExcelMLExportRowCreated(object source, GridExportExcelMLRowCreatedArgs e)
{
    if (e.RowType == GridExportExcelMLRowType.GroupByHeaderRow)
    {
         //this returns null.. the name of the cell is "" but the data in the cell is the data I'm        //looking for I guess if I could set the name some how it would work, but I can't figure          //out how to do that.
      e.Row.Cells.GetCellByName("Group").StyleValue = "groupStyle";
    }
}
 
protected void rgvHealthInspRpt_ExcelMLExportStylesCreated(object source, GridExportExcelMLStyleCreatedArgs e)
{           
    StyleElement groupStyle = new StyleElement("groupStyle");
    groupStyle.FontStyle.Bold = true;
    groupStyle.AlignmentElement.HorizontalAlignment = HorizontalAlignmentType.Left;
    groupStyle.InteriorStyle.Color = System.Drawing.Color.Yellow;
    e.Styles.Add(groupStyle);
}


When that didn't work I just tried to change all headerStyles

protected void rgvHealthInspRpt_ExcelMLExportStylesCreated(object source,       GridExportExcelMLStyleCreatedArgs e)  
    foreach
(StyleElement style in e.Styles)
    {
     switch (style.Id)
     {
         case "headerStyle":
             style.FontStyle.Bold = true;
             style.InteriorStyle.Color = System.Drawing.Color.Yellow;
             style.AlignmentElement.HorizontalAlignment = HorizontalAlignmentType.Left;
             break;
         default:
             break;
      }
    }

 that's not working out for me either... Any help would be appreciated.

Thanks,

Dustin
0
Daniel
Telerik team
answered on 23 Dec 2010, 10:58 PM
Hello Dustin,

Please try the following code-snippet:
protected void RadGrid1_ExcelMLExportStylesCreated(object sender, GridExportExcelMLStyleCreatedArgs e)
{
    StyleElement style = new StyleElement("MyStyle");
    style.InteriorStyle.Color = System.Drawing.Color.LightBlue;
    style.InteriorStyle.Pattern = InteriorPatternType.Solid;
    e.Styles.Add(style);
}
 
protected void RadGrid1_ExcelMLExportRowCreated(object sender, GridExportExcelMLRowCreatedArgs e)
{
    if (e.RowType == GridExportExcelMLRowType.GroupByHeaderRow)
    {
        foreach (CellElement cell in e.Row.Cells)
            cell.StyleValue = "MyStyle";
    }
}

The idea is to create your own style (on ExcelMLExportStylesCreated) and add it to the Styles collection. You can then set this style to all cells in the group row.

Regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Dustin Dodson
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Dustin Dodson
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or