2018-05-23 15:26
浏览 263


I'm encountering an issue when converting docx document into HTML with PHPWord library (

Here is the code snippet I use:

$phpWord = \PhpOffice\PhpWord\IOFactory::load('test.docx');
$htmlWriter = new \PhpOffice\PhpWord\Writer\HTML($phpWord);

The issue is that each block of text is encapsulated in <p> tags regardless if I defined titles in the docx document. I would expect <h1> <h2>... tags to be generated. Bullet list are lost too.

Does it work as designed or did I miss something?

Thank you for your feedback.


图片转代码服务由CSDN问答提供 功能建议

我在使用PHPWord库将docx文档转换为HTML时遇到问题( )。

以下是我的代码片段 使用:

  $ phpWord = \ PhpOffice \ PhpWord \ IOFactory :: load('test.docx'); 
 $ htmlWriter = new \ PhpOffice \ PhpWord \ Writer \ HTML  ($ phpWord); 
 $ htmlWriter-&gt; save('test.html'); 

问题是每个文本块都封装在< 无论我是否在docx文档中定义了标题,代码>&lt; p&gt; 标记。 我希望&lt; h1&gt; &lt; h2&gt; ...要生成的标签。 子弹列表也丢失了。


感谢您的反馈。 \ n


  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dqtm8504 2018-05-25 02:18

    There's a little bit of a problem when it comes to using IOFactory::load of PHPWord such as what you encountered now, depending what saved the file or what version of Microsoft Word is used to create that file. If the encoding and tags of the docx file cannot be found by PHPWord , then it will produce unexpected results

    The code is fine, the problem is already with the dependency.

    解决 无用
    打赏 举报

相关推荐 更多相似问题