FLEX / AS3如何打开docx / odt文件 [英] FLEX/AS3 How to open docx/odt file

查看:440
本文介绍了FLEX / AS3如何打开docx / odt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有创建docx或odt文件的功能。我需要在创建完成后自动在Microsoft / libre办公室打开此文件。如何在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; //这是创建文件的路径
//这里我需要一些代码



$ b< nhealthreports:NhealthReports id = nhealthReports
showBusyCursor =true/>
< s:CallResponder id =create003Resultresult =getFormModuleDataResult_resultHandler(event)/>


解决方案

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

另外你的服务器可能需要一个crossdomain文件,所以你的应用程序可以从它加载文件。

pre $ private $ function getFormModuleDataResult_resultHandler(event:ResultEvent):void
{
/ /加载文件
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE,onLoadingComplete);
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.load(new URLRequest(pathToFile));

$ b $ private函数onLoadingComplete(event:Event):void
{
//获取数据为bytearray
var data:ByteArray = event。 target.data;

//你可能需要从你的服务器路径中找出这个或者在这里定义你自己的
var fileName:String =MyFilename.doc;

//在应用程序存储目录(C:\ Users \YOURUSERHERE\AppData\Roaming\RateBook\Local Store)下创建一个文件
//您可以存储文件在任何地方,但建议在这里做
//作为用户在他们的机器(非管理员用户)有限制访问可能有麻烦保存文件在其他地方
var file:File = File.applicationStorageDirectory .resolvePath(文件名);

//创建文件流以便能够写入文件的内容
var fileStream:FileStream = new FileStream();
//打开文件流并设置Write
fileStream.open(file,FileMode.WRITE);
//写入字节
fileStream.writeBytes(data,0,data.length);
//关闭流
fileStream.close();

//现在文件应该保存到磁盘上,让我们打开它
//当然,这假设用户有与正确的程序相关的文件扩展名(如.doc) MS Word)
file.openWithDefaultApplication();
}


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)"/>

解决方案

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

这篇关于FLEX / AS3如何打开docx / odt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆