PHPWord icon indicating copy to clipboard operation
PHPWord copied to clipboard

Tables inside a bullet list result in a corrupt docx file

Open 10types opened this issue 7 years ago • 6 comments

This is:

  • [x] a bug report
  • [ ] a feature request
  • [ ] not a usage question (ask them on https://stackoverflow.com/questions/tagged/phpword)

Expected Behavior

Creating a table inside a bullet list is valid HTML and valid docx behaviour. In HTML it results in a bullet next to the table. In Word it results in an empty line with the bullet, then the table indented below.

Current Behavior

The XML created looks like it should work, but instead it creates a docx file that refuses to open as it is considered corrupt.

Failure Information

"Unspecified error. Location: Part: /word/document.xml, Line: 0, Column: 0"

How to Reproduce

Feed the following into PHPOffice:

<ul>
<li>I'm a bullet</li>
<li><table><tr><td>I'm a cell</td></tr></table></li>
<li>I'm a bullet</li>
</ul>

Context

  • PHP version:
  • PHPWord version: 0.14

10types avatar Sep 11 '18 08:09 10types

I have exactly the same problem.

gugalamaciek avatar Jul 18 '19 08:07 gugalamaciek

I am facing same issue only in Microsoft word, otherwise working fine with ubuntu editors like Liber office, WPS office, also document open in a Google doc.

Any solutions?

gaurav2262 avatar Oct 10 '19 12:10 gaurav2262

I also facing same issue when I parsed data from docx file to html then bullets table data does not added in html

128yusuf avatar Aug 27 '20 14:08 128yusuf

Hi, I also encounter similar issue, table under ol li [table] ol li will produce this error :

Fatal error: Uncaught BadMethodCallException: Cannot add Table in ListItemRun. in [project-dir]/vendor/phpoffice/phpword/src/PhpWord/Element/AbstractContainer.php:273 Stack trace: #0 [project-dir]/vendor/phpoffice/phpword/src/PhpWord/Element/AbstractContainer.php(138): PhpOffice\PhpWord\Element\AbstractContainer->checkValidity('Table') #1 [internal function]: PhpOffice\PhpWord\Element\AbstractContainer->addElement('Table', Array) #2 [project-dir]/vendor/phpoffice/phpword/src/PhpWord/Element/AbstractContainer.php(119): call_user_func_array(Array, Array) #3 [project-dir]/vendor/phpoffice/phpword/src/PhpWord/Shared/Html.php(420): PhpOffice\PhpWord\Element\AbstractContainer->__call('addtable', Array) #4 [internal function]: PhpOffice\PhpWord\Shared\Html::parseTable(Object(DOMElement), Object(PhpOffice\PhpWord\Element\ListItemRun), Array) #5 [project-dir]/vendor/phpoffice/phpword/src/PhpWord/Shared/Html.php(258): call_user_func_array(Array, Array) #6 /usr/lo in [project-dir]/vendor/phpoffice/phpword/src/PhpWord/Element/AbstractContainer.php on line 273

abydarts avatar Sep 10 '24 13:09 abydarts

@abydarts Hi, have you got a sample docx file with the expected result, please ?

Progi1984 avatar Sep 11 '24 06:09 Progi1984

@abydarts Hi, have you got a sample docx file with the expected result, please ?

Hi @Progi1984 , its not even give me any docx exported because php throw mentioned error even before giving the output docx, but if you want to know the sample html code that I want to export, here it is :

<h3 data-excluded-id="7,18">1.1&nbsp; Heading Title</h3>
<h3>1.1.1&nbsp; Title</h3>
<ol>
    <li>List 1.</li>
    <li>List 2:
        <ol>
            <li><br>
                <table style="border-collapse: collapse; width: 100%; height: 67.5556px;" border="1">
                    <tbody>
                        <tr style="height: 16.8889px;">
                            <td style="width: 22.1701%; height: 16.8889px;"><strong>Col 1</strong></td>
                            <td style="width: 22.1701%; height: 16.8889px;"><strong>Col 2</strong></td>
                            <td style="width: 22.1701%; height: 16.8889px;"><strong>Col 3</strong></td>
                            <td style="width: 22.1701%; height: 16.8889px;">&nbsp;</td>
                        </tr>
                        <tr style="height: 16.8889px;">
                            <td style="width: 22.1701%; height: 16.8889px;">&nbsp;</td>
                            <td style="width: 22.1701%; height: 16.8889px;">&nbsp;</td>
                            <td style="width: 22.1701%; height: 16.8889px;">&nbsp;</td>
                            <td style="width: 22.1701%; height: 16.8889px;">&nbsp;</td>
                        </tr>
                        <tr style="height: 16.8889px;">
                            <td style="width: 22.1701%; height: 16.8889px;">&nbsp;</td>
                            <td style="width: 22.1701%; height: 16.8889px;">&nbsp;</td>
                            <td style="width: 22.1701%; height: 16.8889px;">&nbsp;</td>
                            <td style="width: 22.1701%; height: 16.8889px;">&nbsp;</td>
                        </tr>
                    </tbody>
                </table>
            </li>
        </ol>
    </li>
    <li>List 3.</li>
    <li>List 4.</li>
    <li>List 5 (Rule):
        <ul>
            <li>Sub List 1.</li>
            <li>Sub List 2.</li>
            <li>Sub List 3.</li>
            <li>Sub List 4.</li>
        </ul>
    </li>
</ol>

abydarts avatar Sep 11 '24 11:09 abydarts