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

how to remove link text for export to excel

5 Answers 727 Views
Grid
This is a migrated thread and some comments may be shown as answers.
diane
Top achievements
Rank 1
Veteran
diane asked on 29 Sep 2011, 04:07 PM
how to remove links from header text below. When I set ExportOnlyData="true"  the link is removed but the header text span tags shows in the excel header. Is there a way to edit the header text before exporting to excel.


<telerik:RadGrid
            ID="RadGridReport"
            runat="server"
            CssClass="GridLines"
            ExportSettings-FileName="RadGridReportReport"
            AutoGenerateColumns="false"
            AllowPaging="false"
            AllowSorting="true"
            AllowFilteringByColumn="false"
            AllowMultiRowSelection="false"
            Enabled="true"
            Visible="false"
            OnGridExporting="RadGridReport_GridExporting"
            OnExcelExportCellFormatting="RadGridReport_ExcelExportCellFormatting">
            <ExportSettings OpenInNewWindow="true" />
            <MasterTableView AllowMultiColumnSorting="true"  AllowNaturalSort="false">
                <HeaderStyle HorizontalAlign="Center" Font-Bold="true" />
                <ItemStyle HorizontalAlign="Left" />
                <AlternatingItemStyle HorizontalAlign="Left" />
                <Columns>
                        <telerik:GridTemplateColumn UniqueName="Code" HeaderStyle-Width="15%">
                        <HeaderStyle CssClass="rgHeader hasNestedTable" />
                        <HeaderTemplate>
                            <table class="nestedHeaderTable" cellspacing="0" >
                                <tr style="height:35%;">
                                    <th id="StateCode" colspan="2" align="center"><b>State Code</b></th>
                                </tr>
                                <tr style="height:65%;">
                                    <th id="Code" width="20%" align="center">
                                    <asp:LinkButton  ID="btnCode" Font-Underline ="true" ForeColor ="Blue" Text="Code <span  class = 'hidden'> Select to sort by Code</span>" ToolTip="Sort by Code" CommandName='Sort'  CommandArgument='Code' runat="server" /></th>
                                    <th id="Type" width="80%" align="center">
               <asp:LinkButton  ID="btnType" Font-Underline ="true" ForeColor ="Blue" Text="Type <span  class = 'hidden'> Select to sort by Type</span>" ToolTip="Sort by Type" CommandName='Sort'  CommandArgument='Type' runat="server" /></th>
                                </tr>
                            </table>
                        </HeaderTemplate>
                        <ItemStyle CssClass="hasNestedTable" />
                        <ItemTemplate>
                            <table class="nestedItemTable" cellspacing="0" >
                                <tr>
                                    <td headers ="Code" width="20%" align="left" style="mso-number-format:\@;"><%# DataBinder.Eval(Container.DataItem, "Code")%></td>
                                    <td headers ="Type" width="80%" align="left"><%# DataBinder.Eval(Container.DataItem, "Type")%></td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>

 </Columns>
            </MasterTableView>
        </telerik:RadGrid>

5 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 29 Sep 2011, 05:18 PM
Hello,

please check below code snippet for this.
<ExportSettings ExportOnlyData="true"></ExportSettings>


Thanks,
Jayesh Goyani
0
Alain
Top achievements
Rank 2
answered on 19 May 2016, 12:45 PM

Hello,

But what if I need to keep the controls for GridTemplateColumns. If I set the ExportOnlyData, I can not retriveve some values in the OnExcelExportCellFormatting event.

If (e.FormattedColumn.UniqueName) = "Email" Then
    e.Cell.Width = 200
    Dim myEmail As String = ""
    myEmail = DirectCast((e.Cell.Controls(0)), System.Web.UI.WebControls.HyperLink).NavigateUrl.Replace("mailto: ", "")
    e.Cell.Text = myEmail

endif

0
Maria Ilieva
Telerik team
answered on 24 May 2016, 12:04 PM
Hi Alain,

You can still use the ExportOnlyData property but manually set the header text like this:
 protected void btnExport_Click(object sender, EventArgs e)
    {
        RadGrid1.MasterTableView.GetColumn("ColumnUniqueName").HeaderText = "Your Custom Text";
  
        RadGrid1.ExportSettings.OpenInNewWindow = true;
        RadGrid1.ExportSettings.ExportOnlyData = true;
        RadGrid1.ExportSettings.IgnorePaging = true;
  
        RadGrid1.MasterTableView.ExportToExcel();
  
    }

I hope this helps.

Regards,
Maria Ilieva
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Alain
Top achievements
Rank 2
answered on 24 May 2016, 12:22 PM

Thank you,

But When I set the ExportOnlyData, I have no access to template columns as here :

myEmail = DirectCast((e.Cell.Controls(0)), System.Web.UI.WebControls.HyperLink).NavigateUrl.Replace("mailto: ", "")

This is what I am asking for. How to get rid of the Hyperlinks, without havin to set the header names programmatically, but keeping the values of the template columns so I can set the ouput on the Export events.

Truly.

 

0
Maria Ilieva
Telerik team
answered on 26 May 2016, 01:54 PM
Hi,

Currently this is the only possibility you have, to use the "ExportOnlyData" property and manually put the header text if needed.

Regards,
Maria Ilieva
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
diane
Top achievements
Rank 1
Veteran
Answers by
Jayesh Goyani
Top achievements
Rank 2
Alain
Top achievements
Rank 2
Maria Ilieva
Telerik team
Share this question
or