Nested Tables

Coordinator
Jul 20, 2015 at 6:49 AM
In response to a question from Sudesh K (as follows):

First thanks for providing htmltodocx package, I have been using htmltodocx package to convert html to docx when I was using this I encountered with one issue i.e; I am not able to add any nested tables . There was one note which said nested tables cannot be used,its a constraint in PHPWord When I was seeing PHPWord regarding this issue they said current version of PHPWord has fixed this issue, is there any updated htmltodocx package which will support adding nested table? If so kindly provide the updated htmltodocx package

Reply
If you do have a more recent version of PHP Word which supports nested tables, you are welcome to try it - replace the older version which is bundled with the HTML to docx converter with the newer one. Then, to get nesting to work, you will need to look at h2d_htmlconverter.php, and, look at line 365 and probably removing the lines which prevent nested tables:
if (!$state['table_allowed'] || in_array('td', $state['parents']) || in_array('th', $state['parents'])) {
            $state['table_allowed'] = FALSE; // This is a PHPWord constraint
          } ...
Let me know how you get on.
Jul 22, 2015 at 4:52 AM
I have removed the line as you have mentioned and along with that , I have also removed
$state['table_allowed']
Which were used in the if condition's

Now when I try to download the word document for the table below
<table>
        <tr>
            <td>
                Value1
            </td>
            <td>
                Value2
            </td>
            <td>
                <table>
                    <tr><td>Nested Value</td></tr>
                </table>
            </td>
            <td>
                Value3
            </td>
        </tr>       
    </table>
I am getting 'Value 3' Immediately after 'Nested Value' i.e Value3 is coming under nested table and not under main table
Is there anything else which I need to add/remove?
Coordinator
Jul 22, 2015 at 10:37 AM
First off, are you absolutely sure the version of PHP Word you have can do nested tables? The version of PHP Word bundled with the HTML to docx converter is the same as the one currenlty offered for download on Codeplex as far as I can tell - and that didn't do nested tables. Or are you using a different version from elsewhere? If you haven't done so already, look at the PHPWord documentation and check that you can create nested tables programatically - using just PHP Word (not using HTML to docx converter).