format excel sheet with colors while radgrid export to excel

12 posts, 0 answers
  1. SURESH
    SURESH   avatar
    16 posts
    Member since:
    May 2009

    Posted 06 Jan 2010 Link to this post

    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
  2. Daniel
    Admin
    Daniel avatar
    4950 posts

    Posted 06 Jan 2010 Link to this post

    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.
  3. Ken
    Ken avatar
    3 posts
    Member since:
    Dec 2007

    Posted 20 May 2010 Link to this post

    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?
  4. Daniel
    Admin
    Daniel avatar
    4950 posts

    Posted 25 May 2010 Link to this post

    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.
  5. Syan
    Syan avatar
    14 posts
    Member since:
    Feb 2015

    Posted 24 Feb 2015 Link to this post

    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
  6. Daniel
    Admin
    Daniel avatar
    4950 posts

    Posted 27 Feb 2015 Link to this post

    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.

     
  7. Syan
    Syan avatar
    14 posts
    Member since:
    Feb 2015

    Posted 25 May 2015 in reply to Daniel Link to this post

    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 

  8. Daniel
    Admin
    Daniel avatar
    4950 posts

    Posted 29 May 2015 Link to this post

    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
  9. Syan
    Syan avatar
    14 posts
    Member since:
    Feb 2015

    Posted 29 May 2015 in reply to Daniel Link to this post

    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 

  10. Daniel
    Admin
    Daniel avatar
    4950 posts

    Posted 04 Jun 2015 Link to this post

    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
  11. Syan
    Syan avatar
    14 posts
    Member since:
    Feb 2015

    Posted 10 Jun 2015 in reply to Daniel Link to this post

    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

     

  12. Daniel
    Admin
    Daniel avatar
    4950 posts

    Posted 16 Jun 2015 Link to this post

    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
Back to Top