I think I am doing something wrong but not sure what it is.
I am trying to create a list with some items underlined. I followed
the Example #3 in your API sample https://www.phpdocx.com/api-documentation/word-content/insert-list-nested-Word-document-with-PHP
I tried to include the underlined text but it screws up.
Please see my code
require_once SITE_ROOT . 'include/PHPDocx/classes/CreateDocx.inc';
 Â
  //create document from template
$docx = new CreateDocxFromTemplate(WORD_TEMPLATE_PATH.'radarWordTemplate_uk.docx');
$bullets = array();
foreach($data['bullets'] as $bullet){
if(is_array($bullet['text'])){
//Put underline for items in the special array
$textData = new WordFragment($docx);
$textData->addText(array('text' => $bullet['text']['data'], 'underline' => 'single'));
$bullets[] = $textData;
unset($textData);
// $bullets[] = array('text' => $bullet['text']['data']);
}else{//normal text
$bullets[] = array('text' => $bullet['text']);
}
}
$docx->addList($bullets);
$docId = sha1(microtime());
if(!mkdir(SITE_ROOT . 'docdump/' . $docId . '/')) exit;
$docfile = SITE_ROOT.'docdump/'. $docId . '/RAM';
$docx->createDocx($docfile);
If I uncomment and use $bullets[] = array('text' => $bullet['text']['data']); instead of the active code it displays perfectly but when I use the current code inside the if() instead of the commented one(to make it underlined) the list is fully screwed up. any idea guys ???
just to make it easy this code works (but it does not underline the item which i need)
require_once SITE_ROOT . 'include/PHPDocx/classes/CreateDocx.inc';
//create document from template
$docx = new CreateDocxFromTemplate(WORD_TEMPLATE_PATH.'radarWordTemplate_uk.docx');
$bullets = array();
foreach($data['bullets'] as $bullet){
if(is_array($bullet['text'])){
//Put underline for items in the special array
//$textData = new WordFragment($docx);
// $textData->addText(array('text' => $bullet['text']['data'], 'underline' => 'single'));
//$bullets[] = $textData;
//unset($textData);
$bullets[] = array('text' => $bullet['text']['data']);
}else{//normal text
$bullets[] = array('text' => $bullet['text']);
}
}
$docx->addList($bullets);
$docId = sha1(microtime());
if(!mkdir(SITE_ROOT . 'docdump/' . $docId . '/')) exit;
$docfile = SITE_ROOT.'docdump/'. $docId . '/RAM';
$docx->createDocx($docfile);