Hi guys!
addLink with parameter strikeThrough = false makes strike anyway
phpdocx version 8,10
Hi guys!
addLink with parameter strikeThrough = false makes strike anyway
phpdocx version 8,10
Hello,
From the following sample available in all packages: examples/Core/addLink/sample_1.php:
$docx->addLink('Link to Google', array('url'=> 'http://www.google.es'));
$docx->addText('And now the same link with some additional formatting:');
$linkOptions = array(
'url'=> 'http://www.google.es',
'color' => 'B70000',
'underline' => 'none'
);
$docx->addLink('Link to Google in red color and not underlined', $linkOptions);
No strikethrough is added to the link.
If we set strikeThrough as false:
$linkOptions = array(
'url'=> 'http://www.google.es',
'color' => 'B70000',
'underline' => 'none',
'strikeThrough' => false,
);
$docx->addLink('Link to Google in red color and not underlined', $linkOptions);
the output also has no strikethrough.
Regards.
Maybe i was not clear, i use situation then i put it in a rStyle. I make some example:
<?php
require_once '../../../Classes/Phpdocx/Create/CreateDocx.php';
$docx = new Phpdocx\Create\CreateDocx();
$array = [];
$array['font'] = null;
$array['fontSize'] = null;
$array['bold'] = false;
$array['italic'] = false;
$array['strike'] = true;
$array['color'] = null;
$array['underline'] = null;
$style = array(
'underline' => 'none', 'fontSize' => $array['fontSize'], 'font' => $array['font'], 'color' => $array['color'],
'bold' => $array['bold'], 'underline' => $array['underline'], 'italic' => $array['italic'], 'strikeThrough' => ($array['strike'] == true) ? true : null,
);
// print_r($style);
$docx->createCharacterStyle('leaderCrmStyle1', $style);
$docx->addLink('Link to Google', array('url'=> 'http://www.google.es',
'rStyle' => 'leaderCrmStyle1' ));
$array = [];
$array['font'] = null;
$array['fontSize'] = null;
$array['bold'] = false;
$array['italic'] = false;
$array['strike'] = false;
$array['color'] = null;
$array['underline'] = null;
$style = array(
'underline' => 'none', 'fontSize' => $array['fontSize'], 'font' => $array['font'], 'color' => $array['color'],
'bold' => $array['bold'], 'underline' => $array['underline'], 'italic' => $array['italic'], 'strikeThrough' => $array['strike'],
);
// print_r($style);
$docx->createCharacterStyle('leaderCrmStyle2', $style);
$docx->addLink('Link to Google', array('url'=> 'http://www.google.es',
'rStyle' => 'leaderCrmStyle2' ));
$array = [];
$array['font'] = null;
$array['fontSize'] = null;
$array['bold'] = false;
$array['italic'] = false;
$array['strike'] = true;
$array['color'] = null;
$array['underline'] = null;
$style = array(
'underline' => 'none', 'fontSize' => $array['fontSize'], 'font' => $array['font'], 'color' => $array['color'],
'bold' => $array['bold'], 'underline' => $array['underline'], 'italic' => $array['italic'], 'strikeThrough' => ($array['strike'] == true) ? true : null,
);
// print_r($style);
$docx->createCharacterStyle('leaderCrmStyle3', $style);
$docx->addLink('Link to Google', array('url'=> 'http://www.google.es',
'rStyle' => 'leaderCrmStyle3' ));
$docx->addText('And now the same link with some additional formatting:');
$linkOptions = array('url'=> 'http://www.google.es',
'color' => 'B70000',
'underline' => 'none'
);
$docx->addLink('Link to Google in red color and not underlined', $linkOptions);
$docx->createDocx('example_addLink_1');
Hello,
Thanks for sharing a sample that illustrates your issue. Then the issue is not related to addLink styles but when creating and applying a custom character style.
When applying doubleStrikeThrough and strikeThrough options to a custom style, they are checked internally using isset (other styles such as bold and italic check boolean values). To prevent adding doubleStrikeThrough and strikeThrough when adding a custom style, please avoid setting them with any value.
If you want to get the same behaviour as using bold and italic styles with styleThrough and doubleStrikeThrough styles in custom styles (true/false values), please edit CreateParagraphStyle.php (Classes/Phpdocx/Elements folder in the namespaces package) and change the generateBooleanTrueProp method with the following content:
private function generateBooleanTrueProp($tag)
{
if ($this->style[$tag] == 'on' || $this->style[$tag]) {
// normalize the tag names
if ($tag == 'doubleStrikeThrough') {
$tag = 'dstrike';
} else if ($tag == 'strikeThrough') {
$tag = 'strike';
}
return '<w:' . $tag . '/>';
}
}
The same change has been applied to current testing branch of phpdocx.
Regards.