Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
177 views
in Technique[技术] by (71.8m points)

actionscript 3 - FLEX/AS3 How to open docx/odt file

I have function that create docx or odt file. I need automaticly to open this file in microsoft/libre office, right after creation complete. How to coding this in flex/as3 ?

        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)"/>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

So you'd need to first download the file to the user's machine and then open it. Something like this should do it (copy pasted stuff from my projects so you might need to adjust it a bit).

Also your server might need a crossdomain file so your app can load files from it.

    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:UsersYOURUSERHEREAppDataRoamingRateBookLocal 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();
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...