我们可以将ckeditor数据保存到doc文件中吗?

时间:2011-10-15 09:56:55

标签: php file

在我的网站中,管理员编辑了一些我需要保存到doc文件的数据。所以我用ckeditor实现了这个。它工作正常,但当我尝试打开此文件时,它说“单词无法启动转换器mswrd632.wpc”。我究竟做错了什么?

$content=addslashes(trim($_REQUEST['CKEditor']))
$docfile="convert.doc";
$fp = fopen("files/".$docfile, "w+");
fwrite($fp, $content);                                                           

这是我的代码 我们如何将数据保存到doc文件。还有其他方法吗?

<p class="body">
    England would be keen to finish the summer on a high note by also remaining unbeaten in the upcoming ODI series against world champions India, said Test skipper Andrew Strauss after handing out the visitors a 4-0 whitewash.</p>

1 个答案:

答案 0 :(得分:1)

您的代码没有问题。问题是您正在创建的文件是带有文档扩展名的常规文本文件,换句话说,不是真正的Word文件。如果您不必编写doc文件,只需将其保留为普通的.txt即可解决问题。

现在,如果您的项目规范要求您将该文件作为文档,则可以执行以下操作:

  1. 使用“HTML”方法(无需COM) 看看Sergey Kornilov的帖子:Create Word Document using PHP in Linux

    这里也有类似的问题:Reading/Writing a MS Word file in PHP

  2. 使用COM对象 - 如果您需要精心设计的Word文件,则必须使用该路径

  3. 这是我的经验。让我们希望有人能提出更好,更有效的解决方案。

    祝你好运!

    <强>更新 我自动假设您在Win环境中工作。在这种情况下COM会这样做,如果你需要它在Linux机器上工作,你的替代方案是OpenOffice

    这篇关于COM和文章的文章很不错:http://www.webcheatsheet.com/php/create_word_excel_csv_files_with_php.php#wordcom

    对于OpenOffice,只需查看其API - http://api.openoffice.org/ 看看他们的论坛,我相信他们有PHP的例子。

    我个人的建议是与这些人一起玩,但是如果你有时间,可以在一两天后找到最终的解决方案。编写Word文件肯定不是我的强项,因此可能有另一种处理方式。

    祝你好运!

    <强>更新

    <html>
    <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
    <body>
    <p>England would be keen to finish the summer on a high note by also remaining unbeaten in the upcoming ODI series against world champions India, said Test skipper Andrew Strauss after handing out the visitors a 4-0 whitewash.</p>
    </body>
    </html>
    
相关问题