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
970
hyperlink export
posted

I have a grid with some hyperlinks in it.  I need to export it to PDF and Excel.  ApplyFormula appears to be gone which used to be the correct way in Excel.  This seems a little odd that it isn't handled automatically considering it already knows that it's a hyperlink(<asp:HyperLink ID="HyperLink1"). 

So what am I missing?

Parents
  • 970
    Verified Answer
    Offline posted

    I came up with this for excel, now I'll have to see if I can figure out something for PDF.  I'll also add, for some reason the compiler didn't complain without the reference to Infragistics4.WebUI.Documents.Excel.v13.1, but it was required (it adds ApplyFormula)

            protected void WebExcelExporter1_CellExported(object sender, Infragistics.Web.UI.GridControls.ExcelCellExportedEventArgs e)
            {

                string cellContents = e.WorksheetCell.Value.ToString();
                int iStartPos = -1;
                int iEndPos = -1;
                int iEndPos2 = -1;
                
                string newValue = "=HYPERLINK(";
                string friendlyName;

                if (cellContents.Contains("HyperLink"))
                {
                    iStartPos = cellContents.IndexOf("href=");
                    iEndPos = cellContents.IndexOf(">", iStartPos + 5);
                    iEndPos2 = cellContents.IndexOf("<", iEndPos + 1);
                    friendlyName = cellContents.Substring(iEndPos + 1, iEndPos2 - iEndPos - 1);               
                    if (iStartPos != -1)
                    {
                        newValue += cellContents.Substring(iStartPos + 5, iEndPos - iStartPos - 5) + ",\"" + friendlyName + "\")";
                        e.WorksheetCell.ApplyFormula(newValue);
                    }
                    else
                    {
                        e.WorksheetCell.Value = friendlyName;
                    }
                }
            }

Reply Children
No Data