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

Header is not exporting during export to excel

5 Answers 221 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Abhinandan Bansal
Top achievements
Rank 1
Abhinandan Bansal asked on 01 Apr 2011, 07:39 AM
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

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Apr 2011, 08:11 AM
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.
0
Abhinandan Bansal
Top achievements
Rank 1
answered on 01 Apr 2011, 08:44 AM
Hi Shinu,
Issue is solved. Thanks very much

Thanks,
Abhinandan Bansal
0
Abhinandan Bansal
Top achievements
Rank 1
answered on 01 Apr 2011, 01:46 PM
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
0
Shinu
Top achievements
Rank 2
answered on 04 Apr 2011, 11:28 AM
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.
0
Daniel
Telerik team
answered on 06 Apr 2011, 10:13 PM
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
Tags
Grid
Asked by
Abhinandan Bansal
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Abhinandan Bansal
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or