1

I need to create a hyperlink using XDocReport where both the URL and display name are provided using Velocity tags. There is some reference to this on the XDocReport web site, but no real guidance.

Other things I have tried, like http://blog.softartisans.com/2013/12/31/kb-creating-dynamic-links-with-mergefields-in-microsoft-word/, do not work.

Mark Salamon
  • 569
  • 1
  • 8
  • 21

2 Answers2

0

Manage hyperlink with XDocReport is like mergefield. XDocReport wiki page about hyperlink with docx can be found here, but I agree, it should be improved.

If you cannot manage hyperlink with XDocReport and docx, I suggest :

  1. use the XDocReport macro . There is a link checkbox to insert hyperlink instead of inserting mergefield.
  2. download docxandvelocity-XXX-sample.zip or get Git project fr.opensagres.xdocreport.samples.docxandvelocity. You will find samples with hyperlinks.
Angelo
  • 2,027
  • 13
  • 17
  • I was able to download a template that included hyperlinks (DocxProjectWithVelocityandImageList.docx) to see how it was done. Unfortunately, when I generated my document, the link came out like this: { HYPERLINK: "http:// www.google.com" } . So it replaced my code $record.Link with the URL, but it did not actually create a link in the generated document. – Mark Salamon Jul 01 '14 at 12:44
  • I actually did get it to work. The problem I noted above was that I needed to hit ALT-F9 to hide the codes. However, I have found that once I get a template to work, if I make ANY changes to the template later, even just adding a space somewhere, it no longer works. I don't know why it would be so fragile. But it appears that the last edit I can make in the template is to insert the hyperlink. – Mark Salamon Jul 01 '14 at 15:08
  • You may need to use the technique described in http://stackoverflow.com/questions/16817380/mailmerge-dynamic-hyperlink-fields-lost-after-save-reload-of-document-word-201/16916289#16916289 . I do not think it will work in Mac Word. –  Jul 02 '14 at 05:19
  • @MarkSalamon could you add an answer describing precisely how you have done it. I can't get it works. – gontard Mar 14 '16 at 13:17
  • @gontard Unfortunately, I don't recall and don't have access to this project anymore. – Mark Salamon Mar 15 '16 at 00:36
0

Based on @MarkSalamon suggested link: http://blog.softartisans.com/2013/12/31/kb-creating-dynamic-links-with-mergefields-in-microsoft-word/ , it failed in my case too.

After debugging the opensagres library, it seems that instead of inserting a merge field inside the Hyperlink, the library is expecting there just a simple Freemarker placeholder. So it's enough to create the hyperlink from Word, and at the url definition part, you can specify there: ${url} .

That's it, the library is going to detect that there is a Freemarker syntax and replace the url with back-end data. So you don't have to do the trick with ALT+F9 and replace with merge field codes.

In my case this worked with opensagres version: 2.0.2

brebDev
  • 774
  • 10
  • 27