读书人

给FckEditor增添导入word,wps文档功能

发布时间: 2012-11-23 22:54:33 作者: rapoo

给FckEditor添加导入word,wps文档功能!好变态啊,又弄出来了!!

客户提出一个变态的问题

想给fckeditor添加一个导入word,wps文档的功能。

弄了6个小时总算弄出来了。

下面是代码:

<script type="text/javascript">
?????????????function importWord(){
??????????????//获取文件路径
??????????????var filepath=document.getElementById("importfile").value;
??????????????if(filepath=="" || filepath.substr(filepath.length-4,4)!=".doc"){
???????????????alert("请选择正确的word文档!");
???????????????return false;
??????????????}else{
??????????????//另存为word,使内容变为html
???????????????var?? oWordApp=new? ActiveXObject("Word.Application");??????
???????????????var?? oDocument=oWordApp.Documents.Open(filepath);??????
???????????????oDocument.SaveAs(filepath.substring(0,filepath.length-4)+".html",?? 8);?????
???????????????oWordApp.Quit();
???????????????//读取htm文件内容
????????????????? var fso? = new ActiveXObject("Scripting.FileSystemObject");?
?????????????????? var file = fso.OpenTextFile(filepath.substring(0,filepath.length-4)+".html");?
?????????????????? var text=file.ReadAll();
?????????????????? file.Close();??
?????????????????? //设置fckeditor的内容
?????????????????? FCKeditorAPI.GetInstance("documentContent").SetHTML(FCKeditorAPI.GetInstance("documentContent").GetXHTML(true)+text,false);
???????????????var fso,f1;?????
???????????????fso=new ActiveXObject("Scripting.FileSystemObject");???
???????????????f1= fso.GetFile(filepath.substring(0,filepath.length-4)+".html");???????????
???????????????f1.Delete();???
??????????????}
??????????????
?????????????}
?????????????</script>
?????????????Word:<input type="file" id="importfile"/><input type="button" value="导入" onclick="importWord()"/>
?????????????<br/>
?????????????<script type="text/javascript" >
?????????????function importWps(){
??????????????//获取文件路径
??????????????var filepath=document.getElementById("importfilewps").value;
??????????????if(filepath=="" || filepath.substr(filepath.length-4,4)!=".wps"){
???????????????alert("请选择正确的Wps文档!");
???????????????return false;
??????????????}else{
???????????????var WpsApp =new ActiveXObject("WPS.Application");
????????????????? WpsApp.Visible=true;???
???????????????var?? oDocument=WpsApp.Documents.Open(filepath);??????
???????????????oDocument.SaveAs(filepath.substring(0,filepath.length-4)+".html",?? 8);?????
???????????????WpsApp.Quit();
???????????????//读取htm文件内容
????????????????? var fso? = new ActiveXObject("Scripting.FileSystemObject");?
?????????????????? var file = fso.OpenTextFile(filepath.substring(0,filepath.length-4)+".html");?
?????????????????? var text=file.ReadAll();
?????????????????? file.Close();??
?????????????????? //设置fckeditor的内容
?????????????????? FCKeditorAPI.GetInstance("documentContent").SetHTML(FCKeditorAPI.GetInstance("documentContent").GetXHTML(true)+text,false);
???????????????var fso,f1;?????
???????????????fso=new ActiveXObject("Scripting.FileSystemObject");???
???????????????f1= fso.GetFile(filepath.substring(0,filepath.length-4)+".html");???????????
???????????????f1.Delete();?
??????????????}
?????????????}
?????????????</script>
?????????????wps:<input type="file" id="importfilewps"/><input type="button" value="导入" onclick="importWps()"/>
?????????????
??????????????<FCK:editor id="documentContent"? toolbarStartExpanded="true"? basePath="/fckeditor/"
???????????????imageBrowserURL="/fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector"
???????????????linkBrowserURL="/fckeditor/editor/filemanager/browser/default/browser.html?Connector=connectors/jsp/connector"
???????????????flashBrowserURL="/fckeditor/editor/filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/jsp/connector"
???????????????imageUploadURL="/fckeditor/editor/filemanager/upload/simpleuploader?Type=Image"
???????????????linkUploadURL="/fckeditor/editor/filemanager/upload/simpleuploader?Type=File"
???????????????flashUploadURL="/fckeditor/editor/filemanager/upload/simpleuploader?Type=Flash"
???????????????>
???????????????</FCK:editor>?

转自:http://blog.csdn.net/vkqiang/archive/2010/03/25/5416427.aspx

?

?

读书人网 >Web前端

热点推荐