Forum


Replies: 1   Views: 2462
Problem for insert html table using replacevariablebyhtml
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 nexim5  · 20-07-2018 - 14:51

Hello
I am French (sorry for my bad english)
I am testing phpdocx 8.2 with basi demo
I am trying to replace tag by html

But I cannot replace tag when i use <table>

$html='<table border="4" width="100%" bordercolor="#808080" frame="hsides" rules="rows">
                                                  <tr><th>En-tête 1-1</th><th>En-tête 1-2</th><th>En-tête 1-3</th></tr>
                                                  <tr><td>Cellule 1-1</td><td>Cellule 1-2</td><td>Cellule 1-3</td></tr>
                                                  <tr><td>Cellule 2-1</td><td>Cellule 2-2</td><td>Cellule 2-3</td></tr>
                                                  <tr><td>Cellule 3-1</td><td>Cellule 3-2</td><td>Cellule 3-3</td></tr>
                                                </table> 
                                        ';
$docx->embedHTML($html);
$docx->replaceVariableByHTML('lignes', 'inline', $html, array('isFile' => false, 'parseDivsAsPs' => true, 'downloadImages' => false));
                        

I have the content but without my html table ; I have a simple :

"   En-tête 1-1En-tête 1-2En-tête 1-3Cellule 1-1Cellule 1-2Cellule 1-3Cellule 2-1Cellule 2-2Cellule 2-3Cellule 3-1Cellule 3-2Cellule 3-3"

in my docx file..
           

Posted by admin  · 22-07-2018 - 11:22

Hello,

The problem is that you are using an inline type replacement. You need to use a block type replacement:

$docx->replaceVariableByHTML('lignes', 'block', $html, array('isFile' => false, 'parseDivsAsPs' => true, 'downloadImages' => false));

To keep block tags such as table.

Regards.