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

excel export formatting

3 Answers 212 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ibrahim Imam
Top achievements
Rank 1
Ibrahim Imam asked on 22 Sep 2011, 11:10 AM
hello,


i am using the export to excel feature of radgrid. i need to add some formats to specific cells which should also be exported:

1. setting back-color of certain cells based on the data -> i want to mark the best %-value of the cells in one row but not in every row.
if i set the backcolor of the cell it has no effect on the export. i found some solutions how the set the style at export but i need this also when viewing the grid online. how can this be accomplished without implementing it twice? where should i put the code and how can i access the data needed to decide whether to set the back color or not.

2. setting a thicker border to certain areas:
i found some old forum posts to alter the border but this has an effect to all borders. i need to set some thick borders around certain areas also based on data/structure. during creating the data for my grid i could save the row and column information i need and later i would like to set the border around rows 2-5 and cell 0-10 for example.
the grid exports the usual grid lines (border=1 and black) which should stay as it is.


hope someone can help me out on that

regards

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 Sep 2011, 11:56 AM
Hello Ibrahim,

You can hook the RadGrid1_ExcelExportCellFormatting event and format the cell. Here is the help artiche which explains more on that.
Word/Excel export (HTML-based)

Thanks,
Princy.
0
Ibrahim Imam
Top achievements
Rank 1
answered on 22 Sep 2011, 12:17 PM
hello,

thanks for the link, i already checked out this help section.
i now tried with
e.Cell.Style.Add(HtmlTextWriterStyle.BorderWidth, "2");
            e.Cell.Style.Add(HtmlTextWriterStyle.BorderStyle, "solid");
            e.Cell.Style.Add(HtmlTextWriterStyle.BorderColor, "black");
which works, so i can set the border.

but how can i access the data in this event and set a border not to a individual cell but around multiple cells?
can i access the cell row and column information - for ecxample rowNumber=3 and columnNumber=3 ?

is there a way to set the background color of cells online and have it exported also?
0
Mira
Telerik team
answered on 27 Sep 2011, 01:50 PM
Hello Ibrahim,

In order to set border around multiple cells, you can find them in the ExcelExportCellFormatting event and set the corresponding border of each of them (top/bottom/left/right) so that the overall effect is a closed border around all of them.

In order to find cell /row information, please access the corresponding data item:
protected void RadGrid1_ExcelExportCellFormatting(object source, ExcelExportCellFormattingEventArgs e)
{
    GridDataItem item = e.Cell.Parent as GridDataItem;
    //...
}

I hope this helps.

Kind regards,
Mira
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Ibrahim Imam
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ibrahim Imam
Top achievements
Rank 1
Mira
Telerik team
Share this question
or