We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我尝试将富文本转换为wrod文档。如果HTML代码中有任何标签的width属性值为auto就会引发一个异常:Unsupported operand types: string / int 比如这样的HTML片段:
Unsupported operand types: string / int
<table style="width: auto;"> <tbody> <tr> <td colspan="1" rowspan="1" width="auto">td</td> </tr> </tbody> </table>
我通过跟踪源代码发现是 PhpOffice\PhpWord\Shared\Html::parseInlineStyle();方法中对于width的处理没有考虑到值为auto的情况 ,我认为这是一个小问题,于是我尝试修复它。
PhpOffice\PhpWord\Shared\Html::parseInlineStyle();
我创建了一个 PhpOffice\PhpWord\Shared\Html的子类,希望重写parseInlineStyle方法,但是因为方法内的静态调用(就像self::)和固定了命名空间的函数调用(就像call_user_func_array(array('PhpOffice\PhpWord\Shared\Html', $method), array_values($arguments));),使我不得不在子类里重写了所有调用了parseInlineStyle的方法,也包括addHtml方法。这些方法几乎没有任何改动,仅仅是为了让代码在执行中能正确的调用我修复过的parseInlineStyle方法。
PhpOffice\PhpWord\Shared\Html
parseInlineStyle
self::
call_user_func_array(array('PhpOffice\PhpWord\Shared\Html', $method), array_values($arguments));
addHtml
因此我有一个建议:是否可以在 PhpOffice\PhpWord\Shared\Html类中使用static::代替self::,同时call_user_func_array(array('PhpOffice\PhpWord\Shared\Html', $method), array_values($arguments));这样的代码可以替换成call_user_func_array(array(static::class, $method), array_values($arguments));。
static::
call_user_func_array(array(static::class, $method), array_values($arguments));
<?php require __DIR__ . '/vendor/autoload.php'; $html=<<<html <table style="width: auto;"> <tbody> <tr> <td colspan="1" rowspan="1" width="auto">td</td> </tr> </tbody> </table> html; $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); PhpOffice\PhpWord\Shared\Html::addHtml($section, $html);
我希望它能成功转换
抛出异常:
Unsupported operand types: string / int at /home/vagrant/code/proposition/vendor/phpoffice/phpword/src/PhpWord/Shared/Converter.php:151) [stacktrace] #0 /home/vagrant/code/proposition/vendor/phpoffice/phpword/src/PhpWord/Shared/Html.php(122): PhpOffice\\PhpWord\\Shared\\Converter::pixelToTwip() #1 /home/vagrant/code/proposition/vendor/phpoffice/phpword/src/PhpWord/Shared/Html.php(469): PhpOffice\\PhpWord\\Shared\\Html::parseInlineStyle() #2 /home/vagrant/code/proposition/vendor/phpoffice/phpword/src/PhpWord/Shared/Html.php(416): PhpOffice\\PhpWord\\Shared\\Html::recursiveParseStylesInHierarchy() #3 [internal function]: PhpOffice\\PhpWord\\Shared\\Html::parseCell() #4 /home/vagrant/code/proposition/vendor/phpoffice/phpword/src/PhpWord/Shared/Html.php(215): call_user_func_array() #5 /home/vagrant/code/proposition/vendor/phpoffice/phpword/src/PhpWord/Shared/Html.php(247): PhpOffice\\PhpWord\\Shared\\Html::parseNode() #6 /home/vagrant/code/proposition/vendor/phpoffice/phpword/src/PhpWord/Shared/Html.php(229): PhpOffice\\PhpWord\\Shared\\Html::parseChildNodes() #7 /home/vagrant/code/proposition/vendor/phpoffice/phpword/src/PhpWord/Shared/Html.php(247): PhpOffice\\PhpWord\\Shared\\Html::parseNode() #8 /home/vagrant/code/proposition/vendor/phpoffice/phpword/src/PhpWord/Shared/Html.php(229): PhpOffice\\PhpWord\\Shared\\Html::parseChildNodes() #9 /home/vagrant/code/proposition/vendor/phpoffice/phpword/src/PhpWord/Shared/Html.php(247): PhpOffice\\PhpWord\\Shared\\Html::parseNode() #10 /home/vagrant/code/proposition/vendor/phpoffice/phpword/src/PhpWord/Shared/Html.php(229): PhpOffice\\PhpWord\\Shared\\Html::parseChildNodes() #11 /home/vagrant/code/proposition/vendor/phpoffice/phpword/src/PhpWord/Shared/Html.php(247): PhpOffice\\PhpWord\\Shared\\Html::parseNode() #12 /home/vagrant/code/proposition/vendor/phpoffice/phpword/src/PhpWord/Shared/Html.php(229): PhpOffice\\PhpWord\\Shared\\Html::parseChildNodes() #13 /home/vagrant/code/proposition/vendor/phpoffice/phpword/src/PhpWord/Shared/Html.php(84): PhpOffice\\PhpWord\\Shared\\Html::parseNode() #14 /home/vagrant/code/proposition/app/Http/Controllers/WordController.php(32): PhpOffice\\PhpWord\\Shared\\Html::addHtml() ...
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Describe the Bug
我尝试将富文本转换为wrod文档。如果HTML代码中有任何标签的width属性值为auto就会引发一个异常:
Unsupported operand types: string / int
比如这样的HTML片段:
我通过跟踪源代码发现是
PhpOffice\PhpWord\Shared\Html::parseInlineStyle();
方法中对于width的处理没有考虑到值为auto的情况,我认为这是一个小问题,于是我尝试修复它。
我创建了一个
PhpOffice\PhpWord\Shared\Html
的子类,希望重写parseInlineStyle
方法,但是因为方法内的静态调用(就像self::
)和固定了命名空间的函数调用(就像call_user_func_array(array('PhpOffice\PhpWord\Shared\Html', $method), array_values($arguments));
),使我不得不在子类里重写了所有调用了parseInlineStyle
的方法,也包括addHtml
方法。这些方法几乎没有任何改动,仅仅是为了让代码在执行中能正确的调用我修复过的parseInlineStyle
方法。因此我有一个建议:是否可以在
PhpOffice\PhpWord\Shared\Html
类中使用static::
代替self::
,同时call_user_func_array(array('PhpOffice\PhpWord\Shared\Html', $method), array_values($arguments));
这样的代码可以替换成call_user_func_array(array(static::class, $method), array_values($arguments));
。Steps to Reproduce
Expected Behavior
我希望它能成功转换
Current Behavior
抛出异常:
Context
The text was updated successfully, but these errors were encountered: