如何使用 php 将 php 页面转换为 .doc 文件
最近我在一个项目中工作。 在这个项目中,我需要将页面转换为 Microsoft Word 文档(.doc 文件)并提供文档下载,所有操作均使用 PHP。 但我无法解决这个问题。
请帮我。 非常感谢你,阿里夫
Recently i worked in a project. On this project I need convert page into a Microsoft word document (.doc file) and offer the document for download, all using PHP. But I can't solve this problem.
Please help me. Thank You very much, Arif
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议使用 RTF 格式而不是 .doc - 它更容易编写,并且所有文本编辑器都可以理解它。 当您想要输出 Excel 文件时,也建议使用 .csv。
I would recommend using the RTF format instead of the .doc - it's much simpler to write to, and all text editors understand it. Similar recommendation for .csv when you want to output an Excel file.
也许不是您寻求的答案,但仍然值得注意,有一个名为 abiword 的开源文字处理器,它有一个 CLI(命令行界面)。 您可以使用它轻松地在文档格式之间进行转换。 我知道至少有一个网站使用它来将文本文件转换为各种格式。
它正在积极开发中,可以轻松用作 3de 方黑盒解决方案来转换文档服务器端。
这是一位开发人员关于如何将其与 PHP 集成的博客
服务器端 AbiWord
abiword 主页
Perhaps not the answer you seek, but still interesting to note, there is a open source word processor out there called abiword that has a CLI (Command Line Interface). You can use it to easily convert between document formats. I know that at least one website uses it to convert text files into various formats.
It is actively getting developed and could easily be used as a 3de party black box solution to converting documents server side.
Here is a blog from one of the developers on how to integrate it with PHP
Server-Side AbiWord
abiword home page
这并不容易解决。
首先,如果您想编写真正的 Word 文档,则必须在Windows 上进行。 您可以使用 COM 与 Word 对话,这就是您获得良好结果的方法。 我已经尝试了所有基于 UNIX/Linux 的解决方案,但结果不是很好。
否则,我建议您编写 RTF——这同样好。 最后,您可以调用 .rtf 文件、.doc,没有人会注意到它。 RTF 有一些限制(格式),但另一方面,它都是 ASCII 和 RTF 标准非常全面且有详细记录。
有一个类做得很好 - phpLiveDocx (这个是一个很棒的介绍)。 这个课程还声称可以编写 PDF 和 DOC——但我还没有尝试过。 我使用另一种 PDF 解决方案。
This is not easy to solve.
First off, if you want to write real word documents, you will have to do on Windows. You can use COM to talk to Word and this is how you manage to get good results. I've tried all the unix/linux based solutions and the results were not so great.
Otherwise, I'd suggest you write RTF -- which is just as good. And in the end, you can call the .rtf-file, .doc and no one will notice it. RTF has a couple limitations (formatting), but on the flipside -- it's all ASCII and the RTF standard is pretty comprehensive and well documented.
There's a class which does it pretty nicely -- phpLiveDocx (this is a great introduction). And this class also claims to write PDF and DOC -- but I haven't tried those yet. I use another solution for PDF.