给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="导入" οnclick="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="导入" οnclick="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.youkuaiyun.com/vkqiang/archive/2010/03/25/5416427.aspx

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值