我们可以将ckeditor数据保存到doc文件中吗 [英] Can we save ckeditor data into doc file
问题描述
在我的网站上,管理员编辑了一些我需要保存到doc文件中的数据.所以我用ckeditor实现了这一点.它工作正常,但是当我尝试打开此文件时,它说"word无法启动转换器mswrd632.wpc".我究竟做错了什么?
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);
这是我的代码 我们如何将数据保存到doc文件中?还有其他方法吗?
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>
推荐答案
您的代码没有问题.问题在于您正在创建的文件是带有doc扩展名的常规文本文件,换句话说,不是真正的Word文件.如果您不必编写doc文件,只需将其保存为纯文本.txt即可解决问题.
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:
-
使用"HTML"方法(无需COM) 看看Sergey Kornilov的帖子:在Linux中使用PHP创建Word文档
Use the "HTML" approach(no COM required) Take a look at Sergey Kornilov's post: Create Word Document using PHP in Linux
这里也有类似的问题:读取/编写MS PHP中的Word文件
There is also a similar question here: Reading/Writing a MS Word file in PHP
使用COM对象-如果需要精巧的Word文件,则必须走那条路
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.
祝你好运!
更新: 我自动假定您在Win环境中工作.在这种情况下,COM可以运行,如果您需要在Linux机器上运行它,则可以选择OpenOffice
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
这是有关COM和其他东西的不错的文章: http://www.webcheatsheet .com/php/create_word_excel_csv_files_with_php.php#wordcom
This is a decent article on COM and stuff: http://www.webcheatsheet.com/php/create_word_excel_csv_files_with_php.php#wordcom
对于OpenOffice,只需查看其API- http://api.openoffice.org/ 看看他们的论坛,我确定他们有使用PHP的示例.
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.
我个人的建议是与他们一起玩,但是如果有时间的话,在一两天之后就制定最终解决方案.编写Word文件当然不是我的专长,因此可能存在另一种处理方式.
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.
祝你好运!
更新
<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>
这篇关于我们可以将ckeditor数据保存到doc文件中吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!