Forum


Replies: 5   Views: 939
Issue with addtext(..) in addlist() item
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by dev@ram  · 28-03-2017 - 17:46

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);