We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Hyperlink not working in PDF

Hi,

I have a sheet containing some Hyperlinks. These are created via Aspose Cells HyperlinkCollection.add Method and still work after saving the workbook as pdf.

However, in another worksheet I reference those Hyperlinks via Excel Formula
HYPERLINK(WorksheetName!CellName)
or actually
IF(ISEMPTY(WorksheetName!CellName;"";HYPERLINK(WorksheetName!CellName))

(I’m not exactly sure about these Formulas in english, as I’m using german Excel, but they are correct)

If I then save the Workbook as XLSX the referenced Hyperlinks also work. But if I save it as PDF only the original Hyperlinks work, but not the referenced ones.

Can you please help me with this.

Thanks and Regards,
Sebastian

@urbastiba,

Thanks for the details.

Could you call Workbook.CalculateFormula() method before rendering to PDF file format if it makes any difference. If you still find the issue, kindly do provide us your Excel file (you may save to disk (by Aspose.Cells APIs)) or provide sample code (runnable) to create the Excel file via Aspose.Cells APIs. Also provide your output PDF file. We will check your issue soon.

@Amjad_Sahi ,

thanks for your quick response.

I am calling the Workbook.calculateFormula() method as well as setting PdfSaveOptions.setCalculateFormula(true).

I provide you my output PDF file.
OPL_26.07.2018 (5).pdf (152.8 KB)
On the first Pages you see the not working hyperlinks in the first column.
At the very end, on Page 14/15 you find the datasheet with the working hyperlinks.

I’m not allowed to upload xlsx file here. How can I come around that?

@urbastiba,

Please send your sample Excel file, runnable console application and complete steps to reproduce the issue in a private message and we will update you after investigating it on our end. You can click on my name and find “Message” Button, in order to send a private message. You can also upload the complete package to any file sharing server like Dropbox, Google Drive etc. and share the link here.

@urbastiba,

Aspose.Cells formula calculation engine by default cannot resolve this issue because the resultant hyperlink by HYPERLINK formula cannot be put into the hyperlink collection of the worksheet (it is MS Excel’s behavior). For your, you can put the resultant hyperlinks into sheet’s hyperlink collection by using a custom engine manually, see the sample code for your reference:
e.g
Sample code:

                workbook.CalculateFormula(new CalculationOptions(){CustomEngine = new MyHyperlinkEngine()});
        private class MyHyperlinkEngine : AbstractCalculationEngine
        {
            public override void Calculate(CalculationData data)
            {
                HyperlinkCollection hc = data.Worksheet.Hyperlinks;
                object address = data.GetParamValue(0);
                if (address != null)
                {
                    hc.Add(data.Cell.Name, 1, 1, address.ToString());
                }
            }
        }

After calculating formulas in this way, the generated hyperlinks are in the hyperlink collection too and so they will be printed to the PDF and you can get the expected results. However, because it modified the original workbook and make different behavior from what it should be, so you should not reuse the workbook object later on after saving operation. And, we will consider to do it automatically in upcoming fixes/versions for the users without such impact for the original workbook object when they set PdfSaveOptions.setCalculateFormula(true). We have already logged a ticket for it with an id “CELLSNET-46254” for the enhancements.

Once we have an update on it, we will let you know here.