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

[Solved] ExportToExcel with Hyperlinks

1 Answer 129 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 29 Jan 2010, 11:24 AM
Hi,

I have a RadGrid consisting of a column with hyperlinks.  I would like to ExportToExcel using the following ExcelML option to maintain the formatting:
radGridN.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML; 

However to use the GridExcelExportFormat.ExcelML, I am forced to set ExportOnlyData to true:
radGridN.ExportSettings.ExportOnlyData = true

But then I lose the hyperlink in Excel and see only the Data (as expected).  Is there a way that I can still use ExcelML option to keep the nice formatting and but also get my Hyperlinks to work in Excel?

Greg

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 03 Feb 2010, 03:52 PM
Hello Greg,

This is not supported out-of-the-box but it is easy to achieve it on your own:

<Columns>
    <telerik:GridHyperLinkColumn UniqueName="Links" HeaderText="Links" DataNavigateUrlFields="TargetUrl" DataTextField="TargetText" />
</Columns>

protected void RadGrid1_ExcelMLExportRowCreated(object source, GridExportExcelMLRowCreatedArgs e)
{
    if (e.RowType == GridExportExcelMLRowType.DataRow)
    {
        CellElement cell = e.Row.Cells.GetCellByName("Links");
        GridDataItem item = RadGrid1.MasterTableView.Items[e.Worksheet.Table.Rows.IndexOf(e.Row) - 1];
        cell.Attributes.Add("ss:HRef", (item["Links"].Controls[0] as HyperLink).NavigateUrl);
    }
}

Let me know you need more information.

Best regards,
Daniel
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
Grid
Asked by
Greg
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or