Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
25
Exporting a WebGrid with a hyperlink column does not export the hyperlink into Excel
posted

We are using Version 8.1.20081.2013 CLR 2 with asp.net.  We have a UltraWebGrid that has the first column (a primary key) as a URL/Hyperlink:

 

    protected void uwg_InitializeRow(object sender, RowEventArgs e)
    { UltraGridCell refNbr = e.Row.Cells.FromKey("PrimaryKey");
       refNbr.Column.Type = ColumnType.HyperLink;
       refNbr.TargetURL = string.Format("@{0}/FormX.aspx?PrimaryKey={1}", Request.ApplicationPath.TrimEnd('/'), refNbr.Value);
       refNbr.AllowEditing = AllowEditing.No;
    }

 

The hyperlink displays and works correclty in the grid.  But when exporting to Excel via UltraWebGridExcelExporter, the hyperlink column does not work as a hyperlink...it is simply underlined and colored blue...but it is not a hyperlink.

 

Is there a way for a hyperlink column in an UltraWebGrid to be exported as an Excel formatted hyperlink when using the  UltraWebGridExcelExporter?

 

Thanks!

  • 222
    posted

    Hi,

      I am having the same problem. Did you get any solution for this? Please share with me.

    Thanks

    Saravanan

    • 44743
      posted in reply to saravanan

      Hyperlink style cells are not currently supported by the Excel library, so the grid exporters cannot export hyperlinks. However, you can manually convert the cell value to a hyperlink after the cell has been exported by applying a formula like this: =HYPERLINK(<hyperlink>). You can do this with the ApplyFormula method on the WorksheetCell instance.

      • 45049
        posted in reply to bryian

        bryian,

        Formula support was added to the Infragistics Excel engine in NetAdvantage for .NET 2007 Volume 3.  If you are using an earlier version of the toolset, then this method wouldn't exist.

        • 20
          posted in reply to Derek Harmon

          I would like to know how you get the "ApplyFormula" to work, I kept getting

          Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 'Infragistics.Excel.Workbook' does not contain a definition ApplyFormula !

          • 4960
            posted in reply to saravanan

            When you set-up your WebGrid columns (for example at design-time), it helps to set the column.Type to Infragistics.WebUI.UltraWebGrid.ColumnType.HyperLink so you can easily identify column(s) containing the hyperlinks.  Then you can do this,

            protected void Page_Load( object sender, EventArgs e)
            {
                 // Handle the CellExported event on the exporter.
                 this.UltraWebGridExcelExporter1.CellExported += new
                      Infragistics.WebUI.UltraWebGrid.ExcelExport.CellExportedEventHandler(
                           UltraWebGridExcelExporter1_CellExported);
            }

            void UltraWebGridExcelExporter1_CellExported( object sender,
                 Infragistics.WebUI.UltraWebGrid.ExcelExport.CellExportedEventArgs e)
            {
                 if (e.GridColumn.Type == Infragistics.WebUI.UltraWebGrid.ColumnType.HyperLink)
                 {
                      // When cells in a Hyperlink-type column are exported,
                     
            // apply the =HYPERLINK formula to their string value.
                      e.CurrentWorksheet.Rows[e.CurrentRowIndex].Cells[
                           e.CurrentColumnIndex].ApplyFormula(
                                string.Format("=HYPERLINK(\"{0}\")", e.Value.ToString( )
                           )
                       );
                 }
            }

            protected void btnExportToExcel_Click( object sender, EventArgs e)
            {
                 this.UltraWebGridExcelExporter1.Export( this.UltraWebGrid1);
            }

            • 222
              posted in reply to Mike Dour

              Hi Mike,

                Thanks for the response. I am using UltraWebGridExcelExporter to export to excel.

              How do I use formula on that?

              Can you please explain to me?

              Thanks,

              Saravanan