Header is not exporting during export to excel

6 posts, 0 answers
  1. Abhinandan Bansal
    Abhinandan Bansal avatar
    17 posts
    Member since:
    May 2010

    Posted 01 Apr 2011 Link to this post

    Hi,
    I used following code for grid
    <telerik:RadGrid runat="server" ID="grdLMA" EnableEmbeddedSkins="false" AutoGenerateColumns="false"
                                                CellPadding="4" ForeColor="#333333" GridLines="None">
                                                <MasterTableView AllowSorting="false" AllowPaging="false" >

                                                </MasterTableView>
                                                <HeaderStyle Wrap="false" BackColor="#5D7B9D" ForeColor="White" Font-Bold="true"/>
                                                <ExportSettings ExportOnlyData="true" FileName="Roll-up Live Report" Excel-FileExtension="xls" Excel-Format="ExcelML"
                                                OpenInNewWindow="true"></ExportSettings>
                                                <ItemStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                                <AlternatingItemStyle BackColor="White" ForeColor="#284775" />
                                                <ClientSettings>
                                                    <Scrolling UseStaticHeaders="true" AllowScroll="true" SaveScrollPosition="true"/>
                                                    <Resizing AllowColumnResize="true" AllowRowResize="true" ClipCellContentOnResize="false" ResizeGridOnColumnResize="true" />
                                                </ClientSettings>
                                                <FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="true"/>
                                                </telerik:RadGrid>

    In this grid i add columns dynamically. Please help me.

    Thanks,
    Abhinandan Bansal
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 01 Apr 2011 Link to this post

    Hello Abhinandan,

    I am not sure about the the way that you added the columns. This should take place in the PageLoad event handler, following the rules for a structure object: columns should be added to the corresponding collection first and then values for the properties of this instance should be set.

    Please make sure that you have added the columns as explained.

    C#:
    private void Page_Load(object sender, System.EventArgs e) 
     if ( !IsPostBack ) 
     
       GridBoundColumn boundColumn; 
       //Important: first Add column to the collection 
       boundColumn = new GridBoundColumn(); 
       this.RadGrid1.MasterTableView.Columns.Add(boundColumn); 
       //Then set properties 
       boundColumn.DataField = "CustomerID"
       boundColumn.HeaderText = "CustomerID"
     
    }

    Thanks,
    Shinu.
  3. Abhinandan Bansal
    Abhinandan Bansal avatar
    17 posts
    Member since:
    May 2010

    Posted 01 Apr 2011 Link to this post

    Hi Shinu,
    Issue is solved. Thanks very much

    Thanks,
    Abhinandan Bansal
  4. Abhinandan Bansal
    Abhinandan Bansal avatar
    17 posts
    Member since:
    May 2010

    Posted 01 Apr 2011 Link to this post

    Hi,
    I am facing one more issue in this  that the header row formatting does not comes in export to excel. i set the back color and fore color of header but nothing comes up in excel file.

    Please help me.

    Thanks
    Abhinandan Bansal
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Apr 2011 Link to this post

    Hello Abhinandan,

    I have tried the following code and that worked as expected. Please make a double check with your code.
    C#:
    protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridHeaderItem && isExport)//isExport is a flag set its value on exporting
        {
            e.Item.Style["background-color"] = "Red";
            e.Item.Style["color"] = "Yellow";
        }
     }

    Also take a look at the following help document.
    Word/Excel export (HTML-based)

    Thanks,
    Shinu.
  6. Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 06 Apr 2011 Link to this post

    Hello Abhinandan,

    I recommend that you set the desired styles directly to the cells (and not on the rows).
     Note that this would be needed for the header item only:

    if (e.Item is GridHeaderItem && isExport)
    {
        foreach(TableCell cell in e.Item.Cells)
             cell.Style[....] = ....;
    }

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