Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Desktop, Mobile and non-browser Environments > AIR (Apollo)

Reply
 
Thread Tools Rate Thread Display Modes
Old 12-22-2008, 08:48 AM   #1
dikdikdik
Registered User
 
Join Date: Dec 2008
Posts: 7
Default how to open ms word ?

Hi everybody. I am a newbie in Actionscript language and have a project that relation with Ms word. I want to build an AIR desktop application which can open a Ms word, edit and save as plain text.

I try to search about the issue, and find out some reference code for text editor

private function fileReadHandler(event:Event):void
{
var str:String = stream.readUTFBytes(stream.bytesAvailable);
stream.close();
var lineEndPattern:RegExp = new RegExp(File.lineEnding, "g");
str = str.replace(lineEndPattern, "\n");
mainTextField.text = str;
stream.close();
}

but when I correct code to use for word document, it is error. Anyone can help me to solve the problem?

In addtion, I have new idea about microsoft win32OLE. But I don't know how to use it in actionscript.

Thank any help!!!
dikdikdik is offline   Reply With Quote
Old 12-23-2008, 05:24 AM   #2
evride
2006 Man Of The Year
 
evride's Avatar
 
Join Date: Mar 2007
Posts: 919
Default

first, use the [as] tags around text to format it nicely.
second give me the whole error - number and text.

also, you have to read the byte data into a bytearray and not straight into a string.

ActionScript Code:
var ba:ByteArray = stream.readUTFBytes(stream.bytesAvailable); stream.close();
__________________
As long as people believe in absurdities they will continue to commit atrocities. --Voltaire
evride is offline   Reply With Quote
Old 12-23-2008, 09:38 AM   #3
karthickraj_knowledgeq
Registered User
 
Join Date: Feb 2008
Posts: 35
Default

you try fscommand()?..(This only for open a ms word and i believe it will enough for you)
Regards
Karthick Raj.S
karthickraj_knowledgeq is offline   Reply With Quote
Old 12-23-2008, 06:00 PM   #4
evride
2006 Man Of The Year
 
evride's Avatar
 
Join Date: Mar 2007
Posts: 919
Default

you cant do use fscommand in air.
and what i think he's trying to do is make an app that does the same thing as word (edit .doc/.docx files) and doesnt want to start the program up
__________________
As long as people believe in absurdities they will continue to commit atrocities. --Voltaire
evride is offline   Reply With Quote
Old 12-23-2008, 11:02 PM   #5
corbo950
Corbin U
 
corbo950's Avatar
 
Join Date: Jun 2008
Location: michigan
Posts: 241
Default

You might want to try using Microsoft's SDK for opening word files cause I know that is like what Open Office and the iPhone use to read them. Would also let you save back to .doc/.docx files if you were so inclined
corbo950 is offline   Reply With Quote
Old 12-24-2008, 08:26 AM   #6
dikdikdik
Registered User
 
Join Date: Dec 2008
Posts: 7
Default

Hi evdog, thank your answer but your code don't run.

ActionScript Code:
var ba:ByteArray = stream.readUTFBytes(stream.bytesAvailable); stream.close();

The error is
1067: Implicit coercion of a value of type uint to an unrelated type flash.utils:ByteArray.

I use "text editor" code in adobe website to test with text file and MS document file. It can't read characters in MS document. I think the reason is format of Ms document is different with text file.

My AIR application can be explain that : firstly I open ms document file, the air app try to read bytes or use extern API to read, then display in text area. Secondly I will parse data in text area to some paragraph and save to plain text file.

I have problem when read MS document, I try to use readUTFBytes, readBytes but not ok. I search and find another solution that use Actionscript to call extern API e.g ActiveX objects, win32OLE, Microsoft Office Web Components... to read ms word and convert it to text.
My idea is
1. Read ms word by any program
2. convert it to plain text and save as temporary file
3. display it to text area

May be MS word file can contain tables, so I want to use VBA to convert tables to text after step1 and before step 2.

Thank any suggest

Hai Anh
dikdikdik is offline   Reply With Quote
Old 12-25-2008, 04:56 PM   #7
runawayprisoner
ActionScripted
 
Join Date: Nov 2008
Posts: 94
Default

Quote:
Originally Posted by dikdikdik View Post
Hi evdog, thank your answer but your code don't run.

ActionScript Code:
var ba:ByteArray = stream.readUTFBytes(stream.bytesAvailable); stream.close();

The error is
1067: Implicit coercion of a value of type uint to an unrelated type flash.utils:ByteArray.

I use "text editor" code in adobe website to test with text file and MS document file. It can't read characters in MS document. I think the reason is format of Ms document is different with text file.

My AIR application can be explain that : firstly I open ms document file, the air app try to read bytes or use extern API to read, then display in text area. Secondly I will parse data in text area to some paragraph and save to plain text file.

I have problem when read MS document, I try to use readUTFBytes, readBytes but not ok. I search and find another solution that use Actionscript to call extern API e.g ActiveX objects, win32OLE, Microsoft Office Web Components... to read ms word and convert it to text.
My idea is
1. Read ms word by any program
2. convert it to plain text and save as temporary file
3. display it to text area

May be MS word file can contain tables, so I want to use VBA to convert tables to text after step1 and before step 2.

Thank any suggest

Hai Anh
Okay... apparently, what you are trying to do (make it globally accessible in all platforms?) is a bit... far-fetched at this level.

Anyhow, here's what I use to read all data from a file stream to a ByteArray, and please note that you should open the entire document synchronously and not asynchronously since looping back and forth would be quite a mess for a document.

With that out of the way, here's the code:

Quote:
filestrm.readBytes(mem,0,file.size);
Legend:

mem is a ByteArray. It doesn't matter how big it is, but if you want to conserve memory, pre-define a valid limit. Though a limit may cap the program and somehow prevents it from opening really large documents.

filestrm is the FileStream that we obtained the file from using the 'open' method. (please no 'openAsync' here)

file is the File that we browsed for earlier.

And... there you go.

We can't use writeBytes because FileStream is not a ByteArray, though its behaviors are exactly like one, therefore... readBytes.

So, that's how you obtain the raw data of the word document. Next step is to interprete that binary data, and luckily, Microsoft provided documents.

http://download.microsoft.com/downlo...cification.pdf

^= You can grab the binary specifications for Word 97 - 2007 from that link. It's officially Microsoft's and totally free.

There are just about 210 pages of that document to read. It seems tedious, but if you can understand by the end of the day, you may be able to build something on par with Microsoft Word or OpenOffice Writer.

Good luck.
runawayprisoner is offline   Reply With Quote
Old 12-26-2008, 06:25 AM   #8
dikdikdik
Registered User
 
Join Date: Dec 2008
Posts: 7
Default

Thank runawayprisoner, but if choice the way which decode raw data will loss many time and I'm afraid I don't finish it

I use AIR app mainly in Win OS, so I still find the way to relate Flex with another program that can open MS document file. In Ruby language I can use Win32 OLE from Ruby to call Microsoft Word which help me open and save document to plain text e.g.

require 'win32ole'
word = WIN32OLE.new('Word.Application')
document = word.Documents.Open('abc.doc', 'ReadOnly' => true)
document.SaveAs('abc.txt')
document.Close

But in Actionscript, any one know about the way to use FScommand or ExternalInterface to call the same thing as above? Plz help me
dikdikdik is offline   Reply With Quote
Old 12-29-2008, 09:00 AM   #9
dikdikdik
Registered User
 
Join Date: Dec 2008
Posts: 7
Default

I try to use Javascript inside Actionscript which call MS word to read document. But it error when I initial ActiveXObject. Here is my code

test.mxml

ActionScript Code:
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"     layout="absolute" creationComplete="init()">     <mx:Script>         <![CDATA[         private var calledFromJSHandlerFunction:Function = calledFromJSHandler;         private function init():void{             html.addEventListener(Event.HTML_DOM_INITIALIZE, domInitialized);             html.location = "htmlwithJS.html";         }         private function domInitialized(event:Event):void{             html.htmlLoader.window.calledFromJSHandlerFunction = calledFromJSHandlerFunction;         }         private function calledFromJSHandler():void {             mx.controls.Alert.show("ActionScript called from JavaScript", "Alert");         }               ]]>     </mx:Script>        <mx:HTML id="html" x="137" y="40" width="339"/>     </mx:WindowedApplication>

htmlwithJS.html

HTML Code:
<html>
	<script language="Javascript">
		function loadworddoc(){
	  		var doc = new ActiveXObject("Word.Application"); 
	  		doc.Visible=false; 
	  		doc.Documents.Open("C:\Sam\Sam.doc"); 
	  		var txt;
	  		txt = doc.Documents("C:\Sam\Sam.doc").Content; 
	  		document.all.myarea.value = txt;
	  		doc.quit(0); 
		}
	</script>
	<body>
		<input type="button"
		value="Load"
		onclick="loadworddoc()">
		<br />
		<textarea name="myarea">test now</textarea>
	</body>
</html>

The message is : ReferenceError: Can't find variable: ActiveXObject

Any one can give me some advice?
dikdikdik is offline   Reply With Quote
Old 12-31-2008, 04:36 AM   #10
jewelthief
Registered User
 
Join Date: Dec 2008
Posts: 6
Default

Here is what i have done. I am not an expert but i found the one solution from which you can invoke any kind of executable. As clearly mentioned that you cannot use Fscommand in AIR so there has to be some intermediate solution.

What i have done is to make a Windows service (It runs in the background) in .net and in that service, I used FileSystemWatcher class.

My AIR app creates XML file on filesystem (say C:/) with the path of the executable to run and as soon as it creates XML, the windows service which is constantly watching the file System reads the path of the exe from newly created xml file(from AIR) and invokes that exe.

It worked for me. You can try it.
jewelthief is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ComboBox code to open external swf in movie clip yomsbea Components 5 10-29-2008 01:58 AM
Opening MS Word doc with Flash? MaryAnneL ActionScript 2.0 3 10-10-2007 04:48 PM
Help with code to open pdf files bluechilledkola Projectors and CDs 2 06-16-2007 05:26 PM
Opening Word doc from flash projector, help! Nutbeen Projectors and CDs 0 04-13-2007 01:37 PM
linking to word file bpm125 Projectors and CDs 1 07-20-2002 07:55 AM


All times are GMT. The time now is 07:41 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.