doulun5683
2018-05-23 15:26
浏览 263
已采纳

用phpword问题将docx转换为html

I'm encountering an issue when converting docx document into HTML with PHPWord library (https://github.com/PHPOffice/PHPWord).

Here is the code snippet I use:

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

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.

Regards

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

我在使用PHPWord库将docx文档转换为HTML时遇到问题( https://github.com/PHPOffice/PHPWord )。

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

  $ 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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题