我们可以将ckeditor数据保存到doc文件中吗
在我的网站中,管理员编辑了一些我需要保存到文档文件中的数据。所以我使用ckeditor实现了这个。它工作正常,但当我尝试打开此文件时,它显示“word 无法启动转换器 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>
in my site the admin edits some data which i need to save to a doc file. so i implemented this using ckeditor. It works fine but when i try to open this file it says "word cannot start the converter mswrd632.wpc". what am i doing wrong?
$content=addslashes(trim($_REQUEST['CKEditor']))
$docfile="convert.doc";
$fp = fopen("files/".$docfile, "w+");
fwrite($fp, $content);
this is my code
how can we save data to a doc file.is there any other way?
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的代码没有问题。问题是您正在创建的文件是带有 doc 扩展名的常规文本文件,换句话说,不是真正的 Word 文件。如果您不必编写文档文件,只需将其保留为纯 .txt 即可解决问题。
现在,如果您的项目规范要求您将该文件作为文档,您可以执行以下操作:
使用“HTML”方法(不需要 COM)
看看 Sergey Kornilov 的帖子:在 Linux 中使用 PHP 创建 Word 文档
这里还有一个类似的问题:读/写 MS PHP 中的 Word 文件
使用 COM 对象 - 如果您需要详细的 Word 文件,则必须采用该路线
这是我的经验。我们希望有人能提出更好、更有效的解决方案。
祝你好运!
更新:
我自动假设您正在 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文件当然不是我的强项,所以可能有另一种方法来处理这个问题。
祝你好运!
更新
There is no problem with your code. The problem is that the file you are creating is a regular text file with the doc extension, in other words not a real Word file. If you don't have to write a doc file, just keep it as a plain .txt and that will solve the problem.
Now if your project specs require you to have that file as a doc, you can do the following:
Use the "HTML" approach(no COM required)
Take a look at Sergey Kornilov's post: Create Word Document using PHP in Linux
There is also a similar question here: Reading/Writing a MS Word file in PHP
Use a COM Object - you will have to go that route if you need an elaborate word file
This is from my experience. Let's hope somebody will come up with a better and more efficient solution.
Good Luck!
UPDATE:
I automatically assumed you are working in a Win environment. In this case COM will do, if you need it to work on a Linux machine, your alternative is OpenOffice
This is a decent article on COM and stuff: http://www.webcheatsheet.com/php/create_word_excel_csv_files_with_php.php#wordcom
For OpenOffice just look at their API - http://api.openoffice.org/
Take a look at their forum, I am sure they have examples with PHP.
My personal advice is to play with those, but work on a final solution after a day or two, if you have the time. Writing Word files is certainly not my forte, so there could possibly be another way of handling this.
Good luck!
UPDATE