This project is read-only.

Adding HTML / Adding Line Breaks

Oct 6, 2010 at 5:39 PM

Hi,

I am trying to add HTML content into the document. Directly adding the HTML results in the HTML tags being displayed within the document as raw characters. Is there anyway to achieve this and retain formatting?

Failing this I have been stripping the tags and using regular expressions to generate newlines after <br/> and </p> tags. Unfortunately though when I use the addText function these newlines are stripped out.

Is there any easy way to introduce line breaks into the document without doing additional parsing / splitting and inserting multiple text elements and using addTextBreak()?

Thanks.

Oct 17, 2010 at 12:23 PM

Hi,

I had the same issue and found no solution in PHPword documentation.

As for me I wanted to convert a nested html list item into word  2007 format

I used simplehtmldom written by S.C. Chen to parse the HMTL (Website: http://sourceforge.net/projects/simplehtmldom)

<ul>

  <li>

  <p> <big><em>Status of system requirement baseline (Assessment of system requirement allocated to software (completeness, stability) identification of issue and corresponding baseline Definition issue report open)</em></big></p>

<ol>

<li> cf Action 470,471 and 472

</li>

</ol>

</li>

<li>

<p> <big>Status of plans and schedule</big></p>

<ol>

etc ....

 

$html = str_get_html($str);

foreach($html->find('ul') as $ul) {  

foreach($ul->find('li') as $li) {    

$p=$li->find('p big',0);     

if ($p->innertext != ""){        

$section_landscape->addText($p->plaintext,2);  

}        

foreach($li->find('ol') as $ol){ 

foreach($ol->find('li') as $li2) {  

$text = clean_text($li2->plaintext);         

$section_landscape->addListItem($text, 0);      

  }  

  }    

}

}

It works but I need to put the right tag in my HTML otherwise it is crap

I'm looking forward for a better solution too !

 

Oct 19, 2010 at 4:05 PM

Thanks for the info, I ended up doing something similar and parsing for paragraph and line-breaks and adding the sections manually. The rest of the HTML markup is lost however.