RadGrid Excel Export Issue

5 posts, 0 answers
  1. Leela Prasad
    Leela Prasad avatar
    3 posts
    Member since:
    Jul 2011

    Posted 18 Jul 2011 Link to this post

    Hi Telerik Team,
                             We are currently facing issue when exporting data to excel from Rad grid.
    When we are trying to export only data the button and template coloumns are not exported. If we are trying to export setting ExportOnlyData=false. Some image are not exported and some unwanted grey blocks are appearing and also some javascript error messages are appearing when user tries to click on any headers or link coloumns.

    Please suggest us what can be done to export all the data that is displayed in the grid without any unwanted grey buttons and javascript errors.

    Note: We are almost done with our application and we are having 100+ radgrids so we need of a approach which does not create rework of all which we had done till now.

    Attached the screenshots of exported excel files.
    As i am unable to upload code here. I had uploaded it to my skydrive.
    https://skydrive.live.com/redir.aspx?cid=0a806b2ac61695d9&resid=A806B2AC61695D9!1218

    Thanks & Regards
    Leela Prasad
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 Jul 2011 Link to this post

    Hello Leela,

    I cannot reproduce the issue at my end.Here is the sample code that I tried which worked as expected.

    aspx:
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
     <asp:ScriptManager ID="ScriptManager1" runat="server">
     </asp:ScriptManager>
    <telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource">
          <ExportSettings  ExportOnlyData="true" Excel-Format="Html" IgnorePaging="true">
          </ExportSettings>
          <MasterTableView CommandItemDisplay="Top">
              <CommandItemSettings ShowExportToExcelButton="true"  />
                    <Columns>
                        <telerik:GridBoundColumn HeaderText="EmployeeID" UniqueName="EmployeeID" DataField="EmployeeID">
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn>
                            <ItemTemplate>
                               <asp:TextBox ID="text" runat="server" Text='<%#Eval("EmployeeID") %>'></asp:TextBox>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
          </MasterTableView>
    </telerik:RadGrid>

    Images can not be exported in the resulting excel file. It is a limitation of the Excel that images cannot be placed in an excel cell. Check the following help documentation which explains more about this.
    Word/Excel export (HTML-based).

    Thanks,
    Shinu.
  3. Leela Prasad
    Leela Prasad avatar
    3 posts
    Member since:
    Jul 2011

    Posted 18 Jul 2011 Link to this post

    Hi Shinu,
                    we don't need images to be exported but some unwanted grey blocks are appearing,
    please find the screenshot ExportOnlyData---False.PNG in my intial post where i marked the areas with red boxes, is there a way we can avoid them.

    Or
    Is there any chance of including all the coloumns including button and template coloumns when using ExportOnlyData=true

    Thanks & Regards
    Leela Prasad
  4. Leela Prasad
    Leela Prasad avatar
    3 posts
    Member since:
    Jul 2011

    Posted 18 Jul 2011 Link to this post

    Awaiting for responses
  5. Elitsa
    Elitsa avatar
    1 posts
    Member since:
    Aug 2014

    Posted 21 Aug 2014 in reply to Leela Prasad Link to this post

    Hi Leela,

    Setting AlternateText for my images and ExportOnlyData to true works good for me :)

    I have:

    protected void myRadGrid_OnItemDataBound(object sender, GridItemEventArgs e)
    {
    if (e.Item is GridDataItem)
    {
                    var passInfo = (UserPriductsInfo)e.Item.DataItem;
        if (passInfo != null)
        {
            var imgAttemptPassed = (Image) e.Item.FindControl("imgAttemptPassed");

            if (imgAttemptPassed != null)
            {
                if (passInfo.attemptPassed == true)
                {
                                imgAttemptPassed.ImageUrl = "~/Images/tick.png";
                    imgAttemptPassed.AlternateText = "Yes";
                }
                else
                {
                                imgAttemptPassed.ImageUrl = "~/Images/cross.png";
                                imgAttemptPassed.AlternateText = "No";
                }
            }
        }
    }
    }

    and

    public void myRadGrid_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
            {
                if (e.CommandName == RadGrid.ExportToExcelCommandName)
                {
                    myRadGrid.ExportSettings.ExportOnlyData = true;
                    myRadGrid.ExportSettings.Excel.Format = GridExcelExportFormat.Html;
                    myRadGrid.ExportSettings.IgnorePaging = true;
                    myRadGrid.ExportSettings.FileName = "SpeakerCertificationReport";
                    myRadGrid.ExportSettings.OpenInNewWindow = true;
                    myRadGrid.MasterTableView.ExportToExcel();
                }
    }

    Hope this helps.

    Thank you
    Ellie
Back to Top