Hello
how to add url to text type placeholder. Text is replaced in word document from excel file. Like we used <b> </br> tag in same text can we use <link href="">??
Thank You
Hello
how to add url to text type placeholder. Text is replaced in word document from excel file. Like we used <b> </br> tag in same text can we use <link href="">??
Thank You
Hello,
Sorry, but we are not sure if we understand your question.
If you need to add a link when transforming HTML to DOCX, you can use the a tag:
https://www.phpdocx.com/htmlapi-documentation/html-standard/insert-link-Word-document-with-HTML
to add an external link or a bookmark link.
HTML Extended available in Premium licenses also includes phpdocx_link (https://www.phpdocx.com/htmlapi-documentation/html-extended/insert-link-Word-document-with-HTML).
Regards.
We are not replacing using htmltemplate. Genrating document using $docx = new CreateDocx();
Hello,
Our previous reply can be used with documents created from scratch and DOCX templates.
Links can be added using embedHTML and addLink methods. And also cross-references with addCrossReference.
Regards.
Below is our function to add link to a placeholder -
$fomattedURLWordFragment = addUrlLink($value,$templateDocx,$placeHolderName);
$templateDocx->replaceVariableByWordFragment(array('placeHolderName' => $fomattedURLWordFragment), array('type' => 'inline', 'target' => 'document'));
function addUrlLink($inputText,$templateDocx,$placeHolderName){ Â Â
   echo "In addUrlLink";
  $docx = new CreateDocx();
  $wf = new WordFragment($docx);
   //preg_match('/<link>(.*?)<\/link>/', $inputText, $matches);
  Â
   $text = array();
   //print_r($matches); //die();
   //$url = $matches[1]; // This will contain 'www.hdfcfund.com'
   $url = 'www.hdfcfund.com';
   $link = new WordFragment($docx);
   //$link->addLink($matches[0], array('url'=> $url, 'color' => '0000FF', 'u' => 'single'));
   $link->addLink($inputText, array('url'=> $url, 'color' => '0000FF'));
   $text[] = $link;
  Â
   //print_r($text); //die();
   $wf->addText($text, array('font' => 'Cambria', 'fontSize' => 6.5));
  return $wf;
}
This does not add link to the placeholder variable. Please correct the above code.
Hello,
Please check and run the following sample included in the package: examples/Templates/replaceVariableByWordFragment/sample_2.php . This sample replaces a placeholder in a template with a new WordFragment that includes an image, a link, and a footnote.
The problem with your script is that it's using a new CreateDocx object instead of the DOCX template object to generate the WordFragment. Instead of:
$docx = new CreateDocx();
$wf = new WordFragment($docx);
it needs to use the DOCX template object, not a new object:
$wf = new WordFragment($templateDocx);
Also note that if you want to add a link to a URL you need to use http or https:
$url = 'https://www.hdfcfund.com';
otherwise, a local link is generated.
Regards.