PHP: HTML to DOCX

青春壹個敷衍的年華 提交于 2019-12-12 02:26:12

问题


I am trying to figure out if there is a way to convert HTML to DOCX file using PHP. HTML comes from wysiwyg editor (with inline styles) and I want to be able to create a DOCX file from it.

Looks like PHPWord can do just some basic inline styles and other libraries don't support inline styles at all.

Is there any way to achieve this?


回答1:


You can approach it like this:

<?php
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=document_name.doc");

echo "<html>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
echo "<body>";
echo "<b>My first document</b>";
echo "</body>";
echo "</html>";
?>

You can add inline styles like so:

echo "<h1 style=\"color:red;\"> Hello World! </h1>";


来源:https://stackoverflow.com/questions/43378219/php-html-to-docx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!