PHP:HTML至DOCX [英] PHP: HTML to DOCX

查看:53
本文介绍了PHP:HTML至DOCX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定是否存在使用PHP将HTML转换为DOCX文件的方法.HTML来自所见即所得编辑器(具有内联样式),我希望能够从中创建DOCX文件.

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.

看起来像PHPWord只能做一些基本的内联样式,而其他库根本不支持内联样式.

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?

推荐答案

您可以这样处理:

<?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>";

这篇关于PHP:HTML至DOCX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆