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

format excel sheet with colors while radgrid export to excel

11 Answers 1500 Views
Grid
This is a migrated thread and some comments may be shown as answers.
SURESH
Top achievements
Rank 1
SURESH asked on 06 Jan 2010, 10:05 AM
hi
i am using radgrid to  export data from radgrid to excel.i want the excel format with total and total should be highlighted like some colors and i am not using bound fields in  radgrid .i am using column created by  programmatic

(thanks )
suresh.S

11 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 06 Jan 2010, 10:42 AM
Hello Suresh,

Please examine the following help-topic and let us know if you need more information.
Word/Excel export (HTML-based)

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ken
Top achievements
Rank 2
answered on 21 May 2010, 01:15 AM

I tried the code sample

 protected void RadGrid1_ExcelExportCellFormatting(object source, Telerik.Web.UI.ExcelExportCellFormattingEventArgs e)  
    {  
        GridDataItem item = e.Cell.Parent as GridDataItem;  
        if (item.ItemType == GridItemType.AlternatingItem)  
            item.Style["background-color"] = "#359AFF";  
        else  
            item.Style["background-color"] = "#2D62FF";  
    } 
but the formatting is not being shown in the Excel spreadsheet - what is wrong here?
0
Daniel
Telerik team
answered on 25 May 2010, 09:51 PM
Hello Ken,

This code-snippet is correct. so I suppose either the event handler is not wired or the export format is not HTML Excel.

ExcelML export
Word/Excel export (HTML-based)

Let me know if I'm missing something.

Best 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
Syan
Top achievements
Rank 1
answered on 25 Feb 2015, 03:27 AM
i want to export color while i exporting Excel file 
for eg. in Gird column name [Due date] Color is "Red" while i exporting excel file that "Red" color should also exported as Gird show 
Please help me

Thank You
Regards 
Vikas
0
Daniel
Telerik team
answered on 27 Feb 2015, 05:40 PM
Hello Vikas,

We have different Excel formats. Which one is used in your scenario?
If you let me know how you have changed the color to Red and which format you have I will be able to provide more to the point answer.

Regards,
Daniel
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.

 
0
Syan
Top achievements
Rank 1
answered on 26 May 2015, 02:38 AM

I'm Using ExcelML export

i want export color only show in Gird 

for e.g due date color red so while i exporting excel due date color is red else normal color wil be exported 

please find out attachment 

0
Daniel
Telerik team
answered on 29 May 2015, 08:30 AM
Hello Vikas,

I would recommend that you examine the following links:
ExcelML basics
Excel demo

The easiest way to translate these colors to the ExcelML file would be to use the same logic you used to style them in RadGrid. You can use the ExcelMLExportRowCreated for that purpose.

Regards,
Daniel
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Syan
Top achievements
Rank 1
answered on 29 May 2015, 03:56 PM

Hello Daniel

Thank's For reply 

I've already try ExcelMLExportRowCreated Method apply custom style  

it's exported all the column color as red? I want to check if due date color red in Gird then and then only red color exported otherwise exported as normal black color  

It's possible ?

please help me i'm stuck from last 2 days 

0
Daniel
Telerik team
answered on 04 Jun 2015, 07:09 AM
Hello Vikas,

There are two ways to do that:
- examine the grid item and apply the color to the ExcelML item if needed
- use the same logic you have used to determine which item need to be styled in the grid

Let me know if you have any specific question.

Regards,
Daniel
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Syan
Top achievements
Rank 1
answered on 11 Jun 2015, 03:43 AM

Hello Daniel

can you provide me simple demo so i can understand there functionality?

in grid one column due date which two color red and black.

while i exporting Excel only due date color should be red otherwise date color is black 

please help i'm stuck from last 1 week

Thank You

Syan

 

0
Daniel
Telerik team
answered on 16 Jun 2015, 08:18 AM
Hello Syan,

Please try the following approach:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" OnItemCreated="RadGrid1_ItemCreated" OnExcelMLWorkBookCreated="RadGrid1_ExcelMLWorkBookCreated"
    OnExcelMLExportStylesCreated="RadGrid1_ExcelMLExportStylesCreated">
    <MasterTableView CommandItemDisplay="Top">
        <CommandItemSettings ShowExportToExcelButton="true" />
    </MasterTableView>
    <ExportSettings Excel-Format="ExcelML" ExportOnlyData="true"></ExportSettings>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    SelectCommand="SELECT TOP 20 * FROM [Orders]"></asp:SqlDataSource>

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem && e.Item.ItemIndex % 3 == 0)
        e.Item.BackColor = System.Drawing.Color.Orange;
}
 
protected void RadGrid1_ExcelMLWorkBookCreated(object sender, GridExcelMLWorkBookCreatedEventArgs e)
{
    var table = e.WorkBook.Worksheets[0].Table;
    for (int ri = 1; ri < table.Rows.Count; ri++)
        if (RadGrid1.MasterTableView.Items[ri - 1].BackColor == System.Drawing.Color.Orange)
            ApplyRowStyle(table.Rows[ri], "orangeStyle");
}
 
private void ApplyRowStyle(RowElement rowElement, string styleName)
{
    foreach (CellElement cell in rowElement.Cells)
        cell.StyleValue = "orangeStyle";
}
 
protected void RadGrid1_ExcelMLExportStylesCreated(object sender, GridExportExcelMLStyleCreatedArgs e)
{
    StyleElement style = new StyleElement("orangeStyle");
    style.InteriorStyle.Color = System.Drawing.Color.Orange;
    style.InteriorStyle.Pattern = InteriorPatternType.Solid;
    e.Styles.Add(style);
}

I hope this helps.

Regards,
Daniel
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
SURESH
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Ken
Top achievements
Rank 2
Syan
Top achievements
Rank 1
Share this question
or