4 Replies Latest reply on Dec 9, 2008 4:04 PM by goodwinsvml

    Launch Microsoft word application inside AIR

    hstrong Level 1
      Hi Guys,

      I am stuck up somewhere not able to find the solution to my prolbem.Let me explain the problem in detail.

      I working on an Adobe AIR application and I need to launch the microsoft word application to open a particular document which a user can then modify.

      This word document are some defined documents stored some where in system. The user can then modify the document and can store that locally in the database.My concern is to launch the microsoft word document in my AIR application and then let user do the changes to the document and then i will save the document in my database as BLOB.

      Is there any good way of doing this.I hope Adobe has taken care of such scenarios and there must be some API's or component in Flex builder 3 so that i can use that.

      I am hoping with the finger crossed and waiting for a good response from Flex people.

      ~ Hstrong

        • 1. Re: Launch Microsoft word application inside AIR
          ilsh Level 1
          I don't think you can do this in AIR 1.1. Maybe in the future release?
          • 2. Re: Launch Microsoft word application inside AIR
            1.5 is out, but this feature is still unsupported.
            • 3. Re: Launch Microsoft word application inside AIR
              I am importing Word documents ( in xml format ) into an Air application and storing them in a blob in SQLite. When a user selects a document, I export it to a file and submit a URLRequest to open it. It launches in IE initially (asking if you want to open the document), but when IE sees the xml declares it a Word document, IE opens Word.

              To load the file to the database:
              //set up and open the database
              var sqlConnection:SQLConnection;
              sqlConnection = new SQLConnection();
              var dbFile:File = File.applicationDirectory.resolvePath("cASM_db.db");
              //open the file, read, and close (note reading bytes with readBytes)
              var fileStream : FileStream = new FileStream();
              fileStream.open(asmModel.newTemplate, FileMode.READ);
              var myBlob:ByteArray = new ByteArray();
              fileStream.readBytes(myBlob); //read the object
              //insert the blob into the database (note use of QUOTE function to format blob into hex)
              myStmt.sqlConnection = sqlConnection;
              myStmt.text = "Insert into doctype (" +
              "docname_ch, document_bl) " +
              "values (?, QUOTE(?))";
              myStmt.parameters[0] = asmModel.newTemplate.name; //docname_ch
              myStmt.parameters[1] = myBlob; //template_bl

              To unload the file from the database and open:
              //identify the file to be populated and delete if already there (note use of File type and resolvePath function)
              curFile = File.applicationStorageDirectory;
              curFile = curFile.resolvePath("view/version_" +
              asmModel.selectedDocument.VERSION_NU + "_" +
              //if it is there, delete it
              if (curFile.exists)
              //open the database connection
              var sqlConnection:SQLConnection;
              sqlConnection = new SQLConnection();
              var dbFile:File = File.applicationDirectory.resolvePath("cASM_db.db");
              //get the document (now in hex string format)
              myStmt.sqlConnection = sqlConnection;
              myStmt.text = "Select docname_ch, document_bl " +
              "from doctype " +
              "where docname_ch = ?";
              myStmt.parameters[1] = asmModel.selectedDocument.DOCNAME_CH;
              myResult = myStmt.getResult();
              //now convert the hex string back to a byteArray (note the use of a custom toArray function)
              var myBlob:ByteArray = new ByteArray();
              myBlob = toArray(myResult.data[0].DOCUMENT_BL);
              //now write the document to the file
              var fileStream:FileStream = new FileStream();
              fileStream.open(curFile, FileMode.WRITE);
              //now set up the URLRequest
              var request:URLRequest = new URLRequest("app-storage:/view/version_" +
              asmModel.selectedDocument.VERSION_NU + "_" +
              var docType:String = request.url.substr(request.url.length - 4, 3);
              if ((docType != "pdf") ||
              (HTMLLoader.pdfCapability == HTMLPDFCapability.STATUS_OK))
              Alert.show ("You need to upgrade Adobe Reader.", "Error");
              trace("PDF cannot be displayed. Error code:", HTMLLoader.pdfCapability);

              Here's the custom function toArray:
              public static function toArray(hex:String):ByteArray {
              hex = hex.substring(hex.search("3C3F786D6C"),hex.length - 3);
              var a:ByteArray = new ByteArray;
              //make sure the string has an even number of characters
              if (hex.length&1==1) hex="0"+hex;
              //change each hex pair to a single int (ascii char code)
              // and place the int in the byte array
              for (var i:uint=0;i<hex.length;i+=2) {
              a[i/2] = parseInt(hex.substr(i,2),16);
              //return the byte array
              return a;

              Hope this helps!

              • 4. Re: Launch Microsoft word application inside AIR
                goodwinsvml Level 1
                Oh, by the way. The documents work fine as long as there is not binary data (e.g. an image) in the xml. I am still struggling with that problem, so if you have a solution to it, please post for me.