New to Telerik UI for ASP.NET CoreStart a free 30-day trial

Exporting Links To Excel

Environment

ProductGrid for Progress® Telerik® UI for ASP.NET Core

Description

I have a Telerik UI for ASP.NET Core Grid column that contains a hyperlink. The link is clickable in the Grid. However, when I export the data to Excel, I can no longer interact with it. I want to be able to click on the exported links.

Solution

The Workbook API exposes a configuration that enables you to set hyperlinks to specific cells.

To achieve the desired outcome:

  1. Configure a column with by using the Template component.
  2. Subscribe to the ExcelExport event of the Grid.
  3. Within the handler, generate the hyperlinks array by using information from the already generated Workbook.
  4. (Optional) Define an optional method that enables you to convert the current Grid column index to a corresponding Excel column name. For example: A, B, C ... AA.
Razor
    @{
        var data = new List<GridModel>()
        {
            new GridModel
            {
                Name = "Jane Doe",
                Link = "https://google.com"
            },
            new GridModel
            {
                Name = "Jane Doe",
                Link = "https://youtube.com"
            }
        };
    }

    @(Html.Kendo().Grid<GridModel>()
        .Name("grid")
        .ToolBar(toolbar => toolbar
            .Excel()
        )
        .Columns(columns =>
        {
            columns.Bound(column => column.Name);
            columns.Bound(column => column.Link).ClientTemplate(Html.Kendo().Template()
                                                    .AddHtml(@<text>
                                                        <a href="${data.Link}">${data.Link}</a>
                                                    </text>)
                                                );
        })
        .DataSource(dataSource => dataSource
            .Ajax()
            .Read(read => read.Action("Read_Data", "Grid"))
        )
        .Events(events => events.ExcelExport("onExcelExport"))
        .BindTo(data)
    )

More ASP.NET Core Grid Resources

See Also