在Linux中使用PHP创建Word文档 [英] Create Word Document using PHP in Linux

查看:99
本文介绍了在Linux中使用PHP创建Word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP在Linux环境中创建Word文档的可用解决方案是什么?

Whats the available solutions for PHP to create word document in linux environment?

推荐答案

真实的Word文档

如果需要生成真实的" Word文档,则需要基于Windows的Web服务器和COM自动化.我强烈推荐 Joel在该主题上的文章.

一个比较常见(但不可靠)的选择是:

A rather common (but unreliable) alternative is:

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>Fake word document</b>";
echo "</body>";
echo "</html>"

确保您不使用外部样式表.一切都应该在同一个文件中.

Make sure you don't use external stylesheets. Everything should be in the same file.

请注意,这不会发送实际的Word文档.它只是欺骗浏览器提供下载和默认为.doc文件扩展名的功能.较旧版本的Word可能经常在没有任何警告/安全消息的情况下打开它,而只是将原始HTML导入到Word中. PHP发送带有误导性的Content-Type标头并不构成真正的文件格式转换.

Note that this does not send an actual Word document. It merely tricks browsers into offering it as download and defaulting to a .doc file extension. Older versions of Word may often open this without any warning/security message, and just import the raw HTML into Word. PHP sending sending that misleading Content-Type header along does not constitute a real file format conversion.

这篇关于在Linux中使用PHP创建Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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