PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.29k stars 2.7k forks source link

Converter::pixelToTwip error: Unsupported operand types: string \/ int; #2701

Open Azamat8405 opened 3 days ago

Azamat8405 commented 3 days ago

Describe the bug and add attachments

When I try parse table from HTML by addHTML method I get error:

"Unsupported operand types: string \/ int",
"../phpoffice\/phpword\/src\/PhpWord\/Shared\/Converter.php": 162
<div style="font-size:17px;">
    <figure class="table" style="width:700px;">
        <table style="border:10px #4c4ce5 ridge;" width="700">
            <tbody>
                <tr>
                    <td style="background-color:#e5e54c;width:100px;"></td>
                    <td style="width:400px;">v</td>
                    <td style="width:200px;">v</td>
                </tr>
                <tr>
                    <td width="100px">v</td>
                    <td style="background-color:#4ce5e5;" width="400px"></td>
                    <td width="200px">v</td>
                </tr>
            </tbody>
        </table>
    </figure>
</div>

Expected behavior

There should be no mistake

Steps to reproduce

 $phpWordInstance    = new PhpWord();
    $phpSectionInstance = $phpWordInstance->addSection([
        'orientation'  => 'landscape',
        'marginLeft'   => (int)round(20 * 56.6929133858),
        'marginRight'  => (int)round(20 * 56.6929133858),
        'marginTop'    => (int)round(20 * 56.6929133858),
        'marginBottom' => (int)round(20 * 56.6929133858),
    ]);

    $html = '<div style="font-size:17px;">
                <figure class="table" style="width:700px;">
                    <table style="border:10px #4c4ce5 ridge;" width="700">
                        <tbody>
                            <tr>
                                <td style="background-color:#e5e54c;width:100px;"></td>
                                <td style="width:400px;">v</td>
                                <td style="width:200px;">v</td>
                            </tr>
                            <tr>
                                <td width="100px">v</td>
                                <td style="background-color:#4ce5e5;" width="400px"></td>
                                <td width="200px">v</td>
                            </tr>
                        </tbody>
                    </table>
                </figure>
            </div>';

    Html::addHtml($phpSectionInstance, $html, false, false);

    $fqName = new PhpOffice\PhpWord\Writer\Word2007($phpWordInstance);
    $fqName->save('./t.docx');

PHPWord version(s) where the bug happened

1.3

PHP version(s) where the bug happened

8

Priority