2016-05-11 62 views
-1

我有创建docx或odt文件的功能。在创建完成后,我需要自动在Microsoft/libre办公室打开此文件。如何在flex/as3中对此进行编码?FLEX/AS3如何打开docx/odt文件

 protected function create003(docType:String, patientID:String):void 
     { 
      create003Result.token = nhealthReports.create003(docType, patientID);    
     } 

     protected function getFormModuleDataResult_resultHandler(event:ResultEvent):void 
     { 
      var pathToFile:String; 
      pathToFile=create003Result.lastResult; // this is path to created file 
      // here i need some code from you 
     } 



     <nhealthreports:NhealthReports id="nhealthReports" 
            showBusyCursor="true"/>  
     <s:CallResponder id="create003Result" result="getFormModuleDataResult_resultHandler(event)"/> 
+0

所以这个文件是在服务器上创建的,对吧?这是您正在处理的AIR桌面应用程序吗? – Philarmon

+0

是在php服务器上创建的文件,并发送文件的字符串名称。是的,我使用AIR,而不是浏览器 – Alex

+0

使用** NativeProcess **来运行外部程序(MS Office等)。 –

回答

2

所以你需要先下载文件到用户的机器,然后打开它。像这样的东西应该做到这一点(从我的项目复制粘贴的东西,所以你可能需要调整一下)。

此外,您的服务器可能需要跨域文件,以便您的应用程序可以从中加载文件。

private function getFormModuleDataResult_resultHandler(event:ResultEvent):void 
    { 
     // load file 
     var loader:URLLoader = new URLLoader(); 
     loader.addEventListener(Event.COMPLETE, onLoadingComplete); 
     loader.dataFormat = URLLoaderDataFormat.BINARY; 
     loader.load(new URLRequest(pathToFile)); 
    } 

    private function onLoadingComplete(event:Event):void 
    { 
     // get the data as bytearray 
     var data:ByteArray = event.target.data; 

     // you will probably need to figure this out from your server path or define your own here 
     var fileName:String = "MyFilename.doc"; 

     // create a file under the application storage directory (C:\Users\YOURUSERHERE\AppData\Roaming\RateBook\Local Store) 
     // you can store the file anywhere but it is recommended to do it here 
     // as users with restricted access on their machines (non-admin users) might have trouble saving the files elsewhere 
     var file:File = File.applicationStorageDirectory.resolvePath(fileName); 

     //create a file stream to be able to write the content of the file  
     var fileStream:FileStream = new FileStream(); 
     //open the file stream and set for Write 
     fileStream.open(file, FileMode.WRITE); 
     //writes the bytes 
     fileStream.writeBytes(data, 0, data.length); 
     //close the stream 
     fileStream.close(); 

     // by now the file should be saved to disk, let's open it 
     // Naturally this assumes that the user have the file extension (like .doc) associated with the correct program (MS Word) 
     file.openWithDefaultApplication(); 
    } 
+0

我有一个错误 - 错误#3001:文件或目录访问被拒绝。 您可以请重新为您的示例: 只需打开“D:\ 1.docx”文件。从服务器发送的任何内容都不需要。 – Alex

+0

帮助更多不需要。现在正在工作。非常感谢 ! – Alex

+0

但也许你可以帮助我解决这个问题 - http://stackoverflow.com/questions/37135722/flex-as3-make-mini-icon-under-cursor-when-drag-and-drop-in-process ?? – Alex